remove print_ssl_cert_checks() from openssl application: it is no longer used
[openssl.git] / apps / s_cb.c
index e339a6ce5d5ea26c7c17049d2f2acba17bc116e0..8ba8a041a663c7c7dcee4de98a3ae841cc5b4cfa 100644 (file)
@@ -190,7 +190,8 @@ int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
                BIO_printf(bio_err,"\n");
                break;
        case X509_V_ERR_NO_EXPLICIT_POLICY:
-               policies_print(bio_err, ctx);
+               if (!verify_quiet)
+                       policies_print(bio_err, ctx);
                break;
                }
        if (err == X509_V_OK && ok == 2 && !verify_quiet)
@@ -293,7 +294,6 @@ int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
                ERR_print_errors(bio_err);
                return 0;
                }
-               
        return 1;
        }
 
@@ -424,6 +424,44 @@ int ssl_print_sigalgs(BIO *out, SSL *s)
        return 1;
        }
 
+int ssl_print_point_formats(BIO *out, SSL *s)
+       {
+       int i, nformats;
+       const char *pformats;
+       nformats = SSL_get0_ec_point_formats(s, &pformats);
+       if (nformats <= 0)
+               return 1;
+       BIO_puts(out, "Supported Elliptic Curve Point Formats: ");
+       for (i = 0; i < nformats; i++, pformats++)
+               {
+               if (i)
+                       BIO_puts(out, ":");
+               switch(*pformats)
+                       {
+               case TLSEXT_ECPOINTFORMAT_uncompressed:
+                       BIO_puts(out, "uncompressed");
+                       break;
+
+               case TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime:
+                       BIO_puts(out, "ansiX962_compressed_prime");
+                       break;
+
+               case TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2:
+                       BIO_puts(out, "ansiX962_compressed_char2");
+                       break;
+
+               default:
+                       BIO_printf(out, "unknown(%d)", (int)*pformats);
+                       break;
+
+                       }
+               }
+       if (nformats <= 0)
+               BIO_puts(out, "NONE");
+       BIO_puts(out, "\n");
+       return 1;
+       }
+
 int ssl_print_curves(BIO *out, SSL *s, int noshared)
        {
        int i, ncurves, *curves, nid;
@@ -454,13 +492,13 @@ int ssl_print_curves(BIO *out, SSL *s, int noshared)
                }
        if (ncurves == 0)
                BIO_puts(out, "NONE");
+       OPENSSL_free(curves);
        if (noshared)
                {
                BIO_puts(out, "\n");
                return 1;
                }
        BIO_puts(out, "\nShared Elliptic curves: ");
-       OPENSSL_free(curves);
        ncurves = SSL_get_shared_curve(s, -1);
        for (i = 0; i < ncurves; i++)
                {
@@ -1527,9 +1565,150 @@ void print_ssl_summary(BIO *bio, SSL *s)
                BIO_puts(bio, "No peer certificate\n");
        if (peer)
                X509_free(peer);
+       ssl_print_point_formats(bio, s);
        if (SSL_is_server(s))
                ssl_print_curves(bio, s, 1);
        else
                ssl_print_tmp_key(bio, s);
        }
 
