From 3ad471f5ce9d2511aa93d68a9b768984a6433b85 Mon Sep 17 00:00:00 2001 From: schwarze <> Date: Sat, 7 Apr 2018 13:54:46 +0000 Subject: test X509_NAME_add_entry_by_txt(3); feedback and OK jsing@ --- src/regress/lib/libcrypto/Makefile | 5 +- src/regress/lib/libcrypto/x509/Makefile | 16 +++++++ src/regress/lib/libcrypto/x509/x509name.c | 59 ++++++++++++++++++++++++ src/regress/lib/libcrypto/x509/x509name.expected | 3 ++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/regress/lib/libcrypto/x509/Makefile create mode 100644 src/regress/lib/libcrypto/x509/x509name.c create mode 100644 src/regress/lib/libcrypto/x509/x509name.expected (limited to 'src') diff --git a/src/regress/lib/libcrypto/Makefile b/src/regress/lib/libcrypto/Makefile index f6215fb118..3b3345ee07 100644 --- a/src/regress/lib/libcrypto/Makefile +++ b/src/regress/lib/libcrypto/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.29 2018/03/19 14:34:33 beck Exp $ +# $OpenBSD: Makefile,v 1.30 2018/04/07 13:54:46 schwarze Exp $ SUBDIR= \ aead \ @@ -42,7 +42,8 @@ SUBDIR= \ sha2 \ sha256 \ sha512 \ - utf8 + utf8 \ + x509 install: diff --git a/src/regress/lib/libcrypto/x509/Makefile b/src/regress/lib/libcrypto/x509/Makefile new file mode 100644 index 0000000000..106a9f2bf2 --- /dev/null +++ b/src/regress/lib/libcrypto/x509/Makefile @@ -0,0 +1,16 @@ +# $OpenBSD: Makefile,v 1.1 2018/04/07 13:54:46 schwarze Exp $ + +PROG= x509name +LDADD= -lcrypto +DPADD= ${LIBCRYPTO} +WARNINGS= Yes +CFLAGS+= -Wall -Werror + +REGRESS_TARGETS=regress-x509name +CLEANFILES+= x509name.result + +regress-x509name: ${PROG} + ./${PROG} > x509name.result + diff -u ${.CURDIR}/x509name.expected x509name.result + +.include diff --git a/src/regress/lib/libcrypto/x509/x509name.c b/src/regress/lib/libcrypto/x509/x509name.c new file mode 100644 index 0000000000..4ff8ac6908 --- /dev/null +++ b/src/regress/lib/libcrypto/x509/x509name.c @@ -0,0 +1,59 @@ +/* $OpenBSD: x509name.c,v 1.1 2018/04/07 13:54:46 schwarze Exp $ */ +/* + * Copyright (c) 2018 Ingo Schwarze + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#include + +static void debug_print(X509_NAME *); + +static void +debug_print(X509_NAME *name) +{ + int loc; + + for (loc = 0; loc < X509_NAME_entry_count(name); loc++) + printf("%d:", X509_NAME_get_entry(name, loc)->set); + putchar(' '); + X509_NAME_print_ex_fp(stdout, name, 0, XN_FLAG_SEP_CPLUS_SPC); + putchar('\n'); +} + +int +main(void) +{ + X509_NAME *name; + + if ((name = X509_NAME_new()) == NULL) + err(1, NULL); + X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC, + "BaWue", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, + "KIT", -1, -1, 0); + debug_print(name); + + X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC, + "Karlsruhe", -1, 1, 0); + debug_print(name); + + X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, + "DE", -1, 0, 1); + debug_print(name); + + return 0; +} diff --git a/src/regress/lib/libcrypto/x509/x509name.expected b/src/regress/lib/libcrypto/x509/x509name.expected new file mode 100644 index 0000000000..6cee7cc435 --- /dev/null +++ b/src/regress/lib/libcrypto/x509/x509name.expected @@ -0,0 +1,3 @@ +0:1: ST=BaWue, O=KIT +0:1:2: ST=BaWue, L=Karlsruhe, O=KIT +0:0:1:2: C=DE + ST=BaWue, L=Karlsruhe, O=KIT -- cgit v1.2.3-55-g6feb