Latest update.
This commit is contained in:
@@ -10,12 +10,17 @@
|
||||
#include "apps.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/provider.h>
|
||||
#include <openssl/safestack.h>
|
||||
|
||||
DEFINE_STACK_OF(OSSL_PROVIDER)
|
||||
|
||||
/*
|
||||
* See comments in opt_verify for explanation of this.
|
||||
*/
|
||||
enum prov_range { OPT_PROV_ENUM };
|
||||
|
||||
static STACK_OF(OSSL_PROVIDER) *app_providers = NULL;
|
||||
|
||||
static int opt_provider_load(const char *provider)
|
||||
{
|
||||
OSSL_PROVIDER *prov;
|
||||
@@ -26,9 +31,27 @@ static int opt_provider_load(const char *provider)
|
||||
opt_getprog(), provider);
|
||||
return 0;
|
||||
}
|
||||
if (app_providers == NULL)
|
||||
app_providers = sk_OSSL_PROVIDER_new_null();
|
||||
if (app_providers == NULL
|
||||
|| !sk_OSSL_PROVIDER_push(app_providers, prov)) {
|
||||
app_providers_cleanup();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void provider_free(OSSL_PROVIDER *prov)
|
||||
{
|
||||
OSSL_PROVIDER_unload(prov);
|
||||
}
|
||||
|
||||
void app_providers_cleanup(void)
|
||||
{
|
||||
sk_OSSL_PROVIDER_pop_free(app_providers, provider_free);
|
||||
app_providers = NULL;
|
||||
}
|
||||
|
||||
static int opt_provider_path(const char *path)
|
||||
{
|
||||
if (path != NULL && *path == '\0')
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "apps.h"
|
||||
|
||||
/*
|
||||
* X509_ctrl_str() is sorely lacking in libcrypto, but is still needed to
|
||||
* allow the application to process verification options in a manner similar
|
||||
* to signature or other options that pass through EVP_PKEY_CTX_ctrl_str(),
|
||||
* for uniformity.
|
||||
*
|
||||
* As soon as more stuff is added, the code will need serious rework. For
|
||||
* the moment, it only handles the FIPS 196 / SM2 distinguishing ID.
|
||||
*/
|
||||
#ifdef EVP_PKEY_CTRL_SET1_ID
|
||||
static ASN1_OCTET_STRING *mk_octet_string(void *value, size_t value_n)
|
||||
{
|
||||
ASN1_OCTET_STRING *v = ASN1_OCTET_STRING_new();
|
||||
|
||||
if (v == NULL) {
|
||||
BIO_printf(bio_err, "error: allocation failed\n");
|
||||
} else if (!ASN1_OCTET_STRING_set(v, value, value_n)) {
|
||||
ASN1_OCTET_STRING_free(v);
|
||||
v = NULL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int x509_ctrl(void *object, int cmd, void *value, size_t value_n)
|
||||
{
|
||||
switch (cmd) {
|
||||
#ifdef EVP_PKEY_CTRL_SET1_ID
|
||||
case EVP_PKEY_CTRL_SET1_ID:
|
||||
{
|
||||
ASN1_OCTET_STRING *v = mk_octet_string(value, value_n);
|
||||
|
||||
if (v == NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"error: setting distinguishing ID in certificate failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
X509_set0_distinguishing_id(object, v);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -2; /* typical EVP_PKEY return for "unsupported" */
|
||||
}
|
||||
|
||||
static int x509_req_ctrl(void *object, int cmd, void *value, size_t value_n)
|
||||
{
|
||||
switch (cmd) {
|
||||
#ifdef EVP_PKEY_CTRL_SET1_ID
|
||||
case EVP_PKEY_CTRL_SET1_ID:
|
||||
{
|
||||
ASN1_OCTET_STRING *v = mk_octet_string(value, value_n);
|
||||
|
||||
if (v == NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"error: setting distinguishing ID in certificate signing request failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
X509_REQ_set0_distinguishing_id(object, v);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -2; /* typical EVP_PKEY return for "unsupported" */
|
||||
}
|
||||
|
||||
static int do_x509_ctrl_string(int (*ctrl)(void *object, int cmd,
|
||||
void *value, size_t value_n),
|
||||
void *object, const char *value)
|
||||
{
|
||||
int rv = 0;
|
||||
char *stmp, *vtmp = NULL;
|
||||
size_t vtmp_len = 0;
|
||||
int cmd = 0; /* Will get command values that make sense somehow */
|
||||
|
||||
stmp = OPENSSL_strdup(value);
|
||||
if (stmp == NULL)
|
||||
return -1;
|
||||
vtmp = strchr(stmp, ':');
|
||||
if (vtmp != NULL) {
|
||||
*vtmp = 0;
|
||||
vtmp++;
|
||||
vtmp_len = strlen(vtmp);
|
||||
}
|
||||
|
||||
if (strcmp(stmp, "distid") == 0) {
|
||||
#ifdef EVP_PKEY_CTRL_SET1_ID
|
||||
cmd = EVP_PKEY_CTRL_SET1_ID; /* ... except we put it in X509 */
|
||||
#endif
|
||||
} else if (strcmp(stmp, "hexdistid") == 0) {
|
||||
long hexid_len = 0;
|
||||
void *hexid = OPENSSL_hexstr2buf((const char *)vtmp, &hexid_len);
|
||||
|
||||
OPENSSL_free(stmp);
|
||||
stmp = vtmp = hexid;
|
||||
vtmp_len = (size_t)hexid_len;
|
||||
#ifdef EVP_PKEY_CTRL_SET1_ID
|
||||
cmd = EVP_PKEY_CTRL_SET1_ID; /* ... except we put it in X509 */
|
||||
#endif
|
||||
}
|
||||
|
||||
rv = ctrl(object, cmd, vtmp, vtmp_len);
|
||||
|
||||
OPENSSL_free(stmp);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int x509_ctrl_string(X509 *x, const char *value)
|
||||
{
|
||||
return do_x509_ctrl_string(x509_ctrl, x, value);
|
||||
}
|
||||
|
||||
int x509_req_ctrl_string(X509_REQ *x, const char *value)
|
||||
{
|
||||
return do_x509_ctrl_string(x509_req_ctrl, x, value);
|
||||
}
|
||||
+8
-7
@@ -968,7 +968,7 @@ static int set_table_opts(unsigned long *flags, const char *arg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_name(BIO *out, const char *title, X509_NAME *nm,
|
||||
void print_name(BIO *out, const char *title, const X509_NAME *nm,
|
||||
unsigned long lflags)
|
||||
{
|
||||
char *buf;
|
||||
@@ -1900,7 +1900,8 @@ static X509_CRL *load_crl_crldp(STACK_OF(DIST_POINT) *crldp)
|
||||
* anything.
|
||||
*/
|
||||
|
||||
static STACK_OF(X509_CRL) *crls_http_cb(X509_STORE_CTX *ctx, X509_NAME *nm)
|
||||
static STACK_OF(X509_CRL) *crls_http_cb(const X509_STORE_CTX *ctx,
|
||||
const X509_NAME *nm)
|
||||
{
|
||||
X509 *x;
|
||||
STACK_OF(X509_CRL) *crls = NULL;
|
||||
@@ -1989,7 +1990,7 @@ BIO *app_http_tls_cb(BIO *hbio, void *arg, int connect, int detail)
|
||||
} else if (!connect && !detail) { /* disconnecting after error */
|
||||
const char *hint = tls_error_hint();
|
||||
if (hint != NULL)
|
||||
ERR_add_error_data(1, hint);
|
||||
ERR_add_error_data(2, " : ", hint);
|
||||
/*
|
||||
* If we pop sbio and BIO_free() it this may lead to libssl double free.
|
||||
* Rely on BIO_free_all() done by OSSL_HTTP_transfer() in http_client.c
|
||||
@@ -1999,7 +2000,7 @@ BIO *app_http_tls_cb(BIO *hbio, void *arg, int connect, int detail)
|
||||
}
|
||||
|
||||
ASN1_VALUE *app_http_get_asn1(const char *url, const char *proxy,
|
||||
const char *proxy_port, SSL_CTX *ssl_ctx,
|
||||
const char *no_proxy, SSL_CTX *ssl_ctx,
|
||||
const STACK_OF(CONF_VALUE) *headers,
|
||||
long timeout, const char *expected_content_type,
|
||||
const ASN1_ITEM *it)
|
||||
@@ -2028,7 +2029,7 @@ ASN1_VALUE *app_http_get_asn1(const char *url, const char *proxy,
|
||||
info.use_proxy = proxy != NULL;
|
||||
info.timeout = timeout;
|
||||
info.ssl_ctx = ssl_ctx;
|
||||
resp = OSSL_HTTP_get_asn1(url, proxy, proxy_port,
|
||||
resp = OSSL_HTTP_get_asn1(url, proxy, no_proxy,
|
||||
NULL, NULL, app_http_tls_cb, &info,
|
||||
headers, 0 /* maxline */, 0 /* max_resp_len */,
|
||||
timeout, expected_content_type, it);
|
||||
@@ -2041,7 +2042,7 @@ ASN1_VALUE *app_http_get_asn1(const char *url, const char *proxy,
|
||||
|
||||
ASN1_VALUE *app_http_post_asn1(const char *host, const char *port,
|
||||
const char *path, const char *proxy,
|
||||
const char *proxy_port, SSL_CTX *ssl_ctx,
|
||||
const char *no_proxy, SSL_CTX *ssl_ctx,
|
||||
const STACK_OF(CONF_VALUE) *headers,
|
||||
const char *content_type,
|
||||
ASN1_VALUE *req, const ASN1_ITEM *req_it,
|
||||
@@ -2055,7 +2056,7 @@ ASN1_VALUE *app_http_post_asn1(const char *host, const char *port,
|
||||
info.timeout = timeout;
|
||||
info.ssl_ctx = ssl_ctx;
|
||||
return OSSL_HTTP_post_asn1(host, port, path, ssl_ctx != NULL,
|
||||
proxy, proxy_port,
|
||||
proxy, no_proxy,
|
||||
NULL, NULL, app_http_tls_cb, &info,
|
||||
headers, content_type, req, req_it,
|
||||
0 /* maxline */,
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ ENDIF
|
||||
|
||||
# Source for libapps
|
||||
$LIBAPPSSRC=apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \
|
||||
columns.c app_params.c names.c app_provider.c
|
||||
columns.c app_params.c names.c app_provider.c app_x509.c
|
||||
|
||||
IF[{- !$disabled{apps} -}]
|
||||
LIBS{noinst}=../libapps.a
|
||||
|
||||
Reference in New Issue
Block a user