+int args_ssl(char ***pargs, int *pargc, SSL_CONF_CTX *cctx,
+                       int *badarg, BIO *err, STACK_OF(OPENSSL_STRING) **pstr)
+       {
+       char *arg = **pargs, *argn = (*pargs)[1];
+       int rv;
+
+       /* Attempt to run SSL configuration command */
+       rv = SSL_CONF_cmd_argv(cctx, pargc, pargs);
+       /* If parameter not recognised just return */
+       if (rv == 0)
+               return 0;
+       /* see if missing argument error */
+       if (rv == -3)
+               {
+               BIO_printf(err, "%s needs an argument\n", arg);
+               *badarg = 1;
+               goto end;
+               }
+       /* Check for some other error */
+       if (rv < 0)
+               {
+               BIO_printf(err, "Error with command: \"%s %s\"\n",
+                                               arg, argn ? argn : "");
+               *badarg = 1;
+               goto end;
+               }
+       /* Store command and argument */
+       /* If only one argument processed store value as NULL */
+       if (rv == 1)
+               argn = NULL;
+       if (!*pstr)
+               *pstr = sk_OPENSSL_STRING_new_null();
+       if (!*pstr || !sk_OPENSSL_STRING_push(*pstr, arg) ||
+                               !sk_OPENSSL_STRING_push(*pstr, argn))
+               {
+               BIO_puts(err, "Memory allocation failure\n");
+               goto end;
+               }
+
+       end:
+       if (*badarg)
+               ERR_print_errors(err);
+
+       return 1;
+       }
+
+int args_ssl_call(SSL_CTX *ctx, BIO *err, SSL_CONF_CTX *cctx,
+                               STACK_OF(OPENSSL_STRING) *str, int no_ecdhe)
+       {
+       int i;
+       SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
+       for (i = 0; i < sk_OPENSSL_STRING_num(str); i+= 2)
+               {
+               const char *param = sk_OPENSSL_STRING_value(str, i);
+               const char *value = sk_OPENSSL_STRING_value(str, i + 1);
+               /* If no_ecdhe or named curve already specified don't need
+                * a default.
+                */
+               if (!no_ecdhe && !strcmp(param, "-named_curve"))
+                       no_ecdhe = 1;
+               if (SSL_CONF_cmd(cctx, param, value) <= 0)
+                       {
+                       BIO_printf(err, "Error with command: \"%s %s\"\n",
+                                               param, value ? value : "");
+                       ERR_print_errors(err);
+                       return 0;
+                       }
+               }
+       /* This is a special case to keep existing s_server functionality:
+        * if we don't have any curve specified *and* we haven't disabled
+        * ECDHE then use P-256.
+        */
+       if (!no_ecdhe)
+               {
+               if (SSL_CONF_cmd(cctx, "-named_curve", "P-256") <= 0)
+                       {
+                       BIO_puts(err, "Error setting EC curve\n");
+                       ERR_print_errors(err);
+                       return 0;
+                       }
+               }
+       return 1;
+       }
+
+static int add_crls_store(X509_STORE *st, STACK_OF(X509_CRL) *crls)
+       {
+       X509_CRL *crl;
+       int i;
+       if (crls)
+               {
+               for (i = 0; i < sk_X509_CRL_num(crls); i++)
+                       {
+                       crl = sk_X509_CRL_value(crls, i);
+                       X509_STORE_add_crl(st, crl);
+                       }
+               }
+       return 1;
+       }
+
+int ssl_ctx_add_crls(SSL_CTX *ctx, STACK_OF(X509_CRL) *crls)
+       {
+       X509_STORE *st;
+       if (crls)
+               {
+               st = SSL_CTX_get_cert_store(ctx);
+               add_crls_store(st, crls);
+               }
+       return 1;
+       }
+
+int ssl_load_stores(SSL_CTX *ctx,
+                       const char *vfyCApath, const char *vfyCAfile,
+                       const char *chCApath, const char *chCAfile,
+                       STACK_OF(X509_CRL) *crls)
+       {
+       X509_STORE *vfy = NULL, *ch = NULL;
+       int rv = 0;
+       if (vfyCApath || vfyCAfile)
+               {
+               vfy = X509_STORE_new();
+               if (!X509_STORE_load_locations(vfy, vfyCAfile, vfyCApath))
+                       goto err;
+               add_crls_store(vfy, crls);
+               SSL_CTX_set1_verify_cert_store(ctx, vfy);
+               }
+       if (chCApath || chCAfile)
+               {
+               ch = X509_STORE_new();
+               if (!X509_STORE_load_locations(ch, chCAfile, chCApath))
+                       goto err;
+               SSL_CTX_set1_chain_cert_store(ctx, ch);
+               }
+       rv = 1;
+       err:
+       if (vfy)
+               X509_STORE_free(vfy);
+       if (ch)
+               X509_STORE_free(ch);
+       return rv;
+       }