Add Broadwell performance results.
[openssl.git] / apps / ocsp.c
index 65e20e36d4495ed4e7aa3c338f574128775ef611..a3958ff9cc2be6b3a5729f8c4a26394a21793964 100644 (file)
@@ -105,17 +105,17 @@ static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
                              long maxage);
 
 static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db,
-                       X509 *ca, X509 *rcert, EVP_PKEY *rkey,
+                       X509 *ca, X509 *rcert, EVP_PKEY *rkey, const EVP_MD *md,
                        STACK_OF(X509) *rother, unsigned long flags,
                        int nmin, int ndays, int badsig);
 
 static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser);
-static BIO *init_responder(char *port);
-static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, char *port);
+static BIO *init_responder(const char *port);
+static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, const char *port);
 static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp);
-static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
-                               STACK_OF(CONF_VALUE) *headers,
-                               OCSP_REQUEST *req, int req_timeout);
+static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, const char *path,
+                                     const STACK_OF(CONF_VALUE) *headers,
+                                     OCSP_REQUEST *req, int req_timeout);
 
 #undef PROG
 #define PROG ocsp_main
@@ -127,6 +127,7 @@ int MAIN(int argc, char **argv)
        ENGINE *e = NULL;
        char **args;
        char *host = NULL, *port = NULL, *path = "/";
+       char *thost = NULL, *tport = NULL, *tpath = NULL;
        char *reqin = NULL, *respin = NULL;
        char *reqout = NULL, *respout = NULL;
        char *signfile = NULL, *keyfile = NULL;
@@ -166,7 +167,7 @@ int MAIN(int argc, char **argv)
        char *rca_filename = NULL;
        CA_DB *rdb = NULL;
        int nmin = 0, ndays = -1;
-       const EVP_MD *cert_id_md = NULL;
+       const EVP_MD *cert_id_md = NULL, *rsign_md = NULL;
 
        if (bio_err == NULL) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
 
@@ -206,6 +207,12 @@ int MAIN(int argc, char **argv)
                        }
                else if (!strcmp(*args, "-url"))
                        {
+                       if (thost)
+                               OPENSSL_free(thost);
+                       if (tport)
+                               OPENSSL_free(tport);
+                       if (tpath)
+                               OPENSSL_free(tpath);
                        if (args[1])
                                {
                                args++;
@@ -214,6 +221,9 @@ int MAIN(int argc, char **argv)
                                        BIO_printf(bio_err, "Error parsing URL\n");
                                        badarg = 1;
                                        }
+                               thost = host;
+                               tport = port;
+                               tpath = path;
                                }
                        else badarg = 1;
                        }
@@ -568,6 +578,17 @@ int MAIN(int argc, char **argv)
                                }
                        else badarg = 1;
                        }
