58 #ifndef OPENSSL_NO_OCSP
60 #ifdef OPENSSL_SYS_VMS
61 #define _XOPEN_SOURCE_EXTENDED
80 #if defined(NETWARE_CLIB)
81 # ifdef NETWARE_BSDSOCK
82 # include <sys/socket.h>
83 # include <sys/bsdskt.h>
85 # include <novsock2.h>
87 #elif defined(NETWARE_LIBC)
88 # ifdef NETWARE_BSDSOCK
89 # include <sys/select.h>
91 # include <novsock2.h>
96 #define MAX_VALIDITY_PERIOD (5 * 60)
110 int nmin,
int ndays);
113 static BIO *init_responder(
char *port);
121 #define PROG ocsp_main
123 int MAIN(
int,
char **);
125 int MAIN(
int argc,
char **argv)
129 char *host = NULL, *port = NULL, *path =
"/";
130 char *reqin = NULL, *respin = NULL;
131 char *reqout = NULL, *respout = NULL;
132 char *signfile = NULL, *keyfile = NULL;
133 char *rsignfile = NULL, *rkeyfile = NULL;
134 char *outfile = NULL;
135 int add_nonce = 1, noverify = 0, use_ssl = -1;
140 X509 *issuer = NULL, *cert = NULL;
141 X509 *signer = NULL, *rsigner = NULL;
143 BIO *acbio = NULL, *cbio = NULL;
146 int req_timeout = -1;
147 int req_text = 0, resp_text = 0;
149 char *CAfile = NULL, *CApath = NULL;
151 STACK_OF(
X509) *sign_other = NULL, *verify_other = NULL, *rother = NULL;
152 char *sign_certfile = NULL, *verify_certfile = NULL, *rcertfile = NULL;
153 unsigned long sign_flags = 0, verify_flags = 0, rflags = 0;
155 int accept_count = -1;
162 X509 *rca_cert = NULL;
163 char *ridx_filename = NULL;
164 char *rca_filename = NULL;
166 int nmin = 0, ndays = -1;
167 const EVP_MD *cert_id_md = NULL;
178 while (!badarg && *args && *args[0] ==
'-')
180 if (!strcmp(*args,
"-out"))
189 else if (!strcmp(*args,
"-timeout"))
194 req_timeout = atol(*args);
198 "Illegal timeout value %s\n",
205 else if (!strcmp(*args,
"-url"))
218 else if (!strcmp(*args,
"-host"))
227 else if (!strcmp(*args,
"-port"))
236 else if (!strcmp(*args,
"-header"))
238 if (args[1] && args[2])
246 else if (!strcmp(*args,
"-ignore_err"))
248 else if (!strcmp(*args,
"-noverify"))
250 else if (!strcmp(*args,
"-nonce"))
252 else if (!strcmp(*args,
"-no_nonce"))
254 else if (!strcmp(*args,
"-resp_no_certs"))
256 else if (!strcmp(*args,
"-resp_key_id"))
258 else if (!strcmp(*args,
"-no_certs"))
260 else if (!strcmp(*args,
"-no_signature_verify"))
262 else if (!strcmp(*args,
"-no_cert_verify"))
264 else if (!strcmp(*args,
"-no_chain"))
266 else if (!strcmp(*args,
"-no_cert_checks"))
268 else if (!strcmp(*args,
"-no_explicit"))
270 else if (!strcmp(*args,
"-trust_other"))
272 else if (!strcmp(*args,
"-no_intern"))
274 else if (!strcmp(*args,
"-text"))
279 else if (!strcmp(*args,
"-req_text"))
281 else if (!strcmp(*args,
"-resp_text"))
283 else if (!strcmp(*args,
"-reqin"))
292 else if (!strcmp(*args,
"-respin"))
301 else if (!strcmp(*args,
"-signer"))
310 else if (!strcmp (*args,
"-VAfile"))
315 verify_certfile = *args;
320 else if (!strcmp(*args,
"-sign_other"))
325 sign_certfile = *args;
329 else if (!strcmp(*args,
"-verify_other"))
334 verify_certfile = *args;
338 else if (!strcmp (*args,
"-CAfile"))
347 else if (!strcmp (*args,
"-CApath"))
356 else if (!strcmp (*args,
"-validity_period"))
365 "Illegal validity period %s\n",
372 else if (!strcmp (*args,
"-status_age"))
377 maxage = atol(*args);
381 "Illegal validity age %s\n",
388 else if (!strcmp(*args,
"-signkey"))
397 else if (!strcmp(*args,
"-reqout"))
406 else if (!strcmp(*args,
"-respout"))
415 else if (!strcmp(*args,
"-path"))
424 else if (!strcmp(*args,
"-issuer"))
431 NULL, e,
"issuer certificate");
432 if(!issuer)
goto end;
436 else if (!strcmp (*args,
"-cert"))
443 NULL, e,
"certificate");
445 if (!cert_id_md) cert_id_md =
EVP_sha1();
446 if(!add_ocsp_cert(&req, cert, cert_id_md, issuer, ids))
453 else if (!strcmp(*args,
"-serial"))
458 if (!cert_id_md) cert_id_md =
EVP_sha1();
459 if(!add_ocsp_serial(&req, *args, cert_id_md, issuer, ids))
466 else if (!strcmp(*args,
"-index"))
471 ridx_filename = *args;
475 else if (!strcmp(*args,
"-CA"))
480 rca_filename = *args;
484 else if (!strcmp (*args,
"-nmin"))
493 "Illegal update period %s\n",
502 else if (!strcmp (*args,
"-nrequest"))
507 accept_count = atol(*args);
508 if (accept_count < 0)
511 "Illegal accept count %s\n",
518 else if (!strcmp (*args,
"-ndays"))
527 "Illegal update period %s\n",
534 else if (!strcmp(*args,
"-rsigner"))
543 else if (!strcmp(*args,
"-rkey"))
552 else if (!strcmp(*args,
"-rother"))
569 if (!req && !reqin && !respin && !(port && ridx_filename)) badarg = 1;
582 BIO_printf (
bio_err,
"-sign_other file additional certificates to include in signed request\n");
583 BIO_printf (
bio_err,
"-no_certs don't include any certificates in signed request\n");
587 BIO_printf (
bio_err,
"-reqout file write DER encoded OCSP request to \"file\"\n");
588 BIO_printf (
bio_err,
"-respout file write DER encoded OCSP reponse to \"file\"\n");
589 BIO_printf (
bio_err,
"-reqin file read DER encoded OCSP request from \"file\"\n");
590 BIO_printf (
bio_err,
"-respin file read DER encoded OCSP reponse from \"file\"\n");
599 BIO_printf (
bio_err,
"-validity_period n maximum validity discrepancy in seconds\n");
602 BIO_printf (
bio_err,
"-verify_other file additional certificates to search for signer\n");
604 BIO_printf (
bio_err,
"-no_intern don't search certificates contained in response for signer\n");
605 BIO_printf (
bio_err,
"-no_signature_verify don't check signature on response\n");
608 BIO_printf (
bio_err,
"-no_cert_checks don't do additional checks on signing certificate\n");
612 BIO_printf (
bio_err,
"-rsigner file responder certificate to sign responses with\n");
614 BIO_printf (
bio_err,
"-rother file other certificates to include in response\n");
615 BIO_printf (
bio_err,
"-resp_no_certs don't include any certificates in response\n");
618 BIO_printf (
bio_err,
"-resp_key_id identify reponse by signing certificate key ID\n");
619 BIO_printf (
bio_err,
"-nrequest n number of requests to accept (default unlimited)\n");
633 if (!req && (add_nonce != 2)) add_nonce = 0;
654 acbio = init_responder(port);
659 if (rsignfile && !rdb)
661 if (!rkeyfile) rkeyfile = rsignfile;
663 NULL, e,
"responder certificate");
670 NULL, e,
"CA certificate");
674 NULL, e,
"responder other certificates");
675 if (!rother)
goto end;
678 "responder private key");
689 if (!do_responder(&req, &cbio, acbio, port))
694 send_ocsp_response(cbio, resp);
699 if (!req && (signfile || reqout || host || add_nonce || ridx_filename))
709 if (!keyfile) keyfile = signfile;
711 NULL, e,
"signer certificate");
720 NULL, e,
"signer certificates");
721 if (!sign_other)
goto end;
724 "signer private key");
749 if (ridx_filename && (!rkey || !rsigner || !rca_cert))
751 BIO_printf(
bio_err,
"Need a responder certificate, key and CA for this operation!\n");
755 if (ridx_filename && !rdb)
764 i = make_ocsp_response(&resp, req, rdb, rca_cert, rsigner, rkey, rother, rflags, nmin, ndays);
766 send_ocsp_response(cbio, resp);
770 #ifndef OPENSSL_NO_SOCK
772 port, use_ssl, headers, req_timeout);
834 if (accept_count > 0)
841 OCSP_REQUEST_free(req);
843 OCSP_RESPONSE_free(resp);
857 NULL, e,
"validator certificate");
858 if (!verify_other)
goto end;
895 if (!print_ocsp_summary(out, bs, req, reqnames, ids, nsec, maxage))
914 OCSP_REQUEST_free(req);
915 OCSP_RESPONSE_free(resp);
916 OCSP_BASICRESP_free(bs);
942 if(!*req) *req = OCSP_REQUEST_new();
966 if(!*req) *req = OCSP_REQUEST_new();
977 ASN1_INTEGER_free(sno);
1010 &rev, &thisupd, &nextupd))
1012 BIO_puts(out,
"ERROR: No Status found.\n");
1021 BIO_puts(out,
"WARNING: Status times invalid.\n");
1044 BIO_puts(out,
"\tRevocation Time: ");
1056 int nmin,
int ndays)
1058 ASN1_TIME *thisupd = NULL, *nextupd = NULL;
1061 int i, id_count, ret = 1;
1072 bs = OCSP_BASICRESP_new();
1078 for (i = 0; i < id_count; i++)
1084 const EVP_MD *cert_id_md;
1097 if (ca_id) OCSP_CERTID_free(ca_id);
1110 inf = lookup_serial(db, serial);
1138 ASN1_TIME_free(revtm);
1139 ASN1_GENERALIZEDTIME_free(invtm);
1150 ASN1_TIME_free(thisupd);
1151 ASN1_TIME_free(nextupd);
1152 OCSP_CERTID_free(ca_id);
1153 OCSP_BASICRESP_free(bs);
1163 for (i = 0; i <
DB_NUMBER; i++) row[i] = NULL;
1179 static BIO *init_responder(
char *port)
1181 BIO *acbio = NULL, *bufbio = NULL;
1185 #ifndef OPENSSL_NO_SOCK
1212 int have_post = 0,
len;
1235 if(strncmp(inbuf,
"POST", 4))
1243 if ((inbuf[0] ==
'\r') || (inbuf[0] ==
'\n'))
1266 "HTTP/1.0 200 OK\r\nContent-type: application/ocsp-response\r\n"
1267 "Content-Length: %d\r\n\r\n";
1270 BIO_printf(cbio, http_resp, i2d_OCSP_RESPONSE(resp, NULL));
1288 if (req_timeout != -1)
1295 BIO_puts(err,
"Error connecting BIO\n");
1301 BIO_puts(err,
"Can't get connection fd\n");
1305 if (req_timeout != -1 && rv <= 0)
1310 tv.tv_sec = req_timeout;
1311 rv = select(fd + 1, NULL, (
void *)&confds, NULL, &tv);
1314 BIO_puts(err,
"Timeout on connect\n");
1339 if (req_timeout == -1)
1344 tv.tv_sec = req_timeout;
1346 rv = select(fd + 1, (
void *)&confds, NULL, NULL, &tv);
1348 rv = select(fd + 1, NULL, (
void *)&confds, NULL, &tv);
1351 BIO_puts(err,
"Unexpected retry condition\n");
1356 BIO_puts(err,
"Timeout on request\n");
1374 char *host,
char *path,
char *port,
int use_ssl,
1384 BIO_printf(err,
"Error creating connect BIO\n");
1391 #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
1393 #elif !defined(OPENSSL_NO_SSL3)
1395 #elif !defined(OPENSSL_NO_SSL2)
1403 BIO_printf(err,
"Error creating SSL context.\n");
1410 resp = query_responder(err, cbio, path, headers, req, req_timeout);