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
;
70 char *crl_dist_points
;
72 char *pkcs12_key_name
;
85 int time_stamping_key
;
87 char **key_purpose_oids
;
91 char *proxy_policy_language
;
93 char **ca_issuers_uris
;
101 memset (&cfg
, 0, sizeof (cfg
));
106 #define READ_MULTI_LINE(name, s_name) \
107 val = optionGetValue(pov, name); \
108 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
110 if (s_name == NULL) { \
112 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
114 if (val && !strcmp(val->pzName, name)==0) \
116 s_name[i] = strdup(val->v.strVal); \
118 if (i>=MAX_ENTRIES) \
120 } while((val = optionNextValue(pov, val)) != NULL); \
125 #define READ_MULTI_LINE_TOKENIZED(name, s_name) \
126 val = optionGetValue(pov, name); \
127 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
131 if (s_name == NULL) { \
133 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
135 if (val && !strcmp(val->pzName, name)==0) \
137 strncpy(str, val->v.strVal, sizeof(str)-1); \
138 str[sizeof(str)-1] = 0; \
139 if ((p=strchr(str, ' ')) == NULL && (p=strchr(str, '\t')) == NULL) { \
140 fprintf(stderr, "Error parsing %s\n", name); \
145 s_name[i] = strdup(str); \
146 while(*p==' ' || *p == '\t') p++; \
148 fprintf(stderr, "Error (2) parsing %s\n", name); \
151 s_name[i+1] = strdup(p); \
153 if (i>=MAX_ENTRIES) \
155 } while((val = optionNextValue(pov, val)) != NULL); \
160 #define READ_BOOLEAN(name, s_name) \
161 val = optionGetValue(pov, name); \
167 #define READ_NUMERIC(name, s_name) \
168 val = optionGetValue(pov, name); \
171 if (val->valType == OPARG_TYPE_NUMERIC) \
172 s_name = val->v.longVal; \
173 else if (val->valType == OPARG_TYPE_STRING) \
174 s_name = atoi(val->v.strVal); \
178 template_parse (const char *template)
180 /* Parsing return code */
183 tOptionValue
const * pov
;
184 const tOptionValue
* val
;
186 pov
= configFileLoad(template);
189 perror("configFileLoad");
190 fprintf(stderr
, "Error loading template: %s\n", template);
194 /* Option variables */
195 val
= optionGetValue(pov
, "organization");
196 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
197 cfg
.organization
= strdup(val
->v
.strVal
);
199 val
= optionGetValue(pov
, "unit");
200 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
201 cfg
.unit
= strdup(val
->v
.strVal
);
203 val
= optionGetValue(pov
, "locality");
204 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
205 cfg
.locality
= strdup(val
->v
.strVal
);
207 val
= optionGetValue(pov
, "state");
208 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
209 cfg
.state
= strdup(val
->v
.strVal
);
211 val
= optionGetValue(pov
, "cn");
212 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
213 cfg
.cn
= strdup(val
->v
.strVal
);
215 val
= optionGetValue(pov
, "uid");
216 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
217 cfg
.uid
= strdup(val
->v
.strVal
);
219 val
= optionGetValue(pov
, "challenge_password");
220 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
221 cfg
.challenge_password
= strdup(val
->v
.strVal
);
223 val
= optionGetValue(pov
, "password");
224 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
225 cfg
.password
= strdup(val
->v
.strVal
);
227 val
= optionGetValue(pov
, "pkcs9_email");
228 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
229 cfg
.pkcs9_email
= strdup(val
->v
.strVal
);
231 val
= optionGetValue(pov
, "country");
232 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
233 cfg
.country
= strdup(val
->v
.strVal
);
235 READ_MULTI_LINE("dc", cfg
.dc
);
236 READ_MULTI_LINE("dns_name", cfg
.dns_name
);
237 READ_MULTI_LINE("uri", cfg
.uri
);
239 READ_MULTI_LINE("ip_address", cfg
.ip_addr
);
240 READ_MULTI_LINE("email", cfg
.email
);
241 READ_MULTI_LINE("key_purpose_oid", cfg
.key_purpose_oids
);
243 READ_MULTI_LINE_TOKENIZED("dn_oid", cfg
.dn_oid
);
245 val
= optionGetValue(pov
, "crl_dist_points");
246 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
247 cfg
.crl_dist_points
= strdup(val
->v
.strVal
);
249 val
= optionGetValue(pov
, "pkcs12_key_name");
250 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
251 cfg
.pkcs12_key_name
= strdup(val
->v
.strVal
);
254 READ_NUMERIC("serial", cfg
.serial
);
255 READ_NUMERIC("expiration_days", cfg
.expiration_days
);
256 READ_NUMERIC("crl_next_update", cfg
.crl_next_update
);
257 READ_NUMERIC("crl_number", cfg
.crl_number
);
259 val
= optionGetValue(pov
, "proxy_policy_language");
260 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
261 cfg
.proxy_policy_language
= strdup(val
->v
.strVal
);
263 READ_MULTI_LINE("ocsp_uri", cfg
.ocsp_uris
);
264 READ_MULTI_LINE("ca_issuers_uri", cfg
.ca_issuers_uris
);
266 READ_BOOLEAN("ca", cfg
.ca
);
267 READ_BOOLEAN("honor_crq_extensions", cfg
.crq_extensions
);
268 READ_BOOLEAN("path_len", cfg
.path_len
);
269 READ_BOOLEAN("tls_www_client", cfg
.tls_www_client
);
270 READ_BOOLEAN("tls_www_server", cfg
.tls_www_server
);
271 READ_BOOLEAN("signing_key", cfg
.signing_key
);
272 READ_BOOLEAN("encryption_key", cfg
.encryption_key
);
273 READ_BOOLEAN("cert_signing_key", cfg
.cert_sign_key
);
274 READ_BOOLEAN("crl_signing_key", cfg
.crl_sign_key
);
275 READ_BOOLEAN("code_signing_key", cfg
.code_sign_key
);
276 READ_BOOLEAN("ocsp_signing_key", cfg
.ocsp_sign_key
);
277 READ_BOOLEAN("time_stamping_key", cfg
.time_stamping_key
);
278 READ_BOOLEAN("ipsec_ike_key", cfg
.ipsec_ike_key
);
280 optionUnloadNested(pov
);
285 #define IS_NEWLINE(x) ((x[0] == '\n') || (x[0] == '\r'))
288 read_crt_set (gnutls_x509_crt_t crt
, const char *input_str
, const char *oid
)
293 fputs (input_str
, stderr
);
294 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
297 if (IS_NEWLINE(input
))
301 gnutls_x509_crt_set_dn_by_oid (crt
, oid
, 0, input
, strlen (input
) - 1);
304 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
310 read_crq_set (gnutls_x509_crq_t crq
, const char *input_str
, const char *oid
)
315 fputs (input_str
, stderr
);
316 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
319 if (IS_NEWLINE(input
))
323 gnutls_x509_crq_set_dn_by_oid (crq
, oid
, 0, input
, strlen (input
) - 1);
326 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
331 /* The input_str should contain %d or %u to print the default.
334 read_int_with_default (const char *input_str
, int def
)
338 static char input
[128];
340 fprintf (stderr
, input_str
, def
);
341 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
344 if (IS_NEWLINE(input
))
347 len
= strlen (input
);
349 l
= strtol (input
, &endptr
, 0);
351 if (*endptr
!= '\0' && *endptr
!= '\r' && *endptr
!= '\n')
353 fprintf (stderr
, "Trailing garbage ignored: `%s'\n", endptr
);
357 if (l
<= INT_MIN
|| l
>= INT_MAX
)
359 fprintf (stderr
, "Integer out of range: `%s'\n", input
);
370 read_int (const char *input_str
)
372 return read_int_with_default (input_str
, 0);
376 read_str (const char *input_str
)
378 static char input
[128];
381 fputs (input_str
, stderr
);
382 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
385 if (IS_NEWLINE(input
))
388 len
= strlen (input
);
389 if ((len
> 0) && (input
[len
- 1] == '\n'))
400 read_yesno (const char *input_str
)
404 fputs (input_str
, stderr
);
405 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
408 if (IS_NEWLINE(input
))
411 if (input
[0] == 'y' || input
[0] == 'Y')
418 /* Wrapper functions for non-interactive mode.
426 return getpass ("Enter password: ");
430 get_confirmed_pass (bool empty_ok
)
436 const char *pass
= NULL
;
442 fprintf (stderr
, "Password missmatch, try again.\n");
446 pass
= getpass ("Enter password: ");
447 copy
= strdup (pass
);
448 pass
= getpass ("Confirm password: ");
450 while (strcmp (pass
, copy
) != 0 && !(empty_ok
&& *pass
== '\0'));
459 get_challenge_pass (void)
462 return cfg
.challenge_password
;
464 return getpass ("Enter a challenge password: ");
468 get_crl_dist_point_url (void)
471 return cfg
.crl_dist_points
;
473 return read_str ("Enter the URI of the CRL distribution point: ");
477 get_country_crt_set (gnutls_x509_crt_t crt
)
486 gnutls_x509_crt_set_dn_by_oid (crt
,
487 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
488 cfg
.country
, strlen (cfg
.country
));
491 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
497 read_crt_set (crt
, "Country name (2 chars): ",
498 GNUTLS_OID_X520_COUNTRY_NAME
);
504 get_organization_crt_set (gnutls_x509_crt_t crt
)
510 if (!cfg
.organization
)
514 gnutls_x509_crt_set_dn_by_oid (crt
,
515 GNUTLS_OID_X520_ORGANIZATION_NAME
,
517 strlen (cfg
.organization
));
520 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
526 read_crt_set (crt
, "Organization name: ",
527 GNUTLS_OID_X520_ORGANIZATION_NAME
);
533 get_unit_crt_set (gnutls_x509_crt_t crt
)
543 gnutls_x509_crt_set_dn_by_oid (crt
,
544 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
545 0, cfg
.unit
, strlen (cfg
.unit
));
548 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
554 read_crt_set (crt
, "Organizational unit name: ",
555 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
561 get_state_crt_set (gnutls_x509_crt_t crt
)
570 gnutls_x509_crt_set_dn_by_oid (crt
,
571 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
572 0, cfg
.state
, strlen (cfg
.state
));
575 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
581 read_crt_set (crt
, "State or province name: ",
582 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
588 get_locality_crt_set (gnutls_x509_crt_t crt
)
597 gnutls_x509_crt_set_dn_by_oid (crt
,
598 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
599 cfg
.locality
, strlen (cfg
.locality
));
602 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
608 read_crt_set (crt
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
614 get_cn_crt_set (gnutls_x509_crt_t crt
)
623 gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_X520_COMMON_NAME
,
624 0, cfg
.cn
, strlen (cfg
.cn
));
627 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
633 read_crt_set (crt
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
639 get_uid_crt_set (gnutls_x509_crt_t crt
)
647 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_UID
, 0,
648 cfg
.uid
, strlen (cfg
.uid
));
651 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
657 read_crt_set (crt
, "UID: ", GNUTLS_OID_LDAP_UID
);
663 get_oid_crt_set (gnutls_x509_crt_t crt
)
671 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
673 if (cfg
.dn_oid
[i
+ 1] == NULL
)
675 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
679 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, cfg
.dn_oid
[i
], 0,
681 strlen (cfg
.dn_oid
[i
+ 1]));
685 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));
693 get_key_purpose_set (gnutls_x509_crt_t crt
)
699 if (!cfg
.key_purpose_oids
)
701 for (i
= 0; cfg
.key_purpose_oids
[i
] != NULL
; i
++)
704 gnutls_x509_crt_set_key_purpose_oid (crt
, cfg
.key_purpose_oids
[i
],
709 fprintf (stderr
, "set_key_purpose_oid (%s): %s\n",
710 cfg
.key_purpose_oids
[i
], gnutls_strerror (ret
));
718 get_ocsp_issuer_set (gnutls_x509_crt_t crt
)
727 for (i
= 0; cfg
.ocsp_uris
[i
] != NULL
; i
++)
729 uri
.data
= cfg
.ocsp_uris
[i
];
730 uri
.size
= strlen(cfg
.ocsp_uris
[i
]);
732 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_OCSP_URI
,
736 fprintf (stderr
, "set OCSP URI (%s): %s\n",
737 cfg
.ocsp_uris
[i
], gnutls_strerror (ret
));
745 get_ca_issuers_set (gnutls_x509_crt_t crt
)
752 if (!cfg
.ca_issuers_uris
)
754 for (i
= 0; cfg
.ca_issuers_uris
[i
] != NULL
; i
++)
756 uri
.data
= cfg
.ca_issuers_uris
[i
];
757 uri
.size
= strlen(cfg
.ca_issuers_uris
[i
]);
759 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_CAISSUERS_URI
,
763 fprintf (stderr
, "set CA ISSUERS URI (%s): %s\n",
764 cfg
.ca_issuers_uris
[i
], gnutls_strerror (ret
));
773 get_pkcs9_email_crt_set (gnutls_x509_crt_t crt
)
779 if (!cfg
.pkcs9_email
)
781 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_PKCS9_EMAIL
, 0,
783 strlen (cfg
.pkcs9_email
));
786 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
792 read_crt_set (crt
, "E-mail: ", GNUTLS_OID_PKCS9_EMAIL
);
800 int default_serial
= time (NULL
);
805 return default_serial
;
810 return read_int_with_default
811 ("Enter the certificate's serial number in decimal (default: %u): ",
823 if (cfg
.expiration_days
<= 0)
826 return cfg
.expiration_days
;
832 days
= read_int ("The certificate will expire in (days): ");
849 read_yesno ("Does the certificate belong to an authority? (y/N): ");
854 get_crq_extensions_status (void)
858 return cfg
.crq_extensions
;
864 ("Do you want to honour the extensions from the request? (y/N): ");
869 get_crl_number (void)
873 return cfg
.crl_number
;
877 return read_int_with_default ("CRL Number: ", 1);
890 return read_int_with_default
891 ("Path length constraint (decimal, %d for no constraint): ", -1);
896 get_pkcs12_key_name (void)
902 if (!cfg
.pkcs12_key_name
)
904 return cfg
.pkcs12_key_name
;
910 name
= read_str ("Enter a name for the key: ");
912 while (name
== NULL
);
918 get_tls_client_status (void)
922 return cfg
.tls_www_client
;
926 return read_yesno ("Is this a TLS web client certificate? (y/N): ");
931 get_tls_server_status (void)
935 return cfg
.tls_www_server
;
940 read_yesno ("Is this also a TLS web server certificate? (y/N): ");
944 /* convert a printable IP to binary */
946 string_to_ip (unsigned char *ip
, const char *str
)
948 int len
= strlen (str
);
952 if (strchr (str
, ':') != NULL
|| len
> 16)
954 ret
= inet_pton (AF_INET6
, str
, ip
);
957 fprintf (stderr
, "Error in IPv6 address %s\n", str
);
967 ret
= inet_pton (AF_INET
, str
, ip
);
970 fprintf (stderr
, "Error in IPv4 address %s\n", str
);
980 get_ip_addr_set (int type
, void *crt
)
983 unsigned char ip
[16];
991 for (i
= 0; cfg
.ip_addr
[i
] != NULL
; i
++)
993 len
= string_to_ip (ip
, cfg
.ip_addr
[i
]);
996 fprintf (stderr
, "Error parsing address: %s\n", cfg
.ip_addr
[i
]);
1000 if (type
== TYPE_CRT
)
1002 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1004 GNUTLS_FSAN_APPEND
);
1007 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1009 GNUTLS_FSAN_APPEND
);
1020 read_str ("Enter the IP address of the subject of the certificate: ");
1024 len
= string_to_ip (ip
, p
);
1027 fprintf (stderr
, "Error parsing address: %s\n", p
);
1031 if (type
== TYPE_CRT
)
1032 ret
= gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1034 GNUTLS_FSAN_APPEND
);
1036 ret
= gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1038 GNUTLS_FSAN_APPEND
);
1043 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1049 get_email_set (int type
, void *crt
)
1058 for (i
= 0; cfg
.email
[i
] != NULL
; i
++)
1060 if (type
== TYPE_CRT
)
1062 gnutls_x509_crt_set_subject_alt_name (crt
,
1063 GNUTLS_SAN_RFC822NAME
,
1065 strlen (cfg
.email
[i
]),
1066 GNUTLS_FSAN_APPEND
);
1069 gnutls_x509_crq_set_subject_alt_name (crt
,
1070 GNUTLS_SAN_RFC822NAME
,
1072 strlen (cfg
.email
[i
]),
1073 GNUTLS_FSAN_APPEND
);
1083 p
= read_str ("Enter the e-mail of the subject of the certificate: ");
1087 if (type
== TYPE_CRT
)
1089 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1091 GNUTLS_FSAN_APPEND
);
1094 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1096 GNUTLS_FSAN_APPEND
);
1101 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1108 get_dc_set (int type
, void *crt
)
1117 for (i
= 0; cfg
.dc
[i
] != NULL
; i
++)
1119 if (type
== TYPE_CRT
)
1120 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1121 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1123 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1124 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1136 p
= read_str ("Enter the subject's domain component (DC): ");
1140 if (type
== TYPE_CRT
)
1141 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1144 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1152 fprintf (stderr
, "set_dn_by_oid: %s\n", gnutls_strerror (ret
));
1158 get_dns_name_set (int type
, void *crt
)
1167 for (i
= 0; cfg
.dns_name
[i
] != NULL
; i
++)
1169 if (type
== TYPE_CRT
)
1171 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1173 strlen (cfg
.dns_name
[i
]),
1174 GNUTLS_FSAN_APPEND
);
1177 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1179 strlen (cfg
.dns_name
[i
]),
1180 GNUTLS_FSAN_APPEND
);
1193 read_str ("Enter a dnsName of the subject of the certificate: ");
1197 if (type
== TYPE_CRT
)
1198 ret
= gnutls_x509_crt_set_subject_alt_name
1199 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1201 ret
= gnutls_x509_crq_set_subject_alt_name
1202 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1209 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1215 get_uri_set (int type
, void *crt
)
1224 for (i
= 0; cfg
.uri
[i
] != NULL
; i
++)
1226 if (type
== TYPE_CRT
)
1228 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_URI
,
1230 strlen (cfg
.uri
[i
]),
1231 GNUTLS_FSAN_APPEND
);
1234 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_URI
,
1236 strlen (cfg
.uri
[i
]),
1237 GNUTLS_FSAN_APPEND
);
1250 read_str ("Enter a URI of the subject of the certificate: ");
1254 if (type
== TYPE_CRT
)
1255 ret
= gnutls_x509_crt_set_subject_alt_name
1256 (crt
, GNUTLS_SAN_URI
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1258 ret
= gnutls_x509_crq_set_subject_alt_name
1259 (crt
, GNUTLS_SAN_URI
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1266 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1274 get_sign_status (int server
)
1280 return cfg
.signing_key
;
1286 "Will the certificate be used for signing (DHE and RSA-EXPORT ciphersuites)? (y/N): ";
1289 "Will the certificate be used for signing (required for TLS)? (y/N): ";
1290 return read_yesno (msg
);
1295 get_encrypt_status (int server
)
1301 return cfg
.encryption_key
;
1307 "Will the certificate be used for encryption (RSA ciphersuites)? (y/N): ";
1310 "Will the certificate be used for encryption (not required for TLS)? (y/N): ";
1311 return read_yesno (msg
);
1316 get_cert_sign_status (void)
1320 return cfg
.cert_sign_key
;
1326 ("Will the certificate be used to sign other certificates? (y/N): ");
1331 get_crl_sign_status (void)
1335 return cfg
.crl_sign_key
;
1340 read_yesno ("Will the certificate be used to sign CRLs? (y/N): ");
1345 get_code_sign_status (void)
1349 return cfg
.code_sign_key
;
1354 read_yesno ("Will the certificate be used to sign code? (y/N): ");
1359 get_ocsp_sign_status (void)
1363 return cfg
.ocsp_sign_key
;
1369 ("Will the certificate be used to sign OCSP requests? (y/N): ");
1374 get_time_stamp_status (void)
1378 return cfg
.time_stamping_key
;
1384 ("Will the certificate be used for time stamping? (y/N): ");
1389 get_ipsec_ike_status (void)
1393 return cfg
.ipsec_ike_key
;
1399 ("Will the certificate be used for IPsec IKE operations? (y/N): ");
1404 get_crl_next_update (void)
1410 if (cfg
.crl_next_update
<= 0)
1413 return cfg
.crl_next_update
;
1419 days
= read_int ("The next CRL will be issued in (days): ");
1427 get_proxy_policy (char **policy
, size_t * policylen
)
1433 ret
= cfg
.proxy_policy_language
;
1435 ret
= "1.3.6.1.5.5.7.21.1";
1441 ret
= read_str ("Enter the OID of the proxy policy language: ");
1443 while (ret
== NULL
);
1449 if (strcmp (ret
, "1.3.6.1.5.5.7.21.1") != 0 &&
1450 strcmp (ret
, "1.3.6.1.5.5.7.21.2") != 0)
1452 fprintf (stderr
, "Reading non-standard proxy policy not supported.\n");
1461 get_country_crq_set (gnutls_x509_crq_t crq
)
1470 gnutls_x509_crq_set_dn_by_oid (crq
,
1471 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
1472 cfg
.country
, strlen (cfg
.country
));
1475 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1481 read_crq_set (crq
, "Country name (2 chars): ",
1482 GNUTLS_OID_X520_COUNTRY_NAME
);
1488 get_organization_crq_set (gnutls_x509_crq_t crq
)
1494 if (!cfg
.organization
)
1498 gnutls_x509_crq_set_dn_by_oid (crq
,
1499 GNUTLS_OID_X520_ORGANIZATION_NAME
,
1500 0, cfg
.organization
,
1501 strlen (cfg
.organization
));
1504 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1510 read_crq_set (crq
, "Organization name: ",
1511 GNUTLS_OID_X520_ORGANIZATION_NAME
);
1517 get_unit_crq_set (gnutls_x509_crq_t crq
)
1527 gnutls_x509_crq_set_dn_by_oid (crq
,
1528 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
1529 0, cfg
.unit
, strlen (cfg
.unit
));
1532 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1538 read_crq_set (crq
, "Organizational unit name: ",
1539 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
1545 get_state_crq_set (gnutls_x509_crq_t crq
)
1554 gnutls_x509_crq_set_dn_by_oid (crq
,
1555 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
1556 0, cfg
.state
, strlen (cfg
.state
));
1559 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1565 read_crq_set (crq
, "State or province name: ",
1566 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
1572 get_locality_crq_set (gnutls_x509_crq_t crq
)
1581 gnutls_x509_crq_set_dn_by_oid (crq
,
1582 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
1583 cfg
.locality
, strlen (cfg
.locality
));
1586 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1592 read_crq_set (crq
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
1598 get_cn_crq_set (gnutls_x509_crq_t crq
)
1607 gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_X520_COMMON_NAME
,
1608 0, cfg
.cn
, strlen (cfg
.cn
));
1611 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1617 read_crq_set (crq
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
1623 get_uid_crq_set (gnutls_x509_crq_t crq
)
1631 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_LDAP_UID
, 0,
1632 cfg
.uid
, strlen (cfg
.uid
));
1635 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1641 read_crq_set (crq
, "UID: ", GNUTLS_OID_LDAP_UID
);
1647 get_oid_crq_set (gnutls_x509_crq_t crq
)
1655 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
1657 if (cfg
.dn_oid
[i
+ 1] == NULL
)
1659 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
1663 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, cfg
.dn_oid
[i
], 0,
1665 strlen (cfg
.dn_oid
[i
+ 1]));
1669 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));