2 * Copyright (C) 2004-2012 Free Software Foundation, Inc.
4 * This file is part of GnuTLS.
6 * GnuTLS is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuTLS is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
20 * Written by Nikos Mavrogiannopoulos <nmav@gnutls.org>.
27 #include <certtool-cfg.h>
28 #include <gnutls/x509.h>
33 #include <autoopts/options.h>
36 #include <sys/types.h>
39 # include <sys/socket.h>
41 # include <ws2tcpip.h>
43 #include <arpa/inet.h>
45 /* Gnulib portability files. */
47 #include "certtool-common.h"
51 #define MAX_ENTRIES 128
52 #define MAX_POLICIES 8
54 typedef struct _cfg_ctx
62 char *challenge_password
;
65 char *policy_oid
[MAX_POLICIES
];
66 char *policy_txt
[MAX_POLICIES
];
67 char *policy_url
[MAX_POLICIES
];
74 char *crl_dist_points
;
76 char *pkcs12_key_name
;
89 int time_stamping_key
;
91 char **key_purpose_oids
;
95 char *proxy_policy_language
;
97 char **ca_issuers_uris
;
105 memset (&cfg
, 0, sizeof (cfg
));
110 #define READ_MULTI_LINE(name, s_name) \
111 val = optionGetValue(pov, name); \
112 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
114 if (s_name == NULL) { \
116 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
118 if (val && !strcmp(val->pzName, name)==0) \
120 s_name[i] = strdup(val->v.strVal); \
122 if (i>=MAX_ENTRIES) \
124 } while((val = optionNextValue(pov, val)) != NULL); \
129 #define READ_MULTI_LINE_TOKENIZED(name, s_name) \
130 val = optionGetValue(pov, name); \
131 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
135 if (s_name == NULL) { \
137 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
139 if (val && !strcmp(val->pzName, name)==0) \
141 strncpy(str, val->v.strVal, sizeof(str)-1); \
142 str[sizeof(str)-1] = 0; \
143 if ((p=strchr(str, ' ')) == NULL && (p=strchr(str, '\t')) == NULL) { \
144 fprintf(stderr, "Error parsing %s\n", name); \
149 s_name[i] = strdup(str); \
150 while(*p==' ' || *p == '\t') p++; \
152 fprintf(stderr, "Error (2) parsing %s\n", name); \
155 s_name[i+1] = strdup(p); \
157 if (i>=MAX_ENTRIES) \
159 } while((val = optionNextValue(pov, val)) != NULL); \
164 #define READ_BOOLEAN(name, s_name) \
165 val = optionGetValue(pov, name); \
171 #define READ_NUMERIC(name, s_name) \
172 val = optionGetValue(pov, name); \
175 if (val->valType == OPARG_TYPE_NUMERIC) \
176 s_name = val->v.longVal; \
177 else if (val->valType == OPARG_TYPE_STRING) \
178 s_name = atoi(val->v.strVal); \
182 template_parse (const char *template)
184 /* Parsing return code */
187 tOptionValue
const * pov
;
188 const tOptionValue
* val
;
191 pov
= configFileLoad(template);
194 perror("configFileLoad");
195 fprintf(stderr
, "Error loading template: %s\n", template);
199 /* Option variables */
200 val
= optionGetValue(pov
, "organization");
201 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
202 cfg
.organization
= strdup(val
->v
.strVal
);
204 val
= optionGetValue(pov
, "unit");
205 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
206 cfg
.unit
= strdup(val
->v
.strVal
);
208 val
= optionGetValue(pov
, "locality");
209 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
210 cfg
.locality
= strdup(val
->v
.strVal
);
212 val
= optionGetValue(pov
, "state");
213 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
214 cfg
.state
= strdup(val
->v
.strVal
);
216 val
= optionGetValue(pov
, "cn");
217 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
218 cfg
.cn
= strdup(val
->v
.strVal
);
220 val
= optionGetValue(pov
, "uid");
221 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
222 cfg
.uid
= strdup(val
->v
.strVal
);
224 val
= optionGetValue(pov
, "challenge_password");
225 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
226 cfg
.challenge_password
= strdup(val
->v
.strVal
);
228 val
= optionGetValue(pov
, "password");
229 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
230 cfg
.password
= strdup(val
->v
.strVal
);
232 val
= optionGetValue(pov
, "pkcs9_email");
233 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
234 cfg
.pkcs9_email
= strdup(val
->v
.strVal
);
236 val
= optionGetValue(pov
, "country");
237 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
238 cfg
.country
= strdup(val
->v
.strVal
);
240 for (i
=0;i
<MAX_POLICIES
;i
++)
242 snprintf(tmpstr
, sizeof(tmpstr
), "policy%d", i
+1);
243 val
= optionGetValue(pov
, tmpstr
);
244 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
245 cfg
.policy_oid
[i
] = strdup(val
->v
.strVal
);
247 if (cfg
.policy_oid
[i
] != NULL
)
249 snprintf(tmpstr
, sizeof(tmpstr
), "policy%d_url", i
+1);
250 val
= optionGetValue(pov
, tmpstr
);
251 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
252 cfg
.policy_url
[i
] = strdup(val
->v
.strVal
);
254 snprintf(tmpstr
, sizeof(tmpstr
), "policy%d_txt", i
+1);
255 val
= optionGetValue(pov
, tmpstr
);
256 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
258 cfg
.policy_txt
[i
] = strdup(val
->v
.strVal
);
263 READ_MULTI_LINE("dc", cfg
.dc
);
264 READ_MULTI_LINE("dns_name", cfg
.dns_name
);
265 READ_MULTI_LINE("uri", cfg
.uri
);
267 READ_MULTI_LINE("ip_address", cfg
.ip_addr
);
268 READ_MULTI_LINE("email", cfg
.email
);
269 READ_MULTI_LINE("key_purpose_oid", cfg
.key_purpose_oids
);
271 READ_MULTI_LINE_TOKENIZED("dn_oid", cfg
.dn_oid
);
273 val
= optionGetValue(pov
, "crl_dist_points");
274 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
275 cfg
.crl_dist_points
= strdup(val
->v
.strVal
);
277 val
= optionGetValue(pov
, "pkcs12_key_name");
278 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
279 cfg
.pkcs12_key_name
= strdup(val
->v
.strVal
);
282 READ_NUMERIC("serial", cfg
.serial
);
283 READ_NUMERIC("expiration_days", cfg
.expiration_days
);
284 READ_NUMERIC("crl_next_update", cfg
.crl_next_update
);
285 READ_NUMERIC("crl_number", cfg
.crl_number
);
287 val
= optionGetValue(pov
, "proxy_policy_language");
288 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
289 cfg
.proxy_policy_language
= strdup(val
->v
.strVal
);
291 READ_MULTI_LINE("ocsp_uri", cfg
.ocsp_uris
);
292 READ_MULTI_LINE("ca_issuers_uri", cfg
.ca_issuers_uris
);
294 READ_BOOLEAN("ca", cfg
.ca
);
295 READ_BOOLEAN("honor_crq_extensions", cfg
.crq_extensions
);
296 READ_BOOLEAN("path_len", cfg
.path_len
);
297 READ_BOOLEAN("tls_www_client", cfg
.tls_www_client
);
298 READ_BOOLEAN("tls_www_server", cfg
.tls_www_server
);
299 READ_BOOLEAN("signing_key", cfg
.signing_key
);
300 READ_BOOLEAN("encryption_key", cfg
.encryption_key
);
301 READ_BOOLEAN("cert_signing_key", cfg
.cert_sign_key
);
302 READ_BOOLEAN("crl_signing_key", cfg
.crl_sign_key
);
303 READ_BOOLEAN("code_signing_key", cfg
.code_sign_key
);
304 READ_BOOLEAN("ocsp_signing_key", cfg
.ocsp_sign_key
);
305 READ_BOOLEAN("time_stamping_key", cfg
.time_stamping_key
);
306 READ_BOOLEAN("ipsec_ike_key", cfg
.ipsec_ike_key
);
308 optionUnloadNested(pov
);
313 #define IS_NEWLINE(x) ((x[0] == '\n') || (x[0] == '\r'))
316 read_crt_set (gnutls_x509_crt_t crt
, const char *input_str
, const char *oid
)
321 fputs (input_str
, stderr
);
322 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
325 if (IS_NEWLINE(input
))
329 gnutls_x509_crt_set_dn_by_oid (crt
, oid
, 0, input
, strlen (input
) - 1);
332 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
338 read_crq_set (gnutls_x509_crq_t crq
, const char *input_str
, const char *oid
)
343 fputs (input_str
, stderr
);
344 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
347 if (IS_NEWLINE(input
))
351 gnutls_x509_crq_set_dn_by_oid (crq
, oid
, 0, input
, strlen (input
) - 1);
354 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
359 /* The input_str should contain %d or %u to print the default.
362 read_int_with_default (const char *input_str
, int def
)
366 static char input
[128];
368 fprintf (stderr
, input_str
, def
);
369 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
372 if (IS_NEWLINE(input
))
375 len
= strlen (input
);
377 l
= strtol (input
, &endptr
, 0);
379 if (*endptr
!= '\0' && *endptr
!= '\r' && *endptr
!= '\n')
381 fprintf (stderr
, "Trailing garbage ignored: `%s'\n", endptr
);
385 if (l
<= INT_MIN
|| l
>= INT_MAX
)
387 fprintf (stderr
, "Integer out of range: `%s'\n", input
);
398 read_int (const char *input_str
)
400 return read_int_with_default (input_str
, 0);
404 read_str (const char *input_str
)
406 static char input
[128];
409 fputs (input_str
, stderr
);
410 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
413 if (IS_NEWLINE(input
))
416 len
= strlen (input
);
417 if ((len
> 0) && (input
[len
- 1] == '\n'))
428 read_yesno (const char *input_str
)
432 fputs (input_str
, stderr
);
433 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
436 if (IS_NEWLINE(input
))
439 if (input
[0] == 'y' || input
[0] == 'Y')
446 /* Wrapper functions for non-interactive mode.
454 return getpass ("Enter password: ");
458 get_confirmed_pass (bool empty_ok
)
464 const char *pass
= NULL
;
470 fprintf (stderr
, "Password missmatch, try again.\n");
474 pass
= getpass ("Enter password: ");
475 copy
= strdup (pass
);
476 pass
= getpass ("Confirm password: ");
478 while (strcmp (pass
, copy
) != 0 && !(empty_ok
&& *pass
== '\0'));
487 get_challenge_pass (void)
490 return cfg
.challenge_password
;
492 return getpass ("Enter a challenge password: ");
496 get_crl_dist_point_url (void)
499 return cfg
.crl_dist_points
;
501 return read_str ("Enter the URI of the CRL distribution point: ");
505 get_country_crt_set (gnutls_x509_crt_t crt
)
514 gnutls_x509_crt_set_dn_by_oid (crt
,
515 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
516 cfg
.country
, strlen (cfg
.country
));
519 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
525 read_crt_set (crt
, "Country name (2 chars): ",
526 GNUTLS_OID_X520_COUNTRY_NAME
);
532 get_organization_crt_set (gnutls_x509_crt_t crt
)
538 if (!cfg
.organization
)
542 gnutls_x509_crt_set_dn_by_oid (crt
,
543 GNUTLS_OID_X520_ORGANIZATION_NAME
,
545 strlen (cfg
.organization
));
548 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
554 read_crt_set (crt
, "Organization name: ",
555 GNUTLS_OID_X520_ORGANIZATION_NAME
);
561 get_unit_crt_set (gnutls_x509_crt_t crt
)
571 gnutls_x509_crt_set_dn_by_oid (crt
,
572 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
573 0, cfg
.unit
, strlen (cfg
.unit
));
576 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
582 read_crt_set (crt
, "Organizational unit name: ",
583 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
589 get_state_crt_set (gnutls_x509_crt_t crt
)
598 gnutls_x509_crt_set_dn_by_oid (crt
,
599 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
600 0, cfg
.state
, strlen (cfg
.state
));
603 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
609 read_crt_set (crt
, "State or province name: ",
610 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
616 get_locality_crt_set (gnutls_x509_crt_t crt
)
625 gnutls_x509_crt_set_dn_by_oid (crt
,
626 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
627 cfg
.locality
, strlen (cfg
.locality
));
630 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
636 read_crt_set (crt
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
642 get_cn_crt_set (gnutls_x509_crt_t crt
)
651 gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_X520_COMMON_NAME
,
652 0, cfg
.cn
, strlen (cfg
.cn
));
655 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
661 read_crt_set (crt
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
667 get_uid_crt_set (gnutls_x509_crt_t crt
)
675 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_UID
, 0,
676 cfg
.uid
, strlen (cfg
.uid
));
679 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
685 read_crt_set (crt
, "UID: ", GNUTLS_OID_LDAP_UID
);
691 get_oid_crt_set (gnutls_x509_crt_t crt
)
699 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
701 if (cfg
.dn_oid
[i
+ 1] == NULL
)
703 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
707 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, cfg
.dn_oid
[i
], 0,
709 strlen (cfg
.dn_oid
[i
+ 1]));
713 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));
721 get_key_purpose_set (gnutls_x509_crt_t crt
)
727 if (!cfg
.key_purpose_oids
)
729 for (i
= 0; cfg
.key_purpose_oids
[i
] != NULL
; i
++)
732 gnutls_x509_crt_set_key_purpose_oid (crt
, cfg
.key_purpose_oids
[i
],
737 fprintf (stderr
, "set_key_purpose_oid (%s): %s\n",
738 cfg
.key_purpose_oids
[i
], gnutls_strerror (ret
));
746 get_ocsp_issuer_set (gnutls_x509_crt_t crt
)
755 for (i
= 0; cfg
.ocsp_uris
[i
] != NULL
; i
++)
757 uri
.data
= cfg
.ocsp_uris
[i
];
758 uri
.size
= strlen(cfg
.ocsp_uris
[i
]);
760 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_OCSP_URI
,
764 fprintf (stderr
, "set OCSP URI (%s): %s\n",
765 cfg
.ocsp_uris
[i
], gnutls_strerror (ret
));
773 get_ca_issuers_set (gnutls_x509_crt_t crt
)
780 if (!cfg
.ca_issuers_uris
)
782 for (i
= 0; cfg
.ca_issuers_uris
[i
] != NULL
; i
++)
784 uri
.data
= cfg
.ca_issuers_uris
[i
];
785 uri
.size
= strlen(cfg
.ca_issuers_uris
[i
]);
787 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_CAISSUERS_URI
,
791 fprintf (stderr
, "set CA ISSUERS URI (%s): %s\n",
792 cfg
.ca_issuers_uris
[i
], gnutls_strerror (ret
));
801 get_pkcs9_email_crt_set (gnutls_x509_crt_t crt
)
807 if (!cfg
.pkcs9_email
)
809 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_PKCS9_EMAIL
, 0,
811 strlen (cfg
.pkcs9_email
));
814 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
820 read_crt_set (crt
, "E-mail: ", GNUTLS_OID_PKCS9_EMAIL
);
828 int default_serial
= time (NULL
);
833 return default_serial
;
838 return read_int_with_default
839 ("Enter the certificate's serial number in decimal (default: %u): ",
851 if (cfg
.expiration_days
<= 0)
854 return cfg
.expiration_days
;
860 days
= read_int ("The certificate will expire in (days): ");
877 read_yesno ("Does the certificate belong to an authority? (y/N): ");
882 get_crq_extensions_status (void)
886 return cfg
.crq_extensions
;
892 ("Do you want to honour the extensions from the request? (y/N): ");
897 get_crl_number (void)
901 return cfg
.crl_number
;
905 return read_int_with_default ("CRL Number: ", 1);
918 return read_int_with_default
919 ("Path length constraint (decimal, %d for no constraint): ", -1);
924 get_pkcs12_key_name (void)
930 if (!cfg
.pkcs12_key_name
)
932 return cfg
.pkcs12_key_name
;
938 name
= read_str ("Enter a name for the key: ");
940 while (name
== NULL
);
946 get_tls_client_status (void)
950 return cfg
.tls_www_client
;
954 return read_yesno ("Is this a TLS web client certificate? (y/N): ");
959 get_tls_server_status (void)
963 return cfg
.tls_www_server
;
968 read_yesno ("Is this also a TLS web server certificate? (y/N): ");
972 /* convert a printable IP to binary */
974 string_to_ip (unsigned char *ip
, const char *str
)
976 int len
= strlen (str
);
980 if (strchr (str
, ':') != NULL
|| len
> 16)
982 ret
= inet_pton (AF_INET6
, str
, ip
);
985 fprintf (stderr
, "Error in IPv6 address %s\n", str
);
995 ret
= inet_pton (AF_INET
, str
, ip
);
998 fprintf (stderr
, "Error in IPv4 address %s\n", str
);
1008 get_ip_addr_set (int type
, void *crt
)
1011 unsigned char ip
[16];
1019 for (i
= 0; cfg
.ip_addr
[i
] != NULL
; i
++)
1021 len
= string_to_ip (ip
, cfg
.ip_addr
[i
]);
1024 fprintf (stderr
, "Error parsing address: %s\n", cfg
.ip_addr
[i
]);
1028 if (type
== TYPE_CRT
)
1030 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1032 GNUTLS_FSAN_APPEND
);
1035 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1037 GNUTLS_FSAN_APPEND
);
1048 read_str ("Enter the IP address of the subject of the certificate: ");
1052 len
= string_to_ip (ip
, p
);
1055 fprintf (stderr
, "Error parsing address: %s\n", p
);
1059 if (type
== TYPE_CRT
)
1060 ret
= gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1062 GNUTLS_FSAN_APPEND
);
1064 ret
= gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1066 GNUTLS_FSAN_APPEND
);
1071 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1077 get_email_set (int type
, void *crt
)
1086 for (i
= 0; cfg
.email
[i
] != NULL
; i
++)
1088 if (type
== TYPE_CRT
)
1090 gnutls_x509_crt_set_subject_alt_name (crt
,
1091 GNUTLS_SAN_RFC822NAME
,
1093 strlen (cfg
.email
[i
]),
1094 GNUTLS_FSAN_APPEND
);
1097 gnutls_x509_crq_set_subject_alt_name (crt
,
1098 GNUTLS_SAN_RFC822NAME
,
1100 strlen (cfg
.email
[i
]),
1101 GNUTLS_FSAN_APPEND
);
1111 p
= read_str ("Enter the e-mail of the subject of the certificate: ");
1115 if (type
== TYPE_CRT
)
1117 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1119 GNUTLS_FSAN_APPEND
);
1122 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1124 GNUTLS_FSAN_APPEND
);
1129 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1136 get_dc_set (int type
, void *crt
)
1145 for (i
= 0; cfg
.dc
[i
] != NULL
; i
++)
1147 if (type
== TYPE_CRT
)
1148 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1149 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1151 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1152 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1164 p
= read_str ("Enter the subject's domain component (DC): ");
1168 if (type
== TYPE_CRT
)
1169 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1172 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1180 fprintf (stderr
, "set_dn_by_oid: %s\n", gnutls_strerror (ret
));
1186 get_dns_name_set (int type
, void *crt
)
1195 for (i
= 0; cfg
.dns_name
[i
] != NULL
; i
++)
1197 if (type
== TYPE_CRT
)
1199 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1201 strlen (cfg
.dns_name
[i
]),
1202 GNUTLS_FSAN_APPEND
);
1205 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1207 strlen (cfg
.dns_name
[i
]),
1208 GNUTLS_FSAN_APPEND
);
1221 read_str ("Enter a dnsName of the subject of the certificate: ");
1225 if (type
== TYPE_CRT
)
1226 ret
= gnutls_x509_crt_set_subject_alt_name
1227 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1229 ret
= gnutls_x509_crq_set_subject_alt_name
1230 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1237 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1243 get_policy_set (gnutls_x509_crt_t crt
)
1246 gnutls_x509_policy_st policy
;
1250 if (!cfg
.policy_oid
)
1253 for (i
= 0; cfg
.policy_oid
[i
] != NULL
; i
++)
1255 memset(&policy
, 0, sizeof(policy
));
1256 policy
.oid
= cfg
.policy_oid
[i
];
1258 if (cfg
.policy_txt
[i
] != NULL
)
1260 policy
.qualifier
[policy
.qualifiers
].type
= GNUTLS_X509_QUALIFIER_NOTICE
;
1261 policy
.qualifier
[policy
.qualifiers
].data
= cfg
.policy_txt
[i
];
1262 policy
.qualifier
[policy
.qualifiers
].size
= strlen(cfg
.policy_txt
[i
]);
1263 policy
.qualifiers
++;
1266 if (cfg
.policy_url
[i
] != NULL
)
1268 policy
.qualifier
[policy
.qualifiers
].type
= GNUTLS_X509_QUALIFIER_URI
;
1269 policy
.qualifier
[policy
.qualifiers
].data
= cfg
.policy_url
[i
];
1270 policy
.qualifier
[policy
.qualifiers
].size
= strlen(cfg
.policy_url
[i
]);
1271 policy
.qualifiers
++;
1275 gnutls_x509_crt_set_policy (crt
, &policy
, 0);
1283 fprintf (stderr
, "set_policy: %s\n", gnutls_strerror (ret
));
1289 get_uri_set (int type
, void *crt
)
1298 for (i
= 0; cfg
.uri
[i
] != NULL
; i
++)
1300 if (type
== TYPE_CRT
)
1302 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_URI
,
1304 strlen (cfg
.uri
[i
]),
1305 GNUTLS_FSAN_APPEND
);
1308 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_URI
,
1310 strlen (cfg
.uri
[i
]),
1311 GNUTLS_FSAN_APPEND
);
1324 read_str ("Enter a URI of the subject of the certificate: ");
1328 if (type
== TYPE_CRT
)
1329 ret
= gnutls_x509_crt_set_subject_alt_name
1330 (crt
, GNUTLS_SAN_URI
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1332 ret
= gnutls_x509_crq_set_subject_alt_name
1333 (crt
, GNUTLS_SAN_URI
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1340 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1348 get_sign_status (int server
)
1354 return cfg
.signing_key
;
1360 "Will the certificate be used for signing (DHE and RSA-EXPORT ciphersuites)? (y/N): ";
1363 "Will the certificate be used for signing (required for TLS)? (y/N): ";
1364 return read_yesno (msg
);
1369 get_encrypt_status (int server
)
1375 return cfg
.encryption_key
;
1381 "Will the certificate be used for encryption (RSA ciphersuites)? (y/N): ";
1384 "Will the certificate be used for encryption (not required for TLS)? (y/N): ";
1385 return read_yesno (msg
);
1390 get_cert_sign_status (void)
1394 return cfg
.cert_sign_key
;
1400 ("Will the certificate be used to sign other certificates? (y/N): ");
1405 get_crl_sign_status (void)
1409 return cfg
.crl_sign_key
;
1414 read_yesno ("Will the certificate be used to sign CRLs? (y/N): ");
1419 get_code_sign_status (void)
1423 return cfg
.code_sign_key
;
1428 read_yesno ("Will the certificate be used to sign code? (y/N): ");
1433 get_ocsp_sign_status (void)
1437 return cfg
.ocsp_sign_key
;
1443 ("Will the certificate be used to sign OCSP requests? (y/N): ");
1448 get_time_stamp_status (void)
1452 return cfg
.time_stamping_key
;
1458 ("Will the certificate be used for time stamping? (y/N): ");
1463 get_ipsec_ike_status (void)
1467 return cfg
.ipsec_ike_key
;
1473 ("Will the certificate be used for IPsec IKE operations? (y/N): ");
1478 get_crl_next_update (void)
1484 if (cfg
.crl_next_update
<= 0)
1487 return cfg
.crl_next_update
;
1493 days
= read_int ("The next CRL will be issued in (days): ");
1501 get_proxy_policy (char **policy
, size_t * policylen
)
1507 ret
= cfg
.proxy_policy_language
;
1509 ret
= "1.3.6.1.5.5.7.21.1";
1515 ret
= read_str ("Enter the OID of the proxy policy language: ");
1517 while (ret
== NULL
);
1523 if (strcmp (ret
, "1.3.6.1.5.5.7.21.1") != 0 &&
1524 strcmp (ret
, "1.3.6.1.5.5.7.21.2") != 0)
1526 fprintf (stderr
, "Reading non-standard proxy policy not supported.\n");
1535 get_country_crq_set (gnutls_x509_crq_t crq
)
1544 gnutls_x509_crq_set_dn_by_oid (crq
,
1545 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
1546 cfg
.country
, strlen (cfg
.country
));
1549 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1555 read_crq_set (crq
, "Country name (2 chars): ",
1556 GNUTLS_OID_X520_COUNTRY_NAME
);
1562 get_organization_crq_set (gnutls_x509_crq_t crq
)
1568 if (!cfg
.organization
)
1572 gnutls_x509_crq_set_dn_by_oid (crq
,
1573 GNUTLS_OID_X520_ORGANIZATION_NAME
,
1574 0, cfg
.organization
,
1575 strlen (cfg
.organization
));
1578 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1584 read_crq_set (crq
, "Organization name: ",
1585 GNUTLS_OID_X520_ORGANIZATION_NAME
);
1591 get_unit_crq_set (gnutls_x509_crq_t crq
)
1601 gnutls_x509_crq_set_dn_by_oid (crq
,
1602 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
1603 0, cfg
.unit
, strlen (cfg
.unit
));
1606 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1612 read_crq_set (crq
, "Organizational unit name: ",
1613 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
1619 get_state_crq_set (gnutls_x509_crq_t crq
)
1628 gnutls_x509_crq_set_dn_by_oid (crq
,
1629 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
1630 0, cfg
.state
, strlen (cfg
.state
));
1633 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1639 read_crq_set (crq
, "State or province name: ",
1640 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
1646 get_locality_crq_set (gnutls_x509_crq_t crq
)
1655 gnutls_x509_crq_set_dn_by_oid (crq
,
1656 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
1657 cfg
.locality
, strlen (cfg
.locality
));
1660 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1666 read_crq_set (crq
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
1672 get_cn_crq_set (gnutls_x509_crq_t crq
)
1681 gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_X520_COMMON_NAME
,
1682 0, cfg
.cn
, strlen (cfg
.cn
));
1685 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1691 read_crq_set (crq
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
1697 get_uid_crq_set (gnutls_x509_crq_t crq
)
1705 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_LDAP_UID
, 0,
1706 cfg
.uid
, strlen (cfg
.uid
));
1709 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1715 read_crq_set (crq
, "UID: ", GNUTLS_OID_LDAP_UID
);
1721 get_oid_crq_set (gnutls_x509_crq_t crq
)
1729 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
1731 if (cfg
.dn_oid
[i
+ 1] == NULL
)
1733 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
1737 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, cfg
.dn_oid
[i
], 0,
1739 strlen (cfg
.dn_oid
[i
+ 1]));
1743 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));