+               else if (!strcmp(*args, "-rmd"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               rsign_md = EVP_get_digestbyname(*args);
+                               if (!rsign_md)
+                                       badarg = 1;
+                               }
+                       else badarg = 1;
+                       }
                else if ((cert_id_md = EVP_get_digestbyname((*args)+1))==NULL)
                        {
                        badarg = 1;
@@ -583,51 +604,53 @@ int MAIN(int argc, char **argv)
                BIO_printf (bio_err, "OCSP utility\n");
                BIO_printf (bio_err, "Usage ocsp [options]\n");
                BIO_printf (bio_err, "where options are\n");
-               BIO_printf (bio_err, "-out file          output filename\n");
-               BIO_printf (bio_err, "-issuer file       issuer certificate\n");
-               BIO_printf (bio_err, "-cert file         certificate to check\n");
-               BIO_printf (bio_err, "-serial n          serial number to check\n");
-               BIO_printf (bio_err, "-signer file       certificate to sign OCSP request with\n");
-               BIO_printf (bio_err, "-signkey file      private key to sign OCSP request with\n");
-               BIO_printf (bio_err, "-sign_other file   additional certificates to include in signed request\n");
-               BIO_printf (bio_err, "-no_certs          don't include any certificates in signed request\n");
-               BIO_printf (bio_err, "-req_text          print text form of request\n");
-               BIO_printf (bio_err, "-resp_text         print text form of response\n");
-               BIO_printf (bio_err, "-text              print text form of request and response\n");
-               BIO_printf (bio_err, "-reqout file       write DER encoded OCSP request to \"file\"\n");
-               BIO_printf (bio_err, "-respout file      write DER encoded OCSP reponse to \"file\"\n");
-               BIO_printf (bio_err, "-reqin file        read DER encoded OCSP request from \"file\"\n");
-               BIO_printf (bio_err, "-respin file       read DER encoded OCSP reponse from \"file\"\n");
-               BIO_printf (bio_err, "-nonce             add OCSP nonce to request\n");
-               BIO_printf (bio_err, "-no_nonce          don't add OCSP nonce to request\n");
-               BIO_printf (bio_err, "-url URL           OCSP responder URL\n");
-               BIO_printf (bio_err, "-host host:n       send OCSP request to host on port n\n");
-               BIO_printf (bio_err, "-path              path to use in OCSP request\n");
-               BIO_printf (bio_err, "-CApath dir        trusted certificates directory\n");
-               BIO_printf (bio_err, "-CAfile file       trusted certificates file\n");
-               BIO_printf (bio_err, "-VAfile file       validator certificates file\n");
-               BIO_printf (bio_err, "-validity_period n maximum validity discrepancy in seconds\n");
-               BIO_printf (bio_err, "-status_age n      maximum status age in seconds\n");
-               BIO_printf (bio_err, "-noverify          don't verify response at all\n");
-               BIO_printf (bio_err, "-verify_other file additional certificates to search for signer\n");
-               BIO_printf (bio_err, "-trust_other       don't verify additional certificates\n");
-               BIO_printf (bio_err, "-no_intern         don't search certificates contained in response for signer\n");
+               BIO_printf (bio_err, "-out file            output filename\n");
+               BIO_printf (bio_err, "-issuer file         issuer certificate\n");
+               BIO_printf (bio_err, "-cert file           certificate to check\n");
+               BIO_printf (bio_err, "-serial n            serial number to check\n");
+               BIO_printf (bio_err, "-signer file         certificate to sign OCSP request with\n");
+               BIO_printf (bio_err, "-signkey file        private key to sign OCSP request with\n");
+               BIO_printf (bio_err, "-sign_other file     additional certificates to include in signed request\n");
+               BIO_printf (bio_err, "-no_certs            don't include any certificates in signed request\n");
+               BIO_printf (bio_err, "-req_text            print text form of request\n");
+               BIO_printf (bio_err, "-resp_text           print text form of response\n");
+               BIO_printf (bio_err, "-text                print text form of request and response\n");
+               BIO_printf (bio_err, "-reqout file         write DER encoded OCSP request to \"file\"\n");
+               BIO_printf (bio_err, "-respout file        write DER encoded OCSP reponse to \"file\"\n");
+               BIO_printf (bio_err, "-reqin file          read DER encoded OCSP request from \"file\"\n");
+               BIO_printf (bio_err, "-respin file         read DER encoded OCSP reponse from \"file\"\n");
+               BIO_printf (bio_err, "-nonce               add OCSP nonce to request\n");
+               BIO_printf (bio_err, "-no_nonce            don't add OCSP nonce to request\n");
+               BIO_printf (bio_err, "-url URL             OCSP responder URL\n");
+               BIO_printf (bio_err, "-host host:n         send OCSP request to host on port n\n");
+               BIO_printf (bio_err, "-path                path to use in OCSP request\n");
+               BIO_printf (bio_err, "-CApath dir          trusted certificates directory\n");
+               BIO_printf (bio_err, "-CAfile file         trusted certificates file\n");
+               BIO_printf (bio_err, "-trusted_first       use locally trusted CA's first when building trust chain\n");
+               BIO_printf (bio_err, "-VAfile file         validator certificates file\n");
+               BIO_printf (bio_err, "-validity_period n   maximum validity discrepancy in seconds\n");
+               BIO_printf (bio_err, "-status_age n        maximum status age in seconds\n");
+               BIO_printf (bio_err, "-noverify            don't verify response at all\n");
+               BIO_printf (bio_err, "-verify_other file   additional certificates to search for signer\n");
+               BIO_printf (bio_err, "-trust_other         don't verify additional certificates\n");
+               BIO_printf (bio_err, "-no_intern           don't search certificates contained in response for signer\n");
                BIO_printf (bio_err, "-no_signature_verify don't check signature on response\n");
-               BIO_printf (bio_err, "-no_cert_verify    don't check signing certificate\n");
-               BIO_printf (bio_err, "-no_chain          don't chain verify response\n");
-               BIO_printf (bio_err, "-no_cert_checks    don't do additional checks on signing certificate\n");
-               BIO_printf (bio_err, "-port num          port to run responder on\n");
-               BIO_printf (bio_err, "-index file        certificate status index file\n");
-               BIO_printf (bio_err, "-CA file           CA certificate\n");
-               BIO_printf (bio_err, "-rsigner file      responder certificate to sign responses with\n");
-               BIO_printf (bio_err, "-rkey file         responder key to sign responses with\n");
-               BIO_printf (bio_err, "-rother file       other certificates to include in response\n");
-               BIO_printf (bio_err, "-resp_no_certs     don't include any certificates in response\n");
-               BIO_printf (bio_err, "-nmin n            number of minutes before next update\n");
-               BIO_printf (bio_err, "-ndays n           number of days before next update\n");
-               BIO_printf (bio_err, "-resp_key_id       identify reponse by signing certificate key ID\n");
-               BIO_printf (bio_err, "-nrequest n        number of requests to accept (default unlimited)\n");
-               BIO_printf (bio_err, "-<dgst alg>     use specified digest in the request");
+               BIO_printf (bio_err, "-no_cert_verify      don't check signing certificate\n");
+               BIO_printf (bio_err, "-no_chain            don't chain verify response\n");
+               BIO_printf (bio_err, "-no_cert_checks      don't do additional checks on signing certificate\n");
+               BIO_printf (bio_err, "-port num            port to run responder on\n");
+               BIO_printf (bio_err, "-index file          certificate status index file\n");
+               BIO_printf (bio_err, "-CA file             CA certificate\n");
+               BIO_printf (bio_err, "-rsigner file        responder certificate to sign responses with\n");
+               BIO_printf (bio_err, "-rkey file           responder key to sign responses with\n");
+               BIO_printf (bio_err, "-rother file         other certificates to include in response\n");
+               BIO_printf (bio_err, "-resp_no_certs       don't include any certificates in response\n");
+               BIO_printf (bio_err, "-nmin n              number of minutes before next update\n");
+               BIO_printf (bio_err, "-ndays n             number of days before next update\n");
+               BIO_printf (bio_err, "-resp_key_id         identify reponse by signing certificate key ID\n");
+               BIO_printf (bio_err, "-nrequest n          number of requests to accept (default unlimited)\n");
+               BIO_printf (bio_err, "-<dgst alg>          use specified digest in the request\n");
+               BIO_printf (bio_err, "-timeout n           timeout connection to OCSP responder after n seconds\n");
                goto end;
                }
 
