Add missing \n's to ocsp usage message.
[openssl.git] / apps / ocsp.c
index eaba15f3099172ef5a21a1c5aa450466cc83c956..32506a37cb4d731b286fbdfa7493a1e36538412c 100644 (file)
@@ -95,6 +95,9 @@ int MAIN(int argc, char **argv)
        int req_text = 0, resp_text = 0;
        char *CAfile = NULL, *CApath = NULL;
        X509_STORE *store = NULL;
+       STACK_OF(X509) *sign_other = NULL, *verify_other = NULL;
+       char *sign_certfile = NULL, *verify_certfile = NULL;
+       unsigned long sign_flags = 0, verify_flags = 0;
        int ret = 1;
        int badarg = 0;
        int i;
@@ -131,6 +134,22 @@ int MAIN(int argc, char **argv)
                        add_nonce = 2;
                else if (!strcmp(*args, "-no_nonce"))
                        add_nonce = 0;
+               else if (!strcmp(*args, "-no_certs"))
+                       sign_flags |= OCSP_NOCERTS;
+               else if (!strcmp(*args, "-no_signature_verify"))
+                       verify_flags |= OCSP_NOSIGS;
+               else if (!strcmp(*args, "-no_cert_verify"))
+                       verify_flags |= OCSP_NOVERIFY;
+               else if (!strcmp(*args, "-no_chain"))
+                       verify_flags |= OCSP_NOCHAIN;
+               else if (!strcmp(*args, "-no_cert_checks"))
+                       verify_flags |= OCSP_NOCHECKS;
+               else if (!strcmp(*args, "-no_explicit"))
+                       verify_flags |= OCSP_NOEXPLICIT;
+               else if (!strcmp(*args, "-trust_other"))
+                       verify_flags |= OCSP_TRUSTOTHER;
+               else if (!strcmp(*args, "-no_intern"))
+                       verify_flags |= OCSP_NOINTERN;
                else if (!strcmp(*args, "-text"))
                        {
                        req_text = 1;
@@ -167,6 +186,34 @@ int MAIN(int argc, char **argv)
                                }
                        else badarg = 1;
                        }
+               else if (!strcmp (*args, "-VAfile"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               verify_certfile = *args;
+                               verify_flags |= OCSP_TRUSTOTHER;
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp(*args, "-sign_other"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               sign_certfile = *args;
+                               }
+                       else badarg = 1;
+                       }
+               else if (!strcmp(*args, "-verify_other"))
+                       {
+                       if (args[1])
+                               {
+                               args++;
+                               verify_certfile = *args;
+                               }
+                       else badarg = 1;
+                       }
                else if (!strcmp (*args, "-CAfile"))
                        {
                        if (args[1])
@@ -271,26 +318,36 @@ 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, "-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, "-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, "-noverify     don't verify response\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_certs 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, "-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, "-noverify          don't verify response at all\n");
+               BIO_printf (bio_err, "-verify_certs 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_sig_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");
                goto end;
                }
 
@@ -339,13 +396,18 @@ int MAIN(int argc, char **argv)
                        BIO_printf(bio_err, "Error loading signer certificate\n");
                        goto end;
                        }
+               if (sign_certfile)
+                       {
+                       sign_other = load_certs(bio_err, sign_certfile, FORMAT_PEM);
+                       if (!sign_other) goto end;
+                       }
                key = load_key(bio_err, keyfile, FORMAT_PEM, NULL, NULL);
                if (!key)
                        {
                        BIO_printf(bio_err, "Error loading signer private key\n");
                        goto end;
                        }
-               if (!OCSP_request_sign(req, signer, key, EVP_sha1(), NULL, 0))
+               if (!OCSP_request_sign(req, signer, key, EVP_sha1(), sign_other, sign_flags))
                        {
                        BIO_printf(bio_err, "Error signing OCSP request\n");
                        goto end;
@@ -437,6 +499,11 @@ int MAIN(int argc, char **argv)
 
        store = setup_verify(bio_err, CAfile, CApath);
        if(!store) goto end;
+       if (verify_certfile)
+               {
+               verify_other = load_certs(bio_err, verify_certfile, FORMAT_PEM);
+               if (!verify_other) goto end;
+               }
 
        bs = OCSP_response_get1_basic(resp);
 
@@ -454,7 +521,8 @@ int MAIN(int argc, char **argv)
                        goto end;
                        }
 
-               i = OCSP_basic_verify(bs, NULL, store, 0);
+               i = OCSP_basic_verify(bs, verify_other, store, verify_flags);
+                if (i < 0) i = OCSP_basic_verify(bs, NULL, store, 0);
 
                if(i <= 0)
                        {
@@ -485,6 +553,8 @@ end:
        OCSP_BASICRESP_free(bs);
        sk_free(reqnames);
        sk_OCSP_CERTID_free(ids);
+       sk_X509_pop_free(sign_other, X509_free);
+       sk_X509_pop_free(verify_other, X509_free);
 
        EXIT(ret);
 }
@@ -525,7 +595,7 @@ static int add_ocsp_serial(OCSP_REQUEST **req, char *serial, X509 *issuer,
        if(!*req) *req = OCSP_REQUEST_new();
        if(!*req) goto err;
        iname = X509_get_subject_name(issuer);
-       ikey = issuer->cert_info->key->public_key;
+       ikey = X509_get0_pubkey_bitstr(issuer);
        sno = s2i_ASN1_INTEGER(NULL, serial);
        if(!sno)
                {