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 16
53 typedef struct _cfg_ctx
61 char *challenge_password
;
69 char *crl_dist_points
;
71 char *pkcs12_key_name
;
84 int time_stamping_key
;
86 char **key_purpose_oids
;
90 char *proxy_policy_language
;
92 char **ca_issuers_uris
;
100 memset (&cfg
, 0, sizeof (cfg
));
105 #define READ_MULTI_LINE(name, s_name) \
106 val = optionGetValue(pov, name); \
107 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
109 if (s_name == NULL) { \
111 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
113 if (val && !strcmp(val->pzName, name)==0) \
115 s_name[i] = strdup(val->v.strVal); \
117 if (i>=MAX_ENTRIES) \
119 } while((val = optionNextValue(pov, val)) != NULL); \
124 #define READ_MULTI_LINE_TOKENIZED(name, s_name) \
125 val = optionGetValue(pov, name); \
126 if (val != NULL && val->valType == OPARG_TYPE_STRING) \
130 if (s_name == NULL) { \
132 s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
134 if (val && !strcmp(val->pzName, name)==0) \
136 strncpy(str, val->v.strVal, sizeof(str)-1); \
137 str[sizeof(str)-1] = 0; \
138 if ((p=strchr(str, ' ')) == NULL && (p=strchr(str, '\t')) == NULL) { \
139 fprintf(stderr, "Error parsing %s\n", name); \
144 s_name[i] = strdup(str); \
145 while(*p==' ' || *p == '\t') p++; \
147 fprintf(stderr, "Error (2) parsing %s\n", name); \
150 s_name[i+1] = strdup(p); \
152 if (i>=MAX_ENTRIES) \
154 } while((val = optionNextValue(pov, val)) != NULL); \
159 #define READ_BOOLEAN(name, s_name) \
160 val = optionGetValue(pov, name); \
166 #define READ_NUMERIC(name, s_name) \
167 val = optionGetValue(pov, name); \
170 if (val->valType == OPARG_TYPE_NUMERIC) \
171 s_name = val->v.longVal; \
172 else if (val->valType == OPARG_TYPE_STRING) \
173 s_name = atoi(val->v.strVal); \
177 template_parse (const char *template)
179 /* Parsing return code */
182 tOptionValue
const * pov
;
183 const tOptionValue
* val
;
185 pov
= configFileLoad(template);
188 perror("configFileLoad");
189 fprintf(stderr
, "Error loading template: %s\n", template);
193 /* Option variables */
194 val
= optionGetValue(pov
, "organization");
195 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
196 cfg
.organization
= strdup(val
->v
.strVal
);
198 val
= optionGetValue(pov
, "unit");
199 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
200 cfg
.unit
= strdup(val
->v
.strVal
);
202 val
= optionGetValue(pov
, "locality");
203 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
204 cfg
.locality
= strdup(val
->v
.strVal
);
206 val
= optionGetValue(pov
, "state");
207 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
208 cfg
.state
= strdup(val
->v
.strVal
);
210 val
= optionGetValue(pov
, "cn");
211 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
212 cfg
.cn
= strdup(val
->v
.strVal
);
214 val
= optionGetValue(pov
, "uid");
215 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
216 cfg
.uid
= strdup(val
->v
.strVal
);
218 val
= optionGetValue(pov
, "challenge_password");
219 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
220 cfg
.challenge_password
= strdup(val
->v
.strVal
);
222 val
= optionGetValue(pov
, "password");
223 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
224 cfg
.password
= strdup(val
->v
.strVal
);
226 val
= optionGetValue(pov
, "pkcs9_email");
227 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
228 cfg
.pkcs9_email
= strdup(val
->v
.strVal
);
230 val
= optionGetValue(pov
, "country");
231 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
232 cfg
.country
= strdup(val
->v
.strVal
);
234 READ_MULTI_LINE("dc", cfg
.dc
);
235 READ_MULTI_LINE("dns_name", cfg
.dns_name
);
236 READ_MULTI_LINE("ip_address", cfg
.ip_addr
);
237 READ_MULTI_LINE("email", cfg
.email
);
238 READ_MULTI_LINE("key_purpose_oid", cfg
.key_purpose_oids
);
240 READ_MULTI_LINE_TOKENIZED("dn_oid", cfg
.dn_oid
);
242 val
= optionGetValue(pov
, "crl_dist_points");
243 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
244 cfg
.crl_dist_points
= strdup(val
->v
.strVal
);
246 val
= optionGetValue(pov
, "pkcs12_key_name");
247 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
248 cfg
.pkcs12_key_name
= strdup(val
->v
.strVal
);
251 READ_NUMERIC("serial", cfg
.serial
);
252 READ_NUMERIC("expiration_days", cfg
.expiration_days
);
253 READ_NUMERIC("crl_next_update", cfg
.crl_next_update
);
254 READ_NUMERIC("crl_number", cfg
.crl_number
);
256 val
= optionGetValue(pov
, "proxy_policy_language");
257 if (val
!= NULL
&& val
->valType
== OPARG_TYPE_STRING
)
258 cfg
.proxy_policy_language
= strdup(val
->v
.strVal
);
260 READ_MULTI_LINE("ocsp_uri", cfg
.ocsp_uris
);
261 READ_MULTI_LINE("ca_issuers_uri", cfg
.ca_issuers_uris
);
263 READ_BOOLEAN("ca", cfg
.ca
);
264 READ_BOOLEAN("honor_crq_extensions", cfg
.crq_extensions
);
265 READ_BOOLEAN("path_len", cfg
.path_len
);
266 READ_BOOLEAN("tls_www_client", cfg
.tls_www_client
);
267 READ_BOOLEAN("tls_www_server", cfg
.tls_www_server
);
268 READ_BOOLEAN("signing_key", cfg
.signing_key
);
269 READ_BOOLEAN("encryption_key", cfg
.encryption_key
);
270 READ_BOOLEAN("cert_signing_key", cfg
.cert_sign_key
);
271 READ_BOOLEAN("crl_signing_key", cfg
.crl_sign_key
);
272 READ_BOOLEAN("code_signing_key", cfg
.code_sign_key
);
273 READ_BOOLEAN("ocsp_signing_key", cfg
.ocsp_sign_key
);
274 READ_BOOLEAN("time_stamping_key", cfg
.time_stamping_key
);
275 READ_BOOLEAN("ipsec_ike_key", cfg
.ipsec_ike_key
);
277 optionUnloadNested(pov
);
282 #define IS_NEWLINE(x) ((x[0] == '\n') || (x[0] == '\r'))
285 read_crt_set (gnutls_x509_crt_t crt
, const char *input_str
, const char *oid
)
290 fputs (input_str
, stderr
);
291 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
294 if (IS_NEWLINE(input
))
298 gnutls_x509_crt_set_dn_by_oid (crt
, oid
, 0, input
, strlen (input
) - 1);
301 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
307 read_crq_set (gnutls_x509_crq_t crq
, const char *input_str
, const char *oid
)
312 fputs (input_str
, stderr
);
313 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
316 if (IS_NEWLINE(input
))
320 gnutls_x509_crq_set_dn_by_oid (crq
, oid
, 0, input
, strlen (input
) - 1);
323 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
328 /* The input_str should contain %d or %u to print the default.
331 read_int_with_default (const char *input_str
, int def
)
335 static char input
[128];
337 fprintf (stderr
, input_str
, def
);
338 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
341 if (IS_NEWLINE(input
))
344 len
= strlen (input
);
346 l
= strtol (input
, &endptr
, 0);
348 if (*endptr
!= '\0' && *endptr
!= '\r' && *endptr
!= '\n')
350 fprintf (stderr
, "Trailing garbage ignored: `%s'\n", endptr
);
354 if (l
<= INT_MIN
|| l
>= INT_MAX
)
356 fprintf (stderr
, "Integer out of range: `%s'\n", input
);
367 read_int (const char *input_str
)
369 return read_int_with_default (input_str
, 0);
373 read_str (const char *input_str
)
375 static char input
[128];
378 fputs (input_str
, stderr
);
379 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
382 if (IS_NEWLINE(input
))
385 len
= strlen (input
);
386 if ((len
> 0) && (input
[len
- 1] == '\n'))
397 read_yesno (const char *input_str
)
401 fputs (input_str
, stderr
);
402 if (fgets (input
, sizeof (input
), stdin
) == NULL
)
405 if (IS_NEWLINE(input
))
408 if (input
[0] == 'y' || input
[0] == 'Y')
415 /* Wrapper functions for non-interactive mode.
423 return getpass ("Enter password: ");
427 get_confirmed_pass (bool empty_ok
)
433 const char *pass
= NULL
;
439 printf ("Password missmatch, try again.\n");
443 pass
= getpass ("Enter password: ");
444 copy
= strdup (pass
);
445 pass
= getpass ("Confirm password: ");
447 while (strcmp (pass
, copy
) != 0 && !(empty_ok
&& *pass
== '\0'));
456 get_challenge_pass (void)
459 return cfg
.challenge_password
;
461 return getpass ("Enter a challenge password: ");
465 get_crl_dist_point_url (void)
468 return cfg
.crl_dist_points
;
470 return read_str ("Enter the URI of the CRL distribution point: ");
474 get_country_crt_set (gnutls_x509_crt_t crt
)
483 gnutls_x509_crt_set_dn_by_oid (crt
,
484 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
485 cfg
.country
, strlen (cfg
.country
));
488 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
494 read_crt_set (crt
, "Country name (2 chars): ",
495 GNUTLS_OID_X520_COUNTRY_NAME
);
501 get_organization_crt_set (gnutls_x509_crt_t crt
)
507 if (!cfg
.organization
)
511 gnutls_x509_crt_set_dn_by_oid (crt
,
512 GNUTLS_OID_X520_ORGANIZATION_NAME
,
514 strlen (cfg
.organization
));
517 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
523 read_crt_set (crt
, "Organization name: ",
524 GNUTLS_OID_X520_ORGANIZATION_NAME
);
530 get_unit_crt_set (gnutls_x509_crt_t crt
)
540 gnutls_x509_crt_set_dn_by_oid (crt
,
541 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
542 0, cfg
.unit
, strlen (cfg
.unit
));
545 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
551 read_crt_set (crt
, "Organizational unit name: ",
552 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
558 get_state_crt_set (gnutls_x509_crt_t crt
)
567 gnutls_x509_crt_set_dn_by_oid (crt
,
568 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
569 0, cfg
.state
, strlen (cfg
.state
));
572 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
578 read_crt_set (crt
, "State or province name: ",
579 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
585 get_locality_crt_set (gnutls_x509_crt_t crt
)
594 gnutls_x509_crt_set_dn_by_oid (crt
,
595 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
596 cfg
.locality
, strlen (cfg
.locality
));
599 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
605 read_crt_set (crt
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
611 get_cn_crt_set (gnutls_x509_crt_t crt
)
620 gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_X520_COMMON_NAME
,
621 0, cfg
.cn
, strlen (cfg
.cn
));
624 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
630 read_crt_set (crt
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
636 get_uid_crt_set (gnutls_x509_crt_t crt
)
644 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_UID
, 0,
645 cfg
.uid
, strlen (cfg
.uid
));
648 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
654 read_crt_set (crt
, "UID: ", GNUTLS_OID_LDAP_UID
);
660 get_oid_crt_set (gnutls_x509_crt_t crt
)
668 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
670 if (cfg
.dn_oid
[i
+ 1] == NULL
)
672 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
676 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, cfg
.dn_oid
[i
], 0,
678 strlen (cfg
.dn_oid
[i
+ 1]));
682 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));
690 get_key_purpose_set (gnutls_x509_crt_t crt
)
696 if (!cfg
.key_purpose_oids
)
698 for (i
= 0; cfg
.key_purpose_oids
[i
] != NULL
; i
++)
701 gnutls_x509_crt_set_key_purpose_oid (crt
, cfg
.key_purpose_oids
[i
],
706 fprintf (stderr
, "set_key_purpose_oid (%s): %s\n",
707 cfg
.key_purpose_oids
[i
], gnutls_strerror (ret
));
715 get_ocsp_issuer_set (gnutls_x509_crt_t crt
)
724 for (i
= 0; cfg
.ocsp_uris
[i
] != NULL
; i
++)
726 uri
.data
= cfg
.ocsp_uris
[i
];
727 uri
.size
= strlen(cfg
.ocsp_uris
[i
]);
729 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_OCSP_URI
,
733 fprintf (stderr
, "set OCSP URI (%s): %s\n",
734 cfg
.ocsp_uris
[i
], gnutls_strerror (ret
));
742 get_ca_issuers_set (gnutls_x509_crt_t crt
)
749 if (!cfg
.ca_issuers_uris
)
751 for (i
= 0; cfg
.ca_issuers_uris
[i
] != NULL
; i
++)
753 uri
.data
= cfg
.ca_issuers_uris
[i
];
754 uri
.size
= strlen(cfg
.ca_issuers_uris
[i
]);
756 gnutls_x509_crt_set_authority_info_access (crt
, GNUTLS_IA_CAISSUERS_URI
,
760 fprintf (stderr
, "set CA ISSUERS URI (%s): %s\n",
761 cfg
.ca_issuers_uris
[i
], gnutls_strerror (ret
));
770 get_pkcs9_email_crt_set (gnutls_x509_crt_t crt
)
776 if (!cfg
.pkcs9_email
)
778 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_PKCS9_EMAIL
, 0,
780 strlen (cfg
.pkcs9_email
));
783 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
789 read_crt_set (crt
, "E-mail: ", GNUTLS_OID_PKCS9_EMAIL
);
797 int default_serial
= time (NULL
);
802 return default_serial
;
807 return read_int_with_default
808 ("Enter the certificate's serial number in decimal (default: %u): ",
820 if (cfg
.expiration_days
<= 0)
823 return cfg
.expiration_days
;
829 days
= read_int ("The certificate will expire in (days): ");
846 read_yesno ("Does the certificate belong to an authority? (y/N): ");
851 get_crq_extensions_status (void)
855 return cfg
.crq_extensions
;
861 ("Do you want to honour the extensions from the request? (y/N): ");
866 get_crl_number (void)
870 return cfg
.crl_number
;
874 return read_int_with_default ("CRL Number: ", 1);
887 return read_int_with_default
888 ("Path length constraint (decimal, %d for no constraint): ", -1);
893 get_pkcs12_key_name (void)
899 if (!cfg
.pkcs12_key_name
)
901 return cfg
.pkcs12_key_name
;
907 name
= read_str ("Enter a name for the key: ");
909 while (name
== NULL
);
915 get_tls_client_status (void)
919 return cfg
.tls_www_client
;
923 return read_yesno ("Is this a TLS web client certificate? (y/N): ");
928 get_tls_server_status (void)
932 return cfg
.tls_www_server
;
937 read_yesno ("Is this also a TLS web server certificate? (y/N): ");
941 /* convert a printable IP to binary */
943 string_to_ip (unsigned char *ip
, const char *str
)
945 int len
= strlen (str
);
949 if (strchr (str
, ':') != NULL
|| len
> 16)
951 ret
= inet_pton (AF_INET6
, str
, ip
);
954 fprintf (stderr
, "Error in IPv6 address %s\n", str
);
964 ret
= inet_pton (AF_INET
, str
, ip
);
967 fprintf (stderr
, "Error in IPv4 address %s\n", str
);
977 get_ip_addr_set (int type
, void *crt
)
980 unsigned char ip
[16];
988 for (i
= 0; cfg
.ip_addr
[i
] != NULL
; i
++)
990 len
= string_to_ip (ip
, cfg
.ip_addr
[i
]);
993 fprintf (stderr
, "Error parsing address: %s\n", cfg
.ip_addr
[i
]);
997 if (type
== TYPE_CRT
)
999 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1001 GNUTLS_FSAN_APPEND
);
1004 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1006 GNUTLS_FSAN_APPEND
);
1017 read_str ("Enter the IP address of the subject of the certificate: ");
1021 len
= string_to_ip (ip
, p
);
1024 fprintf (stderr
, "Error parsing address: %s\n", p
);
1028 if (type
== TYPE_CRT
)
1029 ret
= gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1031 GNUTLS_FSAN_APPEND
);
1033 ret
= gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_IPADDRESS
,
1035 GNUTLS_FSAN_APPEND
);
1040 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1046 get_email_set (int type
, void *crt
)
1055 for (i
= 0; cfg
.email
[i
] != NULL
; i
++)
1057 if (type
== TYPE_CRT
)
1059 gnutls_x509_crt_set_subject_alt_name (crt
,
1060 GNUTLS_SAN_RFC822NAME
,
1062 strlen (cfg
.email
[i
]),
1063 GNUTLS_FSAN_APPEND
);
1066 gnutls_x509_crq_set_subject_alt_name (crt
,
1067 GNUTLS_SAN_RFC822NAME
,
1069 strlen (cfg
.email
[i
]),
1070 GNUTLS_FSAN_APPEND
);
1080 p
= read_str ("Enter the e-mail of the subject of the certificate: ");
1084 if (type
== TYPE_CRT
)
1086 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1088 GNUTLS_FSAN_APPEND
);
1091 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_RFC822NAME
, p
,
1093 GNUTLS_FSAN_APPEND
);
1098 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1105 get_dc_set (int type
, void *crt
)
1114 for (i
= 0; cfg
.dc
[i
] != NULL
; i
++)
1116 if (type
== TYPE_CRT
)
1117 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1118 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1120 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1121 0, cfg
.dc
[i
], strlen (cfg
.dc
[i
]));
1133 p
= read_str ("Enter the subject's domain component (DC): ");
1137 if (type
== TYPE_CRT
)
1138 ret
= gnutls_x509_crt_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1141 ret
= gnutls_x509_crq_set_dn_by_oid (crt
, GNUTLS_OID_LDAP_DC
,
1149 fprintf (stderr
, "set_dn_by_oid: %s\n", gnutls_strerror (ret
));
1155 get_dns_name_set (int type
, void *crt
)
1164 for (i
= 0; cfg
.dns_name
[i
] != NULL
; i
++)
1166 if (type
== TYPE_CRT
)
1168 gnutls_x509_crt_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1170 strlen (cfg
.dns_name
[i
]),
1171 GNUTLS_FSAN_APPEND
);
1174 gnutls_x509_crq_set_subject_alt_name (crt
, GNUTLS_SAN_DNSNAME
,
1176 strlen (cfg
.dns_name
[i
]),
1177 GNUTLS_FSAN_APPEND
);
1190 read_str ("Enter a dnsName of the subject of the certificate: ");
1194 if (type
== TYPE_CRT
)
1195 ret
= gnutls_x509_crt_set_subject_alt_name
1196 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1198 ret
= gnutls_x509_crq_set_subject_alt_name
1199 (crt
, GNUTLS_SAN_DNSNAME
, p
, strlen (p
), GNUTLS_FSAN_APPEND
);
1206 fprintf (stderr
, "set_subject_alt_name: %s\n", gnutls_strerror (ret
));
1213 get_sign_status (int server
)
1219 return cfg
.signing_key
;
1225 "Will the certificate be used for signing (DHE and RSA-EXPORT ciphersuites)? (y/N): ";
1228 "Will the certificate be used for signing (required for TLS)? (y/N): ";
1229 return read_yesno (msg
);
1234 get_encrypt_status (int server
)
1240 return cfg
.encryption_key
;
1246 "Will the certificate be used for encryption (RSA ciphersuites)? (y/N): ";
1249 "Will the certificate be used for encryption (not required for TLS)? (y/N): ";
1250 return read_yesno (msg
);
1255 get_cert_sign_status (void)
1259 return cfg
.cert_sign_key
;
1265 ("Will the certificate be used to sign other certificates? (y/N): ");
1270 get_crl_sign_status (void)
1274 return cfg
.crl_sign_key
;
1279 read_yesno ("Will the certificate be used to sign CRLs? (y/N): ");
1284 get_code_sign_status (void)
1288 return cfg
.code_sign_key
;
1293 read_yesno ("Will the certificate be used to sign code? (y/N): ");
1298 get_ocsp_sign_status (void)
1302 return cfg
.ocsp_sign_key
;
1308 ("Will the certificate be used to sign OCSP requests? (y/N): ");
1313 get_time_stamp_status (void)
1317 return cfg
.time_stamping_key
;
1323 ("Will the certificate be used for time stamping? (y/N): ");
1328 get_ipsec_ike_status (void)
1332 return cfg
.ipsec_ike_key
;
1338 ("Will the certificate be used for IPsec IKE operations? (y/N): ");
1343 get_crl_next_update (void)
1349 if (cfg
.crl_next_update
<= 0)
1352 return cfg
.crl_next_update
;
1358 days
= read_int ("The next CRL will be issued in (days): ");
1366 get_proxy_policy (char **policy
, size_t * policylen
)
1372 ret
= cfg
.proxy_policy_language
;
1374 ret
= "1.3.6.1.5.5.7.21.1";
1380 ret
= read_str ("Enter the OID of the proxy policy language: ");
1382 while (ret
== NULL
);
1388 if (strcmp (ret
, "1.3.6.1.5.5.7.21.1") != 0 &&
1389 strcmp (ret
, "1.3.6.1.5.5.7.21.2") != 0)
1391 fprintf (stderr
, "Reading non-standard proxy policy not supported.\n");
1400 get_country_crq_set (gnutls_x509_crq_t crq
)
1409 gnutls_x509_crq_set_dn_by_oid (crq
,
1410 GNUTLS_OID_X520_COUNTRY_NAME
, 0,
1411 cfg
.country
, strlen (cfg
.country
));
1414 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1420 read_crq_set (crq
, "Country name (2 chars): ",
1421 GNUTLS_OID_X520_COUNTRY_NAME
);
1427 get_organization_crq_set (gnutls_x509_crq_t crq
)
1433 if (!cfg
.organization
)
1437 gnutls_x509_crq_set_dn_by_oid (crq
,
1438 GNUTLS_OID_X520_ORGANIZATION_NAME
,
1439 0, cfg
.organization
,
1440 strlen (cfg
.organization
));
1443 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1449 read_crq_set (crq
, "Organization name: ",
1450 GNUTLS_OID_X520_ORGANIZATION_NAME
);
1456 get_unit_crq_set (gnutls_x509_crq_t crq
)
1466 gnutls_x509_crq_set_dn_by_oid (crq
,
1467 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
,
1468 0, cfg
.unit
, strlen (cfg
.unit
));
1471 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1477 read_crq_set (crq
, "Organizational unit name: ",
1478 GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME
);
1484 get_state_crq_set (gnutls_x509_crq_t crq
)
1493 gnutls_x509_crq_set_dn_by_oid (crq
,
1494 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
,
1495 0, cfg
.state
, strlen (cfg
.state
));
1498 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1504 read_crq_set (crq
, "State or province name: ",
1505 GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME
);
1511 get_locality_crq_set (gnutls_x509_crq_t crq
)
1520 gnutls_x509_crq_set_dn_by_oid (crq
,
1521 GNUTLS_OID_X520_LOCALITY_NAME
, 0,
1522 cfg
.locality
, strlen (cfg
.locality
));
1525 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1531 read_crq_set (crq
, "Locality name: ", GNUTLS_OID_X520_LOCALITY_NAME
);
1537 get_cn_crq_set (gnutls_x509_crq_t crq
)
1546 gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_X520_COMMON_NAME
,
1547 0, cfg
.cn
, strlen (cfg
.cn
));
1550 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1556 read_crq_set (crq
, "Common name: ", GNUTLS_OID_X520_COMMON_NAME
);
1562 get_uid_crq_set (gnutls_x509_crq_t crq
)
1570 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, GNUTLS_OID_LDAP_UID
, 0,
1571 cfg
.uid
, strlen (cfg
.uid
));
1574 fprintf (stderr
, "set_dn: %s\n", gnutls_strerror (ret
));
1580 read_crq_set (crq
, "UID: ", GNUTLS_OID_LDAP_UID
);
1586 get_oid_crq_set (gnutls_x509_crq_t crq
)
1594 for (i
= 0; cfg
.dn_oid
[i
] != NULL
; i
+= 2)
1596 if (cfg
.dn_oid
[i
+ 1] == NULL
)
1598 fprintf (stderr
, "dn_oid: %s does not have an argument.\n",
1602 ret
= gnutls_x509_crq_set_dn_by_oid (crq
, cfg
.dn_oid
[i
], 0,
1604 strlen (cfg
.dn_oid
[i
+ 1]));
1608 fprintf (stderr
, "set_dn_oid: %s\n", gnutls_strerror (ret
));