@@ -777,7 +800,7 @@ int MAIN(int argc, char **argv)
 
        if (rdb)
                {
-               i = make_ocsp_response(&resp, req, rdb, rca_cert, rsigner, rkey, rother, rflags, nmin, ndays, badsig);
+               i = make_ocsp_response(&resp, req, rdb, rca_cert, rsigner, rkey,rsign_md, rother, rflags, nmin, ndays, badsig);
                if (cbio)
                        send_ocsp_response(cbio, resp);
                }
@@ -952,12 +975,12 @@ end:
        sk_X509_pop_free(verify_other, X509_free);
        sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
 
-       if (use_ssl != -1)
-               {
-               OPENSSL_free(host);
-               OPENSSL_free(port);
-               OPENSSL_free(path);
-               }
+       if (thost)
+               OPENSSL_free(thost);
+       if (tport)
+               OPENSSL_free(tport);
+       if (tpath)
+               OPENSSL_free(tpath);
 
        OPENSSL_EXIT(ret);
 }
@@ -1083,7 +1106,8 @@ static int print_ocsp_summary(BIO *out, OCSP_BASICRESP *bs, OCSP_REQUEST *req,
 
 
 static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db,
-                       X509 *ca, X509 *rcert, EVP_PKEY *rkey,
+                       X509 *ca, X509 *rcert,
+                       EVP_PKEY *rkey, const EVP_MD *rmd,
                        STACK_OF(X509) *rother, unsigned long flags,
                        int nmin, int ndays, int badsig)
        {
@@ -1174,7 +1198,7 @@ static int make_ocsp_response(OCSP_RESPONSE **resp, OCSP_REQUEST *req, CA_DB *db
 
        OCSP_copy_nonce(bs, req);
        
-       OCSP_basic_sign(bs, rcert, rkey, NULL, rother, flags);
+       OCSP_basic_sign(bs, rcert, rkey, rmd, rother, flags);
 
        if (badsig)
                bs->signature->data[bs->signature->length -1] ^= 0x1;
@@ -1211,7 +1235,7 @@ static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser)
 
 /* Quick and dirty OCSP server: read in and parse input request */
 
-static BIO *init_responder(char *port)
+static BIO *init_responder(const char *port)
        {
        BIO *acbio = NULL, *bufbio = NULL;
        bufbio = BIO_new(BIO_f_buffer());
@@ -1242,7 +1266,8 @@ static BIO *init_responder(char *port)
        return NULL;
        }
 
-static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, char *port)
+static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio,
+                       const char *port)
        {
        int have_post = 0, len;
        OCSP_REQUEST *req = NULL;
@@ -1308,9 +1333,9 @@ static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp)
        return 1;
        }
 
