1 /* $OpenBSD: x509name.c,v 1.2 2018/11/10 01:43:03 tb Exp $ */ 2 /* 3 * Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <err.h> 19 #include <stdio.h> 20 21 #include <openssl/x509.h> 22 23 static void debug_print(X509_NAME *); 24 25 static void 26 debug_print(X509_NAME *name) 27 { 28 int loc; 29 30 for (loc = 0; loc < X509_NAME_entry_count(name); loc++) 31 printf("%d:", X509_NAME_get_entry(name, loc)->set); 32 putchar(' '); 33 X509_NAME_print_ex_fp(stdout, name, 0, XN_FLAG_SEP_CPLUS_SPC); 34 putchar('\n'); 35 } 36 37 int 38 main(void) 39 { 40 X509_NAME *name; 41 42 if ((name = X509_NAME_new()) == NULL) 43 err(1, NULL); 44 X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC, 45 "BaWue", -1, -1, 0); 46 X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, 47 "KIT", -1, -1, 0); 48 debug_print(name); 49 50 X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC, 51 "Karlsruhe", -1, 1, 0); 52 debug_print(name); 53 54 X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, 55 "DE", -1, 0, 1); 56 debug_print(name); 57 58 X509_NAME_free(name); 59 60 return 0; 61 } 62