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
53 typedef struct _cfg_ctx
61 char *challenge_password
;
65 char *policy_txt
[MAX_ENTRIES
];
66 char *policy_url
[MAX_ENTRIES
];
73 char *crl_dist_points
;
75 char *pkcs12_key_name
;
88 int time_stamping_key
;
90 char **key_purpose_oids
;
94 char *proxy_policy_language
;
96 char **ca_issuers_uris
;
104 memset (&cfg
, 0, sizeof (cfg
));
109 #define READ_MULTI_LINE(name, s_name) \
110 val = optionGetValue(pov, name); \
111 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
113 if (s_name == NULL) { \
115 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
117 if (val && !strcmp(val->pzName, name)==0) \
119 s_name[i] = strdup(val->v.strVal); \
121 if (i>=MAX_ENTRIES) \
123 } while((val = optionNextValue(pov, val)) != NULL); \
128 #define READ_MULTI_LINE_TOKENIZED(name, s_name) \
129 val = optionGetValue(pov, name); \
130 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
134 if (s_name == NULL) { \
136 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
138 if (val && !strcmp(val->pzName, name)==0) \
140 strncpy(str, val->v.strVal, sizeof(str)-1); \
141 str[sizeof(str)-1] = 0; \
142 if ((p=strchr(str, ' ')) == NULL && (p=strchr(str, '\t')) == NULL) { \
143 fprintf(stderr, "Error parsing %s\n", name); \
148 s_name[i] = strdup(str); \
149 while(*p==' ' || *p == '\t') p++; \
151 fprintf(stderr, "Error (2) parsing %s\n", name); \
154 s_name[i+1] = strdup(p); \
156 if (i>=MAX_ENTRIES) \
158 } while((val = optionNextValue(pov, val)) != NULL); \
163 #define READ_BOOLEAN(name, s_name) \
164 val = optionGetValue(pov, name); \
170 #define READ_NUMERIC(name, s_name) \
171 val = optionGetValue(pov, name); \
174 if (val->valType == OPARG_TYPE_NUMERIC) \
175 s_name = val->v.longVal; \
176 else if (val->valType == OPARG_TYPE_STRING) \
177 s_name = atoi(val->v.strVal); \
181 template_parse (const char *template)
183 /* Parsing return code */
186 tOptionValue
const * pov
;
187 const tOptionValue
* val
;
190 pov
= configFileLoad(template);
193 perror("configFileLoad");
194 fprintf(stderr
, "Error loading template: %s\n", template);
198 /* Option variables */
199 val
= optionGetValue(pov
, "organization");
200 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
201 cfg
.organization
= strdup(val
->v
.strVal
);
203 val
= optionGetValue(pov
, "unit");
204 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
205 cfg
.unit
= strdup(val
->v
.strVal
);
207 val
= optionGetValue(pov
, "locality");
208 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
209 cfg
.locality
= strdup(val
->v
.strVal
);
211 val
= optionGetValue(pov
, "state");
212 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
213 cfg
.state
= strdup(val
->v
.strVal
);
215 val
= optionGetValue(pov
, "cn");
216 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
217 cfg
.cn
= strdup(val
->v
.strVal
);
219 val
= optionGetValue(pov
, "uid");
220 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
221 cfg
.uid
= strdup(val
->v
.strVal
);
223 val
= optionGetValue(pov
, "challenge_password");
224 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
225 cfg
.challenge_password
= strdup(val
->v
.strVal
);
227 val
= optionGetValue(pov
, "password");
228 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
229 cfg
.password
= strdup(val
->v
.strVal
);
231 val
= optionGetValue(pov
, "pkcs9_email");
232 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
233 cfg
.pkcs9_email
= strdup(val
->v
.strVal
);
235 val
= optionGetValue(pov
, "country");
236 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
237 cfg
.country
= strdup(val
->v
.strVal
);
239 READ_MULTI_LINE("policy", cfg
.policy_oid
);
241 if (cfg
.policy_oid
!= NULL
)
244 while(cfg
.policy_oid
[i
] != NULL
)
246 snprintf(tmpstr
, sizeof(tmpstr
), "policy%d_url", i
+1);
247 val
= optionGetValue(pov
, tmpstr
);
248 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
249 cfg
.policy_url
[i
] = strdup(val
->v
.strVal
);
251 snprintf(tmpstr
, sizeof(tmpstr
), "policy%d_txt", i
+1);
252 val
= optionGetValue(pov
, tmpstr
);
253 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
255 cfg
.policy_txt
[i
] = strdup(val
->v
.strVal
);
262 READ_MULTI_LINE("dc", cfg
.dc
);
263 READ_MULTI_LINE("dns_name", cfg
.dns_name
);
264 READ_MULTI_LINE("uri", cfg
.uri
);
266 READ_MULTI_LINE("ip_address", cfg
.ip_addr
);
267 READ_MULTI_LINE("email", cfg
.email
);
268 READ_MULTI_LINE("key_purpose_oid", cfg
.key_purpose_oids
);
270 READ_MULTI_LINE_TOKENIZED("dn_oid", cfg
.dn_oid
);
272 val
= optionGetValue(pov
, "crl_dist_points");
273 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
274 cfg
.crl_dist_points
= strdup(val
->v
.strVal
);
276 val
= optionGetValue(pov
, "pkcs12_key_name");
277 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
278 cfg
.pkcs12_key_name
= strdup(val
->v
.strVal
);
281 READ_NUMERIC("serial", cfg
.serial
);
282 READ_NUMERIC("expiration_days", cfg
.expiration_days
);
283 READ_NUMERIC("crl_next_update", cfg
.crl_next_update
);
284 READ_NUMERIC("crl_number", cfg
.crl_number
);
286 val
= optionGetValue(pov
, "proxy_policy_language");
287 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
288 cfg
.proxy_policy_language
= strdup(val
->v
.strVal
);
290 READ_MULTI_LINE("ocsp_uri", cfg
.ocsp_uris
);
291 READ_MULTI_LINE("ca_issuers_uri", cfg
.ca_issuers_uris
);
293 READ_BOOLEAN("ca", cfg
.ca
);
294 READ_BOOLEAN("honor_crq_extensions", cfg
.crq_extensions
);
295 READ_BOOLEAN("path_len", cfg
.path_len
);
296 READ_BOOLEAN("tls_www_client", cfg
.tls_www_client
);
297 READ_BOOLEAN("tls_www_server", cfg
.tls_www_server
);
298 READ_BOOLEAN("signing_key", cfg
.signing_key
);
299 READ_BOOLEAN("encryption_key", cfg
.encryption_key
);
300 READ_BOOLEAN("cert_signing_key", cfg
.cert_sign_key
);
301 READ_BOOLEAN("crl_signing_key", cfg
.crl_sign_key
);
302 READ_BOOLEAN("code_signing_key", cfg
.code_sign_key
);
303 READ_BOOLEAN("ocsp_signing_key", cfg
.ocsp_sign_key
);
304 READ_BOOLEAN("time_stamping_key", cfg
.time_stamping_key
);
305 READ_BOOLEAN("ipsec_ike_key", cfg
.ipsec_ike_key
);
307 optionUnloadNested(pov
);
312 #define IS_NEWLINE(x) ((x[0] == '\n') || (x[0] == '\r'))
315 read_crt_set (gnutls_x509_crt_t crt
, const char *input_str
, const char *oid
)
320 fputs (input_str
, stderr
);
321 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
324 if (IS_NEWLINE(input
))
328 gnutls_x509_crt_set_dn_by_oid (crt
, oid
, 0, input
, strlen (input
) - 1);
331 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
337 read_crq_set (gnutls_x509_crq_t crq
, const char *input_str
, const char *oid
)
342 fputs (input_str
, stderr
);
343 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
346 if (IS_NEWLINE(input
))
350 gnutls_x509_crq_set_dn_by_oid (crq
, oid
, 0, input
, strlen (input
) - 1);
353 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
358 /* The input_str should contain %d or %u to print the default.
361 read_int_with_default (const char *input_str
, int def
)
365 static char input
[128];
367 fprintf (stderr
, input_str
, def
);
368 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
371 if (IS_NEWLINE(input
))
374 len
= strlen (input
);
376 l
= strtol (input
, &endptr
, 0);
378 if (*endptr
!= '\0' && *endptr
!= '\r' && *endptr
!= '\n')
380 fprintf (stderr
, "Trailing garbage ignored: `%s'\n", endptr
);
384 if (l
<= INT_MIN
|| l
>= INT_MAX
)
386 fprintf (stderr
, "Integer out of range: `%s'\n", input
);
397 read_int (const char *input_str
)
399 return read_int_with_default (input_str
, 0);
403 read_str (const char *input_str
)
405 static char input
[128];
408 fputs (input_str
, stderr
);
409 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
412 if (IS_NEWLINE(input
))
415 len
= strlen (input
);
416 if ((len
> 0) && (input
[len
- 1] == '\n'))
427 read_yesno (const char *input_str
)
431 fputs (input_str
, stderr
);
432 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
435 if (IS_NEWLINE(input
))
438 if (input
[0] == 'y' || input
[0] == 'Y')
445 /* Wrapper functions for non-interactive mode.
453 return getpass ("Enter password: ");
457 get_confirmed_pass (bool empty_ok
)
463 const char *pass
= NULL
;
469 fprintf (stderr
, "Password missmatch, try again.\n");
473 pass
= getpass ("Enter password: ");
474 copy
= strdup (pass
);
475 pass
= getpass ("Confirm password: ");
477 while (strcmp (pass
, copy
) != 0 && !(empty_ok
&& *pass
== '\0'));
486 get_challenge_pass (void)
489 return cfg
.challenge_password
;
491 return getpass ("Enter a challenge password: ");
495 get_crl_dist_point_url (void)
498 return cfg
.crl_dist_points
;
500 return read_str ("Enter the URI of the CRL distribution point: ");
504 get_country_crt_set (gnutls_x509_crt_t crt
)
513 gnutls_x509_crt_set_dn_by_oid (crt
,
514 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
515 cfg
.country
, strlen (cfg
.country
));
518 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
524 read_crt_set (crt
, "Country name (2 chars): ",
525 GNUTLS_OID_X520_COUNTRY_NAME
);
531 get_organization_crt_set (gnutls_x509_crt_t crt
)
537 if (!cfg
.organization
)
541 gnutls_x509_crt_set_dn_by_oid (crt
,
542 GNUTLS_OID_X520_ORGANIZATION_NAME
,
544 strlen (cfg
.organization
));
547 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
553 read_crt_set (crt
, "Organization name: ",
554 GNUTLS_OID_X520_ORGANIZATION_NAME
);
560 get_unit_crt_set (gnutls_x509_crt_t crt
)
570 gnutls_x509_crt_set_dn_by_oid (crt
,
571 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
572 0, cfg
.unit
, strlen (cfg
.unit
));
575 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
581 read_crt_set (crt
, "Organizational unit name: ",
582 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
588 get_state_crt_set (gnutls_x509_crt_t crt
)
597 gnutls_x509_crt_set_dn_by_oid (crt
,
598 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
599 0, cfg
.state
, strlen (cfg
.state
));
602 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
608 read_crt_set (crt
, "State or province name: ",
609 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
615 get_locality_crt_set (gnutls_x509_crt_t crt
)
624 gnutls_x509_crt_set_dn_by_oid (crt
,
625 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
626 cfg
.locality
, strlen (cfg
.locality
));
629 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
635 read_crt_set (crt
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
641 get_cn_crt_set (gnutls_x509_crt_t crt
)
650 gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_X520_COMMON_NAME
,
651 0, cfg
.cn
, strlen (cfg
.cn
));
654 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
660 read_crt_set (crt
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
666 get_uid_crt_set (gnutls_x509_crt_t crt
)
674 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_UID
, 0,
675 cfg
.uid
, strlen (cfg
.uid
));
678 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
684 read_crt_set (crt
, "UID: ", GNUTLS_OID_LDAP_UID
);
690 get_oid_crt_set (gnutls_x509_crt_t crt
)
698 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
700 if (cfg
.dn_oid
[i
+ 1] == NULL
)
702 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
706 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, cfg
.dn_oid
[i
], 0,
708 strlen (cfg
.dn_oid
[i
+ 1]));
712 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));
720 get_key_purpose_set (gnutls_x509_crt_t crt
)
726 if (!cfg
.key_purpose_oids
)
728 for (i
= 0; cfg
.key_purpose_oids
[i
] != NULL
; i
++)
731 gnutls_x509_crt_set_key_purpose_oid (crt
, cfg
.key_purpose_oids
[i
],
736 fprintf (stderr
, "set_key_purpose_oid (%s): %s\n",
737 cfg
.key_purpose_oids
[i
], gnutls_strerror (ret
));
745 get_ocsp_issuer_set (gnutls_x509_crt_t crt
)
754 for (i
= 0; cfg
.ocsp_uris
[i
] != NULL
; i
++)
756 uri
.data
= cfg
.ocsp_uris
[i
];
757 uri
.size
= strlen(cfg
.ocsp_uris
[i
]);
759 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_OCSP_URI
,
763 fprintf (stderr
, "set OCSP URI (%s): %s\n",
764 cfg
.ocsp_uris
[i
], gnutls_strerror (ret
));
772 get_ca_issuers_set (gnutls_x509_crt_t crt
)
779 if (!cfg
.ca_issuers_uris
)
781 for (i
= 0; cfg
.ca_issuers_uris
[i
] != NULL
; i
++)
783 uri
.data
= cfg
.ca_issuers_uris
[i
];
784 uri
.size
= strlen(cfg
.ca_issuers_uris
[i
]);
786 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_CAISSUERS_URI
,
790 fprintf (stderr
, "set CA ISSUERS URI (%s): %s\n",
791 cfg
.ca_issuers_uris
[i
], gnutls_strerror (ret
));
800 get_pkcs9_email_crt_set (gnutls_x509_crt_t crt
)
806 if (!cfg
.pkcs9_email
)
808 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_PKCS9_EMAIL
, 0,
810 strlen (cfg
.pkcs9_email
));
813 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
819 read_crt_set (crt
, "E-mail: ", GNUTLS_OID_PKCS9_EMAIL
);
827 int default_serial
= time (NULL
);
832 return default_serial
;
837 return read_int_with_default
838 ("Enter the certificate's serial number in decimal (default: %u): ",
850 if (cfg
.expiration_days
<= 0)
853 return cfg
.expiration_days
;
859 days
= read_int ("The certificate will expire in (days): ");
876 read_yesno ("Does the certificate belong to an authority? (y/N): ");
881 get_crq_extensions_status (void)
885 return cfg
.crq_extensions
;
891 ("Do you want to honour the extensions from the request? (y/N): ");
896 get_crl_number (void)
900 return cfg
.crl_number
;
904 return read_int_with_default ("CRL Number: ", 1);
917 return read_int_with_default
918 ("Path length constraint (decimal, %d for no constraint): ", -1);
923 get_pkcs12_key_name (void)
929 if (!cfg
.pkcs12_key_name
)
931 return cfg
.pkcs12_key_name
;
937 name
= read_str ("Enter a name for the key: ");
939 while (name
== NULL
);
945 get_tls_client_status (void)
949 return cfg
.tls_www_client
;
953 return read_yesno ("Is this a TLS web client certificate? (y/N): ");
958 get_tls_server_status (void)
962 return cfg
.tls_www_server
;
967 read_yesno ("Is this also a TLS web server certificate? (y/N): ");
971 /* convert a printable IP to binary */
973 string_to_ip (unsigned char *ip
, const char *str
)
975 int len
= strlen (str
);
979 if (strchr (str
, ':') != NULL
|| len
> 16)
981 ret
= inet_pton (AF_INET6
, str
, ip
);
984 fprintf (stderr
, "Error in IPv6 address %s\n", str
);
994 ret
= inet_pton (AF_INET
, str
, ip
);
997 fprintf (stderr
, "Error in IPv4 address %s\n", str
);
1007 get_ip_addr_set (int type
, void *crt
)
1010 unsigned char ip
[16];
1018 for (i
= 0; cfg
.ip_addr
[i
] != NULL
; i
++)
1020 len
= string_to_ip (ip
, cfg
.ip_addr
[i
]);
1023 fprintf (stderr
, "Error parsing address: %s\n", cfg
.ip_addr
[i
]);
1027 if (type
== TYPE_CRT
)
1029 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1031 GNUTLS_FSAN_APPEND
);
1034 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1036 GNUTLS_FSAN_APPEND
);
1047 read_str ("Enter the IP address of the subject of the certificate: ");
1051 len
= string_to_ip (ip
, p
);
1054 fprintf (stderr
, "Error parsing address: %s\n", p
);
1058 if (type
== TYPE_CRT
)
1059 ret
= gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1061 GNUTLS_FSAN_APPEND
);
1063 ret
= gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1065 GNUTLS_FSAN_APPEND
);
1070 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1076 get_email_set (int type
, void *crt
)
1085 for (i
= 0; cfg
.email
[i
] != NULL
; i
++)
1087 if (type
== TYPE_CRT
)
1089 gnutls_x509_crt_set_subject_alt_name (crt
,
1090 GNUTLS_SAN_RFC822NAME
,
1092 strlen (cfg
.email
[i
]),
1093 GNUTLS_FSAN_APPEND
);
1096 gnutls_x509_crq_set_subject_alt_name (crt
,
1097 GNUTLS_SAN_RFC822NAME
,
1099 strlen (cfg
.email
[i
]),
1100 GNUTLS_FSAN_APPEND
);
1110 p
= read_str ("Enter the e-mail of the subject of the certificate: ");
1114 if (type
== TYPE_CRT
)
1116 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1118 GNUTLS_FSAN_APPEND
);
1121 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1123 GNUTLS_FSAN_APPEND
);
1128 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1135 get_dc_set (int type
, void *crt
)
1144 for (i
= 0; cfg
.dc
[i
] != NULL
; i
++)
1146 if (type
== TYPE_CRT
)
1147 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1148 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1150 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1151 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1163 p
= read_str ("Enter the subject's domain component (DC): ");
1167 if (type
== TYPE_CRT
)
1168 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1171 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1179 fprintf (stderr
, "set_dn_by_oid: %s\n", gnutls_strerror (ret
));
1185 get_dns_name_set (int type
, void *crt
)
1194 for (i
= 0; cfg
.dns_name
[i
] != NULL
; i
++)
1196 if (type
== TYPE_CRT
)
1198 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1200 strlen (cfg
.dns_name
[i
]),
1201 GNUTLS_FSAN_APPEND
);
1204 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1206 strlen (cfg
.dns_name
[i
]),
1207 GNUTLS_FSAN_APPEND
);
1220 read_str ("Enter a dnsName of the subject of the certificate: ");
1224 if (type
== TYPE_CRT
)
1225 ret
= gnutls_x509_crt_set_subject_alt_name
1226 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1228 ret
= gnutls_x509_crq_set_subject_alt_name
1229 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1236 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1242 get_policy_set (gnutls_x509_crt_t crt
)
1245 gnutls_x509_policy_st policy
;
1249 if (!cfg
.policy_oid
)
1252 for (i
= 0; cfg
.policy_oid
[i
] != NULL
; i
++)
1254 memset(&policy
, 0, sizeof(policy
));
1255 policy
.oid
= cfg
.policy_oid
[i
];
1257 if (cfg
.policy_txt
[i
] != NULL
)
1259 policy
.qualifier
[policy
.qualifiers
].type
= GNUTLS_X509_QUALIFIER_NOTICE
;
1260 policy
.qualifier
[policy
.qualifiers
].data
= cfg
.policy_txt
[i
];
1261 policy
.qualifier
[policy
.qualifiers
].size
= strlen(cfg
.policy_txt
[i
]);
1262 policy
.qualifiers
++;
1265 if (cfg
.policy_url
[i
] != NULL
)
1267 policy
.qualifier
[policy
.qualifiers
].type
= GNUTLS_X509_QUALIFIER_URI
;
1268 policy
.qualifier
[policy
.qualifiers
].data
= cfg
.policy_url
[i
];
1269 policy
.qualifier
[policy
.qualifiers
].size
= strlen(cfg
.policy_url
[i
]);
1270 policy
.qualifiers
++;
1273 fprintf(stderr
, "setting policy %s with %d qualifiers\n", policy
.oid
, policy
.qualifiers
);
1276 gnutls_x509_crt_set_policy (crt
, &policy
, 0);
1284 fprintf (stderr
, "set_policy: %s\n", gnutls_strerror (ret
));
1290 get_uri_set (int type
, void *crt
)
1299 for (i
= 0; cfg
.uri
[i
] != NULL
; i
++)
1301 if (type
== TYPE_CRT
)
1303 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_URI
,
1305 strlen (cfg
.uri
[i
]),
1306 GNUTLS_FSAN_APPEND
);
1309 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_URI
,
1311 strlen (cfg
.uri
[i
]),
1312 GNUTLS_FSAN_APPEND
);
1325 read_str ("Enter a URI of the subject of the certificate: ");
1329 if (type
== TYPE_CRT
)
1330 ret
= gnutls_x509_crt_set_subject_alt_name
1331 (crt
, GNUTLS_SAN_URI
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1333 ret
= gnutls_x509_crq_set_subject_alt_name
1334 (crt
, GNUTLS_SAN_URI
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1341 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1349 get_sign_status (int server
)
1355 return cfg
.signing_key
;
1361 "Will the certificate be used for signing (DHE and RSA-EXPORT ciphersuites)? (y/N): ";
1364 "Will the certificate be used for signing (required for TLS)? (y/N): ";
1365 return read_yesno (msg
);
1370 get_encrypt_status (int server
)
1376 return cfg
.encryption_key
;
1382 "Will the certificate be used for encryption (RSA ciphersuites)? (y/N): ";
1385 "Will the certificate be used for encryption (not required for TLS)? (y/N): ";
1386 return read_yesno (msg
);
1391 get_cert_sign_status (void)
1395 return cfg
.cert_sign_key
;
1401 ("Will the certificate be used to sign other certificates? (y/N): ");
1406 get_crl_sign_status (void)
1410 return cfg
.crl_sign_key
;
1415 read_yesno ("Will the certificate be used to sign CRLs? (y/N): ");
1420 get_code_sign_status (void)
1424 return cfg
.code_sign_key
;
1429 read_yesno ("Will the certificate be used to sign code? (y/N): ");
1434 get_ocsp_sign_status (void)
1438 return cfg
.ocsp_sign_key
;
1444 ("Will the certificate be used to sign OCSP requests? (y/N): ");
1449 get_time_stamp_status (void)
1453 return cfg
.time_stamping_key
;
1459 ("Will the certificate be used for time stamping? (y/N): ");
1464 get_ipsec_ike_status (void)
1468 return cfg
.ipsec_ike_key
;
1474 ("Will the certificate be used for IPsec IKE operations? (y/N): ");
1479 get_crl_next_update (void)
1485 if (cfg
.crl_next_update
<= 0)
1488 return cfg
.crl_next_update
;
1494 days
= read_int ("The next CRL will be issued in (days): ");
1502 get_proxy_policy (char **policy
, size_t * policylen
)
1508 ret
= cfg
.proxy_policy_language
;
1510 ret
= "1.3.6.1.5.5.7.21.1";
1516 ret
= read_str ("Enter the OID of the proxy policy language: ");
1518 while (ret
== NULL
);
1524 if (strcmp (ret
, "1.3.6.1.5.5.7.21.1") != 0 &&
1525 strcmp (ret
, "1.3.6.1.5.5.7.21.2") != 0)
1527 fprintf (stderr
, "Reading non-standard proxy policy not supported.\n");
1536 get_country_crq_set (gnutls_x509_crq_t crq
)
1545 gnutls_x509_crq_set_dn_by_oid (crq
,
1546 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
1547 cfg
.country
, strlen (cfg
.country
));
1550 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1556 read_crq_set (crq
, "Country name (2 chars): ",
1557 GNUTLS_OID_X520_COUNTRY_NAME
);
1563 get_organization_crq_set (gnutls_x509_crq_t crq
)
1569 if (!cfg
.organization
)
1573 gnutls_x509_crq_set_dn_by_oid (crq
,
1574 GNUTLS_OID_X520_ORGANIZATION_NAME
,
1575 0, cfg
.organization
,
1576 strlen (cfg
.organization
));
1579 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1585 read_crq_set (crq
, "Organization name: ",
1586 GNUTLS_OID_X520_ORGANIZATION_NAME
);
1592 get_unit_crq_set (gnutls_x509_crq_t crq
)
1602 gnutls_x509_crq_set_dn_by_oid (crq
,
1603 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
1604 0, cfg
.unit
, strlen (cfg
.unit
));
1607 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1613 read_crq_set (crq
, "Organizational unit name: ",
1614 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
1620 get_state_crq_set (gnutls_x509_crq_t crq
)
1629 gnutls_x509_crq_set_dn_by_oid (crq
,
1630 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
1631 0, cfg
.state
, strlen (cfg
.state
));
1634 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1640 read_crq_set (crq
, "State or province name: ",
1641 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
1647 get_locality_crq_set (gnutls_x509_crq_t crq
)
1656 gnutls_x509_crq_set_dn_by_oid (crq
,
1657 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
1658 cfg
.locality
, strlen (cfg
.locality
));
1661 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1667 read_crq_set (crq
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
1673 get_cn_crq_set (gnutls_x509_crq_t crq
)
1682 gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_X520_COMMON_NAME
,
1683 0, cfg
.cn
, strlen (cfg
.cn
));
1686 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1692 read_crq_set (crq
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
1698 get_uid_crq_set (gnutls_x509_crq_t crq
)
1706 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_LDAP_UID
, 0,
1707 cfg
.uid
, strlen (cfg
.uid
));
1710 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1716 read_crq_set (crq
, "UID: ", GNUTLS_OID_LDAP_UID
);
1722 get_oid_crq_set (gnutls_x509_crq_t crq
)
1730 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
1732 if (cfg
.dn_oid
[i
+ 1] == NULL
)
1734 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
1738 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, cfg
.dn_oid
[i
], 0,
1740 strlen (cfg
.dn_oid
[i
+ 1]));
1744 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));