-static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
-                               STACK_OF(CONF_VALUE) *headers,
-                               OCSP_REQUEST *req, int req_timeout)
+static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, const char *path,
+                                     const STACK_OF(CONF_VALUE) *headers,
+                                     OCSP_REQUEST *req, int req_timeout)
        {
        int fd;
        int rv;
@@ -1406,9 +1431,10 @@ static OCSP_RESPONSE *query_responder(BIO *err, BIO *cbio, char *path,
        }
 
 OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
-                       char *host, char *path, char *port, int use_ssl,
-                       STACK_OF(CONF_VALUE) *headers,
-                       int req_timeout)
+                                const char *host, const char *path,
+                                const char *port, int use_ssl,
+                                const STACK_OF(CONF_VALUE) *headers,
+                                int req_timeout)
        {
        BIO *cbio = NULL;
        SSL_CTX *ctx = NULL;
@@ -1423,16 +1449,7 @@ OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
        if (use_ssl == 1)
                {
                BIO *sbio;
-#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
                ctx = SSL_CTX_new(SSLv23_client_method());
-#elif !defined(OPENSSL_NO_SSL3)
-               ctx = SSL_CTX_new(SSLv3_client_method());
-#elif !defined(OPENSSL_NO_SSL2)
-               ctx = SSL_CTX_new(SSLv2_client_method());
-#else
-               BIO_printf(err, "SSL is disabled\n");
-                       goto end;
-#endif
                if (ctx == NULL)
                        {
                        BIO_printf(err, "Error creating SSL context.\n");
@@ -1444,7 +1461,7 @@ OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
                }
        resp = query_responder(err, cbio, path, headers, req, req_timeout);
        if (!resp)
-               BIO_printf(bio_err, "Error querying OCSP responsder\n");
+               BIO_printf(bio_err, "Error querying OCSP responder\n");
        end:
        if (cbio)
                BIO_free_all(cbio);