Latest update.
This commit is contained in:
+4
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-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
|
||||
@@ -18,6 +18,9 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
DEFINE_STACK_OF(ASN1_OBJECT)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_INFORM, OPT_IN, OPT_OUT, OPT_INDENT, OPT_NOOUT,
|
||||
|
||||
+4
-1
@@ -44,7 +44,7 @@ IF[{- !$disabled{'engine'} -}]
|
||||
$OPENSSLSRC=$OPENSSLSRC engine.c
|
||||
ENDIF
|
||||
IF[{- !$disabled{'cmp'} -}]
|
||||
$OPENSSLSRC=$OPENSSLSRC cmp_mock_srv.c
|
||||
$OPENSSLSRC=$OPENSSLSRC cmp.c cmp_mock_srv.c
|
||||
ENDIF
|
||||
|
||||
IF[{- !$disabled{apps} -}]
|
||||
@@ -59,6 +59,9 @@ IF[{- !$disabled{apps} -}]
|
||||
# progs.pl tries to read all 'openssl' sources, including progs.c, so we make
|
||||
# sure things are generated in the correct order.
|
||||
DEPEND[progs.h]=progs.c
|
||||
# Because the files to look through may change (depends on $OPENSSLSRC),
|
||||
# always depend on a changed configuration.
|
||||
DEPEND[progs.c]=../configdata.pm
|
||||
|
||||
IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-)/ -}]
|
||||
GENERATE[openssl.rc]=../util/mkrc.pl openssl
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
#include "apps.h"
|
||||
#include "progs.h"
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_EXTENSION)
|
||||
DEFINE_STACK_OF(CONF_VALUE)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#ifndef W_OK
|
||||
# define F_OK 0
|
||||
# define W_OK 2
|
||||
@@ -210,12 +215,12 @@ const OPTIONS ca_options[] = {
|
||||
OPT_SECTION("Signing"),
|
||||
{"md", OPT_MD, 's', "md to use; one of md2, md5, sha or sha1"},
|
||||
{"keyfile", OPT_KEYFILE, 's', "Private key"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Private key file format (PEM or ENGINE)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Private key file format (ENGINE, other values ignored)"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
{"key", OPT_KEY, 's', "Key to decode the private key if it is encrypted"},
|
||||
{"cert", OPT_CERT, '<', "The CA cert"},
|
||||
{"certform", OPT_CERTFORM, 'F',
|
||||
"certificate input format (DER or PEM); default PEM"},
|
||||
"certificate input format (DER/PEM/P12); has no effect"},
|
||||
{"selfsign", OPT_SELFSIGN, '-',
|
||||
"Sign a cert with the key associated with it"},
|
||||
{"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"},
|
||||
@@ -380,7 +385,7 @@ opthelp:
|
||||
certfile = opt_arg();
|
||||
break;
|
||||
case OPT_CERTFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &certformat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &certformat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_SELFSIGN:
|
||||
@@ -568,8 +573,7 @@ end_of_options:
|
||||
}
|
||||
}
|
||||
pkey = load_key(keyfile, keyformat, 0, key, e, "CA private key");
|
||||
if (key != NULL)
|
||||
OPENSSL_cleanse(key, strlen(key));
|
||||
cleanse(key);
|
||||
if (pkey == NULL)
|
||||
/* load_key() has already printed an appropriate message */
|
||||
goto end;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
DEFINE_STACK_OF_CONST(SSL_CIPHER)
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_STDNAME,
|
||||
|
||||
+3174
@@ -0,0 +1,3174 @@
|
||||
/*
|
||||
* Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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 <ctype.h>
|
||||
|
||||
#include "apps.h"
|
||||
#include "http_server.h"
|
||||
#include "s_apps.h"
|
||||
#include "progs.h"
|
||||
|
||||
#include "cmp_mock_srv.h"
|
||||
|
||||
/* tweaks needed due to missing unistd.h on Windows */
|
||||
#ifdef _WIN32
|
||||
# define access _access
|
||||
#endif
|
||||
#ifndef F_OK
|
||||
# define F_OK 0
|
||||
#endif
|
||||
|
||||
#include <openssl/ui.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
#include <stdlib.h>
|
||||
#include <openssl/cmp.h>
|
||||
#include <openssl/cmp_util.h>
|
||||
#include <openssl/crmf.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/store.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_EXTENSION)
|
||||
DEFINE_STACK_OF(OSSL_CMP_ITAV)
|
||||
|
||||
static char *opt_config = NULL;
|
||||
#define CMP_SECTION "cmp"
|
||||
#define SECTION_NAME_MAX 40 /* max length of section name */
|
||||
#define DEFAULT_SECTION "default"
|
||||
static char *opt_section = CMP_SECTION;
|
||||
|
||||
#undef PROG
|
||||
#define PROG cmp_main
|
||||
static char *prog = "cmp";
|
||||
|
||||
static int read_config(void);
|
||||
|
||||
static CONF *conf = NULL; /* OpenSSL config file context structure */
|
||||
static OSSL_CMP_CTX *cmp_ctx = NULL; /* the client-side CMP context */
|
||||
|
||||
/* the type of cmp command we want to send */
|
||||
typedef enum {
|
||||
CMP_IR,
|
||||
CMP_KUR,
|
||||
CMP_CR,
|
||||
CMP_P10CR,
|
||||
CMP_RR,
|
||||
CMP_GENM
|
||||
} cmp_cmd_t;
|
||||
|
||||
/* message transfer */
|
||||
static char *opt_server = NULL;
|
||||
static char server_port_s[32] = { '\0' };
|
||||
static int server_port = 0;
|
||||
static char *opt_proxy = NULL;
|
||||
static char *opt_no_proxy = NULL;
|
||||
static char *opt_path = "/";
|
||||
static int opt_msg_timeout = -1;
|
||||
static int opt_total_timeout = -1;
|
||||
|
||||
/* server authentication */
|
||||
static char *opt_trusted = NULL;
|
||||
static char *opt_untrusted = NULL;
|
||||
static char *opt_srvcert = NULL;
|
||||
static char *opt_recipient = NULL;
|
||||
static char *opt_expect_sender = NULL;
|
||||
static int opt_ignore_keyusage = 0;
|
||||
static int opt_unprotected_errors = 0;
|
||||
static char *opt_extracertsout = NULL;
|
||||
static char *opt_cacertsout = NULL;
|
||||
|
||||
/* client authentication */
|
||||
static char *opt_ref = NULL;
|
||||
static char *opt_secret = NULL;
|
||||
static char *opt_cert = NULL;
|
||||
static char *opt_key = NULL;
|
||||
static char *opt_keypass = NULL;
|
||||
static char *opt_digest = NULL;
|
||||
static char *opt_mac = NULL;
|
||||
static char *opt_extracerts = NULL;
|
||||
static int opt_unprotected_requests = 0;
|
||||
|
||||
/* generic message */
|
||||
static char *opt_cmd_s = NULL;
|
||||
static int opt_cmd = -1;
|
||||
static char *opt_geninfo = NULL;
|
||||
static char *opt_infotype_s = NULL;
|
||||
static int opt_infotype = NID_undef;
|
||||
|
||||
/* certificate enrollment */
|
||||
static char *opt_newkey = NULL;
|
||||
static char *opt_newkeypass = NULL;
|
||||
static char *opt_subject = NULL;
|
||||
static char *opt_issuer = NULL;
|
||||
static int opt_days = 0;
|
||||
static char *opt_reqexts = NULL;
|
||||
static char *opt_sans = NULL;
|
||||
static int opt_san_nodefault = 0;
|
||||
static char *opt_policies = NULL;
|
||||
static char *opt_policy_oids = NULL;
|
||||
static int opt_policy_oids_critical = 0;
|
||||
static int opt_popo = OSSL_CRMF_POPO_NONE - 1;
|
||||
static char *opt_csr = NULL;
|
||||
static char *opt_out_trusted = NULL;
|
||||
static int opt_implicit_confirm = 0;
|
||||
static int opt_disable_confirm = 0;
|
||||
static char *opt_certout = NULL;
|
||||
|
||||
/* certificate enrollment and revocation */
|
||||
static char *opt_oldcert = NULL;
|
||||
static int opt_revreason = CRL_REASON_NONE;
|
||||
|
||||
/* credentials format */
|
||||
static char *opt_certform_s = "PEM";
|
||||
static int opt_certform = FORMAT_PEM;
|
||||
static char *opt_keyform_s = "PEM";
|
||||
static int opt_keyform = FORMAT_PEM;
|
||||
static char *opt_certsform_s = "PEM";
|
||||
static int opt_certsform = FORMAT_PEM;
|
||||
static char *opt_otherpass = NULL;
|
||||
static char *opt_engine = NULL;
|
||||
|
||||
/* TLS connection */
|
||||
static int opt_tls_used = 0;
|
||||
static char *opt_tls_cert = NULL;
|
||||
static char *opt_tls_key = NULL;
|
||||
static char *opt_tls_keypass = NULL;
|
||||
static char *opt_tls_extra = NULL;
|
||||
static char *opt_tls_trusted = NULL;
|
||||
static char *opt_tls_host = NULL;
|
||||
|
||||
/* client-side debugging */
|
||||
static int opt_batch = 0;
|
||||
static int opt_repeat = 1;
|
||||
static char *opt_reqin = NULL;
|
||||
static int opt_reqin_new_tid = 0;
|
||||
static char *opt_reqout = NULL;
|
||||
static char *opt_rspin = NULL;
|
||||
static char *opt_rspout = NULL;
|
||||
static int opt_use_mock_srv = 0;
|
||||
|
||||
/* server-side debugging */
|
||||
static char *opt_port = NULL;
|
||||
static int opt_max_msgs = 0;
|
||||
|
||||
static char *opt_srv_ref = NULL;
|
||||
static char *opt_srv_secret = NULL;
|
||||
static char *opt_srv_cert = NULL;
|
||||
static char *opt_srv_key = NULL;
|
||||
static char *opt_srv_keypass = NULL;
|
||||
|
||||
static char *opt_srv_trusted = NULL;
|
||||
static char *opt_srv_untrusted = NULL;
|
||||
static char *opt_rsp_cert = NULL;
|
||||
static char *opt_rsp_extracerts = NULL;
|
||||
static char *opt_rsp_capubs = NULL;
|
||||
static int opt_poll_count = 0;
|
||||
static int opt_check_after = 1;
|
||||
static int opt_grant_implicitconf = 0;
|
||||
|
||||
static int opt_pkistatus = OSSL_CMP_PKISTATUS_accepted;
|
||||
static int opt_failure = INT_MIN;
|
||||
static int opt_failurebits = 0;
|
||||
static char *opt_statusstring = NULL;
|
||||
static int opt_send_error = 0;
|
||||
static int opt_send_unprotected = 0;
|
||||
static int opt_send_unprot_err = 0;
|
||||
static int opt_accept_unprotected = 0;
|
||||
static int opt_accept_unprot_err = 0;
|
||||
static int opt_accept_raverified = 0;
|
||||
|
||||
static X509_VERIFY_PARAM *vpm = NULL;
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_CONFIG, OPT_SECTION,
|
||||
|
||||
OPT_CMD, OPT_INFOTYPE, OPT_GENINFO,
|
||||
|
||||
OPT_NEWKEY, OPT_NEWKEYPASS, OPT_SUBJECT, OPT_ISSUER,
|
||||
OPT_DAYS, OPT_REQEXTS,
|
||||
OPT_SANS, OPT_SAN_NODEFAULT,
|
||||
OPT_POLICIES, OPT_POLICY_OIDS, OPT_POLICY_OIDS_CRITICAL,
|
||||
OPT_POPO, OPT_CSR,
|
||||
OPT_OUT_TRUSTED, OPT_IMPLICIT_CONFIRM, OPT_DISABLE_CONFIRM,
|
||||
OPT_CERTOUT,
|
||||
|
||||
OPT_OLDCERT, OPT_REVREASON,
|
||||
|
||||
OPT_SERVER, OPT_PROXY, OPT_NO_PROXY, OPT_PATH,
|
||||
OPT_MSG_TIMEOUT, OPT_TOTAL_TIMEOUT,
|
||||
|
||||
OPT_TRUSTED, OPT_UNTRUSTED, OPT_SRVCERT,
|
||||
OPT_RECIPIENT, OPT_EXPECT_SENDER,
|
||||
OPT_IGNORE_KEYUSAGE, OPT_UNPROTECTED_ERRORS,
|
||||
OPT_EXTRACERTSOUT, OPT_CACERTSOUT,
|
||||
|
||||
OPT_REF, OPT_SECRET, OPT_CERT, OPT_KEY, OPT_KEYPASS,
|
||||
OPT_DIGEST, OPT_MAC, OPT_EXTRACERTS,
|
||||
OPT_UNPROTECTED_REQUESTS,
|
||||
|
||||
OPT_CERTFORM, OPT_KEYFORM, OPT_CERTSFORM,
|
||||
OPT_OTHERPASS,
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
OPT_ENGINE,
|
||||
#endif
|
||||
OPT_PROV_ENUM,
|
||||
|
||||
OPT_TLS_USED, OPT_TLS_CERT, OPT_TLS_KEY,
|
||||
OPT_TLS_KEYPASS,
|
||||
OPT_TLS_EXTRA, OPT_TLS_TRUSTED, OPT_TLS_HOST,
|
||||
|
||||
OPT_BATCH, OPT_REPEAT,
|
||||
OPT_REQIN, OPT_REQIN_NEW_TID, OPT_REQOUT, OPT_RSPIN, OPT_RSPOUT,
|
||||
|
||||
OPT_USE_MOCK_SRV, OPT_PORT, OPT_MAX_MSGS,
|
||||
OPT_SRV_REF, OPT_SRV_SECRET,
|
||||
OPT_SRV_CERT, OPT_SRV_KEY, OPT_SRV_KEYPASS,
|
||||
OPT_SRV_TRUSTED, OPT_SRV_UNTRUSTED,
|
||||
OPT_RSP_CERT, OPT_RSP_EXTRACERTS, OPT_RSP_CAPUBS,
|
||||
OPT_POLL_COUNT, OPT_CHECK_AFTER,
|
||||
OPT_GRANT_IMPLICITCONF,
|
||||
OPT_PKISTATUS, OPT_FAILURE,
|
||||
OPT_FAILUREBITS, OPT_STATUSSTRING,
|
||||
OPT_SEND_ERROR, OPT_SEND_UNPROTECTED,
|
||||
OPT_SEND_UNPROT_ERR, OPT_ACCEPT_UNPROTECTED,
|
||||
OPT_ACCEPT_UNPROT_ERR, OPT_ACCEPT_RAVERIFIED,
|
||||
|
||||
OPT_V_ENUM
|
||||
} OPTION_CHOICE;
|
||||
|
||||
const OPTIONS cmp_options[] = {
|
||||
/* entries must be in the same order as enumerated above!! */
|
||||
{"help", OPT_HELP, '-', "Display this summary"},
|
||||
{"config", OPT_CONFIG, 's',
|
||||
"Configuration file to use. \"\" = none. Default from env variable OPENSSL_CONF"},
|
||||
{"section", OPT_SECTION, 's',
|
||||
"Section(s) in config file to get options from. \"\" = 'default'. Default 'cmp'"},
|
||||
|
||||
OPT_SECTION("Generic message"),
|
||||
{"cmd", OPT_CMD, 's', "CMP request to send: ir/cr/kur/p10cr/rr/genm"},
|
||||
{"infotype", OPT_INFOTYPE, 's',
|
||||
"InfoType name for requesting specific info in genm, e.g. 'signKeyPairTypes'"},
|
||||
{"geninfo", OPT_GENINFO, 's',
|
||||
"generalInfo integer values to place in request PKIHeader with given OID"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"specified in the form <OID>:int:<n>, e.g. \"1.2.3:int:987\""},
|
||||
|
||||
OPT_SECTION("Certificate enrollment"),
|
||||
{"newkey", OPT_NEWKEY, 's',
|
||||
"Private or public key for the requested cert. Default: CSR key or client key"},
|
||||
{"newkeypass", OPT_NEWKEYPASS, 's', "New private key pass phrase source"},
|
||||
{"subject", OPT_SUBJECT, 's',
|
||||
"Distinguished Name (DN) of subject to use in the requested cert template"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"For kur, default is the subject DN of the reference cert (see -oldcert);"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"this default is used for ir and cr only if no Subject Alt Names are set"},
|
||||
{"issuer", OPT_ISSUER, 's',
|
||||
"DN of the issuer to place in the requested certificate template"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"also used as recipient if neither -recipient nor -srvcert are given"},
|
||||
{"days", OPT_DAYS, 'n',
|
||||
"Requested validity time of the new certificate in number of days"},
|
||||
{"reqexts", OPT_REQEXTS, 's',
|
||||
"Name of config file section defining certificate request extensions"},
|
||||
{"sans", OPT_SANS, 's',
|
||||
"Subject Alt Names (IPADDR/DNS/URI) to add as (critical) cert req extension"},
|
||||
{"san_nodefault", OPT_SAN_NODEFAULT, '-',
|
||||
"Do not take default SANs from reference certificate (see -oldcert)"},
|
||||
{"policies", OPT_POLICIES, 's',
|
||||
"Name of config file section defining policies certificate request extension"},
|
||||
{"policy_oids", OPT_POLICY_OIDS, 's',
|
||||
"Policy OID(s) to add as policies certificate request extension"},
|
||||
{"policy_oids_critical", OPT_POLICY_OIDS_CRITICAL, '-',
|
||||
"Flag the policy OID(s) given with -policy_oids as critical"},
|
||||
{"popo", OPT_POPO, 'n',
|
||||
"Proof-of-Possession (POPO) method to use for ir/cr/kur where"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"-1 = NONE, 0 = RAVERIFIED, 1 = SIGNATURE (default), 2 = KEYENC"},
|
||||
{"csr", OPT_CSR, 's',
|
||||
"CSR file in PKCS#10 format to use in p10cr for legacy support"},
|
||||
{"out_trusted", OPT_OUT_TRUSTED, 's',
|
||||
"Certificates to trust when verifying newly enrolled certificates"},
|
||||
{"implicit_confirm", OPT_IMPLICIT_CONFIRM, '-',
|
||||
"Request implicit confirmation of newly enrolled certificates"},
|
||||
{"disable_confirm", OPT_DISABLE_CONFIRM, '-',
|
||||
"Do not confirm newly enrolled certificate w/o requesting implicit"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"confirmation. WARNING: This leads to behavior violating RFC 4210"},
|
||||
{"certout", OPT_CERTOUT, 's',
|
||||
"File to save newly enrolled certificate"},
|
||||
|
||||
OPT_SECTION("Certificate enrollment and revocation"),
|
||||
|
||||
{"oldcert", OPT_OLDCERT, 's',
|
||||
"Certificate to be updated (defaulting to -cert) or to be revoked in rr;"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"also used as reference (defaulting to -cert) for subject DN and SANs."},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"Its issuer is used as recipient unless -srvcert, -recipient or -issuer given"},
|
||||
{"revreason", OPT_REVREASON, 'n',
|
||||
"Reason code to include in revocation request (rr); possible values:"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"0..6, 8..10 (see RFC5280, 5.3.1) or -1. Default -1 = none included"},
|
||||
|
||||
OPT_SECTION("Message transfer"),
|
||||
{"server", OPT_SERVER, 's',
|
||||
"[http[s]://]address[:port] of CMP server. Default port 80 or 443."},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"The address may be a DNS name or an IP address"},
|
||||
{"proxy", OPT_PROXY, 's',
|
||||
"[http[s]://]address[:port][/path] of HTTP(S) proxy to use; path is ignored"},
|
||||
{"no_proxy", OPT_NO_PROXY, 's',
|
||||
"List of addresses of servers not to use HTTP(S) proxy for"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"Default from environment variable 'no_proxy', else 'NO_PROXY', else none"},
|
||||
{"path", OPT_PATH, 's',
|
||||
"HTTP path (aka CMP alias) at the CMP server. Default \"/\""},
|
||||
{"msg_timeout", OPT_MSG_TIMEOUT, 'n',
|
||||
"Timeout per CMP message round trip (or 0 for none). Default 120 seconds"},
|
||||
{"total_timeout", OPT_TOTAL_TIMEOUT, 'n',
|
||||
"Overall time an enrollment incl. polling may take. Default 0 = infinite"},
|
||||
|
||||
OPT_SECTION("Server authentication"),
|
||||
{"trusted", OPT_TRUSTED, 's',
|
||||
"Trusted certs used for CMP server authentication when verifying responses"},
|
||||
{OPT_MORE_STR, 0, 0, "unless -srvcert is given"},
|
||||
{"untrusted", OPT_UNTRUSTED, 's',
|
||||
"Intermediate certs for chain construction verifying CMP/TLS/enrolled certs"},
|
||||
{"srvcert", OPT_SRVCERT, 's',
|
||||
"Specific CMP server cert to use and trust directly when verifying responses"},
|
||||
{"recipient", OPT_RECIPIENT, 's',
|
||||
"Distinguished Name (DN) of the recipient to use unless -srvcert is given"},
|
||||
{"expect_sender", OPT_EXPECT_SENDER, 's',
|
||||
"DN of expected response sender. Defaults to DN of -srvcert, if provided"},
|
||||
{"ignore_keyusage", OPT_IGNORE_KEYUSAGE, '-',
|
||||
"Ignore CMP signer cert key usage, else 'digitalSignature' must be allowed"},
|
||||
{"unprotected_errors", OPT_UNPROTECTED_ERRORS, '-',
|
||||
"Accept missing or invalid protection of regular error messages and negative"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"certificate responses (ip/cp/kup), revocation responses (rp), and PKIConf"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"WARNING: This setting leads to behavior allowing violation of RFC 4210"},
|
||||
{"extracertsout", OPT_EXTRACERTSOUT, 's',
|
||||
"File to save extra certificates received in the extraCerts field"},
|
||||
{"cacertsout", OPT_CACERTSOUT, 's',
|
||||
"File to save CA certificates received in the caPubs field of 'ip' messages"},
|
||||
|
||||
OPT_SECTION("Client authentication"),
|
||||
{"ref", OPT_REF, 's',
|
||||
"Reference value to use as senderKID in case no -cert is given"},
|
||||
{"secret", OPT_SECRET, 's',
|
||||
"Password source for client authentication with a pre-shared key (secret)"},
|
||||
{"cert", OPT_CERT, 's',
|
||||
"Client's current certificate (needed unless using -secret for PBM);"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"any further certs included are appended in extraCerts field"},
|
||||
{"key", OPT_KEY, 's', "Private key for the client's current certificate"},
|
||||
{"keypass", OPT_KEYPASS, 's',
|
||||
"Client private key (and cert and old cert file) pass phrase source"},
|
||||
{"digest", OPT_DIGEST, 's',
|
||||
"Digest to use in message protection and POPO signatures. Default \"sha256\""},
|
||||
{"mac", OPT_MAC, 's',
|
||||
"MAC algorithm to use in PBM-based message protection. Default \"hmac-sha1\""},
|
||||
{"extracerts", OPT_EXTRACERTS, 's',
|
||||
"Certificates to append in extraCerts field of outgoing messages"},
|
||||
{"unprotected_requests", OPT_UNPROTECTED_REQUESTS, '-',
|
||||
"Send messages without CMP-level protection"},
|
||||
|
||||
OPT_SECTION("Credentials format"),
|
||||
{"certform", OPT_CERTFORM, 's',
|
||||
"Format (PEM or DER) to use when saving a certificate to a file. Default PEM"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"This also determines format to use for writing (not supported for P12)"},
|
||||
{"keyform", OPT_KEYFORM, 's',
|
||||
"Format to assume when reading key files. Default PEM"},
|
||||
{"certsform", OPT_CERTSFORM, 's',
|
||||
"Format (PEM/DER/P12) to try first reading multiple certs. Default PEM"},
|
||||
{"otherpass", OPT_OTHERPASS, 's',
|
||||
"Pass phrase source potentially needed for loading certificates of others"},
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
{"engine", OPT_ENGINE, 's',
|
||||
"Use crypto engine with given identifier, possibly a hardware device."},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"Engines may be defined in OpenSSL config file engine section."},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"Options like -key specifying keys held in the engine can give key IDs"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"prefixed by 'engine:', e.g. '-key engine:pkcs11:object=mykey;pin-value=1234'"},
|
||||
#endif
|
||||
OPT_PROV_OPTIONS,
|
||||
|
||||
OPT_SECTION("TLS connection"),
|
||||
{"tls_used", OPT_TLS_USED, '-',
|
||||
"Enable using TLS (also when other TLS options are not set)"},
|
||||
{"tls_cert", OPT_TLS_CERT, 's',
|
||||
"Client's TLS certificate. May include chain to be provided to TLS server"},
|
||||
{"tls_key", OPT_TLS_KEY, 's',
|
||||
"Private key for the client's TLS certificate"},
|
||||
{"tls_keypass", OPT_TLS_KEYPASS, 's',
|
||||
"Pass phrase source for the client's private TLS key (and TLS cert file)"},
|
||||
{"tls_extra", OPT_TLS_EXTRA, 's',
|
||||
"Extra certificates to provide to TLS server during TLS handshake"},
|
||||
{"tls_trusted", OPT_TLS_TRUSTED, 's',
|
||||
"Trusted certificates to use for verifying the TLS server certificate;"},
|
||||
{OPT_MORE_STR, 0, 0, "this implies host name validation"},
|
||||
{"tls_host", OPT_TLS_HOST, 's',
|
||||
"Address to be checked (rather than -server) during TLS host name validation"},
|
||||
|
||||
OPT_SECTION("Client-side debugging"),
|
||||
{"batch", OPT_BATCH, '-',
|
||||
"Do not interactively prompt for input when a password is required etc."},
|
||||
{"repeat", OPT_REPEAT, 'n',
|
||||
"Invoke the transaction the given number of times. Default 1"},
|
||||
{"reqin", OPT_REQIN, 's', "Take sequence of CMP requests from file(s)"},
|
||||
{"reqin_new_tid", OPT_REQIN_NEW_TID, '-',
|
||||
"Use fresh transactionID for CMP requests read from -reqin"},
|
||||
{"reqout", OPT_REQOUT, 's', "Save sequence of CMP requests to file(s)"},
|
||||
{"rspin", OPT_RSPIN, 's',
|
||||
"Process sequence of CMP responses provided in file(s), skipping server"},
|
||||
{"rspout", OPT_RSPOUT, 's', "Save sequence of CMP responses to file(s)"},
|
||||
|
||||
{"use_mock_srv", OPT_USE_MOCK_SRV, '-', "Use mock server at API level, bypassing HTTP"},
|
||||
|
||||
OPT_SECTION("Mock server"),
|
||||
{"port", OPT_PORT, 's', "Act as HTTP mock server listening on given port"},
|
||||
{"max_msgs", OPT_MAX_MSGS, 'n',
|
||||
"max number of messages handled by HTTP mock server. Default: 0 = unlimited"},
|
||||
|
||||
{"srv_ref", OPT_SRV_REF, 's',
|
||||
"Reference value to use as senderKID of server in case no -srv_cert is given"},
|
||||
{"srv_secret", OPT_SRV_SECRET, 's',
|
||||
"Password source for server authentication with a pre-shared key (secret)"},
|
||||
{"srv_cert", OPT_SRV_CERT, 's', "Certificate of the server"},
|
||||
{"srv_key", OPT_SRV_KEY, 's',
|
||||
"Private key used by the server for signing messages"},
|
||||
{"srv_keypass", OPT_SRV_KEYPASS, 's',
|
||||
"Server private key (and cert) file pass phrase source"},
|
||||
|
||||
{"srv_trusted", OPT_SRV_TRUSTED, 's',
|
||||
"Trusted certificates for client authentication"},
|
||||
{"srv_untrusted", OPT_SRV_UNTRUSTED, 's',
|
||||
"Intermediate certs that may be useful for verifying CMP protection"},
|
||||
{"rsp_cert", OPT_RSP_CERT, 's',
|
||||
"Certificate to be returned as mock enrollment result"},
|
||||
{"rsp_extracerts", OPT_RSP_EXTRACERTS, 's',
|
||||
"Extra certificates to be included in mock certification responses"},
|
||||
{"rsp_capubs", OPT_RSP_CAPUBS, 's',
|
||||
"CA certificates to be included in mock ip response"},
|
||||
{"poll_count", OPT_POLL_COUNT, 'n',
|
||||
"Number of times the client must poll before receiving a certificate"},
|
||||
{"check_after", OPT_CHECK_AFTER, 'n',
|
||||
"The check_after value (time to wait) to include in poll response"},
|
||||
{"grant_implicitconf", OPT_GRANT_IMPLICITCONF, '-',
|
||||
"Grant implicit confirmation of newly enrolled certificate"},
|
||||
|
||||
{"pkistatus", OPT_PKISTATUS, 'n',
|
||||
"PKIStatus to be included in server response. Possible values: 0..6"},
|
||||
{"failure", OPT_FAILURE, 'n',
|
||||
"A single failure info bit number to include in server response, 0..26"},
|
||||
{"failurebits", OPT_FAILUREBITS, 'n',
|
||||
"Number representing failure bits to include in server response, 0..2^27 - 1"},
|
||||
{"statusstring", OPT_STATUSSTRING, 's',
|
||||
"Status string to be included in server response"},
|
||||
{"send_error", OPT_SEND_ERROR, '-',
|
||||
"Force server to reply with error message"},
|
||||
{"send_unprotected", OPT_SEND_UNPROTECTED, '-',
|
||||
"Send response messages without CMP-level protection"},
|
||||
{"send_unprot_err", OPT_SEND_UNPROT_ERR, '-',
|
||||
"In case of negative responses, server shall send unprotected error messages,"},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"certificate responses (ip/cp/kup), and revocation responses (rp)."},
|
||||
{OPT_MORE_STR, 0, 0,
|
||||
"WARNING: This setting leads to behavior violating RFC 4210"},
|
||||
{"accept_unprotected", OPT_ACCEPT_UNPROTECTED, '-',
|
||||
"Accept missing or invalid protection of requests"},
|
||||
{"accept_unprot_err", OPT_ACCEPT_UNPROT_ERR, '-',
|
||||
"Accept unprotected error messages from client"},
|
||||
{"accept_raverified", OPT_ACCEPT_RAVERIFIED, '-',
|
||||
"Accept RAVERIFIED as proof-of-possession (POPO)"},
|
||||
|
||||
OPT_V_OPTIONS,
|
||||
{NULL}
|
||||
};
|
||||
|
||||
typedef union {
|
||||
char **txt;
|
||||
int *num;
|
||||
long *num_long;
|
||||
} varref;
|
||||
static varref cmp_vars[] = { /* must be in same order as enumerated above! */
|
||||
{&opt_config}, {&opt_section},
|
||||
|
||||
{&opt_cmd_s}, {&opt_infotype_s}, {&opt_geninfo},
|
||||
|
||||
{&opt_newkey}, {&opt_newkeypass}, {&opt_subject}, {&opt_issuer},
|
||||
{(char **)&opt_days}, {&opt_reqexts},
|
||||
{&opt_sans}, {(char **)&opt_san_nodefault},
|
||||
{&opt_policies}, {&opt_policy_oids}, {(char **)&opt_policy_oids_critical},
|
||||
{(char **)&opt_popo}, {&opt_csr},
|
||||
{&opt_out_trusted},
|
||||
{(char **)&opt_implicit_confirm}, {(char **)&opt_disable_confirm},
|
||||
{&opt_certout},
|
||||
|
||||
{&opt_oldcert}, {(char **)&opt_revreason},
|
||||
|
||||
{&opt_server}, {&opt_proxy}, {&opt_no_proxy}, {&opt_path},
|
||||
{(char **)&opt_msg_timeout}, {(char **)&opt_total_timeout},
|
||||
|
||||
{&opt_trusted}, {&opt_untrusted}, {&opt_srvcert},
|
||||
{&opt_recipient}, {&opt_expect_sender},
|
||||
{(char **)&opt_ignore_keyusage}, {(char **)&opt_unprotected_errors},
|
||||
{&opt_extracertsout}, {&opt_cacertsout},
|
||||
|
||||
{&opt_ref}, {&opt_secret}, {&opt_cert}, {&opt_key}, {&opt_keypass},
|
||||
{&opt_digest}, {&opt_mac}, {&opt_extracerts},
|
||||
{(char **)&opt_unprotected_requests},
|
||||
|
||||
{&opt_certform_s}, {&opt_keyform_s}, {&opt_certsform_s},
|
||||
{&opt_otherpass},
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
{&opt_engine},
|
||||
#endif
|
||||
|
||||
{(char **)&opt_tls_used}, {&opt_tls_cert}, {&opt_tls_key},
|
||||
{&opt_tls_keypass},
|
||||
{&opt_tls_extra}, {&opt_tls_trusted}, {&opt_tls_host},
|
||||
|
||||
{(char **)&opt_batch}, {(char **)&opt_repeat},
|
||||
{&opt_reqin}, {(char **)&opt_reqin_new_tid},
|
||||
{&opt_reqout}, {&opt_rspin}, {&opt_rspout},
|
||||
|
||||
{(char **)&opt_use_mock_srv}, {&opt_port}, {(char **)&opt_max_msgs},
|
||||
{&opt_srv_ref}, {&opt_srv_secret},
|
||||
{&opt_srv_cert}, {&opt_srv_key}, {&opt_srv_keypass},
|
||||
{&opt_srv_trusted}, {&opt_srv_untrusted},
|
||||
{&opt_rsp_cert}, {&opt_rsp_extracerts}, {&opt_rsp_capubs},
|
||||
{(char **)&opt_poll_count}, {(char **)&opt_check_after},
|
||||
{(char **)&opt_grant_implicitconf},
|
||||
{(char **)&opt_pkistatus}, {(char **)&opt_failure},
|
||||
{(char **)&opt_failurebits}, {&opt_statusstring},
|
||||
{(char **)&opt_send_error}, {(char **)&opt_send_unprotected},
|
||||
{(char **)&opt_send_unprot_err}, {(char **)&opt_accept_unprotected},
|
||||
{(char **)&opt_accept_unprot_err}, {(char **)&opt_accept_raverified},
|
||||
|
||||
{NULL}
|
||||
};
|
||||
|
||||
#ifndef NDEBUG
|
||||
# define FUNC (strcmp(OPENSSL_FUNC, "(unknown function)") == 0 \
|
||||
? "CMP" : "OPENSSL_FUNC")
|
||||
# define PRINT_LOCATION(bio) BIO_printf(bio, "%s:%s:%d:", \
|
||||
FUNC, OPENSSL_FILE, OPENSSL_LINE)
|
||||
#else
|
||||
# define PRINT_LOCATION(bio) ((void)0)
|
||||
#endif
|
||||
#define CMP_print(bio, prefix, msg, a1, a2, a3) \
|
||||
(PRINT_LOCATION(bio), \
|
||||
BIO_printf(bio, "CMP %s: " msg "\n", prefix, a1, a2, a3))
|
||||
#define CMP_INFO(msg, a1, a2, a3) CMP_print(bio_out, "info", msg, a1, a2, a3)
|
||||
#define CMP_info(msg) CMP_INFO(msg"%s%s%s", "", "", "")
|
||||
#define CMP_info1(msg, a1) CMP_INFO(msg"%s%s", a1, "", "")
|
||||
#define CMP_info2(msg, a1, a2) CMP_INFO(msg"%s", a1, a2, "")
|
||||
#define CMP_info3(msg, a1, a2, a3) CMP_INFO(msg, a1, a2, a3)
|
||||
#define CMP_WARN(m, a1, a2, a3) CMP_print(bio_out, "warning", m, a1, a2, a3)
|
||||
#define CMP_warn(msg) CMP_WARN(msg"%s%s%s", "", "", "")
|
||||
#define CMP_warn1(msg, a1) CMP_WARN(msg"%s%s", a1, "", "")
|
||||
#define CMP_warn2(msg, a1, a2) CMP_WARN(msg"%s", a1, a2, "")
|
||||
#define CMP_warn3(msg, a1, a2, a3) CMP_WARN(msg, a1, a2, a3)
|
||||
#define CMP_ERR(msg, a1, a2, a3) CMP_print(bio_err, "error", msg, a1, a2, a3)
|
||||
#define CMP_err(msg) CMP_ERR(msg"%s%s%s", "", "", "")
|
||||
#define CMP_err1(msg, a1) CMP_ERR(msg"%s%s", a1, "", "")
|
||||
#define CMP_err2(msg, a1, a2) CMP_ERR(msg"%s", a1, a2, "")
|
||||
#define CMP_err3(msg, a1, a2, a3) CMP_ERR(msg, a1, a2, a3)
|
||||
|
||||
static int print_to_bio_out(const char *func, const char *file, int line,
|
||||
OSSL_CMP_severity level, const char *msg)
|
||||
{
|
||||
return OSSL_CMP_print_to_bio(bio_out, func, file, line, level, msg);
|
||||
}
|
||||
|
||||
/* code duplicated from crypto/cmp/cmp_util.c */
|
||||
static int sk_X509_add1_cert(STACK_OF(X509) *sk, X509 *cert,
|
||||
int no_dup, int prepend)
|
||||
{
|
||||
if (no_dup) {
|
||||
/*
|
||||
* not using sk_X509_set_cmp_func() and sk_X509_find()
|
||||
* because this re-orders the certs on the stack
|
||||
*/
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sk_X509_num(sk); i++) {
|
||||
if (X509_cmp(sk_X509_value(sk, i), cert) == 0)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!X509_up_ref(cert))
|
||||
return 0;
|
||||
if (!sk_X509_insert(sk, cert, prepend ? 0 : -1)) {
|
||||
X509_free(cert);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* code duplicated from crypto/cmp/cmp_util.c */
|
||||
static int sk_X509_add1_certs(STACK_OF(X509) *sk, STACK_OF(X509) *certs,
|
||||
int no_self_signed, int no_dups, int prepend)
|
||||
/* compiler would allow 'const' for the list of certs, yet they are up-ref'ed */
|
||||
{
|
||||
int i;
|
||||
|
||||
if (sk == NULL)
|
||||
return 0;
|
||||
if (certs == NULL)
|
||||
return 1;
|
||||
for (i = 0; i < sk_X509_num(certs); i++) {
|
||||
X509 *cert = sk_X509_value(certs, i);
|
||||
|
||||
if (!no_self_signed || X509_check_issued(cert, cert) != X509_V_OK) {
|
||||
if (!sk_X509_add1_cert(sk, cert, no_dups, prepend))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO potentially move to apps/lib/apps.c */
|
||||
static char *next_item(char *opt) /* in list separated by comma and/or space */
|
||||
{
|
||||
/* advance to separator (comma or whitespace), if any */
|
||||
while (*opt != ',' && !isspace(*opt) && *opt != '\0') {
|
||||
if (*opt == '\\' && opt[1] != '\0')
|
||||
/* skip and unescape '\' escaped char */
|
||||
memmove(opt, opt + 1, strlen(opt));
|
||||
opt++;
|
||||
}
|
||||
if (*opt != '\0') {
|
||||
/* terminate current item */
|
||||
*opt++ = '\0';
|
||||
/* skip over any whitespace after separator */
|
||||
while (isspace(*opt))
|
||||
opt++;
|
||||
}
|
||||
return *opt == '\0' ? NULL : opt; /* NULL indicates end of input */
|
||||
}
|
||||
|
||||
static EVP_PKEY *load_key_pwd(const char *uri, int format,
|
||||
const char *pass, ENGINE *e, const char *desc)
|
||||
{
|
||||
char *pass_string = get_passwd(pass, desc);
|
||||
EVP_PKEY *pkey = load_key(uri, format, 0, pass_string, e, desc);
|
||||
|
||||
clear_free(pass_string);
|
||||
return pkey;
|
||||
}
|
||||
|
||||
static X509 *load_cert_pwd(const char *uri, const char *pass, const char *desc)
|
||||
{
|
||||
X509 *cert;
|
||||
char *pass_string = get_passwd(pass, desc);
|
||||
|
||||
cert = load_cert_pass(uri, 0, pass_string, desc);
|
||||
clear_free(pass_string);
|
||||
return cert;
|
||||
}
|
||||
|
||||
/* TODO remove when PR #4930 is merged */
|
||||
static int load_pkcs12(BIO *in, const char *desc,
|
||||
pem_password_cb *pem_cb, void *cb_data,
|
||||
EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
|
||||
{
|
||||
const char *pass;
|
||||
char tpass[PEM_BUFSIZE];
|
||||
int len;
|
||||
int ret = 0;
|
||||
PKCS12 *p12 = d2i_PKCS12_bio(in, NULL);
|
||||
|
||||
if (desc == NULL)
|
||||
desc = "PKCS12 input";
|
||||
if (p12 == NULL) {
|
||||
BIO_printf(bio_err, "error loading PKCS12 file for %s\n", desc);
|
||||
goto die;
|
||||
}
|
||||
|
||||
/* See if an empty password will do */
|
||||
if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, NULL, 0)) {
|
||||
pass = "";
|
||||
} else {
|
||||
if (pem_cb == NULL)
|
||||
pem_cb = wrap_password_callback;
|
||||
len = pem_cb(tpass, PEM_BUFSIZE, 0, cb_data);
|
||||
if (len < 0) {
|
||||
BIO_printf(bio_err, "passphrase callback error for %s\n", desc);
|
||||
goto die;
|
||||
}
|
||||
if (len < PEM_BUFSIZE)
|
||||
tpass[len] = 0;
|
||||
if (!PKCS12_verify_mac(p12, tpass, len)) {
|
||||
BIO_printf(bio_err,
|
||||
"mac verify error (wrong password?) in PKCS12 file for %s\n",
|
||||
desc);
|
||||
goto die;
|
||||
}
|
||||
pass = tpass;
|
||||
}
|
||||
ret = PKCS12_parse(p12, pass, pkey, cert, ca);
|
||||
die:
|
||||
PKCS12_free(p12);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* TODO potentially move this and related functions to apps/lib/apps.c */
|
||||
static int adjust_format(const char **infile, int format, int engine_ok)
|
||||
{
|
||||
if (!strncasecmp(*infile, "http://", 7)
|
||||
|| !strncasecmp(*infile, "https://", 8)) {
|
||||
format = FORMAT_HTTP;
|
||||
} else if (engine_ok && strncasecmp(*infile, "engine:", 7) == 0) {
|
||||
*infile += 7;
|
||||
format = FORMAT_ENGINE;
|
||||
} else {
|
||||
if (strncasecmp(*infile, "file:", 5) == 0)
|
||||
*infile += 5;
|
||||
/*
|
||||
* the following is a heuristic whether first to try PEM or DER
|
||||
* or PKCS12 as the input format for files
|
||||
*/
|
||||
if (strlen(*infile) >= 4) {
|
||||
const char *extension = *infile + strlen(*infile) - 4;
|
||||
|
||||
if (strncasecmp(extension, ".crt", 4) == 0
|
||||
|| strncasecmp(extension, ".pem", 4) == 0)
|
||||
/* weak recognition of PEM format */
|
||||
format = FORMAT_PEM;
|
||||
else if (strncasecmp(extension, ".cer", 4) == 0
|
||||
|| strncasecmp(extension, ".der", 4) == 0)
|
||||
/* weak recognition of DER format */
|
||||
format = FORMAT_ASN1;
|
||||
else if (strncasecmp(extension, ".p12", 4) == 0)
|
||||
/* weak recognition of PKCS#12 format */
|
||||
format = FORMAT_PKCS12;
|
||||
/* else retain given format */
|
||||
}
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO potentially move this and related functions to apps/lib/
|
||||
* or even better extend OSSL_STORE with type OSSL_STORE_INFO_CRL
|
||||
*/
|
||||
static X509_REQ *load_csr_autofmt(const char *infile, const char *desc)
|
||||
{
|
||||
X509_REQ *csr;
|
||||
BIO *bio_bak = bio_err;
|
||||
int can_retry;
|
||||
int format = adjust_format(&infile, FORMAT_PEM, 0);
|
||||
|
||||
can_retry = format == FORMAT_PEM || format == FORMAT_ASN1;
|
||||
if (can_retry)
|
||||
bio_err = NULL; /* do not show errors on more than one try */
|
||||
csr = load_csr(infile, format, desc);
|
||||
bio_err = bio_bak;
|
||||
if (csr == NULL && can_retry) {
|
||||
ERR_clear_error();
|
||||
format = (format == FORMAT_PEM ? FORMAT_ASN1 : FORMAT_PEM);
|
||||
csr = load_csr(infile, format, desc);
|
||||
}
|
||||
if (csr == NULL) {
|
||||
ERR_print_errors(bio_err);
|
||||
BIO_printf(bio_err, "error: unable to load %s from file '%s'\n", desc,
|
||||
infile);
|
||||
}
|
||||
return csr;
|
||||
}
|
||||
|
||||
/* TODO replace by calling generalized load_certs() when PR #4930 is merged */
|
||||
static int load_certs_preliminary(const char *file, STACK_OF(X509) **certs,
|
||||
int format, const char *pass,
|
||||
const char *desc)
|
||||
{
|
||||
X509 *cert = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (format == FORMAT_PKCS12) {
|
||||
BIO *bio = bio_open_default(file, 'r', format);
|
||||
|
||||
if (bio != NULL) {
|
||||
EVP_PKEY *pkey = NULL; /* pkey is needed until PR #4930 is merged */
|
||||
PW_CB_DATA cb_data;
|
||||
|
||||
cb_data.password = pass;
|
||||
cb_data.prompt_info = file;
|
||||
ret = load_pkcs12(bio, desc, wrap_password_callback,
|
||||
&cb_data, &pkey, &cert, certs);
|
||||
EVP_PKEY_free(pkey);
|
||||
BIO_free(bio);
|
||||
}
|
||||
} else if (format == FORMAT_ASN1) { /* load only one cert in this case */
|
||||
CMP_warn1("can load only one certificate in DER format from %s", file);
|
||||
cert = load_cert_pass(file, 0, pass, desc);
|
||||
}
|
||||
if (format == FORMAT_PKCS12 || format == FORMAT_ASN1) {
|
||||
if (cert) {
|
||||
if (*certs == NULL)
|
||||
*certs = sk_X509_new_null();
|
||||
if (*certs != NULL)
|
||||
ret = sk_X509_insert(*certs, cert, 0);
|
||||
else
|
||||
X509_free(cert);
|
||||
}
|
||||
} else {
|
||||
ret = load_certs(file, certs, format, pass, desc);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void warn_certs_expired(const char *file, STACK_OF(X509) **certs)
|
||||
{
|
||||
int i, res;
|
||||
X509 *cert;
|
||||
char *subj;
|
||||
|
||||
for (i = 0; i < sk_X509_num(*certs); i++) {
|
||||
cert = sk_X509_value(*certs, i);
|
||||
res = X509_cmp_timeframe(vpm, X509_get0_notBefore(cert),
|
||||
X509_get0_notAfter(cert));
|
||||
if (res != 0) {
|
||||
subj = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
|
||||
CMP_warn3("certificate from '%s' with subject '%s' %s", file, subj,
|
||||
res > 0 ? "has expired" : "not yet valid");
|
||||
OPENSSL_free(subj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO potentially move this and related functions to apps/lib/
|
||||
* or even better extend OSSL_STORE with type OSSL_STORE_INFO_CERTS
|
||||
*/
|
||||
static int load_certs_autofmt(const char *infile, STACK_OF(X509) **certs,
|
||||
int exclude_http, const char *pass,
|
||||
const char *desc)
|
||||
{
|
||||
int ret = 0;
|
||||
char *pass_string;
|
||||
BIO *bio_bak = bio_err;
|
||||
int format = adjust_format(&infile, opt_certsform, 0);
|
||||
|
||||
if (exclude_http && format == FORMAT_HTTP) {
|
||||
BIO_printf(bio_err, "error: HTTP retrieval not allowed for %s\n", desc);
|
||||
return ret;
|
||||
}
|
||||
pass_string = get_passwd(pass, desc);
|
||||
if (format != FORMAT_HTTP)
|
||||
bio_err = NULL; /* do not show errors on more than one try */
|
||||
ret = load_certs_preliminary(infile, certs, format, pass_string, desc);
|
||||
bio_err = bio_bak;
|
||||
if (!ret && format != FORMAT_HTTP) {
|
||||
int format2 = format == FORMAT_PEM ? FORMAT_ASN1 : FORMAT_PEM;
|
||||
|
||||
ERR_clear_error();
|
||||
ret = load_certs_preliminary(infile, certs, format2, pass_string, desc);
|
||||
}
|
||||
clear_free(pass_string);
|
||||
|
||||
if (ret)
|
||||
warn_certs_expired(infile, certs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* set expected host name/IP addr and clears the email addr in the given ts */
|
||||
static int truststore_set_host_etc(X509_STORE *ts, char *host)
|
||||
{
|
||||
X509_VERIFY_PARAM *ts_vpm = X509_STORE_get0_param(ts);
|
||||
|
||||
/* first clear any host names, IP, and email addresses */
|
||||
if (!X509_VERIFY_PARAM_set1_host(ts_vpm, NULL, 0)
|
||||
|| !X509_VERIFY_PARAM_set1_ip(ts_vpm, NULL, 0)
|
||||
|| !X509_VERIFY_PARAM_set1_email(ts_vpm, NULL, 0))
|
||||
return 0;
|
||||
X509_VERIFY_PARAM_set_hostflags(ts_vpm,
|
||||
X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT |
|
||||
X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
|
||||
return (host != NULL && X509_VERIFY_PARAM_set1_ip_asc(ts_vpm, host))
|
||||
|| X509_VERIFY_PARAM_set1_host(ts_vpm, host, 0);
|
||||
}
|
||||
|
||||
static X509_STORE *sk_X509_to_store(X509_STORE *store /* may be NULL */,
|
||||
const STACK_OF(X509) *certs /* may NULL */)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (store == NULL)
|
||||
store = X509_STORE_new();
|
||||
if (store == NULL)
|
||||
return NULL;
|
||||
for (i = 0; i < sk_X509_num(certs); i++) {
|
||||
if (!X509_STORE_add_cert(store, sk_X509_value(certs, i))) {
|
||||
X509_STORE_free(store);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return store;
|
||||
}
|
||||
|
||||
/* write OSSL_CMP_MSG DER-encoded to the specified file name item */
|
||||
static int write_PKIMESSAGE(const OSSL_CMP_MSG *msg, char **filenames)
|
||||
{
|
||||
char *file;
|
||||
BIO *bio;
|
||||
|
||||
if (msg == NULL || filenames == NULL) {
|
||||
CMP_err("NULL arg to write_PKIMESSAGE");
|
||||
return 0;
|
||||
}
|
||||
if (*filenames == NULL) {
|
||||
CMP_err("Not enough file names provided for writing PKIMessage");
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = *filenames;
|
||||
*filenames = next_item(file);
|
||||
bio = BIO_new_file(file, "wb");
|
||||
if (bio == NULL) {
|
||||
CMP_err1("Cannot open file '%s' for writing", file);
|
||||
return 0;
|
||||
}
|
||||
if (i2d_OSSL_CMP_MSG_bio(bio, msg) < 0) {
|
||||
CMP_err1("Cannot write PKIMessage to file '%s'", file);
|
||||
BIO_free(bio);
|
||||
return 0;
|
||||
}
|
||||
BIO_free(bio);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* read DER-encoded OSSL_CMP_MSG from the specified file name item */
|
||||
static OSSL_CMP_MSG *read_PKIMESSAGE(char **filenames)
|
||||
{
|
||||
char *file;
|
||||
BIO *bio;
|
||||
OSSL_CMP_MSG *ret;
|
||||
|
||||
if (filenames == NULL) {
|
||||
CMP_err("NULL arg to read_PKIMESSAGE");
|
||||
return NULL;
|
||||
}
|
||||
if (*filenames == NULL) {
|
||||
CMP_err("Not enough file names provided for reading PKIMessage");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file = *filenames;
|
||||
*filenames = next_item(file);
|
||||
bio = BIO_new_file(file, "rb");
|
||||
if (bio == NULL) {
|
||||
CMP_err1("Cannot open file '%s' for reading", file);
|
||||
return NULL;
|
||||
}
|
||||
ret = d2i_OSSL_CMP_MSG_bio(bio, NULL);
|
||||
if (ret == NULL)
|
||||
CMP_err1("Cannot read PKIMessage from file '%s'", file);
|
||||
BIO_free(bio);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*-
|
||||
* Sends the PKIMessage req and on success place the response in *res
|
||||
* basically like OSSL_CMP_MSG_http_perform(), but in addition allows
|
||||
* to dump the sequence of requests and responses to files and/or
|
||||
* to take the sequence of requests and responses from files.
|
||||
*/
|
||||
static OSSL_CMP_MSG *read_write_req_resp(OSSL_CMP_CTX *ctx,
|
||||
const OSSL_CMP_MSG *req)
|
||||
{
|
||||
OSSL_CMP_MSG *req_new = NULL;
|
||||
OSSL_CMP_MSG *res = NULL;
|
||||
OSSL_CMP_PKIHEADER *hdr;
|
||||
|
||||
if (req != NULL && opt_reqout != NULL
|
||||
&& !write_PKIMESSAGE(req, &opt_reqout))
|
||||
goto err;
|
||||
if (opt_reqin != NULL && opt_rspin == NULL) {
|
||||
if ((req_new = read_PKIMESSAGE(&opt_reqin)) == NULL)
|
||||
goto err;
|
||||
/*-
|
||||
* The transaction ID in req_new read from opt_reqin may not be fresh.
|
||||
* In this case the server may complain "Transaction id already in use."
|
||||
* The following workaround unfortunately requires re-protection.
|
||||
*/
|
||||
if (opt_reqin_new_tid
|
||||
&& !OSSL_CMP_MSG_update_transactionID(ctx, req_new))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (opt_rspin != NULL) {
|
||||
res = read_PKIMESSAGE(&opt_rspin);
|
||||
} else {
|
||||
const OSSL_CMP_MSG *actual_req = opt_reqin != NULL ? req_new : req;
|
||||
|
||||
res = opt_use_mock_srv
|
||||
? OSSL_CMP_CTX_server_perform(ctx, actual_req)
|
||||
: OSSL_CMP_MSG_http_perform(ctx, actual_req);
|
||||
}
|
||||
if (res == NULL)
|
||||
goto err;
|
||||
|
||||
if (opt_reqin != NULL || opt_rspin != NULL) {
|
||||
/* need to satisfy nonce and transactionID checks */
|
||||
ASN1_OCTET_STRING *nonce;
|
||||
ASN1_OCTET_STRING *tid;
|
||||
|
||||
hdr = OSSL_CMP_MSG_get0_header(res);
|
||||
nonce = OSSL_CMP_HDR_get0_recipNonce(hdr);
|
||||
tid = OSSL_CMP_HDR_get0_transactionID(hdr);
|
||||
if (!OSSL_CMP_CTX_set1_senderNonce(ctx, nonce)
|
||||
|| !OSSL_CMP_CTX_set1_transactionID(ctx, tid)) {
|
||||
OSSL_CMP_MSG_free(res);
|
||||
res = NULL;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_rspout != NULL && !write_PKIMESSAGE(res, &opt_rspout)) {
|
||||
OSSL_CMP_MSG_free(res);
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
err:
|
||||
OSSL_CMP_MSG_free(req_new);
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* parse string as integer value, not allowing trailing garbage, see also
|
||||
* https://www.gnu.org/software/libc/manual/html_node/Parsing-of-Integers.html
|
||||
*
|
||||
* returns integer value, or INT_MIN on error
|
||||
*/
|
||||
static int atoint(const char *str)
|
||||
{
|
||||
char *tailptr;
|
||||
long res = strtol(str, &tailptr, 10);
|
||||
|
||||
if ((*tailptr != '\0') || (res < INT_MIN) || (res > INT_MAX))
|
||||
return INT_MIN;
|
||||
else
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
static int parse_addr(char **opt_string, int port, const char *name)
|
||||
{
|
||||
char *port_string;
|
||||
|
||||
if (strncasecmp(*opt_string, OSSL_HTTP_PREFIX,
|
||||
strlen(OSSL_HTTP_PREFIX)) == 0) {
|
||||
*opt_string += strlen(OSSL_HTTP_PREFIX);
|
||||
} else if (strncasecmp(*opt_string, OSSL_HTTPS_PREFIX,
|
||||
strlen(OSSL_HTTPS_PREFIX)) == 0) {
|
||||
*opt_string += strlen(OSSL_HTTPS_PREFIX);
|
||||
if (port == 0)
|
||||
port = 443; /* == integer value of OSSL_HTTPS_PORT */
|
||||
}
|
||||
|
||||
if ((port_string = strrchr(*opt_string, ':')) == NULL)
|
||||
return port; /* using default */
|
||||
*(port_string++) = '\0';
|
||||
port = atoint(port_string);
|
||||
if ((port <= 0) || (port > 65535)) {
|
||||
CMP_err2("invalid %s port '%s' given, sane range 1-65535",
|
||||
name, port_string);
|
||||
return -1;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
static int set1_store_parameters(X509_STORE *ts)
|
||||
{
|
||||
if (ts == NULL)
|
||||
return 0;
|
||||
|
||||
/* copy vpm to store */
|
||||
if (!X509_STORE_set1_param(ts, vpm /* may be NULL */)) {
|
||||
BIO_printf(bio_err, "error setting verification parameters\n");
|
||||
OSSL_CMP_CTX_print_errors(cmp_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
X509_STORE_set_verify_cb(ts, X509_STORE_CTX_print_verify_cb);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int set_name(const char *str,
|
||||
int (*set_fn) (OSSL_CMP_CTX *ctx, const X509_NAME *name),
|
||||
OSSL_CMP_CTX *ctx, const char *desc)
|
||||
{
|
||||
if (str != NULL) {
|
||||
X509_NAME *n = parse_name(str, MBSTRING_ASC, 0);
|
||||
|
||||
if (n == NULL) {
|
||||
CMP_err2("cannot parse %s DN '%s'", desc, str);
|
||||
return 0;
|
||||
}
|
||||
if (!(*set_fn) (ctx, n)) {
|
||||
X509_NAME_free(n);
|
||||
CMP_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
X509_NAME_free(n);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int set_gennames(OSSL_CMP_CTX *ctx, char *names, const char *desc)
|
||||
{
|
||||
char *next;
|
||||
|
||||
for (; names != NULL; names = next) {
|
||||
GENERAL_NAME *n;
|
||||
|
||||
next = next_item(names);
|
||||
if (strcmp(names, "critical") == 0) {
|
||||
(void)OSSL_CMP_CTX_set_option(ctx,
|
||||
OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL,
|
||||
1);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* try IP address first, then URI or domain name */
|
||||
(void)ERR_set_mark();
|
||||
n = a2i_GENERAL_NAME(NULL, NULL, NULL, GEN_IPADD, names, 0);
|
||||
if (n == NULL)
|
||||
n = a2i_GENERAL_NAME(NULL, NULL, NULL,
|
||||
strchr(names, ':') != NULL ? GEN_URI : GEN_DNS,
|
||||
names, 0);
|
||||
(void)ERR_pop_to_mark();
|
||||
|
||||
if (n == NULL) {
|
||||
CMP_err2("bad syntax of %s '%s'", desc, names);
|
||||
return 0;
|
||||
}
|
||||
if (!OSSL_CMP_CTX_push1_subjectAltName(ctx, n)) {
|
||||
GENERAL_NAME_free(n);
|
||||
CMP_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
GENERAL_NAME_free(n);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO potentially move to apps/lib/apps.c */
|
||||
/*
|
||||
* create cert store structure with certificates read from given file(s)
|
||||
* returns pointer to created X509_STORE on success, NULL on error
|
||||
*/
|
||||
static X509_STORE *load_certstore(char *input, const char *desc)
|
||||
{
|
||||
X509_STORE *store = NULL;
|
||||
STACK_OF(X509) *certs = NULL;
|
||||
|
||||
if (input == NULL)
|
||||
goto err;
|
||||
|
||||
while (input != NULL) {
|
||||
char *next = next_item(input); \
|
||||
|
||||
if (!load_certs_autofmt(input, &certs, 1, opt_otherpass, desc)
|
||||
|| !(store = sk_X509_to_store(store, certs))) {
|
||||
/* CMP_err("out of memory"); */
|
||||
X509_STORE_free(store);
|
||||
store = NULL;
|
||||
goto err;
|
||||
}
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
certs = NULL;
|
||||
input = next;
|
||||
}
|
||||
err:
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
return store;
|
||||
}
|
||||
|
||||
/* TODO potentially move to apps/lib/apps.c */
|
||||
static STACK_OF(X509) *load_certs_multifile(char *files,
|
||||
const char *pass, const char *desc)
|
||||
{
|
||||
STACK_OF(X509) *certs = NULL;
|
||||
STACK_OF(X509) *result = sk_X509_new_null();
|
||||
|
||||
if (files == NULL)
|
||||
goto err;
|
||||
if (result == NULL)
|
||||
goto oom;
|
||||
|
||||
while (files != NULL) {
|
||||
char *next = next_item(files);
|
||||
|
||||
if (!load_certs_autofmt(files, &certs, 0, pass, desc))
|
||||
goto err;
|
||||
if (!sk_X509_add1_certs(result, certs, 0, 1 /* no dups */, 0))
|
||||
goto oom;
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
certs = NULL;
|
||||
files = next;
|
||||
}
|
||||
return result;
|
||||
|
||||
oom:
|
||||
BIO_printf(bio_err, "out of memory\n");
|
||||
err:
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
sk_X509_pop_free(result, X509_free);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedef int (*add_X509_stack_fn_t)(void *ctx, const STACK_OF(X509) *certs);
|
||||
typedef int (*add_X509_fn_t)(void *ctx, const X509 *cert);
|
||||
|
||||
static int setup_certs(char *files, const char *desc, void *ctx,
|
||||
add_X509_stack_fn_t addn_fn, add_X509_fn_t add1_fn)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
if (files != NULL) {
|
||||
STACK_OF(X509) *certs = load_certs_multifile(files, opt_otherpass,
|
||||
desc);
|
||||
if (certs == NULL) {
|
||||
ret = 0;
|
||||
} else {
|
||||
if (addn_fn != NULL) {
|
||||
ret = (*addn_fn)(ctx, certs);
|
||||
} else {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sk_X509_num(certs /* may be NULL */); i++)
|
||||
ret &= (*add1_fn)(ctx, sk_X509_value(certs, i));
|
||||
}
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* parse and transform some options, checking their syntax.
|
||||
* Returns 1 on success, 0 on error
|
||||
*/
|
||||
static int transform_opts(void)
|
||||
{
|
||||
if (opt_cmd_s != NULL) {
|
||||
if (!strcmp(opt_cmd_s, "ir")) {
|
||||
opt_cmd = CMP_IR;
|
||||
} else if (!strcmp(opt_cmd_s, "kur")) {
|
||||
opt_cmd = CMP_KUR;
|
||||
} else if (!strcmp(opt_cmd_s, "cr")) {
|
||||
opt_cmd = CMP_CR;
|
||||
} else if (!strcmp(opt_cmd_s, "p10cr")) {
|
||||
opt_cmd = CMP_P10CR;
|
||||
} else if (!strcmp(opt_cmd_s, "rr")) {
|
||||
opt_cmd = CMP_RR;
|
||||
} else if (!strcmp(opt_cmd_s, "genm")) {
|
||||
opt_cmd = CMP_GENM;
|
||||
} else {
|
||||
CMP_err1("unknown cmp command '%s'", opt_cmd_s);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
CMP_err("no cmp command to execute");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_NO_ENGINE
|
||||
# define FORMAT_OPTIONS (OPT_FMT_PEMDER | OPT_FMT_PKCS12 | OPT_FMT_ENGINE)
|
||||
#else
|
||||
# define FORMAT_OPTIONS (OPT_FMT_PEMDER | OPT_FMT_PKCS12)
|
||||
#endif
|
||||
|
||||
if (opt_keyform_s != NULL
|
||||
&& !opt_format(opt_keyform_s, FORMAT_OPTIONS, &opt_keyform)) {
|
||||
CMP_err("unknown option given for key loading format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef FORMAT_OPTIONS
|
||||
|
||||
if (opt_certform_s != NULL
|
||||
&& !opt_format(opt_certform_s, OPT_FMT_PEMDER, &opt_certform)) {
|
||||
CMP_err("unknown option given for certificate storing format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (opt_certsform_s != NULL
|
||||
&& !opt_format(opt_certsform_s, OPT_FMT_PEMDER | OPT_FMT_PKCS12,
|
||||
&opt_certsform)) {
|
||||
CMP_err("unknown option given for certificate list loading format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static OSSL_CMP_SRV_CTX *setup_srv_ctx(ENGINE *e)
|
||||
{
|
||||
OSSL_CMP_CTX *ctx; /* extra CMP (client) ctx partly used by server */
|
||||
OSSL_CMP_SRV_CTX *srv_ctx = ossl_cmp_mock_srv_new();
|
||||
|
||||
if (srv_ctx == NULL)
|
||||
return NULL;
|
||||
ctx = OSSL_CMP_SRV_CTX_get0_cmp_ctx(srv_ctx);
|
||||
|
||||
if (opt_srv_ref == NULL) {
|
||||
if (opt_srv_cert == NULL) {
|
||||
/* opt_srv_cert should determine the sender */
|
||||
CMP_err("must give -srv_ref for server if no -srv_cert given");
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
if (!OSSL_CMP_CTX_set1_referenceValue(ctx, (unsigned char *)opt_srv_ref,
|
||||
strlen(opt_srv_ref)))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (opt_srv_secret != NULL) {
|
||||
int res;
|
||||
char *pass_str = get_passwd(opt_srv_secret, "PBMAC secret of server");
|
||||
|
||||
if (pass_str != NULL) {
|
||||
cleanse(opt_srv_secret);
|
||||
res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_str,
|
||||
strlen(pass_str));
|
||||
clear_free(pass_str);
|
||||
if (res == 0)
|
||||
goto err;
|
||||
}
|
||||
} else if (opt_srv_cert == NULL) {
|
||||
CMP_err("server credentials must be given if -use_mock_srv or -port is used");
|
||||
goto err;
|
||||
} else {
|
||||
CMP_warn("server will not be able to handle PBM-protected requests since -srv_secret is not given");
|
||||
}
|
||||
|
||||
if (opt_srv_secret == NULL
|
||||
&& ((opt_srv_cert == NULL) != (opt_srv_key == NULL))) {
|
||||
CMP_err("must give both -srv_cert and -srv_key options or neither");
|
||||
goto err;
|
||||
}
|
||||
if (opt_srv_cert != NULL) {
|
||||
X509 *srv_cert = load_cert_pwd(opt_srv_cert, opt_srv_keypass,
|
||||
"certificate of the server");
|
||||
|
||||
if (srv_cert == NULL || !OSSL_CMP_CTX_set1_cert(ctx, srv_cert)) {
|
||||
X509_free(srv_cert);
|
||||
goto err;
|
||||
}
|
||||
X509_free(srv_cert);
|
||||
}
|
||||
if (opt_srv_key != NULL) {
|
||||
EVP_PKEY *pkey = load_key_pwd(opt_srv_key, opt_keyform,
|
||||
opt_srv_keypass,
|
||||
e, "private key for server cert");
|
||||
|
||||
if (pkey == NULL || !OSSL_CMP_CTX_set1_pkey(ctx, pkey)) {
|
||||
EVP_PKEY_free(pkey);
|
||||
goto err;
|
||||
}
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
cleanse(opt_srv_keypass);
|
||||
|
||||
if (opt_srv_trusted != NULL) {
|
||||
X509_STORE *ts =
|
||||
load_certstore(opt_srv_trusted, "certificates trusted by server");
|
||||
|
||||
if (ts == NULL)
|
||||
goto err;
|
||||
if (!set1_store_parameters(ts)
|
||||
|| !truststore_set_host_etc(ts, NULL)
|
||||
|| !OSSL_CMP_CTX_set0_trustedStore(ctx, ts)) {
|
||||
X509_STORE_free(ts);
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
CMP_warn("server will not be able to handle signature-protected requests since -srv_trusted is not given");
|
||||
}
|
||||
if (!setup_certs(opt_srv_untrusted, "untrusted certificates", ctx,
|
||||
(add_X509_stack_fn_t)OSSL_CMP_CTX_set1_untrusted_certs,
|
||||
NULL))
|
||||
goto err;
|
||||
|
||||
if (opt_rsp_cert == NULL) {
|
||||
CMP_err("must give -rsp_cert for mock server");
|
||||
goto err;
|
||||
} else {
|
||||
X509 *cert = load_cert_pwd(opt_rsp_cert, opt_keypass,
|
||||
"cert to be returned by the mock server");
|
||||
|
||||
if (cert == NULL)
|
||||
goto err;
|
||||
/* from server perspective the server is the client */
|
||||
if (!ossl_cmp_mock_srv_set1_certOut(srv_ctx, cert)) {
|
||||
X509_free(cert);
|
||||
goto err;
|
||||
}
|
||||
X509_free(cert);
|
||||
}
|
||||
/* TODO find a cleaner solution not requiring type casts */
|
||||
if (!setup_certs(opt_rsp_extracerts,
|
||||
"CMP extra certificates for mock server", srv_ctx,
|
||||
(add_X509_stack_fn_t)ossl_cmp_mock_srv_set1_chainOut,
|
||||
NULL))
|
||||
goto err;
|
||||
if (!setup_certs(opt_rsp_capubs, "caPubs for mock server", srv_ctx,
|
||||
(add_X509_stack_fn_t)ossl_cmp_mock_srv_set1_caPubsOut,
|
||||
NULL))
|
||||
goto err;
|
||||
(void)ossl_cmp_mock_srv_set_pollCount(srv_ctx, opt_poll_count);
|
||||
(void)ossl_cmp_mock_srv_set_checkAfterTime(srv_ctx, opt_check_after);
|
||||
if (opt_grant_implicitconf)
|
||||
(void)OSSL_CMP_SRV_CTX_set_grant_implicit_confirm(srv_ctx, 1);
|
||||
|
||||
if (opt_failure != INT_MIN) { /* option has been set explicity */
|
||||
if (opt_failure < 0 || OSSL_CMP_PKIFAILUREINFO_MAX < opt_failure) {
|
||||
CMP_err1("-failure out of range, should be >= 0 and <= %d",
|
||||
OSSL_CMP_PKIFAILUREINFO_MAX);
|
||||
goto err;
|
||||
}
|
||||
if (opt_failurebits != 0)
|
||||
CMP_warn("-failurebits overrides -failure");
|
||||
else
|
||||
opt_failurebits = 1 << opt_failure;
|
||||
}
|
||||
if ((unsigned)opt_failurebits > OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN) {
|
||||
CMP_err("-failurebits out of range");
|
||||
goto err;
|
||||
}
|
||||
if (!ossl_cmp_mock_srv_set_statusInfo(srv_ctx, opt_pkistatus,
|
||||
opt_failurebits, opt_statusstring))
|
||||
goto err;
|
||||
|
||||
if (opt_send_error)
|
||||
(void)ossl_cmp_mock_srv_set_send_error(srv_ctx, 1);
|
||||
|
||||
if (opt_send_unprotected)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_SEND, 1);
|
||||
if (opt_send_unprot_err)
|
||||
(void)OSSL_CMP_SRV_CTX_set_send_unprotected_errors(srv_ctx, 1);
|
||||
if (opt_accept_unprotected)
|
||||
(void)OSSL_CMP_SRV_CTX_set_accept_unprotected(srv_ctx, 1);
|
||||
if (opt_accept_unprot_err)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_ERRORS, 1);
|
||||
if (opt_accept_raverified)
|
||||
(void)OSSL_CMP_SRV_CTX_set_accept_raverified(srv_ctx, 1);
|
||||
|
||||
return srv_ctx;
|
||||
|
||||
err:
|
||||
ossl_cmp_mock_srv_free(srv_ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* set up verification aspects of OSSL_CMP_CTX w.r.t. opts from config file/CLI.
|
||||
* Returns pointer on success, NULL on error
|
||||
*/
|
||||
static int setup_verification_ctx(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
if (!setup_certs(opt_untrusted, "untrusted certificates", ctx,
|
||||
(add_X509_stack_fn_t)OSSL_CMP_CTX_set1_untrusted_certs,
|
||||
NULL))
|
||||
goto err;
|
||||
|
||||
if (opt_srvcert != NULL || opt_trusted != NULL) {
|
||||
X509_STORE *ts = NULL;
|
||||
|
||||
if (opt_srvcert != NULL) {
|
||||
X509 *srvcert;
|
||||
|
||||
if (opt_trusted != NULL) {
|
||||
CMP_warn("-trusted option is ignored since -srvcert option is present");
|
||||
opt_trusted = NULL;
|
||||
}
|
||||
if (opt_recipient != NULL) {
|
||||
CMP_warn("-recipient option is ignored since -srvcert option is present");
|
||||
opt_recipient = NULL;
|
||||
}
|
||||
srvcert = load_cert_pwd(opt_srvcert, opt_otherpass,
|
||||
"directly trusted CMP server certificate");
|
||||
if (srvcert == NULL)
|
||||
/*
|
||||
* opt_otherpass is needed in case
|
||||
* opt_srvcert is an encrypted PKCS#12 file
|
||||
*/
|
||||
goto err;
|
||||
if (!OSSL_CMP_CTX_set1_srvCert(ctx, srvcert)) {
|
||||
X509_free(srvcert);
|
||||
goto oom;
|
||||
}
|
||||
X509_free(srvcert);
|
||||
if ((ts = X509_STORE_new()) == NULL)
|
||||
goto oom;
|
||||
}
|
||||
if (opt_trusted != NULL
|
||||
&& (ts = load_certstore(opt_trusted, "trusted certificates"))
|
||||
== NULL)
|
||||
goto err;
|
||||
if (!set1_store_parameters(ts) /* also copies vpm */
|
||||
/*
|
||||
* clear any expected host/ip/email address;
|
||||
* opt_expect_sender is used instead
|
||||
*/
|
||||
|| !truststore_set_host_etc(ts, NULL)
|
||||
|| !OSSL_CMP_CTX_set0_trustedStore(ctx, ts)) {
|
||||
X509_STORE_free(ts);
|
||||
goto oom;
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_ignore_keyusage)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_IGNORE_KEYUSAGE, 1);
|
||||
|
||||
if (opt_unprotected_errors)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_ERRORS, 1);
|
||||
|
||||
if (opt_out_trusted != NULL) { /* for use in OSSL_CMP_certConf_cb() */
|
||||
X509_VERIFY_PARAM *out_vpm = NULL;
|
||||
X509_STORE *out_trusted =
|
||||
load_certstore(opt_out_trusted,
|
||||
"trusted certs for verifying newly enrolled cert");
|
||||
|
||||
if (out_trusted == NULL)
|
||||
goto err;
|
||||
/* any -verify_hostname, -verify_ip, and -verify_email apply here */
|
||||
if (!set1_store_parameters(out_trusted))
|
||||
goto oom;
|
||||
/* ignore any -attime here, new certs are current anyway */
|
||||
out_vpm = X509_STORE_get0_param(out_trusted);
|
||||
X509_VERIFY_PARAM_clear_flags(out_vpm, X509_V_FLAG_USE_CHECK_TIME);
|
||||
|
||||
(void)OSSL_CMP_CTX_set_certConf_cb_arg(ctx, out_trusted);
|
||||
}
|
||||
|
||||
if (opt_disable_confirm)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_DISABLE_CONFIRM, 1);
|
||||
|
||||
if (opt_implicit_confirm)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_IMPLICIT_CONFIRM, 1);
|
||||
|
||||
(void)OSSL_CMP_CTX_set_certConf_cb(ctx, OSSL_CMP_certConf_cb);
|
||||
|
||||
return 1;
|
||||
|
||||
oom:
|
||||
CMP_err("out of memory");
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
/*
|
||||
* set up ssl_ctx for the OSSL_CMP_CTX based on options from config file/CLI.
|
||||
* Returns pointer on success, NULL on error
|
||||
*/
|
||||
static SSL_CTX *setup_ssl_ctx(OSSL_CMP_CTX *ctx, ENGINE *e)
|
||||
{
|
||||
STACK_OF(X509) *untrusted_certs = OSSL_CMP_CTX_get0_untrusted_certs(ctx);
|
||||
EVP_PKEY *pkey = NULL;
|
||||
X509_STORE *trust_store = NULL;
|
||||
SSL_CTX *ssl_ctx;
|
||||
int i;
|
||||
|
||||
ssl_ctx = SSL_CTX_new(TLS_client_method());
|
||||
if (ssl_ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
|
||||
|
||||
if (opt_tls_trusted != NULL) {
|
||||
if ((trust_store = load_certstore(opt_tls_trusted,
|
||||
"trusted TLS certificates")) == NULL)
|
||||
goto err;
|
||||
SSL_CTX_set_cert_store(ssl_ctx, trust_store);
|
||||
/* for improved diagnostics on SSL_CTX_build_cert_chain() errors: */
|
||||
X509_STORE_set_verify_cb(trust_store, X509_STORE_CTX_print_verify_cb);
|
||||
}
|
||||
|
||||
if (opt_tls_cert != NULL && opt_tls_key != NULL) {
|
||||
X509 *cert;
|
||||
STACK_OF(X509) *certs = NULL;
|
||||
|
||||
if (!load_certs_autofmt(opt_tls_cert, &certs, 0, opt_tls_keypass,
|
||||
"TLS client certificate (optionally with chain)"))
|
||||
/*
|
||||
* opt_tls_keypass is needed in case opt_tls_cert is an encrypted
|
||||
* PKCS#12 file
|
||||
*/
|
||||
goto err;
|
||||
|
||||
cert = sk_X509_delete(certs, 0);
|
||||
if (cert == NULL || SSL_CTX_use_certificate(ssl_ctx, cert) <= 0) {
|
||||
CMP_err1("unable to use client TLS certificate file '%s'",
|
||||
opt_tls_cert);
|
||||
X509_free(cert);
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
goto err;
|
||||
}
|
||||
X509_free(cert); /* we do not need the handle any more */
|
||||
|
||||
/*
|
||||
* Any further certs and any untrusted certs are used for constructing
|
||||
* the client cert chain to be provided along with the TLS client cert
|
||||
* to the TLS server.
|
||||
*/
|
||||
if (!SSL_CTX_set0_chain(ssl_ctx, certs)) {
|
||||
CMP_err("could not set TLS client cert chain");
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
goto err;
|
||||
}
|
||||
for (i = 0; i < sk_X509_num(untrusted_certs); i++) {
|
||||
cert = sk_X509_value(untrusted_certs, i);
|
||||
if (!SSL_CTX_add1_chain_cert(ssl_ctx, cert)) {
|
||||
CMP_err("could not add untrusted cert to TLS client cert chain");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!SSL_CTX_build_cert_chain(ssl_ctx,
|
||||
SSL_BUILD_CHAIN_FLAG_UNTRUSTED |
|
||||
SSL_BUILD_CHAIN_FLAG_NO_ROOT)) {
|
||||
CMP_warn("could not build cert chain for own TLS cert");
|
||||
OSSL_CMP_CTX_print_errors(ctx);
|
||||
}
|
||||
|
||||
/* If present we append to the list also the certs from opt_tls_extra */
|
||||
if (opt_tls_extra != NULL) {
|
||||
STACK_OF(X509) *tls_extra = load_certs_multifile(opt_tls_extra,
|
||||
opt_otherpass,
|
||||
"extra certificates for TLS");
|
||||
int res = 1;
|
||||
|
||||
if (tls_extra == NULL)
|
||||
goto err;
|
||||
for (i = 0; i < sk_X509_num(tls_extra); i++) {
|
||||
cert = sk_X509_value(tls_extra, i);
|
||||
if (res != 0)
|
||||
res = SSL_CTX_add_extra_chain_cert(ssl_ctx, cert);
|
||||
if (res == 0)
|
||||
X509_free(cert);
|
||||
}
|
||||
sk_X509_free(tls_extra);
|
||||
if (res == 0) {
|
||||
BIO_printf(bio_err, "error: unable to add TLS extra certs\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
pkey = load_key_pwd(opt_tls_key, opt_keyform, opt_tls_keypass,
|
||||
e, "TLS client private key");
|
||||
cleanse(opt_tls_keypass);
|
||||
if (pkey == NULL)
|
||||
goto err;
|
||||
/*
|
||||
* verify the key matches the cert,
|
||||
* not using SSL_CTX_check_private_key(ssl_ctx)
|
||||
* because it gives poor and sometimes misleading diagnostics
|
||||
*/
|
||||
if (!X509_check_private_key(SSL_CTX_get0_certificate(ssl_ctx),
|
||||
pkey)) {
|
||||
CMP_err2("TLS private key '%s' does not match the TLS certificate '%s'\n",
|
||||
opt_tls_key, opt_tls_cert);
|
||||
EVP_PKEY_free(pkey);
|
||||
pkey = NULL; /* otherwise, for some reason double free! */
|
||||
goto err;
|
||||
}
|
||||
if (SSL_CTX_use_PrivateKey(ssl_ctx, pkey) <= 0) {
|
||||
CMP_err1("unable to use TLS client private key '%s'", opt_tls_key);
|
||||
EVP_PKEY_free(pkey);
|
||||
pkey = NULL; /* otherwise, for some reason double free! */
|
||||
goto err;
|
||||
}
|
||||
EVP_PKEY_free(pkey); /* we do not need the handle any more */
|
||||
}
|
||||
if (opt_tls_trusted != NULL) {
|
||||
/* enable and parameterize server hostname/IP address check */
|
||||
if (!truststore_set_host_etc(trust_store,
|
||||
opt_tls_host != NULL ?
|
||||
opt_tls_host : opt_server))
|
||||
/* TODO: is the server host name correct for TLS via proxy? */
|
||||
goto err;
|
||||
SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, NULL);
|
||||
}
|
||||
return ssl_ctx;
|
||||
err:
|
||||
SSL_CTX_free(ssl_ctx);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* set up protection aspects of OSSL_CMP_CTX based on options from config
|
||||
* file/CLI while parsing options and checking their consistency.
|
||||
* Returns 1 on success, 0 on error
|
||||
*/
|
||||
static int setup_protection_ctx(OSSL_CMP_CTX *ctx, ENGINE *e)
|
||||
{
|
||||
if (!opt_unprotected_requests && opt_secret == NULL && opt_cert == NULL) {
|
||||
CMP_err("must give client credentials unless -unprotected_requests is set");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (opt_ref == NULL && opt_cert == NULL && opt_subject == NULL) {
|
||||
/* cert or subject should determine the sender */
|
||||
CMP_err("must give -ref if no -cert and no -subject given");
|
||||
goto err;
|
||||
}
|
||||
if (!opt_secret && ((opt_cert == NULL) != (opt_key == NULL))) {
|
||||
CMP_err("must give both -cert and -key options or neither");
|
||||
goto err;
|
||||
}
|
||||
if (opt_secret != NULL) {
|
||||
char *pass_string = get_passwd(opt_secret, "PBMAC");
|
||||
int res;
|
||||
|
||||
if (pass_string != NULL) {
|
||||
cleanse(opt_secret);
|
||||
res = OSSL_CMP_CTX_set1_secretValue(ctx,
|
||||
(unsigned char *)pass_string,
|
||||
strlen(pass_string));
|
||||
clear_free(pass_string);
|
||||
if (res == 0)
|
||||
goto err;
|
||||
}
|
||||
if (opt_cert != NULL || opt_key != NULL)
|
||||
CMP_warn("no signature-based protection used since -secret is given");
|
||||
}
|
||||
if (opt_ref != NULL
|
||||
&& !OSSL_CMP_CTX_set1_referenceValue(ctx, (unsigned char *)opt_ref,
|
||||
strlen(opt_ref)))
|
||||
goto err;
|
||||
|
||||
if (opt_key != NULL) {
|
||||
EVP_PKEY *pkey = load_key_pwd(opt_key, opt_keyform, opt_keypass, e,
|
||||
"private key for CMP client certificate");
|
||||
|
||||
if (pkey == NULL || !OSSL_CMP_CTX_set1_pkey(ctx, pkey)) {
|
||||
EVP_PKEY_free(pkey);
|
||||
goto err;
|
||||
}
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (opt_secret == NULL && opt_srvcert == NULL && opt_trusted == NULL) {
|
||||
CMP_err("missing -secret or -srvcert or -trusted");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (opt_cert != NULL) {
|
||||
X509 *cert;
|
||||
STACK_OF(X509) *certs = NULL;
|
||||
int ok;
|
||||
|
||||
if (!load_certs_autofmt(opt_cert, &certs, 0, opt_keypass,
|
||||
"CMP client certificate (and optionally extra certs)"))
|
||||
/* opt_keypass is needed if opt_cert is an encrypted PKCS#12 file */
|
||||
goto err;
|
||||
|
||||
cert = sk_X509_delete(certs, 0);
|
||||
if (cert == NULL) {
|
||||
CMP_err("no client certificate found");
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
goto err;
|
||||
}
|
||||
ok = OSSL_CMP_CTX_set1_cert(ctx, cert);
|
||||
X509_free(cert);
|
||||
|
||||
if (ok) {
|
||||
/* add any remaining certs to the list of untrusted certs */
|
||||
STACK_OF(X509) *untrusted = OSSL_CMP_CTX_get0_untrusted_certs(ctx);
|
||||
ok = untrusted != NULL ?
|
||||
sk_X509_add1_certs(untrusted, certs, 0, 1 /* no dups */, 0) :
|
||||
OSSL_CMP_CTX_set1_untrusted_certs(ctx, certs);
|
||||
}
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
if (!ok)
|
||||
goto oom;
|
||||
}
|
||||
|
||||
if (!setup_certs(opt_extracerts, "extra certificates for CMP", ctx,
|
||||
(add_X509_stack_fn_t)OSSL_CMP_CTX_set1_extraCertsOut,
|
||||
NULL))
|
||||
goto err;
|
||||
cleanse(opt_otherpass);
|
||||
|
||||
if (opt_unprotected_requests)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_SEND, 1);
|
||||
|
||||
if (opt_digest != NULL) {
|
||||
int digest = OBJ_ln2nid(opt_digest);
|
||||
|
||||
if (digest == NID_undef) {
|
||||
CMP_err1("digest algorithm name not recognized: '%s'", opt_digest);
|
||||
goto err;
|
||||
}
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_DIGEST_ALGNID, digest);
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_OWF_ALGNID, digest);
|
||||
}
|
||||
|
||||
if (opt_mac != NULL) {
|
||||
int mac = OBJ_ln2nid(opt_mac);
|
||||
if (mac == NID_undef) {
|
||||
CMP_err1("MAC algorithm name not recognized: '%s'", opt_mac);
|
||||
goto err;
|
||||
}
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_MAC_ALGNID, mac);
|
||||
}
|
||||
return 1;
|
||||
|
||||
oom:
|
||||
CMP_err("out of memory");
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* set up IR/CR/KUR/CertConf/RR specific parts of the OSSL_CMP_CTX
|
||||
* based on options from config file/CLI.
|
||||
* Returns pointer on success, NULL on error
|
||||
*/
|
||||
static int setup_request_ctx(OSSL_CMP_CTX *ctx, ENGINE *e)
|
||||
{
|
||||
if (opt_subject == NULL && opt_oldcert == NULL && opt_cert == NULL)
|
||||
CMP_warn("no -subject given, neither -oldcert nor -cert available as default");
|
||||
if (!set_name(opt_subject, OSSL_CMP_CTX_set1_subjectName, ctx, "subject")
|
||||
|| !set_name(opt_issuer, OSSL_CMP_CTX_set1_issuer, ctx, "issuer"))
|
||||
goto err;
|
||||
|
||||
if (opt_newkey != NULL) {
|
||||
const char *file = opt_newkey;
|
||||
const int format = opt_keyform;
|
||||
const char *pass = opt_newkeypass;
|
||||
const char *desc = "new private or public key for cert to be enrolled";
|
||||
EVP_PKEY *pkey = load_key_pwd(file, format, pass, e, NULL);
|
||||
int priv = 1;
|
||||
|
||||
if (pkey == NULL) {
|
||||
ERR_clear_error();
|
||||
pkey = load_pubkey(file, format, 0, pass, e, desc);
|
||||
priv = 0;
|
||||
}
|
||||
cleanse(opt_newkeypass);
|
||||
if (pkey == NULL || !OSSL_CMP_CTX_set0_newPkey(ctx, priv, pkey)) {
|
||||
EVP_PKEY_free(pkey);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_days > 0)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_VALIDITY_DAYS,
|
||||
opt_days);
|
||||
|
||||
if (opt_policies != NULL && opt_policy_oids != NULL) {
|
||||
CMP_err("cannot have policies both via -policies and via -policy_oids");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (opt_reqexts != NULL || opt_policies != NULL) {
|
||||
X509V3_CTX ext_ctx;
|
||||
X509_EXTENSIONS *exts = sk_X509_EXTENSION_new_null();
|
||||
|
||||
if (exts == NULL)
|
||||
goto err;
|
||||
X509V3_set_ctx(&ext_ctx, NULL, NULL, NULL, NULL, 0);
|
||||
X509V3_set_nconf(&ext_ctx, conf);
|
||||
if (opt_reqexts != NULL
|
||||
&& !X509V3_EXT_add_nconf_sk(conf, &ext_ctx, opt_reqexts, &exts)) {
|
||||
CMP_err1("cannot load certificate request extension section '%s'",
|
||||
opt_reqexts);
|
||||
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
|
||||
goto err;
|
||||
}
|
||||
if (opt_policies != NULL
|
||||
&& !X509V3_EXT_add_nconf_sk(conf, &ext_ctx, opt_policies, &exts)) {
|
||||
CMP_err1("cannot load policy cert request extension section '%s'",
|
||||
opt_policies);
|
||||
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
|
||||
goto err;
|
||||
}
|
||||
OSSL_CMP_CTX_set0_reqExtensions(ctx, exts);
|
||||
}
|
||||
if (OSSL_CMP_CTX_reqExtensions_have_SAN(ctx) && opt_sans != NULL) {
|
||||
CMP_err("cannot have Subject Alternative Names both via -reqexts and via -sans");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!set_gennames(ctx, opt_sans, "Subject Alternative Name"))
|
||||
goto err;
|
||||
|
||||
if (opt_san_nodefault) {
|
||||
if (opt_sans != NULL)
|
||||
CMP_warn("-opt_san_nodefault has no effect when -sans is used");
|
||||
(void)OSSL_CMP_CTX_set_option(ctx,
|
||||
OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT, 1);
|
||||
}
|
||||
|
||||
if (opt_policy_oids_critical) {
|
||||
if (opt_policy_oids == NULL)
|
||||
CMP_warn("-opt_policy_oids_critical has no effect unless -policy_oids is given");
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_POLICIES_CRITICAL, 1);
|
||||
}
|
||||
|
||||
while (opt_policy_oids != NULL) {
|
||||
ASN1_OBJECT *policy;
|
||||
POLICYINFO *pinfo;
|
||||
char *next = next_item(opt_policy_oids);
|
||||
|
||||
if ((policy = OBJ_txt2obj(opt_policy_oids, 1)) == 0) {
|
||||
CMP_err1("unknown policy OID '%s'", opt_policy_oids);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((pinfo = POLICYINFO_new()) == NULL) {
|
||||
ASN1_OBJECT_free(policy);
|
||||
goto err;
|
||||
}
|
||||
pinfo->policyid = policy;
|
||||
|
||||
if (!OSSL_CMP_CTX_push0_policy(ctx, pinfo)) {
|
||||
CMP_err1("cannot add policy with OID '%s'", opt_policy_oids);
|
||||
POLICYINFO_free(pinfo);
|
||||
goto err;
|
||||
}
|
||||
opt_policy_oids = next;
|
||||
}
|
||||
|
||||
if (opt_popo >= OSSL_CRMF_POPO_NONE)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_POPO_METHOD, opt_popo);
|
||||
|
||||
if (opt_csr != NULL) {
|
||||
if (opt_cmd != CMP_P10CR) {
|
||||
CMP_warn("-csr option is ignored for command other than p10cr");
|
||||
} else {
|
||||
X509_REQ *csr =
|
||||
load_csr_autofmt(opt_csr, "PKCS#10 CSR for p10cr");
|
||||
|
||||
if (csr == NULL)
|
||||
goto err;
|
||||
if (!OSSL_CMP_CTX_set1_p10CSR(ctx, csr)) {
|
||||
X509_REQ_free(csr);
|
||||
goto oom;
|
||||
}
|
||||
X509_REQ_free(csr);
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_oldcert != NULL) {
|
||||
X509 *oldcert = load_cert_pwd(opt_oldcert, opt_keypass,
|
||||
"certificate to be updated/revoked");
|
||||
/* opt_keypass is needed if opt_oldcert is an encrypted PKCS#12 file */
|
||||
|
||||
if (oldcert == NULL)
|
||||
goto err;
|
||||
if (!OSSL_CMP_CTX_set1_oldCert(ctx, oldcert)) {
|
||||
X509_free(oldcert);
|
||||
goto oom;
|
||||
}
|
||||
X509_free(oldcert);
|
||||
}
|
||||
cleanse(opt_keypass);
|
||||
if (opt_revreason > CRL_REASON_NONE)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_REVOCATION_REASON,
|
||||
opt_revreason);
|
||||
|
||||
return 1;
|
||||
|
||||
oom:
|
||||
CMP_err("out of memory");
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_opt_geninfo(OSSL_CMP_CTX *ctx)
|
||||
{
|
||||
long value;
|
||||
ASN1_OBJECT *type;
|
||||
ASN1_INTEGER *aint;
|
||||
ASN1_TYPE *val;
|
||||
OSSL_CMP_ITAV *itav;
|
||||
char *endstr;
|
||||
char *valptr = strchr(opt_geninfo, ':');
|
||||
|
||||
if (valptr == NULL) {
|
||||
CMP_err("missing ':' in -geninfo option");
|
||||
return 0;
|
||||
}
|
||||
valptr[0] = '\0';
|
||||
valptr++;
|
||||
|
||||
if (strncasecmp(valptr, "int:", 4) != 0) {
|
||||
CMP_err("missing 'int:' in -geninfo option");
|
||||
return 0;
|
||||
}
|
||||
valptr += 4;
|
||||
|
||||
value = strtol(valptr, &endstr, 10);
|
||||
if (endstr == valptr || *endstr != '\0') {
|
||||
CMP_err("cannot parse int in -geninfo option");
|
||||
return 0;
|
||||
}
|
||||
|
||||
type = OBJ_txt2obj(opt_geninfo, 1);
|
||||
if (type == NULL) {
|
||||
CMP_err("cannot parse OID in -geninfo option");
|
||||
return 0;
|
||||
}
|
||||
|
||||
aint = ASN1_INTEGER_new();
|
||||
if (aint == NULL || !ASN1_INTEGER_set(aint, value))
|
||||
goto oom;
|
||||
|
||||
val = ASN1_TYPE_new();
|
||||
if (val == NULL) {
|
||||
ASN1_INTEGER_free(aint);
|
||||
goto oom;
|
||||
}
|
||||
ASN1_TYPE_set(val, V_ASN1_INTEGER, aint);
|
||||
itav = OSSL_CMP_ITAV_create(type, val);
|
||||
if (itav == NULL) {
|
||||
ASN1_TYPE_free(val);
|
||||
goto oom;
|
||||
}
|
||||
|
||||
if (!OSSL_CMP_CTX_push0_geninfo_ITAV(ctx, itav)) {
|
||||
OSSL_CMP_ITAV_free(itav);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
oom:
|
||||
CMP_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set up the client-side OSSL_CMP_CTX based on options from config file/CLI
|
||||
* while parsing options and checking their consistency.
|
||||
* Prints reason for error to bio_err.
|
||||
* Returns 1 on success, 0 on error
|
||||
*/
|
||||
static int setup_client_ctx(OSSL_CMP_CTX *ctx, ENGINE *e)
|
||||
{
|
||||
int ret = 0;
|
||||
char server_buf[200] = { '\0' };
|
||||
char proxy_buf[200] = { '\0' };
|
||||
char *proxy_host = NULL;
|
||||
char *proxy_port_str = NULL;
|
||||
|
||||
if (opt_server == NULL) {
|
||||
CMP_err("missing server address[:port]");
|
||||
goto err;
|
||||
} else if ((server_port =
|
||||
parse_addr(&opt_server, server_port, "server")) < 0) {
|
||||
goto err;
|
||||
}
|
||||
if (server_port != 0)
|
||||
BIO_snprintf(server_port_s, sizeof(server_port_s), "%d", server_port);
|
||||
if (!OSSL_CMP_CTX_set1_server(ctx, opt_server)
|
||||
|| !OSSL_CMP_CTX_set_serverPort(ctx, server_port)
|
||||
|| !OSSL_CMP_CTX_set1_serverPath(ctx, opt_path))
|
||||
goto oom;
|
||||
if (opt_proxy != NULL && !OSSL_CMP_CTX_set1_proxy(ctx, opt_proxy))
|
||||
goto oom;
|
||||
(void)BIO_snprintf(server_buf, sizeof(server_buf), "http%s://%s%s%s/%s",
|
||||
opt_tls_used ? "s" : "", opt_server,
|
||||
server_port == 0 ? "" : ":", server_port_s,
|
||||
opt_path[0] == '/' ? opt_path + 1 : opt_path);
|
||||
|
||||
if (opt_proxy != NULL)
|
||||
(void)BIO_snprintf(proxy_buf, sizeof(proxy_buf), " via %s", opt_proxy);
|
||||
CMP_info2("will contact %s%s", server_buf, proxy_buf);
|
||||
|
||||
if (!transform_opts())
|
||||
goto err;
|
||||
|
||||
if (opt_cmd == CMP_IR || opt_cmd == CMP_CR || opt_cmd == CMP_KUR) {
|
||||
if (opt_newkey == NULL && opt_key == NULL && opt_csr == NULL) {
|
||||
CMP_err("missing -newkey (or -key) to be certified");
|
||||
goto err;
|
||||
}
|
||||
if (opt_certout == NULL) {
|
||||
CMP_err("-certout not given, nowhere to save certificate");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (opt_cmd == CMP_KUR) {
|
||||
char *ref_cert = opt_oldcert != NULL ? opt_oldcert : opt_cert;
|
||||
|
||||
if (ref_cert == NULL) {
|
||||
CMP_err("missing -oldcert option for certificate to be updated");
|
||||
goto err;
|
||||
}
|
||||
if (opt_subject != NULL)
|
||||
CMP_warn2("-subject '%s' given, which overrides the subject of '%s' in KUR",
|
||||
opt_subject, ref_cert);
|
||||
}
|
||||
if (opt_cmd == CMP_RR && opt_oldcert == NULL) {
|
||||
CMP_err("missing certificate to be revoked");
|
||||
goto err;
|
||||
}
|
||||
if (opt_cmd == CMP_P10CR && opt_csr == NULL) {
|
||||
CMP_err("missing PKCS#10 CSR for p10cr");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (opt_recipient == NULL && opt_srvcert == NULL && opt_issuer == NULL
|
||||
&& opt_oldcert == NULL && opt_cert == NULL)
|
||||
CMP_warn("missing -recipient, -srvcert, -issuer, -oldcert or -cert; recipient will be set to \"NULL-DN\"");
|
||||
|
||||
if (opt_infotype_s != NULL) {
|
||||
char id_buf[100] = "id-it-";
|
||||
|
||||
strncat(id_buf, opt_infotype_s, sizeof(id_buf) - strlen(id_buf) - 1);
|
||||
if ((opt_infotype = OBJ_sn2nid(id_buf)) == NID_undef) {
|
||||
CMP_err("unknown OID name in -infotype option");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!setup_verification_ctx(ctx))
|
||||
goto err;
|
||||
|
||||
if (opt_msg_timeout >= 0) /* must do this before setup_ssl_ctx() */
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_MSG_TIMEOUT,
|
||||
opt_msg_timeout);
|
||||
if (opt_total_timeout >= 0)
|
||||
(void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_TOTAL_TIMEOUT,
|
||||
opt_total_timeout);
|
||||
|
||||
if (opt_reqin != NULL && opt_rspin != NULL)
|
||||
CMP_warn("-reqin is ignored since -rspin is present");
|
||||
if (opt_reqin_new_tid && opt_reqin == NULL)
|
||||
CMP_warn("-reqin_new_tid is ignored since -reqin is not present");
|
||||
if (opt_reqin != NULL || opt_reqout != NULL
|
||||
|| opt_rspin != NULL || opt_rspout != NULL || opt_use_mock_srv)
|
||||
(void)OSSL_CMP_CTX_set_transfer_cb(ctx, read_write_req_resp);
|
||||
|
||||
if ((opt_tls_cert != NULL || opt_tls_key != NULL
|
||||
|| opt_tls_keypass != NULL || opt_tls_extra != NULL
|
||||
|| opt_tls_trusted != NULL || opt_tls_host != NULL)
|
||||
&& !opt_tls_used)
|
||||
CMP_warn("TLS options(s) given but not -tls_used");
|
||||
if (opt_tls_used) {
|
||||
#ifdef OPENSSL_NO_SOCK
|
||||
BIO_printf(bio_err, "Cannot use TLS - sockets not supported\n");
|
||||
goto err;
|
||||
#else
|
||||
APP_HTTP_TLS_INFO *info;
|
||||
|
||||
if (opt_tls_cert != NULL
|
||||
|| opt_tls_key != NULL || opt_tls_keypass != NULL) {
|
||||
if (opt_tls_key == NULL) {
|
||||
CMP_err("missing -tls_key option");
|
||||
goto err;
|
||||
} else if (opt_tls_cert == NULL) {
|
||||
CMP_err("missing -tls_cert option");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (opt_use_mock_srv) {
|
||||
CMP_err("cannot use TLS options together with -use_mock_srv");
|
||||
goto err;
|
||||
}
|
||||
if ((info = OPENSSL_zalloc(sizeof(*info))) == NULL)
|
||||
goto err;
|
||||
(void)OSSL_CMP_CTX_set_http_cb_arg(ctx, info);
|
||||
/* info will be freed along with CMP ctx */
|
||||
info->server = opt_server;
|
||||
info->port = server_port_s;
|
||||
info->use_proxy = opt_proxy != NULL;
|
||||
info->timeout = OSSL_CMP_CTX_get_option(ctx, OSSL_CMP_OPT_MSG_TIMEOUT);
|
||||
info->ssl_ctx = setup_ssl_ctx(ctx, e);
|
||||
if (info->ssl_ctx == NULL)
|
||||
goto err;
|
||||
(void)OSSL_CMP_CTX_set_http_cb(ctx, app_http_tls_cb);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!setup_protection_ctx(ctx, e))
|
||||
goto err;
|
||||
|
||||
if (!setup_request_ctx(ctx, e))
|
||||
goto err;
|
||||
|
||||
if (!set_name(opt_recipient, OSSL_CMP_CTX_set1_recipient, ctx, "recipient")
|
||||
|| !set_name(opt_expect_sender, OSSL_CMP_CTX_set1_expected_sender,
|
||||
ctx, "expected sender"))
|
||||
goto oom;
|
||||
|
||||
if (opt_geninfo != NULL && !handle_opt_geninfo(ctx))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(proxy_host);
|
||||
OPENSSL_free(proxy_port_str);
|
||||
return ret;
|
||||
oom:
|
||||
CMP_err("out of memory");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* write out the given certificate to the output specified by bio.
|
||||
* Depending on options use either PEM or DER format.
|
||||
* Returns 1 on success, 0 on error
|
||||
*/
|
||||
static int write_cert(BIO *bio, X509 *cert)
|
||||
{
|
||||
if ((opt_certform == FORMAT_PEM && PEM_write_bio_X509(bio, cert))
|
||||
|| (opt_certform == FORMAT_ASN1 && i2d_X509_bio(bio, cert)))
|
||||
return 1;
|
||||
if (opt_certform != FORMAT_PEM && opt_certform != FORMAT_ASN1)
|
||||
BIO_printf(bio_err,
|
||||
"error: unsupported type '%s' for writing certificates\n",
|
||||
opt_certform_s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* writes out a stack of certs to the given file.
|
||||
* Depending on options use either PEM or DER format,
|
||||
* where DER does not make much sense for writing more than one cert!
|
||||
* Returns number of written certificates on success, 0 on error.
|
||||
*/
|
||||
static int save_certs(OSSL_CMP_CTX *ctx,
|
||||
STACK_OF(X509) *certs, char *destFile, char *desc)
|
||||
{
|
||||
BIO *bio = NULL;
|
||||
int i;
|
||||
int n = sk_X509_num(certs);
|
||||
|
||||
CMP_info3("received %d %s certificate(s), saving to file '%s'",
|
||||
n, desc, destFile);
|
||||
if (n > 1 && opt_certform != FORMAT_PEM)
|
||||
CMP_warn("saving more than one certificate in non-PEM format");
|
||||
|
||||
if (destFile == NULL || (bio = BIO_new(BIO_s_file())) == NULL
|
||||
|| !BIO_write_filename(bio, (char *)destFile)) {
|
||||
CMP_err1("could not open file '%s' for writing", destFile);
|
||||
n = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!write_cert(bio, sk_X509_value(certs, i))) {
|
||||
CMP_err1("cannot write certificate to file '%s'", destFile);
|
||||
n = -1;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
err:
|
||||
BIO_free(bio);
|
||||
return n;
|
||||
}
|
||||
|
||||
static void print_itavs(STACK_OF(OSSL_CMP_ITAV) *itavs)
|
||||
{
|
||||
OSSL_CMP_ITAV *itav = NULL;
|
||||
char buf[128];
|
||||
int i;
|
||||
int n = sk_OSSL_CMP_ITAV_num(itavs); /* itavs == NULL leads to 0 */
|
||||
|
||||
if (n == 0) {
|
||||
CMP_info("genp contains no ITAV");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
itav = sk_OSSL_CMP_ITAV_value(itavs, i);
|
||||
OBJ_obj2txt(buf, 128, OSSL_CMP_ITAV_get0_type(itav), 0);
|
||||
CMP_info1("genp contains ITAV of type: %s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
static char opt_item[SECTION_NAME_MAX + 1];
|
||||
/* get previous name from a comma-separated list of names */
|
||||
static const char *prev_item(const char *opt, const char *end)
|
||||
{
|
||||
const char *beg;
|
||||
size_t len;
|
||||
|
||||
if (end == opt)
|
||||
return NULL;
|
||||
beg = end;
|
||||
while (beg != opt && beg[-1] != ',' && !isspace(beg[-1]))
|
||||
beg--;
|
||||
len = end - beg;
|
||||
if (len > SECTION_NAME_MAX)
|
||||
len = SECTION_NAME_MAX;
|
||||
strncpy(opt_item, beg, len);
|
||||
opt_item[SECTION_NAME_MAX] = '\0'; /* avoid gcc v8 O3 stringop-truncation */
|
||||
opt_item[len] = '\0';
|
||||
if (len > SECTION_NAME_MAX)
|
||||
CMP_warn2("using only first %d characters of section name starting with \"%s\"",
|
||||
SECTION_NAME_MAX, opt_item);
|
||||
while (beg != opt && (beg[-1] == ',' || isspace(beg[-1])))
|
||||
beg--;
|
||||
return beg;
|
||||
}
|
||||
|
||||
/* get str value for name from a comma-separated hierarchy of config sections */
|
||||
static char *conf_get_string(const CONF *src_conf, const char *groups,
|
||||
const char *name)
|
||||
{
|
||||
char *res = NULL;
|
||||
const char *end = groups + strlen(groups);
|
||||
|
||||
while ((end = prev_item(groups, end)) != NULL) {
|
||||
if ((res = NCONF_get_string(src_conf, opt_item, name)) != NULL)
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* get long val for name from a comma-separated hierarchy of config sections */
|
||||
static int conf_get_number_e(const CONF *conf_, const char *groups,
|
||||
const char *name, long *result)
|
||||
{
|
||||
char *str = conf_get_string(conf_, groups, name);
|
||||
char *tailptr;
|
||||
long res;
|
||||
|
||||
if (str == NULL || *str == '\0')
|
||||
return 0;
|
||||
|
||||
res = strtol(str, &tailptr, 10);
|
||||
if (res == LONG_MIN || res == LONG_MAX || *tailptr != '\0')
|
||||
return 0;
|
||||
|
||||
*result = res;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* use the command line option table to read values from the CMP section
|
||||
* of openssl.cnf. Defaults are taken from the config file, they can be
|
||||
* overwritten on the command line.
|
||||
*/
|
||||
static int read_config(void)
|
||||
{
|
||||
unsigned int i;
|
||||
long num = 0;
|
||||
char *txt = NULL;
|
||||
const OPTIONS *opt;
|
||||
int provider_option;
|
||||
int verification_option;
|
||||
|
||||
/*
|
||||
* starting with offset OPT_SECTION because OPT_CONFIG and OPT_SECTION would
|
||||
* not make sense within the config file. They have already been handled.
|
||||
*/
|
||||
for (i = OPT_SECTION - OPT_HELP, opt = &cmp_options[OPT_SECTION];
|
||||
opt->name; i++, opt++) {
|
||||
if (!strcmp(opt->name, OPT_SECTION_STR)
|
||||
|| !strcmp(opt->name, OPT_MORE_STR)) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
provider_option = (OPT_PROV__FIRST <= opt->retval
|
||||
&& opt->retval < OPT_PROV__LAST);
|
||||
verification_option = (OPT_V__FIRST <= opt->retval
|
||||
&& opt->retval < OPT_V__LAST);
|
||||
if (provider_option || verification_option)
|
||||
i--;
|
||||
if (cmp_vars[i].txt == NULL) {
|
||||
CMP_err1("internal: cmp_vars array too short, i=%d", i);
|
||||
return 0;
|
||||
}
|
||||
switch (opt->valtype) {
|
||||
case '-':
|
||||
case 'n':
|
||||
case 'l':
|
||||
if (!conf_get_number_e(conf, opt_section, opt->name, &num)) {
|
||||
ERR_clear_error();
|
||||
continue; /* option not provided */
|
||||
}
|
||||
break;
|
||||
/*
|
||||
* do not use '<' in cmp_options. Incorrect treatment
|
||||
* somewhere in args_verify() can wrongly set badarg = 1
|
||||
*/
|
||||
case '<':
|
||||
case 's':
|
||||
case 'M':
|
||||
txt = conf_get_string(conf, opt_section, opt->name);
|
||||
if (txt == NULL) {
|
||||
ERR_clear_error();
|
||||
continue; /* option not provided */
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CMP_err2("internal: unsupported type '%c' for option '%s'",
|
||||
opt->valtype, opt->name);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
if (provider_option || verification_option) {
|
||||
int conf_argc = 1;
|
||||
char *conf_argv[3];
|
||||
char arg1[82];
|
||||
|
||||
BIO_snprintf(arg1, 81, "-%s", (char *)opt->name);
|
||||
conf_argv[0] = prog;
|
||||
conf_argv[1] = arg1;
|
||||
if (opt->valtype == '-') {
|
||||
if (num != 0)
|
||||
conf_argc = 2;
|
||||
} else {
|
||||
conf_argc = 3;
|
||||
conf_argv[2] = conf_get_string(conf, opt_section, opt->name);
|
||||
/* not NULL */
|
||||
}
|
||||
if (conf_argc > 1) {
|
||||
(void)opt_init(conf_argc, conf_argv, cmp_options);
|
||||
|
||||
if (provider_option
|
||||
? !opt_provider(opt_next())
|
||||
: !opt_verify(opt_next(), vpm)) {
|
||||
CMP_err2("for option '%s' in config file section '%s'",
|
||||
opt->name, opt_section);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (opt->valtype) {
|
||||
case '-':
|
||||
case 'n':
|
||||
if (num < INT_MIN || INT_MAX < num) {
|
||||
BIO_printf(bio_err,
|
||||
"integer value out of range for option '%s'\n",
|
||||
opt->name);
|
||||
return 0;
|
||||
}
|
||||
*cmp_vars[i].num = (int)num;
|
||||
break;
|
||||
case 'l':
|
||||
*cmp_vars[i].num_long = num;
|
||||
break;
|
||||
default:
|
||||
if (txt != NULL && txt[0] == '\0')
|
||||
txt = NULL; /* reset option on empty string input */
|
||||
*cmp_vars[i].txt = txt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *opt_str(char *opt)
|
||||
{
|
||||
char *arg = opt_arg();
|
||||
|
||||
if (arg[0] == '\0') {
|
||||
CMP_warn1("argument of -%s option is empty string, resetting option",
|
||||
opt);
|
||||
arg = NULL;
|
||||
} else if (arg[0] == '-') {
|
||||
CMP_warn1("argument of -%s option starts with hyphen", opt);
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
static int opt_nat(void)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if (opt_int(opt_arg(), &result) && result < 0)
|
||||
BIO_printf(bio_err, "error: argument '%s' must not be negative\n",
|
||||
opt_arg());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* returns 1 on success, 0 on error, -1 on -help (i.e., stop with success) */
|
||||
static int get_opts(int argc, char **argv)
|
||||
{
|
||||
OPTION_CHOICE o;
|
||||
|
||||
prog = opt_init(argc, argv, cmp_options);
|
||||
|
||||
while ((o = opt_next()) != OPT_EOF) {
|
||||
switch (o) {
|
||||
case OPT_EOF:
|
||||
case OPT_ERR:
|
||||
goto opt_err;
|
||||
case OPT_HELP:
|
||||
opt_help(cmp_options);
|
||||
return -1;
|
||||
case OPT_CONFIG: /* has already been handled */
|
||||
break;
|
||||
case OPT_SECTION: /* has already been handled */
|
||||
break;
|
||||
case OPT_SERVER:
|
||||
opt_server = opt_str("server");
|
||||
break;
|
||||
case OPT_PROXY:
|
||||
opt_proxy = opt_str("proxy");
|
||||
break;
|
||||
case OPT_NO_PROXY:
|
||||
opt_no_proxy = opt_str("no_proxy");
|
||||
break;
|
||||
case OPT_PATH:
|
||||
opt_path = opt_str("path");
|
||||
break;
|
||||
case OPT_MSG_TIMEOUT:
|
||||
if ((opt_msg_timeout = opt_nat()) < 0)
|
||||
goto opt_err;
|
||||
break;
|
||||
case OPT_TOTAL_TIMEOUT:
|
||||
if ((opt_total_timeout = opt_nat()) < 0)
|
||||
goto opt_err;
|
||||
break;
|
||||
case OPT_TLS_USED:
|
||||
opt_tls_used = 1;
|
||||
break;
|
||||
case OPT_TLS_CERT:
|
||||
opt_tls_cert = opt_str("tls_cert");
|
||||
break;
|
||||
case OPT_TLS_KEY:
|
||||
opt_tls_key = opt_str("tls_key");
|
||||
break;
|
||||
case OPT_TLS_KEYPASS:
|
||||
opt_tls_keypass = opt_str("tls_keypass");
|
||||
break;
|
||||
case OPT_TLS_EXTRA:
|
||||
opt_tls_extra = opt_str("tls_extra");
|
||||
break;
|
||||
case OPT_TLS_TRUSTED:
|
||||
opt_tls_trusted = opt_str("tls_trusted");
|
||||
break;
|
||||
case OPT_TLS_HOST:
|
||||
opt_tls_host = opt_str("tls_host");
|
||||
break;
|
||||
case OPT_REF:
|
||||
opt_ref = opt_str("ref");
|
||||
break;
|
||||
case OPT_SECRET:
|
||||
opt_secret = opt_str("secret");
|
||||
break;
|
||||
case OPT_CERT:
|
||||
opt_cert = opt_str("cert");
|
||||
break;
|
||||
case OPT_KEY:
|
||||
opt_key = opt_str("key");
|
||||
break;
|
||||
case OPT_KEYPASS:
|
||||
opt_keypass = opt_str("keypass");
|
||||
break;
|
||||
case OPT_DIGEST:
|
||||
opt_digest = opt_str("digest");
|
||||
break;
|
||||
case OPT_MAC:
|
||||
opt_mac = opt_str("mac");
|
||||
break;
|
||||
case OPT_EXTRACERTS:
|
||||
opt_extracerts = opt_str("extracerts");
|
||||
break;
|
||||
case OPT_UNPROTECTED_REQUESTS:
|
||||
opt_unprotected_requests = 1;
|
||||
break;
|
||||
|
||||
case OPT_TRUSTED:
|
||||
opt_trusted = opt_str("trusted");
|
||||
break;
|
||||
case OPT_UNTRUSTED:
|
||||
opt_untrusted = opt_str("untrusted");
|
||||
break;
|
||||
case OPT_SRVCERT:
|
||||
opt_srvcert = opt_str("srvcert");
|
||||
break;
|
||||
case OPT_RECIPIENT:
|
||||
opt_recipient = opt_str("recipient");
|
||||
break;
|
||||
case OPT_EXPECT_SENDER:
|
||||
opt_expect_sender = opt_str("expect_sender");
|
||||
break;
|
||||
case OPT_IGNORE_KEYUSAGE:
|
||||
opt_ignore_keyusage = 1;
|
||||
break;
|
||||
case OPT_UNPROTECTED_ERRORS:
|
||||
opt_unprotected_errors = 1;
|
||||
break;
|
||||
case OPT_EXTRACERTSOUT:
|
||||
opt_extracertsout = opt_str("extracertsout");
|
||||
break;
|
||||
case OPT_CACERTSOUT:
|
||||
opt_cacertsout = opt_str("cacertsout");
|
||||
break;
|
||||
|
||||
case OPT_V_CASES:
|
||||
if (!opt_verify(o, vpm))
|
||||
goto opt_err;
|
||||
break;
|
||||
case OPT_CMD:
|
||||
opt_cmd_s = opt_str("cmd");
|
||||
break;
|
||||
case OPT_INFOTYPE:
|
||||
opt_infotype_s = opt_str("infotype");
|
||||
break;
|
||||
case OPT_GENINFO:
|
||||
opt_geninfo = opt_str("geninfo");
|
||||
break;
|
||||
|
||||
case OPT_NEWKEY:
|
||||
opt_newkey = opt_str("newkey");
|
||||
break;
|
||||
case OPT_NEWKEYPASS:
|
||||
opt_newkeypass = opt_str("newkeypass");
|
||||
break;
|
||||
case OPT_SUBJECT:
|
||||
opt_subject = opt_str("subject");
|
||||
break;
|
||||
case OPT_ISSUER:
|
||||
opt_issuer = opt_str("issuer");
|
||||
break;
|
||||
case OPT_DAYS:
|
||||
if ((opt_days = opt_nat()) < 0)
|
||||
goto opt_err;
|
||||
break;
|
||||
case OPT_REQEXTS:
|
||||
opt_reqexts = opt_str("reqexts");
|
||||
break;
|
||||
case OPT_SANS:
|
||||
opt_sans = opt_str("sans");
|
||||
break;
|
||||
case OPT_SAN_NODEFAULT:
|
||||
opt_san_nodefault = 1;
|
||||
break;
|
||||
case OPT_POLICIES:
|
||||
opt_policies = opt_str("policies");
|
||||
break;
|
||||
case OPT_POLICY_OIDS:
|
||||
opt_policy_oids = opt_str("policy_oids");
|
||||
break;
|
||||
case OPT_POLICY_OIDS_CRITICAL:
|
||||
opt_policy_oids_critical = 1;
|
||||
break;
|
||||
case OPT_POPO:
|
||||
if (!opt_int(opt_arg(), &opt_popo)
|
||||
|| opt_popo < OSSL_CRMF_POPO_NONE
|
||||
|| opt_popo > OSSL_CRMF_POPO_KEYENC) {
|
||||
CMP_err("invalid popo spec. Valid values are -1 .. 2");
|
||||
goto opt_err;
|
||||
}
|
||||
break;
|
||||
case OPT_CSR:
|
||||
opt_csr = opt_arg();
|
||||
break;
|
||||
case OPT_OUT_TRUSTED:
|
||||
opt_out_trusted = opt_str("out_trusted");
|
||||
break;
|
||||
case OPT_IMPLICIT_CONFIRM:
|
||||
opt_implicit_confirm = 1;
|
||||
break;
|
||||
case OPT_DISABLE_CONFIRM:
|
||||
opt_disable_confirm = 1;
|
||||
break;
|
||||
case OPT_CERTOUT:
|
||||
opt_certout = opt_str("certout");
|
||||
break;
|
||||
case OPT_OLDCERT:
|
||||
opt_oldcert = opt_str("oldcert");
|
||||
break;
|
||||
case OPT_REVREASON:
|
||||
if (!opt_int(opt_arg(), &opt_revreason)
|
||||
|| opt_revreason < CRL_REASON_NONE
|
||||
|| opt_revreason > CRL_REASON_AA_COMPROMISE
|
||||
|| opt_revreason == 7) {
|
||||
CMP_err("invalid revreason. Valid values are -1 .. 6, 8 .. 10");
|
||||
goto opt_err;
|
||||
}
|
||||
break;
|
||||
case OPT_CERTFORM:
|
||||
opt_certform_s = opt_str("certform");
|
||||
break;
|
||||
case OPT_KEYFORM:
|
||||
opt_keyform_s = opt_str("keyform");
|
||||
break;
|
||||
case OPT_CERTSFORM:
|
||||
opt_certsform_s = opt_str("certsform");
|
||||
break;
|
||||
case OPT_OTHERPASS:
|
||||
opt_otherpass = opt_str("otherpass");
|
||||
break;
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
case OPT_ENGINE:
|
||||
opt_engine = opt_str("engine");
|
||||
break;
|
||||
#endif
|
||||
case OPT_PROV_CASES:
|
||||
if (!opt_provider(o))
|
||||
goto opt_err;
|
||||
break;
|
||||
|
||||
case OPT_BATCH:
|
||||
opt_batch = 1;
|
||||
break;
|
||||
case OPT_REPEAT:
|
||||
opt_repeat = opt_nat();
|
||||
break;
|
||||
case OPT_REQIN:
|
||||
opt_reqin = opt_str("reqin");
|
||||
break;
|
||||
case OPT_REQIN_NEW_TID:
|
||||
opt_reqin_new_tid = 1;
|
||||
break;
|
||||
case OPT_REQOUT:
|
||||
opt_reqout = opt_str("reqout");
|
||||
break;
|
||||
case OPT_RSPIN:
|
||||
opt_rspin = opt_str("rspin");
|
||||
break;
|
||||
case OPT_RSPOUT:
|
||||
opt_rspout = opt_str("rspout");
|
||||
break;
|
||||
case OPT_USE_MOCK_SRV:
|
||||
opt_use_mock_srv = 1;
|
||||
break;
|
||||
case OPT_PORT:
|
||||
opt_port = opt_str("port");
|
||||
break;
|
||||
case OPT_MAX_MSGS:
|
||||
if ((opt_max_msgs = opt_nat()) < 0)
|
||||
goto opt_err;
|
||||
break;
|
||||
case OPT_SRV_REF:
|
||||
opt_srv_ref = opt_str("srv_ref");
|
||||
break;
|
||||
case OPT_SRV_SECRET:
|
||||
opt_srv_secret = opt_str("srv_secret");
|
||||
break;
|
||||
case OPT_SRV_CERT:
|
||||
opt_srv_cert = opt_str("srv_cert");
|
||||
break;
|
||||
case OPT_SRV_KEY:
|
||||
opt_srv_key = opt_str("srv_key");
|
||||
break;
|
||||
case OPT_SRV_KEYPASS:
|
||||
opt_srv_keypass = opt_str("srv_keypass");
|
||||
break;
|
||||
case OPT_SRV_TRUSTED:
|
||||
opt_srv_trusted = opt_str("srv_trusted");
|
||||
break;
|
||||
case OPT_SRV_UNTRUSTED:
|
||||
opt_srv_untrusted = opt_str("srv_untrusted");
|
||||
break;
|
||||
case OPT_RSP_CERT:
|
||||
opt_rsp_cert = opt_str("rsp_cert");
|
||||
break;
|
||||
case OPT_RSP_EXTRACERTS:
|
||||
opt_rsp_extracerts = opt_str("rsp_extracerts");
|
||||
break;
|
||||
case OPT_RSP_CAPUBS:
|
||||
opt_rsp_capubs = opt_str("rsp_capubs");
|
||||
break;
|
||||
case OPT_POLL_COUNT:
|
||||
opt_poll_count = opt_nat();
|
||||
break;
|
||||
case OPT_CHECK_AFTER:
|
||||
opt_check_after = opt_nat();
|
||||
break;
|
||||
case OPT_GRANT_IMPLICITCONF:
|
||||
opt_grant_implicitconf = 1;
|
||||
break;
|
||||
case OPT_PKISTATUS:
|
||||
opt_pkistatus = opt_nat();
|
||||
break;
|
||||
case OPT_FAILURE:
|
||||
opt_failure = opt_nat();
|
||||
break;
|
||||
case OPT_FAILUREBITS:
|
||||
opt_failurebits = opt_nat();
|
||||
break;
|
||||
case OPT_STATUSSTRING:
|
||||
opt_statusstring = opt_str("statusstring");
|
||||
break;
|
||||
case OPT_SEND_ERROR:
|
||||
opt_send_error = 1;
|
||||
break;
|
||||
case OPT_SEND_UNPROTECTED:
|
||||
opt_send_unprotected = 1;
|
||||
break;
|
||||
case OPT_SEND_UNPROT_ERR:
|
||||
opt_send_unprot_err = 1;
|
||||
break;
|
||||
case OPT_ACCEPT_UNPROTECTED:
|
||||
opt_accept_unprotected = 1;
|
||||
break;
|
||||
case OPT_ACCEPT_UNPROT_ERR:
|
||||
opt_accept_unprot_err = 1;
|
||||
break;
|
||||
case OPT_ACCEPT_RAVERIFIED:
|
||||
opt_accept_raverified = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc = opt_num_rest();
|
||||
argv = opt_rest();
|
||||
if (argc != 0) {
|
||||
CMP_err1("unknown parameter %s", argv[0]);
|
||||
goto opt_err;
|
||||
}
|
||||
return 1;
|
||||
|
||||
opt_err:
|
||||
CMP_err1("use -help for summary of '%s' options", prog);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmp_main(int argc, char **argv)
|
||||
{
|
||||
char *configfile = NULL;
|
||||
int i;
|
||||
X509 *newcert = NULL;
|
||||
ENGINE *e = NULL;
|
||||
char mock_server[] = "mock server:1";
|
||||
int ret = 0; /* default: failure */
|
||||
|
||||
if (argc <= 1) {
|
||||
opt_help(cmp_options);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* handle OPT_CONFIG and OPT_SECTION upfront to take effect for other opts
|
||||
*/
|
||||
for (i = 1; i < argc - 1; i++) {
|
||||
if (*argv[i] == '-') {
|
||||
if (!strcmp(argv[i] + 1, cmp_options[OPT_CONFIG - OPT_HELP].name))
|
||||
opt_config = argv[i + 1];
|
||||
else if (!strcmp(argv[i] + 1,
|
||||
cmp_options[OPT_SECTION - OPT_HELP].name))
|
||||
opt_section = argv[i + 1];
|
||||
}
|
||||
}
|
||||
if (opt_section[0] == '\0') /* empty string */
|
||||
opt_section = DEFAULT_SECTION;
|
||||
|
||||
vpm = X509_VERIFY_PARAM_new();
|
||||
if (vpm == NULL) {
|
||||
CMP_err("out of memory");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* read default values for options from config file */
|
||||
configfile = opt_config != NULL ? opt_config : default_config_file;
|
||||
if (configfile && configfile[0] != '\0' /* non-empty string */
|
||||
&& (configfile != default_config_file
|
||||
|| access(configfile, F_OK) != -1)) {
|
||||
CMP_info1("using OpenSSL configuration file '%s'", configfile);
|
||||
conf = app_load_config(configfile);
|
||||
if (conf == NULL) {
|
||||
goto err;
|
||||
} else {
|
||||
if (strcmp(opt_section, CMP_SECTION) == 0) { /* default */
|
||||
if (!NCONF_get_section(conf, opt_section))
|
||||
CMP_info2("no [%s] section found in config file '%s';"
|
||||
" will thus use just [default] and unnamed section if present",
|
||||
opt_section, configfile);
|
||||
} else {
|
||||
const char *end = opt_section + strlen(opt_section);
|
||||
while ((end = prev_item(opt_section, end)) != NULL) {
|
||||
if (!NCONF_get_section(conf, opt_item)) {
|
||||
CMP_err2("no [%s] section found in config file '%s'",
|
||||
opt_item, configfile);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!read_config())
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
(void)BIO_flush(bio_err); /* prevent interference with opt_help() */
|
||||
|
||||
ret = get_opts(argc, argv);
|
||||
if (ret <= 0)
|
||||
goto err;
|
||||
ret = 0;
|
||||
|
||||
if (opt_batch) {
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
UI_METHOD *ui_fallback_method;
|
||||
# ifndef OPENSSL_NO_UI_CONSOLE
|
||||
ui_fallback_method = UI_OpenSSL();
|
||||
# else
|
||||
ui_fallback_method = (UI_METHOD *)UI_null();
|
||||
# endif
|
||||
UI_method_set_reader(ui_fallback_method, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (opt_engine != NULL)
|
||||
e = setup_engine_methods(opt_engine, 0 /* not: ENGINE_METHOD_ALL */, 0);
|
||||
|
||||
if (opt_port != NULL) {
|
||||
if (opt_use_mock_srv) {
|
||||
CMP_err("cannot use both -port and -use_mock_srv options");
|
||||
goto err;
|
||||
}
|
||||
if (opt_server != NULL) {
|
||||
CMP_err("cannot use both -port and -server options");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if ((cmp_ctx = OSSL_CMP_CTX_new()) == NULL) {
|
||||
CMP_err("out of memory");
|
||||
goto err;
|
||||
}
|
||||
if (!OSSL_CMP_CTX_set_log_cb(cmp_ctx, print_to_bio_out)) {
|
||||
CMP_err1("cannot set up error reporting and logging for %s", prog);
|
||||
goto err;
|
||||
}
|
||||
if ((opt_use_mock_srv || opt_port != NULL)) {
|
||||
OSSL_CMP_SRV_CTX *srv_ctx;
|
||||
|
||||
if ((srv_ctx = setup_srv_ctx(e)) == NULL)
|
||||
goto err;
|
||||
OSSL_CMP_CTX_set_transfer_cb_arg(cmp_ctx, srv_ctx);
|
||||
if (!OSSL_CMP_CTX_set_log_cb(OSSL_CMP_SRV_CTX_get0_cmp_ctx(srv_ctx),
|
||||
print_to_bio_out)) {
|
||||
CMP_err1("cannot set up error reporting and logging for %s", prog);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (opt_port != NULL) { /* act as very basic CMP HTTP server */
|
||||
#ifdef OPENSSL_NO_SOCK
|
||||
BIO_printf(bio_err, "Cannot act as server - sockets not supported\n");
|
||||
#else
|
||||
BIO *acbio;
|
||||
BIO *cbio = NULL;
|
||||
int msgs = 0;
|
||||
|
||||
if ((acbio = http_server_init_bio(prog, opt_port)) == NULL)
|
||||
goto err;
|
||||
while (opt_max_msgs <= 0 || msgs < opt_max_msgs) {
|
||||
OSSL_CMP_MSG *req = NULL;
|
||||
OSSL_CMP_MSG *resp = NULL;
|
||||
|
||||
ret = http_server_get_asn1_req(ASN1_ITEM_rptr(OSSL_CMP_MSG),
|
||||
(ASN1_VALUE **)&req, &cbio, acbio,
|
||||
prog, 0, 0);
|
||||
if (ret == 0)
|
||||
continue;
|
||||
if (ret++ == -1)
|
||||
break; /* fatal error */
|
||||
|
||||
ret = 0;
|
||||
msgs++;
|
||||
if (req != NULL) {
|
||||
resp = OSSL_CMP_CTX_server_perform(cmp_ctx, req);
|
||||
OSSL_CMP_MSG_free(req);
|
||||
if (resp == NULL)
|
||||
break; /* treated as fatal error */
|
||||
ret = http_server_send_asn1_resp(cbio, "application/pkixcmp",
|
||||
ASN1_ITEM_rptr(OSSL_CMP_MSG),
|
||||
(const ASN1_VALUE *)resp);
|
||||
OSSL_CMP_MSG_free(resp);
|
||||
if (!ret)
|
||||
break; /* treated as fatal error */
|
||||
}
|
||||
BIO_free_all(cbio);
|
||||
cbio = NULL;
|
||||
}
|
||||
BIO_free_all(cbio);
|
||||
BIO_free_all(acbio);
|
||||
#endif
|
||||
goto err;
|
||||
}
|
||||
/* else act as CMP client */
|
||||
|
||||
if (opt_use_mock_srv) {
|
||||
if (opt_server != NULL) {
|
||||
CMP_err("cannot use both -use_mock_srv and -server options");
|
||||
goto err;
|
||||
}
|
||||
if (opt_proxy != NULL) {
|
||||
CMP_err("cannot use both -use_mock_srv and -proxy options");
|
||||
goto err;
|
||||
}
|
||||
opt_server = mock_server;
|
||||
opt_proxy = "API";
|
||||
} else {
|
||||
if (opt_server == NULL) {
|
||||
CMP_err("missing -server option");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!setup_client_ctx(cmp_ctx, e)) {
|
||||
CMP_err("cannot set up CMP context");
|
||||
goto err;
|
||||
}
|
||||
for (i = 0; i < opt_repeat; i++) {
|
||||
/* everything is ready, now connect and perform the command! */
|
||||
switch (opt_cmd) {
|
||||
case CMP_IR:
|
||||
newcert = OSSL_CMP_exec_IR_ses(cmp_ctx);
|
||||
if (newcert == NULL)
|
||||
goto err;
|
||||
break;
|
||||
case CMP_KUR:
|
||||
newcert = OSSL_CMP_exec_KUR_ses(cmp_ctx);
|
||||
if (newcert == NULL)
|
||||
goto err;
|
||||
break;
|
||||
case CMP_CR:
|
||||
newcert = OSSL_CMP_exec_CR_ses(cmp_ctx);
|
||||
if (newcert == NULL)
|
||||
goto err;
|
||||
break;
|
||||
case CMP_P10CR:
|
||||
newcert = OSSL_CMP_exec_P10CR_ses(cmp_ctx);
|
||||
if (newcert == NULL)
|
||||
goto err;
|
||||
break;
|
||||
case CMP_RR:
|
||||
if (OSSL_CMP_exec_RR_ses(cmp_ctx) == NULL)
|
||||
goto err;
|
||||
break;
|
||||
case CMP_GENM:
|
||||
{
|
||||
STACK_OF(OSSL_CMP_ITAV) *itavs;
|
||||
|
||||
if (opt_infotype != NID_undef) {
|
||||
OSSL_CMP_ITAV *itav =
|
||||
OSSL_CMP_ITAV_create(OBJ_nid2obj(opt_infotype), NULL);
|
||||
if (itav == NULL)
|
||||
goto err;
|
||||
OSSL_CMP_CTX_push0_genm_ITAV(cmp_ctx, itav);
|
||||
}
|
||||
|
||||
if ((itavs = OSSL_CMP_exec_GENM_ses(cmp_ctx)) == NULL)
|
||||
goto err;
|
||||
print_itavs(itavs);
|
||||
sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
/* print PKIStatusInfo (this is in case there has been no error) */
|
||||
int status = OSSL_CMP_CTX_get_status(cmp_ctx);
|
||||
char *buf = app_malloc(OSSL_CMP_PKISI_BUFLEN, "PKIStatusInfo buf");
|
||||
const char *string =
|
||||
OSSL_CMP_CTX_snprint_PKIStatus(cmp_ctx, buf,
|
||||
OSSL_CMP_PKISI_BUFLEN);
|
||||
|
||||
CMP_print(bio_err,
|
||||
status == OSSL_CMP_PKISTATUS_accepted ? "info" :
|
||||
status == OSSL_CMP_PKISTATUS_rejection ? "server error" :
|
||||
status == OSSL_CMP_PKISTATUS_waiting ? "internal error"
|
||||
: "warning",
|
||||
"received from %s %s %s", opt_server,
|
||||
string != NULL ? string : "<unknown PKIStatus>", "");
|
||||
OPENSSL_free(buf);
|
||||
}
|
||||
|
||||
if (opt_cacertsout != NULL) {
|
||||
STACK_OF(X509) *certs = OSSL_CMP_CTX_get1_caPubs(cmp_ctx);
|
||||
|
||||
if (sk_X509_num(certs) > 0
|
||||
&& save_certs(cmp_ctx, certs, opt_cacertsout, "CA") < 0) {
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
goto err;
|
||||
}
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
}
|
||||
|
||||
if (opt_extracertsout != NULL) {
|
||||
STACK_OF(X509) *certs = OSSL_CMP_CTX_get1_extraCertsIn(cmp_ctx);
|
||||
if (sk_X509_num(certs) > 0
|
||||
&& save_certs(cmp_ctx, certs, opt_extracertsout,
|
||||
"extra") < 0) {
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
goto err;
|
||||
}
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
}
|
||||
|
||||
if (opt_certout != NULL && newcert != NULL) {
|
||||
STACK_OF(X509) *certs = sk_X509_new_null();
|
||||
|
||||
if (certs == NULL || !sk_X509_push(certs, newcert)
|
||||
|| save_certs(cmp_ctx, certs, opt_certout,
|
||||
"enrolled") < 0) {
|
||||
sk_X509_free(certs);
|
||||
goto err;
|
||||
}
|
||||
sk_X509_free(certs);
|
||||
}
|
||||
if (!OSSL_CMP_CTX_reinit(cmp_ctx))
|
||||
goto err;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
/* in case we ended up here on error without proper cleaning */
|
||||
cleanse(opt_keypass);
|
||||
cleanse(opt_newkeypass);
|
||||
cleanse(opt_otherpass);
|
||||
cleanse(opt_tls_keypass);
|
||||
cleanse(opt_secret);
|
||||
cleanse(opt_srv_keypass);
|
||||
cleanse(opt_srv_secret);
|
||||
|
||||
if (ret != 1)
|
||||
OSSL_CMP_CTX_print_errors(cmp_ctx);
|
||||
|
||||
ossl_cmp_mock_srv_free(OSSL_CMP_CTX_get_transfer_cb_arg(cmp_ctx));
|
||||
{
|
||||
APP_HTTP_TLS_INFO *http_tls_info =
|
||||
OSSL_CMP_CTX_get_http_cb_arg(cmp_ctx);
|
||||
|
||||
if (http_tls_info != NULL) {
|
||||
SSL_CTX_free(http_tls_info->ssl_ctx);
|
||||
OPENSSL_free(http_tls_info);
|
||||
}
|
||||
}
|
||||
X509_STORE_free(OSSL_CMP_CTX_get_certConf_cb_arg(cmp_ctx));
|
||||
OSSL_CMP_CTX_free(cmp_ctx);
|
||||
X509_VERIFY_PARAM_free(vpm);
|
||||
release_engine(e);
|
||||
|
||||
NCONF_free(conf); /* must not do as long as opt_... variables are used */
|
||||
OSSL_CMP_log_close();
|
||||
|
||||
return ret == 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
@@ -15,6 +15,10 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cmperr.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(OSSL_CMP_ITAV)
|
||||
DEFINE_STACK_OF(ASN1_UTF8STRING)
|
||||
|
||||
/* the context for the CMP mock server */
|
||||
typedef struct
|
||||
{
|
||||
|
||||
+14
-7
@@ -23,6 +23,12 @@
|
||||
# include <openssl/x509v3.h>
|
||||
# include <openssl/cms.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(CMS_SignerInfo)
|
||||
DEFINE_STACK_OF(GENERAL_NAME)
|
||||
DEFINE_STACK_OF(GENERAL_NAMES)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
static int save_certs(char *signerfile, STACK_OF(X509) *signers);
|
||||
static int cms_cb(int ok, X509_STORE_CTX *ctx);
|
||||
static void receipt_request_print(CMS_ContentInfo *cms);
|
||||
@@ -190,7 +196,7 @@ const OPTIONS cms_options[] = {
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
{"inkey", OPT_INKEY, 's',
|
||||
"Input private key (if not signer or recipient)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Input private key format (PEM or ENGINE)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Input private key format (ENGINE, other values ignored)"},
|
||||
{"keyopt", OPT_KEYOPT, 's', "Set public key parameters as n:v pairs"},
|
||||
|
||||
OPT_SECTION("Mail header"),
|
||||
@@ -570,7 +576,7 @@ int cms_main(int argc, char **argv)
|
||||
if (operation == SMIME_ENCRYPT) {
|
||||
if (encerts == NULL && (encerts = sk_X509_new_null()) == NULL)
|
||||
goto end;
|
||||
cert = load_cert(opt_arg(), FORMAT_PEM,
|
||||
cert = load_cert(opt_arg(), FORMAT_UNDEF,
|
||||
"recipient certificate file");
|
||||
if (cert == NULL)
|
||||
goto end;
|
||||
@@ -750,7 +756,7 @@ int cms_main(int argc, char **argv)
|
||||
if ((encerts = sk_X509_new_null()) == NULL)
|
||||
goto end;
|
||||
while (*argv) {
|
||||
if ((cert = load_cert(*argv, FORMAT_PEM,
|
||||
if ((cert = load_cert(*argv, FORMAT_UNDEF,
|
||||
"recipient certificate file")) == NULL)
|
||||
goto end;
|
||||
sk_X509_push(encerts, cert);
|
||||
@@ -768,7 +774,7 @@ int cms_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (recipfile != NULL && (operation == SMIME_DECRYPT)) {
|
||||
if ((recip = load_cert(recipfile, FORMAT_PEM,
|
||||
if ((recip = load_cert(recipfile, FORMAT_UNDEF,
|
||||
"recipient certificate file")) == NULL) {
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
@@ -776,7 +782,7 @@ int cms_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (originatorfile != NULL) {
|
||||
if ((originator = load_cert(originatorfile, FORMAT_PEM,
|
||||
if ((originator = load_cert(originatorfile, FORMAT_UNDEF,
|
||||
"originator certificate file")) == NULL) {
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
@@ -784,7 +790,7 @@ int cms_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (operation == SMIME_SIGN_RECEIPT) {
|
||||
if ((signer = load_cert(signerfile, FORMAT_PEM,
|
||||
if ((signer = load_cert(signerfile, FORMAT_UNDEF,
|
||||
"receipt signer certificate file")) == NULL) {
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
@@ -1013,7 +1019,8 @@ int cms_main(int argc, char **argv)
|
||||
signerfile = sk_OPENSSL_STRING_value(sksigners, i);
|
||||
keyfile = sk_OPENSSL_STRING_value(skkeys, i);
|
||||
|
||||
signer = load_cert(signerfile, FORMAT_PEM, "signer certificate");
|
||||
signer = load_cert(signerfile, FORMAT_UNDEF,
|
||||
"signer certificate");
|
||||
if (signer == NULL) {
|
||||
ret = 2;
|
||||
goto end;
|
||||
|
||||
+3
-3
@@ -34,9 +34,9 @@ const OPTIONS crl_options[] = {
|
||||
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, '<', "Input file - default stdin"},
|
||||
{"inform", OPT_INFORM, 'F', "Input format; default PEM"},
|
||||
{"inform", OPT_INFORM, 'F', "CRL input format (DER or PEM); has no effect"},
|
||||
{"key", OPT_KEY, '<', "CRL signing Private key to use"},
|
||||
{"keyform", OPT_KEYFORM, 'F', "Private key file format (PEM or ENGINE)"},
|
||||
{"keyform", OPT_KEYFORM, 'F', "Private key file format (DER/PEM/P12); has no effect"},
|
||||
|
||||
OPT_SECTION("Output"),
|
||||
{"out", OPT_OUT, '>', "output file - default stdout"},
|
||||
@@ -122,7 +122,7 @@ int crl_main(int argc, char **argv)
|
||||
outfile = opt_arg();
|
||||
break;
|
||||
case OPT_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &keyformat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_KEY:
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_INFO)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile);
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
|
||||
+3
-1
@@ -21,6 +21,8 @@
|
||||
#include <openssl/hmac.h>
|
||||
#include <ctype.h>
|
||||
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#undef BUFSIZE
|
||||
#define BUFSIZE 1024*8
|
||||
|
||||
@@ -62,7 +64,7 @@ const OPTIONS dgst_options[] = {
|
||||
{"c", OPT_C, '-', "Print the digest with separating colons"},
|
||||
{"r", OPT_R, '-', "Print the digest in coreutils format"},
|
||||
{"out", OPT_OUT, '>', "Output to filename rather than stdout"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Key file format (PEM or ENGINE)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Key file format (ENGINE, other values ignored)"},
|
||||
{"hex", OPT_HEX, '-', "Print as hex dump"},
|
||||
{"binary", OPT_BINARY, '-', "Print in binary form"},
|
||||
{"d", OPT_DEBUG, '-', "Print debug info"},
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ const OPTIONS dsa_options[] = {
|
||||
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, 's', "Input key"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format, DER PEM PVK"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format (DER/PEM/PVK); has no effect"},
|
||||
{"pubin", OPT_PUBIN, '-', "Expect a public key in input file"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ const OPTIONS ec_options[] = {
|
||||
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, 's', "Input file"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format - DER or PEM"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format (DER/PEM/P12/ENGINE)"},
|
||||
{"pubin", OPT_PUBIN, '-', "Expect a public key in input file"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
{"check", OPT_CHECK, '-', "check key consistency"},
|
||||
|
||||
+1
-1
@@ -538,7 +538,7 @@ int enc_main(int argc, char **argv)
|
||||
goto end;
|
||||
}
|
||||
/* wiping secret data as we no longer need it */
|
||||
OPENSSL_cleanse(hkey, strlen(hkey));
|
||||
cleanse(hkey);
|
||||
}
|
||||
|
||||
if ((benc = BIO_new(BIO_f_cipher())) == NULL)
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/store.h>
|
||||
|
||||
DEFINE_STACK_OF_STRING()
|
||||
DEFINE_STACK_OF_CSTRING()
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_C, OPT_T, OPT_TT, OPT_PRE, OPT_POST,
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "apps.h"
|
||||
#include "progs.h"
|
||||
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#define BUFSIZE 4096
|
||||
#define DEFAULT_MAC_NAME "HMAC"
|
||||
#define DEFAULT_FIPS_SECTION "fips_check_section"
|
||||
|
||||
+19
-15
@@ -12,6 +12,7 @@
|
||||
|
||||
# include "e_os.h" /* struct timeval for DTLS */
|
||||
# include "internal/nelem.h"
|
||||
# include "internal/sockets.h" /* for openssl_fdset() */
|
||||
# include <assert.h>
|
||||
|
||||
# include <sys/types.h>
|
||||
@@ -35,19 +36,12 @@
|
||||
# include "fmt.h"
|
||||
# include "platform.h"
|
||||
|
||||
/* also in include/internal/sockets.h */
|
||||
# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
|
||||
# define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
|
||||
# else
|
||||
# define openssl_fdset(a,b) FD_SET(a, b)
|
||||
# endif
|
||||
|
||||
/*
|
||||
* quick macro when you need to pass an unsigned char instead of a char.
|
||||
* this is true for some implementations of the is*() functions, for
|
||||
* example.
|
||||
*/
|
||||
#define _UC(c) ((unsigned char)(c))
|
||||
# define _UC(c) ((unsigned char)(c))
|
||||
|
||||
void app_RAND_load_conf(CONF *c, const char *section);
|
||||
void app_RAND_write(void);
|
||||
@@ -102,19 +96,28 @@ int set_cert_ex(unsigned long *flags, const char *arg);
|
||||
int set_name_ex(unsigned long *flags, const char *arg);
|
||||
int set_ext_copy(int *copy_type, const char *arg);
|
||||
int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
|
||||
char *get_passwd(const char *pass, const char *desc);
|
||||
int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2);
|
||||
int add_oid_section(CONF *conf);
|
||||
X509_REQ *load_csr(const char *file, int format, const char *desc);
|
||||
X509 *load_cert(const char *file, int format, const char *desc);
|
||||
X509_CRL *load_crl(const char *infile, int format, const char *desc);
|
||||
EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
|
||||
X509 *load_cert_pass(const char *uri, int maybe_stdin,
|
||||
const char *pass, const char *desc);
|
||||
/* the format parameter is meanwhile not needed anymore and thus ignored */
|
||||
X509 *load_cert(const char *uri, int format, const char *desc);
|
||||
X509_CRL *load_crl(const char *uri, int format, const char *desc);
|
||||
void cleanse(char *str);
|
||||
void clear_free(char *str);
|
||||
EVP_PKEY *load_key(const char *uri, int format, int maybe_stdin,
|
||||
const char *pass, ENGINE *e, const char *desc);
|
||||
EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
|
||||
EVP_PKEY *load_pubkey(const char *uri, int format, int maybe_stdin,
|
||||
const char *pass, ENGINE *e, const char *desc);
|
||||
int load_certs(const char *file, STACK_OF(X509) **certs, int format,
|
||||
const char *pass, const char *desc);
|
||||
int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format,
|
||||
const char *pass, const char *desc);
|
||||
int load_key_cert_crl(const char *uri, int maybe_stdin,
|
||||
const char *pass, const char *desc,
|
||||
EVP_PKEY **ppkey, X509 **pcert, X509_CRL **pcrl);
|
||||
X509_STORE *setup_verify(const char *CAfile, int noCAfile,
|
||||
const char *CApath, int noCApath,
|
||||
const char *CAstore, int noCAstore);
|
||||
@@ -123,7 +126,7 @@ __owur int ctx_set_verify_locations(SSL_CTX *ctx,
|
||||
const char *CApath, int noCApath,
|
||||
const char *CAstore, int noCAstore);
|
||||
|
||||
#ifndef OPENSSL_NO_CT
|
||||
# ifndef OPENSSL_NO_CT
|
||||
|
||||
/*
|
||||
* Sets the file to load the Certificate Transparency log list from.
|
||||
@@ -132,9 +135,10 @@ __owur int ctx_set_verify_locations(SSL_CTX *ctx,
|
||||
*/
|
||||
__owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
|
||||
|
||||
#endif
|
||||
# endif
|
||||
|
||||
ENGINE *setup_engine(const char *engine, int debug);
|
||||
ENGINE *setup_engine_methods(const char *id, unsigned int methods, int debug);
|
||||
# define setup_engine(e, debug) setup_engine_methods(e, (unsigned int)-1, debug)
|
||||
void release_engine(ENGINE *e);
|
||||
|
||||
# ifndef OPENSSL_NO_OCSP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 1995-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
|
||||
*/
|
||||
|
||||
#ifndef OSSL_HTTP_SERVER_H
|
||||
# define OSSL_HTTP_SERVER_H
|
||||
|
||||
# include "apps.h"
|
||||
|
||||
# ifndef HAVE_FORK
|
||||
# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
|
||||
# define HAVE_FORK 0
|
||||
# else
|
||||
# define HAVE_FORK 1
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if HAVE_FORK
|
||||
# undef NO_FORK
|
||||
# else
|
||||
# define NO_FORK
|
||||
# endif
|
||||
|
||||
# if !defined(NO_FORK) && !defined(OPENSSL_NO_SOCK) \
|
||||
&& !defined(OPENSSL_NO_POSIX_IO)
|
||||
# define HTTP_DAEMON
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
# include <syslog.h>
|
||||
# include <signal.h>
|
||||
# define MAXERRLEN 1000 /* limit error text sent to syslog to 1000 bytes */
|
||||
# else
|
||||
# undef LOG_INFO
|
||||
# undef LOG_WARNING
|
||||
# undef LOG_ERR
|
||||
# define LOG_INFO 0
|
||||
# define LOG_WARNING 1
|
||||
# define LOG_ERR 2
|
||||
# endif
|
||||
|
||||
/*-
|
||||
* Log a message to syslog if multi-threaded HTTP_DAEMON, else to bio_err
|
||||
* prog: the name of the current app
|
||||
* level: the severity of the message, e.g., LOG_ERR
|
||||
* fmt: message with potential extra parameters like with printf()
|
||||
* returns nothing
|
||||
*/
|
||||
void log_message(const char *prog, int level, const char *fmt, ...);
|
||||
|
||||
# ifndef OPENSSL_NO_SOCK
|
||||
/*-
|
||||
* Initialize an HTTP server by setting up its listening BIO
|
||||
* prog: the name of the current app
|
||||
* port: the port to listen on
|
||||
* returns a BIO for accepting requests, NULL on error
|
||||
*/
|
||||
BIO *http_server_init_bio(const char *prog, const char *port);
|
||||
/*-
|
||||
* Accept an ASN.1-formatted HTTP request
|
||||
* it: the expected request ASN.1 type
|
||||
* preq: pointer to variable where to place the parsed request
|
||||
* pcbio: pointer to variable where to place the BIO for sending the response to
|
||||
* acbio: the listening bio (typically as returned by http_server_init_bio())
|
||||
* prog: the name of the current app
|
||||
* accept_get: wheter to accept GET requests (in addition to POST requests)
|
||||
* timeout: connection timeout (in seconds), or 0 for none/infinite
|
||||
* returns 0 in case caller should retry, then *preq == *pcbio == NULL
|
||||
* returns -1 on fatal error; also in this case *preq == *pcbio == NULL
|
||||
* returns 1 otherwise. In this case it is guaranteed that *pcbio != NULL
|
||||
* while *preq == NULL if and only if request is invalid
|
||||
*/
|
||||
int http_server_get_asn1_req(const ASN1_ITEM *it, ASN1_VALUE **preq,
|
||||
BIO **pcbio, BIO *acbio,
|
||||
const char *prog, int accept_get, int timeout);
|
||||
/*-
|
||||
* Send an ASN.1-formatted HTTP response
|
||||
* cbio: destination BIO (typically as returned by http_server_get_asn1_req())
|
||||
* note: cbio should not do an encoding that changes the output length
|
||||
* content_type: string identifying the type of the response
|
||||
* it: the response ASN.1 type
|
||||
* valit: the response ASN.1 type
|
||||
* resp: the response to send
|
||||
* returns 1 on success, 0 on failure
|
||||
*/
|
||||
int http_server_send_asn1_resp(BIO *cbio, const char *content_type,
|
||||
const ASN1_ITEM *it, const ASN1_VALUE *resp);
|
||||
# endif
|
||||
|
||||
# ifdef HTTP_DAEMON
|
||||
extern int multi;
|
||||
extern int acfd;
|
||||
|
||||
void socket_timeout(int signum);
|
||||
void spawn_loop(const char *prog);
|
||||
# endif
|
||||
|
||||
#endif
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
@@ -132,9 +132,9 @@
|
||||
{ "xchain_build", OPT_X_CHAIN_BUILD, '-', \
|
||||
"build certificate chain for the extended certificates"}, \
|
||||
{ "xcertform", OPT_X_CERTFORM, 'F', \
|
||||
"format of Extended certificate (PEM or DER) PEM default " }, \
|
||||
"format of Extended certificate (PEM/DER/P12); has no effect" }, \
|
||||
{ "xkeyform", OPT_X_KEYFORM, 'F', \
|
||||
"format of Extended certificate's key (PEM or DER) PEM default"}
|
||||
"format of Extended certificate's key (DER/PEM/P12); has no effect"}
|
||||
|
||||
# define OPT_X_CASES \
|
||||
OPT_X__FIRST: case OPT_X__LAST: break; \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-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
|
||||
@@ -32,6 +32,7 @@ int init_client(int *sock, const char *host, const char *port,
|
||||
const char *bindhost, const char *bindport,
|
||||
int family, int type, int protocol);
|
||||
int should_retry(int i);
|
||||
void do_ssl_shutdown(SSL *ssl);
|
||||
|
||||
long bio_dump_callback(BIO *bio, int cmd, const char *argp,
|
||||
int argi, long argl, long ret);
|
||||
|
||||
+3
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/params.h>
|
||||
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_KDFOPT, OPT_BIN, OPT_KEYLEN, OPT_OUT,
|
||||
|
||||
+8
-5
@@ -106,12 +106,15 @@ static int do_x509_ctrl_string(int (*ctrl)(void *object, int cmd,
|
||||
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);
|
||||
if (vtmp != NULL) {
|
||||
void *hexid;
|
||||
long hexid_len = 0;
|
||||
|
||||
OPENSSL_free(stmp);
|
||||
stmp = vtmp = hexid;
|
||||
vtmp_len = (size_t)hexid_len;
|
||||
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
|
||||
|
||||
+220
-242
@@ -29,6 +29,7 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/store.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/ui.h>
|
||||
#include <openssl/safestack.h>
|
||||
@@ -57,6 +58,17 @@ static int WIN32_rename(const char *from, const char *to);
|
||||
|
||||
#define PASS_SOURCE_SIZE_MAX 4
|
||||
|
||||
DEFINE_STACK_OF(CONF)
|
||||
DEFINE_STACK_OF(CONF_VALUE)
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
DEFINE_STACK_OF(X509_INFO)
|
||||
DEFINE_STACK_OF(X509_EXTENSION)
|
||||
DEFINE_STACK_OF(X509_POLICY_NODE)
|
||||
DEFINE_STACK_OF(GENERAL_NAME)
|
||||
DEFINE_STACK_OF(DIST_POINT)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
unsigned long flag;
|
||||
@@ -198,6 +210,24 @@ int wrap_password_callback(char *buf, int bufsiz, int verify, void *userdata)
|
||||
|
||||
static char *app_get_pass(const char *arg, int keepbio);
|
||||
|
||||
char *get_passwd(const char *pass, const char *desc)
|
||||
{
|
||||
char *result = NULL;
|
||||
|
||||
if (desc == NULL)
|
||||
desc = "<unknown>";
|
||||
if (!app_passwd(pass, NULL, &result, NULL))
|
||||
BIO_printf(bio_err, "Error getting password for %s\n", desc);
|
||||
if (pass != NULL && result == NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Trying plain input string (better precede with 'pass:')\n");
|
||||
result = OPENSSL_strdup(pass);
|
||||
if (result == NULL)
|
||||
BIO_printf(bio_err, "Out of memory getting password for %s\n", desc);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2)
|
||||
{
|
||||
int same = arg1 != NULL && arg2 != NULL && strcmp(arg1, arg2) == 0;
|
||||
@@ -401,122 +431,44 @@ int add_oid_section(CONF *conf)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int load_pkcs12(BIO *in, const char *desc,
|
||||
pem_password_cb *pem_cb, PW_CB_DATA *cb_data,
|
||||
EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
|
||||
X509 *load_cert_pass(const char *uri, int maybe_stdin,
|
||||
const char *pass, const char *desc)
|
||||
{
|
||||
const char *pass;
|
||||
char tpass[PEM_BUFSIZE];
|
||||
int len, ret = 0;
|
||||
PKCS12 *p12;
|
||||
p12 = d2i_PKCS12_bio(in, NULL);
|
||||
if (p12 == NULL && desc != NULL) {
|
||||
BIO_printf(bio_err, "Error loading PKCS12 file for %s\n", desc);
|
||||
goto die;
|
||||
}
|
||||
/* See if an empty password will do */
|
||||
if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, NULL, 0)) {
|
||||
pass = "";
|
||||
} else {
|
||||
if (pem_cb == NULL)
|
||||
pem_cb = (pem_password_cb *)password_callback;
|
||||
len = pem_cb(tpass, PEM_BUFSIZE, 0, cb_data);
|
||||
if (len < 0) {
|
||||
BIO_printf(bio_err, "Passphrase callback error for %s\n",
|
||||
desc != NULL ? desc : "PKCS12 input");
|
||||
goto die;
|
||||
}
|
||||
if (len < PEM_BUFSIZE)
|
||||
tpass[len] = 0;
|
||||
if (!PKCS12_verify_mac(p12, tpass, len)) {
|
||||
BIO_printf(bio_err,
|
||||
"Mac verify error (wrong password?) in PKCS12 file for %s\n",
|
||||
desc != NULL ? desc : "PKCS12 input");
|
||||
goto die;
|
||||
}
|
||||
pass = tpass;
|
||||
}
|
||||
ret = PKCS12_parse(p12, pass, pkey, cert, ca);
|
||||
die:
|
||||
PKCS12_free(p12);
|
||||
return ret;
|
||||
}
|
||||
X509 *cert = NULL;
|
||||
|
||||
X509 *load_cert(const char *file, int format, const char *desc)
|
||||
{
|
||||
X509 *x = NULL;
|
||||
BIO *cert;
|
||||
|
||||
if (format == FORMAT_HTTP) {
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
x = X509_load_http(file, NULL, NULL, 0 /* timeout */);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
||||
if (file == NULL) {
|
||||
if (desc == NULL)
|
||||
desc = "certificate";
|
||||
if (uri == NULL) {
|
||||
unbuffer(stdin);
|
||||
cert = dup_bio_in(format);
|
||||
} else {
|
||||
cert = bio_open_default(file, 'r', format);
|
||||
uri = "";
|
||||
}
|
||||
if (cert == NULL)
|
||||
goto end;
|
||||
|
||||
if (format == FORMAT_ASN1) {
|
||||
x = d2i_X509_bio(cert, NULL);
|
||||
} else if (format == FORMAT_PEM) {
|
||||
x = PEM_read_bio_X509_AUX(cert, NULL,
|
||||
(pem_password_cb *)password_callback, NULL);
|
||||
} else if (format == FORMAT_PKCS12) {
|
||||
if (!load_pkcs12(cert, desc, NULL, NULL, NULL, &x, NULL))
|
||||
goto end;
|
||||
} else {
|
||||
print_format_error(format,
|
||||
#if !defined(OPENSSL_NO_OCSP) && !defined(OPENSSL_NO_SOCK)
|
||||
OPT_FMT_HTTP |
|
||||
#endif
|
||||
OPT_FMT_PEMDER | OPT_FMT_PKCS12);
|
||||
}
|
||||
|
||||
end:
|
||||
if (x == NULL && desc != NULL) {
|
||||
(void)load_key_cert_crl(uri, maybe_stdin, pass, desc, NULL, &cert, NULL);
|
||||
if (cert == NULL) {
|
||||
BIO_printf(bio_err, "Unable to load %s\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
BIO_free(cert);
|
||||
return x;
|
||||
return cert;
|
||||
}
|
||||
|
||||
X509_CRL *load_crl(const char *infile, int format, const char *desc)
|
||||
/* the format parameter is meanwhile not needed anymore and thus ignored */
|
||||
X509 *load_cert(const char *uri, int format, const char *desc)
|
||||
{
|
||||
X509_CRL *x = NULL;
|
||||
BIO *in = NULL;
|
||||
return load_cert_pass(uri, 0, NULL, desc);
|
||||
}
|
||||
|
||||
if (format == FORMAT_HTTP) {
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
x = X509_CRL_load_http(infile, NULL, NULL, 0 /* timeout */);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
/* the format parameter is meanwhile not needed anymore and thus ignored */
|
||||
X509_CRL *load_crl(const char *uri, int format, const char *desc)
|
||||
{
|
||||
X509_CRL *crl = NULL;
|
||||
|
||||
in = bio_open_default(infile, 'r', format);
|
||||
if (in == NULL)
|
||||
goto end;
|
||||
if (format == FORMAT_ASN1) {
|
||||
x = d2i_X509_CRL_bio(in, NULL);
|
||||
} else if (format == FORMAT_PEM) {
|
||||
x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
|
||||
} else
|
||||
print_format_error(format, OPT_FMT_PEMDER);
|
||||
|
||||
end:
|
||||
if (x == NULL && desc != NULL) {
|
||||
if (desc == NULL)
|
||||
desc = "CRL";
|
||||
(void)load_key_cert_crl(uri, 0, NULL, desc, NULL, NULL, &crl);
|
||||
if (crl == NULL) {
|
||||
BIO_printf(bio_err, "Unable to load %s\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
BIO_free(in);
|
||||
return x;
|
||||
return crl;
|
||||
}
|
||||
|
||||
X509_REQ *load_csr(const char *file, int format, const char *desc)
|
||||
@@ -524,6 +476,8 @@ X509_REQ *load_csr(const char *file, int format, const char *desc)
|
||||
X509_REQ *req = NULL;
|
||||
BIO *in;
|
||||
|
||||
if (desc == NULL)
|
||||
desc = "CSR";
|
||||
in = bio_open_default(file, 'r', format);
|
||||
if (in == NULL)
|
||||
goto end;
|
||||
@@ -536,7 +490,7 @@ X509_REQ *load_csr(const char *file, int format, const char *desc)
|
||||
print_format_error(format, OPT_FMT_PEMDER);
|
||||
|
||||
end:
|
||||
if (req == NULL && desc != NULL) {
|
||||
if (req == NULL) {
|
||||
BIO_printf(bio_err, "Unable to load %s\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
@@ -544,173 +498,92 @@ X509_REQ *load_csr(const char *file, int format, const char *desc)
|
||||
return req;
|
||||
}
|
||||
|
||||
EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
|
||||
void cleanse(char *str)
|
||||
{
|
||||
if (str != NULL)
|
||||
OPENSSL_cleanse(str, strlen(str));
|
||||
}
|
||||
|
||||
void clear_free(char *str)
|
||||
{
|
||||
if (str != NULL)
|
||||
OPENSSL_clear_free(str, strlen(str));
|
||||
}
|
||||
|
||||
EVP_PKEY *load_key(const char *uri, int format, int may_stdin,
|
||||
const char *pass, ENGINE *e, const char *desc)
|
||||
{
|
||||
BIO *key = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
PW_CB_DATA cb_data;
|
||||
|
||||
cb_data.password = pass;
|
||||
cb_data.prompt_info = file;
|
||||
if (desc == NULL)
|
||||
desc = "private key";
|
||||
|
||||
if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE)) {
|
||||
BIO_printf(bio_err, "No keyfile specified\n");
|
||||
goto end;
|
||||
}
|
||||
if (format == FORMAT_ENGINE) {
|
||||
if (e == NULL) {
|
||||
BIO_printf(bio_err, "No engine specified\n");
|
||||
BIO_printf(bio_err, "No engine specified for loading %s\n", desc);
|
||||
} else {
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
PW_CB_DATA cb_data;
|
||||
|
||||
cb_data.password = pass;
|
||||
cb_data.prompt_info = uri;
|
||||
if (ENGINE_init(e)) {
|
||||
pkey = ENGINE_load_private_key(e, file,
|
||||
pkey = ENGINE_load_private_key(e, uri,
|
||||
(UI_METHOD *)get_ui_method(),
|
||||
&cb_data);
|
||||
ENGINE_finish(e);
|
||||
}
|
||||
if (pkey == NULL && desc != NULL) {
|
||||
if (pkey == NULL) {
|
||||
BIO_printf(bio_err, "Cannot load %s from engine\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
#else
|
||||
BIO_printf(bio_err, "Engines not supported\n");
|
||||
BIO_printf(bio_err, "Engines not supported for loading %s\n", desc);
|
||||
#endif
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
if (file == NULL && maybe_stdin) {
|
||||
unbuffer(stdin);
|
||||
key = dup_bio_in(format);
|
||||
} else {
|
||||
key = bio_open_default(file, 'r', format);
|
||||
}
|
||||
if (key == NULL)
|
||||
goto end;
|
||||
if (format == FORMAT_ASN1) {
|
||||
pkey = d2i_PrivateKey_bio(key, NULL);
|
||||
} else if (format == FORMAT_PEM) {
|
||||
pkey = PEM_read_bio_PrivateKey(key, NULL, wrap_password_callback, &cb_data);
|
||||
} else if (format == FORMAT_PKCS12) {
|
||||
if (!load_pkcs12(key, desc,
|
||||
(pem_password_cb *)password_callback, &cb_data,
|
||||
&pkey, NULL, NULL))
|
||||
goto end;
|
||||
#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
|
||||
} else if (format == FORMAT_MSBLOB) {
|
||||
pkey = b2i_PrivateKey_bio(key);
|
||||
} else if (format == FORMAT_PVK) {
|
||||
pkey = b2i_PVK_bio(key, wrap_password_callback, &cb_data);
|
||||
#endif
|
||||
} else {
|
||||
print_format_error(format, OPT_FMT_PEMDER | OPT_FMT_PKCS12
|
||||
#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
|
||||
| OPT_FMT_MSBLOB | FORMAT_PVK
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
| OPT_FMT_ENGINE
|
||||
#endif
|
||||
);
|
||||
(void)load_key_cert_crl(uri, may_stdin, pass, desc, &pkey, NULL, NULL);
|
||||
}
|
||||
|
||||
end:
|
||||
BIO_free(key);
|
||||
if (pkey == NULL && desc != NULL) {
|
||||
if (pkey == NULL) {
|
||||
BIO_printf(bio_err, "Unable to load %s\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
return pkey;
|
||||
}
|
||||
|
||||
EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
|
||||
EVP_PKEY *load_pubkey(const char *uri, int format, int maybe_stdin,
|
||||
const char *pass, ENGINE *e, const char *desc)
|
||||
{
|
||||
BIO *key = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
PW_CB_DATA cb_data;
|
||||
|
||||
cb_data.password = pass;
|
||||
cb_data.prompt_info = file;
|
||||
if (desc == NULL)
|
||||
desc = "public key";
|
||||
|
||||
if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE)) {
|
||||
BIO_printf(bio_err, "No keyfile specified\n");
|
||||
goto end;
|
||||
}
|
||||
if (format == FORMAT_ENGINE) {
|
||||
if (e == NULL) {
|
||||
BIO_printf(bio_err, "No engine specified\n");
|
||||
BIO_printf(bio_err, "No engine specified for loading %s\n", desc);
|
||||
} else {
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
pkey = ENGINE_load_public_key(e, file, (UI_METHOD *)get_ui_method(),
|
||||
PW_CB_DATA cb_data;
|
||||
|
||||
cb_data.password = pass;
|
||||
cb_data.prompt_info = uri;
|
||||
pkey = ENGINE_load_public_key(e, uri, (UI_METHOD *)get_ui_method(),
|
||||
&cb_data);
|
||||
if (pkey == NULL && desc != NULL) {
|
||||
if (pkey == NULL) {
|
||||
BIO_printf(bio_err, "Cannot load %s from engine\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
#else
|
||||
BIO_printf(bio_err, "Engines not supported\n");
|
||||
BIO_printf(bio_err, "Engines not supported for loading %s\n", desc);
|
||||
#endif
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
if (file == NULL && maybe_stdin) {
|
||||
unbuffer(stdin);
|
||||
key = dup_bio_in(format);
|
||||
} else {
|
||||
key = bio_open_default(file, 'r', format);
|
||||
(void)load_key_cert_crl(uri, maybe_stdin, pass, desc, &pkey,
|
||||
NULL, NULL);
|
||||
}
|
||||
if (key == NULL)
|
||||
goto end;
|
||||
if (format == FORMAT_ASN1) {
|
||||
pkey = d2i_PUBKEY_bio(key, NULL);
|
||||
} else if (format == FORMAT_ASN1RSA) {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
RSA *rsa;
|
||||
rsa = d2i_RSAPublicKey_bio(key, NULL);
|
||||
if (rsa) {
|
||||
pkey = EVP_PKEY_new();
|
||||
if (pkey != NULL)
|
||||
EVP_PKEY_set1_RSA(pkey, rsa);
|
||||
RSA_free(rsa);
|
||||
} else
|
||||
#else
|
||||
BIO_printf(bio_err, "RSA keys not supported\n");
|
||||
#endif
|
||||
pkey = NULL;
|
||||
} else if (format == FORMAT_PEMRSA) {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
RSA *rsa;
|
||||
rsa = PEM_read_bio_RSAPublicKey(key, NULL,
|
||||
(pem_password_cb *)password_callback,
|
||||
&cb_data);
|
||||
if (rsa != NULL) {
|
||||
pkey = EVP_PKEY_new();
|
||||
if (pkey != NULL)
|
||||
EVP_PKEY_set1_RSA(pkey, rsa);
|
||||
RSA_free(rsa);
|
||||
} else
|
||||
#else
|
||||
BIO_printf(bio_err, "RSA keys not supported\n");
|
||||
#endif
|
||||
pkey = NULL;
|
||||
} else if (format == FORMAT_PEM) {
|
||||
pkey = PEM_read_bio_PUBKEY(key, NULL,
|
||||
(pem_password_cb *)password_callback,
|
||||
&cb_data);
|
||||
#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
|
||||
} else if (format == FORMAT_MSBLOB) {
|
||||
pkey = b2i_PublicKey_bio(key);
|
||||
#endif
|
||||
} else {
|
||||
print_format_error(format, OPT_FMT_PEMDER
|
||||
#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
|
||||
| OPT_FMT_MSBLOB
|
||||
#endif
|
||||
);
|
||||
}
|
||||
end:
|
||||
BIO_free(key);
|
||||
if (pkey == NULL && desc != NULL) {
|
||||
if (pkey == NULL) {
|
||||
BIO_printf(bio_err, "Unable to load %s\n", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
@@ -792,11 +665,8 @@ static int load_certs_crls(const char *file, int format,
|
||||
sk_X509_CRL_pop_free(*pcrls, X509_CRL_free);
|
||||
*pcrls = NULL;
|
||||
}
|
||||
if (desc != NULL) {
|
||||
BIO_printf(bio_err, "Unable to load %s for %s\n",
|
||||
pcerts ? "certificates" : "CRLs", desc);
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
BIO_printf(bio_err, "Unable to load %s\n", desc != NULL ? desc :
|
||||
pcerts != NULL ? "certificates" : "CRLs");
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -832,6 +702,102 @@ int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format,
|
||||
return load_certs_crls(file, format, pass, desc, NULL, crls);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load those types of credentials for which the result pointer is not NULL.
|
||||
* Reads from stdio if uri is NULL and maybe_stdin is nonzero.
|
||||
* For each type the first credential found in the store is loaded.
|
||||
* May yield partial result even if rv == 0.
|
||||
*/
|
||||
int load_key_cert_crl(const char *uri, int maybe_stdin,
|
||||
const char *pass, const char *desc,
|
||||
EVP_PKEY **ppkey, X509 **pcert, X509_CRL **pcrl)
|
||||
{
|
||||
PW_CB_DATA uidata;
|
||||
OSSL_STORE_CTX *ctx = NULL;
|
||||
int ret = 0;
|
||||
/* TODO make use of the engine reference 'eng' when loading pkeys */
|
||||
|
||||
if (ppkey != NULL)
|
||||
*ppkey = NULL;
|
||||
if (pcert != NULL)
|
||||
*pcert = NULL;
|
||||
if (pcrl != NULL)
|
||||
*pcrl = NULL;
|
||||
|
||||
if (desc == NULL)
|
||||
desc = "key/certificate/CRL";
|
||||
uidata.password = pass;
|
||||
uidata.prompt_info = uri;
|
||||
|
||||
if (uri == NULL) {
|
||||
BIO *bio;
|
||||
|
||||
if (!maybe_stdin) {
|
||||
BIO_printf(bio_err, "No filename or uri specified for loading %s\n",
|
||||
desc);
|
||||
goto end;
|
||||
}
|
||||
unbuffer(stdin);
|
||||
bio = BIO_new_fp(stdin, 0);
|
||||
if (bio != NULL)
|
||||
ctx = OSSL_STORE_attach(bio, NULL, "file", NULL,
|
||||
get_ui_method(), &uidata, NULL, NULL);
|
||||
uri = "<stdin>";
|
||||
} else {
|
||||
ctx = OSSL_STORE_open(uri, get_ui_method(), &uidata, NULL, NULL);
|
||||
}
|
||||
if (ctx == NULL) {
|
||||
BIO_printf(bio_err, "Could not open file or uri %s for loading %s\n",
|
||||
uri, desc);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
OSSL_STORE_INFO *info = OSSL_STORE_load(ctx);
|
||||
int type = info == NULL ? 0 : OSSL_STORE_INFO_get_type(info);
|
||||
const char *infostr =
|
||||
info == NULL ? NULL : OSSL_STORE_INFO_type_string(type);
|
||||
int err = 0;
|
||||
|
||||
if (info == NULL) {
|
||||
if (OSSL_STORE_eof(ctx))
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case OSSL_STORE_INFO_PKEY:
|
||||
if (ppkey != NULL && *ppkey == NULL)
|
||||
err = ((*ppkey = OSSL_STORE_INFO_get1_PKEY(info)) == NULL);
|
||||
break;
|
||||
case OSSL_STORE_INFO_CERT:
|
||||
if (pcert != NULL && *pcert == NULL)
|
||||
err = ((*pcert = OSSL_STORE_INFO_get1_CERT(info)) == NULL);
|
||||
break;
|
||||
case OSSL_STORE_INFO_CRL:
|
||||
if (pcrl != NULL && *pcrl == NULL)
|
||||
err = ((*pcrl = OSSL_STORE_INFO_get1_CRL(info)) == NULL);
|
||||
break;
|
||||
default:
|
||||
/* skip any other type */
|
||||
break;
|
||||
}
|
||||
OSSL_STORE_INFO_free(info);
|
||||
if (err) {
|
||||
BIO_printf(bio_err, "Could not read %s of %s from %s\n",
|
||||
infostr, desc, uri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
OSSL_STORE_close(ctx);
|
||||
if (!ret)
|
||||
ERR_print_errors(bio_err);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#define X509V3_EXT_UNKNOWN_MASK (0xfL << 16)
|
||||
/* Return error for unknown extensions */
|
||||
#define X509V3_EXT_DEFAULT 0
|
||||
@@ -1149,29 +1115,28 @@ static ENGINE *try_load_engine(const char *engine)
|
||||
}
|
||||
#endif
|
||||
|
||||
ENGINE *setup_engine(const char *engine, int debug)
|
||||
ENGINE *setup_engine_methods(const char *id, unsigned int methods, int debug)
|
||||
{
|
||||
ENGINE *e = NULL;
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (engine != NULL) {
|
||||
if (strcmp(engine, "auto") == 0) {
|
||||
if (id != NULL) {
|
||||
if (strcmp(id, "auto") == 0) {
|
||||
BIO_printf(bio_err, "Enabling auto ENGINE support\n");
|
||||
ENGINE_register_all_complete();
|
||||
return NULL;
|
||||
}
|
||||
if ((e = ENGINE_by_id(engine)) == NULL
|
||||
&& (e = try_load_engine(engine)) == NULL) {
|
||||
BIO_printf(bio_err, "Invalid engine \"%s\"\n", engine);
|
||||
if ((e = ENGINE_by_id(id)) == NULL
|
||||
&& (e = try_load_engine(id)) == NULL) {
|
||||
BIO_printf(bio_err, "Invalid engine \"%s\"\n", id);
|
||||
ERR_print_errors(bio_err);
|
||||
return NULL;
|
||||
}
|
||||
if (debug) {
|
||||
ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM, 0, bio_err, 0);
|
||||
}
|
||||
ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, (void *)get_ui_method(),
|
||||
0, 1);
|
||||
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
|
||||
if (debug)
|
||||
(void)ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM, 0, bio_err, 0);
|
||||
if (!ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0,
|
||||
(void *)get_ui_method(), 0, 1)
|
||||
|| !ENGINE_set_default(e, methods)) {
|
||||
BIO_printf(bio_err, "Cannot use engine \"%s\"\n", ENGINE_get_id(e));
|
||||
ERR_print_errors(bio_err);
|
||||
ENGINE_free(e);
|
||||
@@ -2305,17 +2270,30 @@ double app_tminterval(int stop, int usertime)
|
||||
double app_tminterval(int stop, int usertime)
|
||||
{
|
||||
double ret = 0;
|
||||
struct tms rus;
|
||||
clock_t now = times(&rus);
|
||||
clock_t now;
|
||||
static clock_t tmstart;
|
||||
long int tck = sysconf(_SC_CLK_TCK);
|
||||
# ifdef __TMS
|
||||
struct tms rus;
|
||||
|
||||
now = times(&rus);
|
||||
if (usertime)
|
||||
now = rus.tms_utime;
|
||||
# else
|
||||
if (usertime)
|
||||
now = clock(); /* sum of user and kernel times */
|
||||
else {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
now = (clock_t)((unsigned long long)tv.tv_sec * tck +
|
||||
(unsigned long long)tv.tv_usec * (1000000 / tck)
|
||||
);
|
||||
}
|
||||
# endif
|
||||
|
||||
if (stop == TM_START) {
|
||||
tmstart = now;
|
||||
} else {
|
||||
long int tck = sysconf(_SC_CLK_TCK);
|
||||
ret = (now - tmstart) / (double)tck;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
|
||||
+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 app_x509.c
|
||||
columns.c app_params.c names.c app_provider.c app_x509.c http_server.c
|
||||
|
||||
IF[{- !$disabled{apps} -}]
|
||||
LIBS{noinst}=../libapps.a
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* Copyright 1995-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
|
||||
*/
|
||||
|
||||
/* Very basic HTTP server */
|
||||
|
||||
#if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
|
||||
/*
|
||||
* On VMS, you need to define this to get the declaration of fileno(). The
|
||||
* value 2 is to make sure no function defined in POSIX-2 is left undefined.
|
||||
*/
|
||||
# define _POSIX_C_SOURCE 2
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "http_server.h"
|
||||
#include "internal/sockets.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
int multi = 0; /* run multiple responder processes */
|
||||
|
||||
#ifdef HTTP_DAEMON
|
||||
int acfd = (int) INVALID_SOCKET;
|
||||
#endif
|
||||
|
||||
#ifdef HTTP_DAEMON
|
||||
static int print_syslog(const char *str, size_t len, void *levPtr)
|
||||
{
|
||||
int level = *(int *)levPtr;
|
||||
int ilen = len > MAXERRLEN ? MAXERRLEN : len;
|
||||
|
||||
syslog(level, "%.*s", ilen, str);
|
||||
|
||||
return ilen;
|
||||
}
|
||||
#endif
|
||||
|
||||
void log_message(const char *prog, int level, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
#ifdef HTTP_DAEMON
|
||||
if (multi) {
|
||||
char buf[1024];
|
||||
|
||||
if (vsnprintf(buf, sizeof(buf), fmt, ap) > 0)
|
||||
syslog(level, "%s", buf);
|
||||
if (level >= LOG_ERR)
|
||||
ERR_print_errors_cb(print_syslog, &level);
|
||||
}
|
||||
#endif
|
||||
if (!multi) {
|
||||
BIO_printf(bio_err, "%s: ", prog);
|
||||
BIO_vprintf(bio_err, fmt, ap);
|
||||
BIO_printf(bio_err, "\n");
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef HTTP_DAEMON
|
||||
void socket_timeout(int signum)
|
||||
{
|
||||
if (acfd != (int)INVALID_SOCKET)
|
||||
(void)shutdown(acfd, SHUT_RD);
|
||||
}
|
||||
|
||||
static void killall(int ret, pid_t *kidpids)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < multi; ++i)
|
||||
if (kidpids[i] != 0)
|
||||
(void)kill(kidpids[i], SIGTERM);
|
||||
OPENSSL_free(kidpids);
|
||||
sleep(1);
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static int termsig = 0;
|
||||
|
||||
static void noteterm(int sig)
|
||||
{
|
||||
termsig = sig;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop spawning up to `multi` child processes, only child processes return
|
||||
* from this function. The parent process loops until receiving a termination
|
||||
* signal, kills extant children and exits without returning.
|
||||
*/
|
||||
void spawn_loop(const char *prog)
|
||||
{
|
||||
pid_t *kidpids = NULL;
|
||||
int status;
|
||||
int procs = 0;
|
||||
int i;
|
||||
|
||||
openlog(prog, LOG_PID, LOG_DAEMON);
|
||||
|
||||
if (setpgid(0, 0)) {
|
||||
syslog(LOG_ERR, "fatal: error detaching from parent process group: %s",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
kidpids = app_malloc(multi * sizeof(*kidpids), "child PID array");
|
||||
for (i = 0; i < multi; ++i)
|
||||
kidpids[i] = 0;
|
||||
|
||||
signal(SIGINT, noteterm);
|
||||
signal(SIGTERM, noteterm);
|
||||
|
||||
while (termsig == 0) {
|
||||
pid_t fpid;
|
||||
|
||||
/*
|
||||
* Wait for a child to replace when we're at the limit.
|
||||
* Slow down if a child exited abnormally or waitpid() < 0
|
||||
*/
|
||||
while (termsig == 0 && procs >= multi) {
|
||||
if ((fpid = waitpid(-1, &status, 0)) > 0) {
|
||||
for (i = 0; i < procs; ++i) {
|
||||
if (kidpids[i] == fpid) {
|
||||
kidpids[i] = 0;
|
||||
--procs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= multi) {
|
||||
syslog(LOG_ERR, "fatal: internal error: "
|
||||
"no matching child slot for pid: %ld",
|
||||
(long) fpid);
|
||||
killall(1, kidpids);
|
||||
}
|
||||
if (status != 0) {
|
||||
if (WIFEXITED(status))
|
||||
syslog(LOG_WARNING, "child process: %ld, exit status: %d",
|
||||
(long)fpid, WEXITSTATUS(status));
|
||||
else if (WIFSIGNALED(status))
|
||||
syslog(LOG_WARNING, "child process: %ld, term signal %d%s",
|
||||
(long)fpid, WTERMSIG(status),
|
||||
# ifdef WCOREDUMP
|
||||
WCOREDUMP(status) ? " (core dumped)" :
|
||||
# endif
|
||||
"");
|
||||
sleep(1);
|
||||
}
|
||||
break;
|
||||
} else if (errno != EINTR) {
|
||||
syslog(LOG_ERR, "fatal: waitpid(): %s", strerror(errno));
|
||||
killall(1, kidpids);
|
||||
}
|
||||
}
|
||||
if (termsig)
|
||||
break;
|
||||
|
||||
switch (fpid = fork()) {
|
||||
case -1: /* error */
|
||||
/* System critically low on memory, pause and try again later */
|
||||
sleep(30);
|
||||
break;
|
||||
case 0: /* child */
|
||||
OPENSSL_free(kidpids);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
if (termsig)
|
||||
_exit(0);
|
||||
if (RAND_poll() <= 0) {
|
||||
syslog(LOG_ERR, "fatal: RAND_poll() failed");
|
||||
_exit(1);
|
||||
}
|
||||
return;
|
||||
default: /* parent */
|
||||
for (i = 0; i < multi; ++i) {
|
||||
if (kidpids[i] == 0) {
|
||||
kidpids[i] = fpid;
|
||||
procs++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= multi) {
|
||||
syslog(LOG_ERR, "fatal: internal error: no free child slots");
|
||||
killall(1, kidpids);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* The loop above can only break on termsig */
|
||||
syslog(LOG_INFO, "terminating on signal: %d", termsig);
|
||||
killall(0, kidpids);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
BIO *http_server_init_bio(const char *prog, const char *port)
|
||||
{
|
||||
BIO *acbio = NULL, *bufbio;
|
||||
|
||||
bufbio = BIO_new(BIO_f_buffer());
|
||||
if (bufbio == NULL)
|
||||
goto err;
|
||||
acbio = BIO_new(BIO_s_accept());
|
||||
if (acbio == NULL
|
||||
|| BIO_set_bind_mode(acbio, BIO_BIND_REUSEADDR) < 0
|
||||
|| BIO_set_accept_port(acbio, port) < 0) {
|
||||
log_message(prog, LOG_ERR, "Error setting up accept BIO");
|
||||
goto err;
|
||||
}
|
||||
|
||||
BIO_set_accept_bios(acbio, bufbio);
|
||||
bufbio = NULL;
|
||||
if (BIO_do_accept(acbio) <= 0) {
|
||||
log_message(prog, LOG_ERR, "Error starting accept");
|
||||
goto err;
|
||||
}
|
||||
|
||||
return acbio;
|
||||
|
||||
err:
|
||||
BIO_free_all(acbio);
|
||||
BIO_free(bufbio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode %xx URL-decoding in-place. Ignores malformed sequences.
|
||||
*/
|
||||
static int urldecode(char *p)
|
||||
{
|
||||
unsigned char *out = (unsigned char *)p;
|
||||
unsigned char *save = out;
|
||||
|
||||
for (; *p; p++) {
|
||||
if (*p != '%') {
|
||||
*out++ = *p;
|
||||
} else if (isxdigit(_UC(p[1])) && isxdigit(_UC(p[2]))) {
|
||||
/* Don't check, can't fail because of ixdigit() call. */
|
||||
*out++ = (OPENSSL_hexchar2int(p[1]) << 4)
|
||||
| OPENSSL_hexchar2int(p[2]);
|
||||
p += 2;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*out = '\0';
|
||||
return (int)(out - save);
|
||||
}
|
||||
|
||||
int http_server_get_asn1_req(const ASN1_ITEM *it, ASN1_VALUE **preq,
|
||||
BIO **pcbio, BIO *acbio,
|
||||
const char *prog, int accept_get, int timeout)
|
||||
{
|
||||
BIO *cbio = NULL, *getbio = NULL, *b64 = NULL;
|
||||
int len;
|
||||
char reqbuf[2048], inbuf[2048];
|
||||
char *url, *end;
|
||||
ASN1_VALUE *req;
|
||||
int ret = 1;
|
||||
|
||||
*preq = NULL;
|
||||
*pcbio = NULL;
|
||||
|
||||
/* Connection loss before accept() is routine, ignore silently */
|
||||
if (BIO_do_accept(acbio) <= 0)
|
||||
return 0;
|
||||
|
||||
cbio = BIO_pop(acbio);
|
||||
*pcbio = cbio;
|
||||
if (cbio == NULL) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
# ifdef HTTP_DAEMON
|
||||
if (timeout > 0) {
|
||||
(void)BIO_get_fd(cbio, &acfd);
|
||||
alarm(timeout);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Read the request line. */
|
||||
len = BIO_gets(cbio, reqbuf, sizeof(reqbuf));
|
||||
if (len <= 0)
|
||||
goto out;
|
||||
|
||||
if (accept_get && strncmp(reqbuf, "GET ", 4) == 0) {
|
||||
/* Expecting GET {sp} /URL {sp} HTTP/1.x */
|
||||
for (url = reqbuf + 4; *url == ' '; ++url)
|
||||
continue;
|
||||
if (*url != '/') {
|
||||
log_message(prog, LOG_INFO,
|
||||
"Invalid GET -- URL does not begin with '/': %s", url);
|
||||
goto out;
|
||||
}
|
||||
url++;
|
||||
|
||||
/* Splice off the HTTP version identifier. */
|
||||
for (end = url; *end != '\0'; end++)
|
||||
if (*end == ' ')
|
||||
break;
|
||||
if (strncmp(end, " HTTP/1.", 7) != 0) {
|
||||
log_message(prog, LOG_INFO,
|
||||
"Invalid GET -- bad HTTP/version string: %s", end + 1);
|
||||
goto out;
|
||||
}
|
||||
*end = '\0';
|
||||
|
||||
/*-
|
||||
* Skip "GET / HTTP..." requests often used by load-balancers.
|
||||
* 'url' was incremented above to point to the first byte *after*
|
||||
* the leading slash, so in case 'GET / ' it is now an empty string.
|
||||
*/
|
||||
if (url[0] == '\0')
|
||||
goto out;
|
||||
|
||||
len = urldecode(url);
|
||||
if (len <= 0) {
|
||||
log_message(prog, LOG_INFO,
|
||||
"Invalid GET request -- bad URL encoding: %s", url);
|
||||
goto out;
|
||||
}
|
||||
if ((getbio = BIO_new_mem_buf(url, len)) == NULL
|
||||
|| (b64 = BIO_new(BIO_f_base64())) == NULL) {
|
||||
log_message(prog, LOG_ERR,
|
||||
"Could not allocate base64 bio with size = %d", len);
|
||||
BIO_free_all(cbio);
|
||||
*pcbio = NULL;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
|
||||
getbio = BIO_push(b64, getbio);
|
||||
} else if (strncmp(reqbuf, "POST ", 5) != 0) {
|
||||
log_message(prog, LOG_INFO,
|
||||
"HTTP request does not start with GET/POST: %s", reqbuf);
|
||||
/* TODO provide better diagnosis in case client tries TLS */
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Read and skip past the headers. */
|
||||
for (;;) {
|
||||
len = BIO_gets(cbio, inbuf, sizeof(inbuf));
|
||||
if (len <= 0) {
|
||||
log_message(prog, LOG_ERR,
|
||||
"Error skipping remaining HTTP headers");
|
||||
goto out;
|
||||
}
|
||||
if ((inbuf[0] == '\r') || (inbuf[0] == '\n'))
|
||||
break;
|
||||
}
|
||||
|
||||
# ifdef HTTP_DAEMON
|
||||
/* Clear alarm before we close the client socket */
|
||||
alarm(0);
|
||||
timeout = 0;
|
||||
# endif
|
||||
|
||||
/* Try to read and parse request */
|
||||
req = ASN1_item_d2i_bio(it, getbio != NULL ? getbio : cbio, NULL);
|
||||
if (req == NULL)
|
||||
log_message(prog, LOG_ERR, "Error parsing request");
|
||||
|
||||
*preq = req;
|
||||
|
||||
out:
|
||||
BIO_free_all(getbio);
|
||||
# ifdef HTTP_DAEMON
|
||||
if (timeout > 0)
|
||||
alarm(0);
|
||||
acfd = (int)INVALID_SOCKET;
|
||||
# endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* assumes that cbio does not do an encoding that changes the output length */
|
||||
int http_server_send_asn1_resp(BIO *cbio, const char *content_type,
|
||||
const ASN1_ITEM *it, const ASN1_VALUE *resp)
|
||||
{
|
||||
int ret = BIO_printf(cbio, "HTTP/1.0 200 OK\r\nContent-type: %s\r\n"
|
||||
"Content-Length: %d\r\n\r\n", content_type,
|
||||
ASN1_item_i2d(resp, NULL, it)) > 0
|
||||
&& ASN1_item_i2d_bio(it, cbio, resp) > 0;
|
||||
|
||||
(void)BIO_flush(cbio);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <openssl/safestack.h>
|
||||
#include "names.h"
|
||||
|
||||
DEFINE_STACK_OF_CSTRING()
|
||||
|
||||
#ifdef _WIN32
|
||||
# define strcasecmp _stricmp
|
||||
#endif
|
||||
|
||||
+7
-2
@@ -26,6 +26,11 @@
|
||||
|
||||
#define COOKIE_SECRET_LENGTH 16
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
DEFINE_STACK_OF(X509_NAME)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
VERIFY_CB_ARGS verify_args = { -1, 0, X509_V_OK, 0 };
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
@@ -1089,11 +1094,11 @@ int args_excert(int opt, SSL_EXCERT **pexc)
|
||||
exc->build_chain = 1;
|
||||
break;
|
||||
case OPT_X_CERTFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &exc->certform))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &exc->certform))
|
||||
return 0;
|
||||
break;
|
||||
case OPT_X_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &exc->keyform))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &exc->keyform))
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-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
|
||||
@@ -392,4 +392,25 @@ int do_server(int *accept_sock, const char *host, const char *port,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void do_ssl_shutdown(SSL *ssl)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do {
|
||||
/* We only do unidirectional shutdown */
|
||||
ret = SSL_shutdown(ssl);
|
||||
if (ret < 0) {
|
||||
switch (SSL_get_error(ssl, ret)) {
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
case SSL_ERROR_WANT_ASYNC:
|
||||
case SSL_ERROR_WANT_ASYNC_JOB:
|
||||
/* We just do busy waiting. Nothing clever */
|
||||
continue;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
} while (ret < 0);
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_SOCK */
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "opt.h"
|
||||
#include "names.h"
|
||||
|
||||
DEFINE_STACK_OF_CSTRING()
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
static void legacy_cipher_fn(const EVP_CIPHER *c,
|
||||
|
||||
+3
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* 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
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/params.h>
|
||||
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#undef BUFSIZE
|
||||
#define BUFSIZE 1024*8
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_TOSEQ, OPT_IN, OPT_OUT,
|
||||
|
||||
+49
-411
@@ -22,6 +22,7 @@
|
||||
|
||||
/* Needs to be included before the openssl headers */
|
||||
#include "apps.h"
|
||||
#include "http_server.h"
|
||||
#include "progs.h"
|
||||
#include "internal/sockets.h"
|
||||
#include <openssl/e_os2.h>
|
||||
@@ -31,38 +32,11 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#ifndef HAVE_FORK
|
||||
# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
|
||||
# define HAVE_FORK 0
|
||||
# else
|
||||
# define HAVE_FORK 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if HAVE_FORK
|
||||
# undef NO_FORK
|
||||
#else
|
||||
# define NO_FORK
|
||||
#endif
|
||||
|
||||
#if !defined(NO_FORK) && !defined(OPENSSL_NO_SOCK) \
|
||||
&& !defined(OPENSSL_NO_POSIX_IO)
|
||||
# define OCSP_DAEMON
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
# include <syslog.h>
|
||||
# include <signal.h>
|
||||
# define MAXERRLEN 1000 /* limit error text sent to syslog to 1000 bytes */
|
||||
#else
|
||||
# undef LOG_INFO
|
||||
# undef LOG_WARNING
|
||||
# undef LOG_ERR
|
||||
# define LOG_INFO 0
|
||||
# define LOG_WARNING 1
|
||||
# define LOG_ERR 2
|
||||
#endif
|
||||
DEFINE_STACK_OF(OCSP_CERTID)
|
||||
DEFINE_STACK_OF(CONF_VALUE)
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#if defined(OPENSSL_SYS_VXWORKS)
|
||||
/* not supported */
|
||||
@@ -100,19 +74,13 @@ static void make_ocsp_response(BIO *err, OCSP_RESPONSE **resp, OCSP_REQUEST *req
|
||||
const EVP_MD *resp_md);
|
||||
|
||||
static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser);
|
||||
static BIO *init_responder(const char *port);
|
||||
static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, int timeout);
|
||||
static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp);
|
||||
static void log_message(int level, const char *fmt, ...);
|
||||
static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio,
|
||||
int timeout);
|
||||
static int send_ocsp_response(BIO *cbio, const OCSP_RESPONSE *resp);
|
||||
static char *prog;
|
||||
static int multi = 0;
|
||||
|
||||
#ifdef OCSP_DAEMON
|
||||
static int acfd = (int) INVALID_SOCKET;
|
||||
#ifdef HTTP_DAEMON
|
||||
static int index_changed(CA_DB *);
|
||||
static void spawn_loop(void);
|
||||
static int print_syslog(const char *str, size_t len, void *levPtr);
|
||||
static void socket_timeout(int signum);
|
||||
#endif
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
@@ -157,7 +125,7 @@ const OPTIONS ocsp_options[] = {
|
||||
"Connection timeout (in seconds) to the OCSP responder"},
|
||||
{"resp_no_certs", OPT_RESP_NO_CERTS, '-',
|
||||
"Don't include any certificates in response"},
|
||||
#ifdef OCSP_DAEMON
|
||||
#ifdef HTTP_DAEMON
|
||||
{"multi", OPT_MULTI, 'p', "run multiple responder processes"},
|
||||
#endif
|
||||
{"no_certs", OPT_NO_CERTS, '-',
|
||||
@@ -436,7 +404,8 @@ int ocsp_main(int argc, char **argv)
|
||||
path = opt_arg();
|
||||
break;
|
||||
case OPT_ISSUER:
|
||||
issuer = load_cert(opt_arg(), FORMAT_PEM, "issuer certificate");
|
||||
issuer = load_cert(opt_arg(), FORMAT_UNDEF,
|
||||
"issuer certificate");
|
||||
if (issuer == NULL)
|
||||
goto end;
|
||||
if (issuers == NULL) {
|
||||
@@ -448,7 +417,7 @@ int ocsp_main(int argc, char **argv)
|
||||
break;
|
||||
case OPT_CERT:
|
||||
X509_free(cert);
|
||||
cert = load_cert(opt_arg(), FORMAT_PEM, "certificate");
|
||||
cert = load_cert(opt_arg(), FORMAT_UNDEF, "certificate");
|
||||
if (cert == NULL)
|
||||
goto end;
|
||||
if (cert_id_md == NULL)
|
||||
@@ -535,7 +504,7 @@ int ocsp_main(int argc, char **argv)
|
||||
trailing_md = 1;
|
||||
break;
|
||||
case OPT_MULTI:
|
||||
#ifdef OCSP_DAEMON
|
||||
#ifdef HTTP_DAEMON
|
||||
multi = atoi(opt_arg());
|
||||
#endif
|
||||
break;
|
||||
@@ -579,15 +548,21 @@ int ocsp_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (req == NULL && port != NULL) {
|
||||
acbio = init_responder(port);
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
acbio = http_server_init_bio(prog, port);
|
||||
if (acbio == NULL)
|
||||
goto end;
|
||||
#else
|
||||
BIO_printf(bio_err, "Cannot act as server - sockets not supported\n");
|
||||
goto end;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rsignfile != NULL) {
|
||||
if (rkeyfile == NULL)
|
||||
rkeyfile = rsignfile;
|
||||
rsigner = load_cert(rsignfile, FORMAT_PEM, "responder certificate");
|
||||
rsigner = load_cert(rsignfile, FORMAT_UNDEF,
|
||||
"responder certificate");
|
||||
if (rsigner == NULL) {
|
||||
BIO_printf(bio_err, "Error loading responder certificate\n");
|
||||
goto end;
|
||||
@@ -625,20 +600,20 @@ int ocsp_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OCSP_DAEMON
|
||||
#ifdef HTTP_DAEMON
|
||||
if (multi && acbio != NULL)
|
||||
spawn_loop();
|
||||
spawn_loop(prog);
|
||||
if (acbio != NULL && req_timeout > 0)
|
||||
signal(SIGALRM, socket_timeout);
|
||||
#endif
|
||||
|
||||
if (acbio != NULL)
|
||||
log_message(LOG_INFO, "waiting for OCSP client connections...");
|
||||
log_message(prog, LOG_INFO, "waiting for OCSP client connections...");
|
||||
|
||||
redo_accept:
|
||||
|
||||
if (acbio != NULL) {
|
||||
#ifdef OCSP_DAEMON
|
||||
#ifdef HTTP_DAEMON
|
||||
if (index_changed(rdb)) {
|
||||
CA_DB *newrdb = load_index(ridx_filename, NULL);
|
||||
|
||||
@@ -647,7 +622,7 @@ redo_accept:
|
||||
rdb = newrdb;
|
||||
} else {
|
||||
free_index(newrdb);
|
||||
log_message(LOG_ERR, "error reloading updated index: %s",
|
||||
log_message(prog, LOG_ERR, "error reloading updated index: %s",
|
||||
ridx_filename);
|
||||
}
|
||||
}
|
||||
@@ -658,9 +633,8 @@ redo_accept:
|
||||
goto redo_accept;
|
||||
|
||||
if (req == NULL) {
|
||||
resp =
|
||||
OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST,
|
||||
NULL);
|
||||
resp = OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST,
|
||||
NULL);
|
||||
send_ocsp_response(cbio, resp);
|
||||
goto done_resp;
|
||||
}
|
||||
@@ -681,7 +655,7 @@ redo_accept:
|
||||
if (signfile != NULL) {
|
||||
if (keyfile == NULL)
|
||||
keyfile = signfile;
|
||||
signer = load_cert(signfile, FORMAT_PEM, "signer certificate");
|
||||
signer = load_cert(signfile, FORMAT_UNDEF, "signer certificate");
|
||||
if (signer == NULL) {
|
||||
BIO_printf(bio_err, "Error loading signer certificate\n");
|
||||
goto end;
|
||||
@@ -728,7 +702,7 @@ redo_accept:
|
||||
goto end;
|
||||
#else
|
||||
BIO_printf(bio_err,
|
||||
"Error creating connect BIO - sockets not supported.\n");
|
||||
"Error creating connect BIO - sockets not supported\n");
|
||||
goto end;
|
||||
#endif
|
||||
} else if (respin != NULL) {
|
||||
@@ -868,41 +842,7 @@ redo_accept:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
log_message(int level, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
#ifdef OCSP_DAEMON
|
||||
if (multi) {
|
||||
char buf[1024];
|
||||
if (vsnprintf(buf, sizeof(buf), fmt, ap) > 0) {
|
||||
syslog(level, "%s", buf);
|
||||
}
|
||||
if (level >= LOG_ERR)
|
||||
ERR_print_errors_cb(print_syslog, &level);
|
||||
}
|
||||
#endif
|
||||
if (!multi) {
|
||||
BIO_printf(bio_err, "%s: ", prog);
|
||||
BIO_vprintf(bio_err, fmt, ap);
|
||||
BIO_printf(bio_err, "\n");
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef OCSP_DAEMON
|
||||
|
||||
static int print_syslog(const char *str, size_t len, void *levPtr)
|
||||
{
|
||||
int level = *(int *)levPtr;
|
||||
int ilen = (len > MAXERRLEN) ? MAXERRLEN : len;
|
||||
|
||||
syslog(level, "%.*s", ilen, str);
|
||||
|
||||
return ilen;
|
||||
}
|
||||
#ifdef HTTP_DAEMON
|
||||
|
||||
static int index_changed(CA_DB *rdb)
|
||||
{
|
||||
@@ -920,131 +860,6 @@ static int index_changed(CA_DB *rdb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void killall(int ret, pid_t *kidpids)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < multi; ++i)
|
||||
if (kidpids[i] != 0)
|
||||
(void)kill(kidpids[i], SIGTERM);
|
||||
OPENSSL_free(kidpids);
|
||||
sleep(1);
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static int termsig = 0;
|
||||
|
||||
static void noteterm (int sig)
|
||||
{
|
||||
termsig = sig;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop spawning up to `multi` child processes, only child processes return
|
||||
* from this function. The parent process loops until receiving a termination
|
||||
* signal, kills extant children and exits without returning.
|
||||
*/
|
||||
static void spawn_loop(void)
|
||||
{
|
||||
pid_t *kidpids = NULL;
|
||||
int status;
|
||||
int procs = 0;
|
||||
int i;
|
||||
|
||||
openlog(prog, LOG_PID, LOG_DAEMON);
|
||||
|
||||
if (setpgid(0, 0)) {
|
||||
syslog(LOG_ERR, "fatal: error detaching from parent process group: %s",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
kidpids = app_malloc(multi * sizeof(*kidpids), "child PID array");
|
||||
for (i = 0; i < multi; ++i)
|
||||
kidpids[i] = 0;
|
||||
|
||||
signal(SIGINT, noteterm);
|
||||
signal(SIGTERM, noteterm);
|
||||
|
||||
while (termsig == 0) {
|
||||
pid_t fpid;
|
||||
|
||||
/*
|
||||
* Wait for a child to replace when we're at the limit.
|
||||
* Slow down if a child exited abnormally or waitpid() < 0
|
||||
*/
|
||||
while (termsig == 0 && procs >= multi) {
|
||||
if ((fpid = waitpid(-1, &status, 0)) > 0) {
|
||||
for (i = 0; i < procs; ++i) {
|
||||
if (kidpids[i] == fpid) {
|
||||
kidpids[i] = 0;
|
||||
--procs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= multi) {
|
||||
syslog(LOG_ERR, "fatal: internal error: "
|
||||
"no matching child slot for pid: %ld",
|
||||
(long) fpid);
|
||||
killall(1, kidpids);
|
||||
}
|
||||
if (status != 0) {
|
||||
if (WIFEXITED(status))
|
||||
syslog(LOG_WARNING, "child process: %ld, exit status: %d",
|
||||
(long)fpid, WEXITSTATUS(status));
|
||||
else if (WIFSIGNALED(status))
|
||||
syslog(LOG_WARNING, "child process: %ld, term signal %d%s",
|
||||
(long)fpid, WTERMSIG(status),
|
||||
#ifdef WCOREDUMP
|
||||
WCOREDUMP(status) ? " (core dumped)" :
|
||||
#endif
|
||||
"");
|
||||
sleep(1);
|
||||
}
|
||||
break;
|
||||
} else if (errno != EINTR) {
|
||||
syslog(LOG_ERR, "fatal: waitpid(): %s", strerror(errno));
|
||||
killall(1, kidpids);
|
||||
}
|
||||
}
|
||||
if (termsig)
|
||||
break;
|
||||
|
||||
switch(fpid = fork()) {
|
||||
case -1: /* error */
|
||||
/* System critically low on memory, pause and try again later */
|
||||
sleep(30);
|
||||
break;
|
||||
case 0: /* child */
|
||||
OPENSSL_free(kidpids);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
if (termsig)
|
||||
_exit(0);
|
||||
if (RAND_poll() <= 0) {
|
||||
syslog(LOG_ERR, "fatal: RAND_poll() failed");
|
||||
_exit(1);
|
||||
}
|
||||
return;
|
||||
default: /* parent */
|
||||
for (i = 0; i < multi; ++i) {
|
||||
if (kidpids[i] == 0) {
|
||||
kidpids[i] = fpid;
|
||||
procs++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= multi) {
|
||||
syslog(LOG_ERR, "fatal: internal error: no free child slots");
|
||||
killall(1, kidpids);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* The loop above can only break on termsig */
|
||||
syslog(LOG_INFO, "terminating on signal: %d", termsig);
|
||||
killall(0, kidpids);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert,
|
||||
@@ -1331,209 +1146,32 @@ static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser)
|
||||
return rrow;
|
||||
}
|
||||
|
||||
/* Quick and dirty OCSP server: read in and parse input request */
|
||||
|
||||
static BIO *init_responder(const char *port)
|
||||
{
|
||||
#ifdef OPENSSL_NO_SOCK
|
||||
BIO_printf(bio_err,
|
||||
"Error setting up accept BIO - sockets not supported.\n");
|
||||
return NULL;
|
||||
#else
|
||||
BIO *acbio = NULL, *bufbio = NULL;
|
||||
|
||||
bufbio = BIO_new(BIO_f_buffer());
|
||||
if (bufbio == NULL)
|
||||
goto err;
|
||||
acbio = BIO_new(BIO_s_accept());
|
||||
if (acbio == NULL
|
||||
|| BIO_set_bind_mode(acbio, BIO_BIND_REUSEADDR) < 0
|
||||
|| BIO_set_accept_port(acbio, port) < 0) {
|
||||
log_message(LOG_ERR, "Error setting up accept BIO");
|
||||
goto err;
|
||||
}
|
||||
|
||||
BIO_set_accept_bios(acbio, bufbio);
|
||||
bufbio = NULL;
|
||||
if (BIO_do_accept(acbio) <= 0) {
|
||||
log_message(LOG_ERR, "Error starting accept");
|
||||
goto err;
|
||||
}
|
||||
|
||||
return acbio;
|
||||
|
||||
err:
|
||||
BIO_free_all(acbio);
|
||||
BIO_free(bufbio);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
/*
|
||||
* Decode %xx URL-decoding in-place. Ignores mal-formed sequences.
|
||||
*/
|
||||
static int urldecode(char *p)
|
||||
{
|
||||
unsigned char *out = (unsigned char *)p;
|
||||
unsigned char *save = out;
|
||||
|
||||
for (; *p; p++) {
|
||||
if (*p != '%')
|
||||
*out++ = *p;
|
||||
else if (isxdigit(_UC(p[1])) && isxdigit(_UC(p[2]))) {
|
||||
/* Don't check, can't fail because of ixdigit() call. */
|
||||
*out++ = (OPENSSL_hexchar2int(p[1]) << 4)
|
||||
| OPENSSL_hexchar2int(p[2]);
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
*out = '\0';
|
||||
return (int)(out - save);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OCSP_DAEMON
|
||||
static void socket_timeout(int signum)
|
||||
{
|
||||
if (acfd != (int)INVALID_SOCKET)
|
||||
(void)shutdown(acfd, SHUT_RD);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio,
|
||||
int timeout)
|
||||
{
|
||||
#ifdef OPENSSL_NO_SOCK
|
||||
return 0;
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
return http_server_get_asn1_req(ASN1_ITEM_rptr(OCSP_RESPONSE),
|
||||
(ASN1_VALUE **)preq, pcbio, acbio,
|
||||
prog, 1 /* accept_get */, timeout);
|
||||
#else
|
||||
int len;
|
||||
OCSP_REQUEST *req = NULL;
|
||||
char inbuf[2048], reqbuf[2048];
|
||||
char *p, *q;
|
||||
BIO *cbio = NULL, *getbio = NULL, *b64 = NULL;
|
||||
const char *client;
|
||||
|
||||
BIO_printf(bio_err,
|
||||
"Error getting OCSP request - sockets not supported\n");
|
||||
*preq = NULL;
|
||||
|
||||
/* Connection loss before accept() is routine, ignore silently */
|
||||
if (BIO_do_accept(acbio) <= 0)
|
||||
return 0;
|
||||
|
||||
cbio = BIO_pop(acbio);
|
||||
*pcbio = cbio;
|
||||
client = BIO_get_peer_name(cbio);
|
||||
|
||||
# ifdef OCSP_DAEMON
|
||||
if (timeout > 0) {
|
||||
(void) BIO_get_fd(cbio, &acfd);
|
||||
alarm(timeout);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Read the request line. */
|
||||
len = BIO_gets(cbio, reqbuf, sizeof(reqbuf));
|
||||
if (len <= 0)
|
||||
goto out;
|
||||
|
||||
if (strncmp(reqbuf, "GET ", 4) == 0) {
|
||||
/* Expecting GET {sp} /URL {sp} HTTP/1.x */
|
||||
for (p = reqbuf + 4; *p == ' '; ++p)
|
||||
continue;
|
||||
if (*p != '/') {
|
||||
log_message(LOG_INFO, "Invalid request -- bad URL: %s", client);
|
||||
goto out;
|
||||
}
|
||||
p++;
|
||||
|
||||
/* Splice off the HTTP version identifier. */
|
||||
for (q = p; *q; q++)
|
||||
if (*q == ' ')
|
||||
break;
|
||||
if (strncmp(q, " HTTP/1.", 8) != 0) {
|
||||
log_message(LOG_INFO,
|
||||
"Invalid request -- bad HTTP version: %s", client);
|
||||
goto out;
|
||||
}
|
||||
*q = '\0';
|
||||
|
||||
/*
|
||||
* Skip "GET / HTTP..." requests often used by load-balancers. Note:
|
||||
* 'p' was incremented above to point to the first byte *after* the
|
||||
* leading slash, so with 'GET / ' it is now an empty string.
|
||||
*/
|
||||
if (p[0] == '\0')
|
||||
goto out;
|
||||
|
||||
len = urldecode(p);
|
||||
if (len <= 0) {
|
||||
log_message(LOG_INFO,
|
||||
"Invalid request -- bad URL encoding: %s", client);
|
||||
goto out;
|
||||
}
|
||||
if ((getbio = BIO_new_mem_buf(p, len)) == NULL
|
||||
|| (b64 = BIO_new(BIO_f_base64())) == NULL) {
|
||||
log_message(LOG_ERR, "Could not allocate base64 bio: %s", client);
|
||||
goto out;
|
||||
}
|
||||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
|
||||
getbio = BIO_push(b64, getbio);
|
||||
} else if (strncmp(reqbuf, "POST ", 5) != 0) {
|
||||
log_message(LOG_INFO, "Invalid request -- bad HTTP verb: %s", client);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Read and skip past the headers. */
|
||||
for (;;) {
|
||||
len = BIO_gets(cbio, inbuf, sizeof(inbuf));
|
||||
if (len <= 0)
|
||||
goto out;
|
||||
if ((inbuf[0] == '\r') || (inbuf[0] == '\n'))
|
||||
break;
|
||||
}
|
||||
|
||||
# ifdef OCSP_DAEMON
|
||||
/* Clear alarm before we close the client socket */
|
||||
alarm(0);
|
||||
timeout = 0;
|
||||
# endif
|
||||
|
||||
/* Try to read OCSP request */
|
||||
if (getbio != NULL) {
|
||||
req = d2i_OCSP_REQUEST_bio(getbio, NULL);
|
||||
BIO_free_all(getbio);
|
||||
} else {
|
||||
req = d2i_OCSP_REQUEST_bio(cbio, NULL);
|
||||
}
|
||||
|
||||
if (req == NULL)
|
||||
log_message(LOG_ERR, "Error parsing OCSP request");
|
||||
|
||||
*preq = req;
|
||||
|
||||
out:
|
||||
# ifdef OCSP_DAEMON
|
||||
if (timeout > 0)
|
||||
alarm(0);
|
||||
acfd = (int)INVALID_SOCKET;
|
||||
# endif
|
||||
return 1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp)
|
||||
static int send_ocsp_response(BIO *cbio, const OCSP_RESPONSE *resp)
|
||||
{
|
||||
char http_resp[] =
|
||||
"HTTP/1.0 200 OK\r\nContent-type: application/ocsp-response\r\n"
|
||||
"Content-Length: %d\r\n\r\n";
|
||||
if (cbio == NULL)
|
||||
return 0;
|
||||
BIO_printf(cbio, http_resp, i2d_OCSP_RESPONSE(resp, NULL));
|
||||
i2d_OCSP_RESPONSE_bio(cbio, resp);
|
||||
(void)BIO_flush(cbio);
|
||||
return 1;
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
return http_server_send_asn1_resp(cbio, "application/ocsp-response",
|
||||
ASN1_ITEM_rptr(OCSP_RESPONSE),
|
||||
(const ASN1_VALUE *)resp);
|
||||
#else
|
||||
BIO_printf(bio_err,
|
||||
"Error sending OCSP response - sockets not supported\n");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
|
||||
@@ -348,3 +348,59 @@ ess_cert_id_chain = no # Must the ESS cert id chain be included?
|
||||
# (optional, default: no)
|
||||
ess_cert_id_alg = sha1 # algorithm to compute certificate
|
||||
# identifier (optional, default: sha1)
|
||||
|
||||
[insta] # CMP using Insta Demo CA
|
||||
# Message transfer
|
||||
server = pki.certificate.fi:8700
|
||||
# proxy = # set this as far as needed, e.g., http://192.168.1.1:8080
|
||||
# tls_use = 0
|
||||
path = pkix/
|
||||
|
||||
# Server authentication
|
||||
recipient = "/C=FI/O=Insta Demo/CN=Insta Demo CA" # or set srvcert or issuer
|
||||
ignore_keyusage = 1 # potentially needed quirk
|
||||
unprotected_errors = 1 # potentially needed quirk
|
||||
extracertsout = insta.extracerts.pem
|
||||
|
||||
# Client authentication
|
||||
ref = 3078 # user identification
|
||||
secret = pass:insta # can be used for both client and server side
|
||||
|
||||
# Generic message options
|
||||
cmd = ir # default operation, can be overridden on cmd line with, e.g., kur
|
||||
|
||||
# Certificate enrollment
|
||||
subject = "/CN=openssl-cmp-test"
|
||||
newkey = insta.priv.pem
|
||||
out_trusted = insta.ca.crt
|
||||
certout = insta.cert.pem
|
||||
|
||||
[pbm] # Password-based protection for Insta CA
|
||||
# Server and client authentication
|
||||
ref = $insta::ref # 3078
|
||||
secret = $insta::secret # pass:insta
|
||||
|
||||
[signature] # Signature-based protection for Insta CA
|
||||
# Server authentication
|
||||
trusted = insta.ca.crt # does not include keyUsage digitalSignature
|
||||
|
||||
# Client authentication
|
||||
secret = # disable PBM
|
||||
key = $insta::newkey # insta.priv.pem
|
||||
cert = $insta::certout # insta.cert.pem
|
||||
|
||||
[ir]
|
||||
cmd = ir
|
||||
|
||||
[cr]
|
||||
cmd = cr
|
||||
|
||||
[kur]
|
||||
# Certificate update
|
||||
cmd = kur
|
||||
oldcert = $insta::certout # insta.cert.pem
|
||||
|
||||
[rr]
|
||||
# Certificate revocation
|
||||
cmd = rr
|
||||
oldcert = $insta::certout # insta.cert.pem
|
||||
@@ -348,3 +348,59 @@ ess_cert_id_chain = no # Must the ESS cert id chain be included?
|
||||
# (optional, default: no)
|
||||
ess_cert_id_alg = sha1 # algorithm to compute certificate
|
||||
# identifier (optional, default: sha1)
|
||||
|
||||
[insta] # CMP using Insta Demo CA
|
||||
# Message transfer
|
||||
server = pki.certificate.fi:8700
|
||||
# proxy = # set this as far as needed, e.g., http://192.168.1.1:8080
|
||||
# tls_use = 0
|
||||
path = pkix/
|
||||
|
||||
# Server authentication
|
||||
recipient = "/C=FI/O=Insta Demo/CN=Insta Demo CA" # or set srvcert or issuer
|
||||
ignore_keyusage = 1 # potentially needed quirk
|
||||
unprotected_errors = 1 # potentially needed quirk
|
||||
extracertsout = insta.extracerts.pem
|
||||
|
||||
# Client authentication
|
||||
ref = 3078 # user identification
|
||||
secret = pass:insta # can be used for both client and server side
|
||||
|
||||
# Generic message options
|
||||
cmd = ir # default operation, can be overridden on cmd line with, e.g., kur
|
||||
|
||||
# Certificate enrollment
|
||||
subject = "/CN=openssl-cmp-test"
|
||||
newkey = insta.priv.pem
|
||||
out_trusted = insta.ca.crt
|
||||
certout = insta.cert.pem
|
||||
|
||||
[pbm] # Password-based protection for Insta CA
|
||||
# Server and client authentication
|
||||
ref = $insta::ref # 3078
|
||||
secret = $insta::secret # pass:insta
|
||||
|
||||
[signature] # Signature-based protection for Insta CA
|
||||
# Server authentication
|
||||
trusted = insta.ca.crt # does not include keyUsage digitalSignature
|
||||
|
||||
# Client authentication
|
||||
secret = # disable PBM
|
||||
key = $insta::newkey # insta.priv.pem
|
||||
cert = $insta::certout # insta.cert.pem
|
||||
|
||||
[ir]
|
||||
cmd = ir
|
||||
|
||||
[cr]
|
||||
cmd = cr
|
||||
|
||||
[kur]
|
||||
# Certificate update
|
||||
cmd = kur
|
||||
oldcert = $insta::certout # insta.cert.pem
|
||||
|
||||
[rr]
|
||||
# Certificate revocation
|
||||
cmd = rr
|
||||
oldcert = $insta::certout # insta.cert.pem
|
||||
@@ -19,6 +19,12 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(PKCS7)
|
||||
DEFINE_STACK_OF(PKCS12_SAFEBAG)
|
||||
DEFINE_STACK_OF(X509_ATTRIBUTE)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#define NOKEYS 0x1
|
||||
#define NOCERTS 0x2
|
||||
#define INFO 0x4
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#include <openssl/pkcs7.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_NOOUT,
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ const OPTIONS pkey_options[] = {
|
||||
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, 's', "Input key"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format (DER or PEM)"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format (DER/PEM/P12/ENGINE)"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
{"pubin", OPT_PUBIN, '-',
|
||||
"Read public key from input (default is private key)"},
|
||||
|
||||
+7
-5
@@ -15,6 +15,8 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#define KEY_NONE 0
|
||||
#define KEY_PRIVKEY 1
|
||||
#define KEY_PUBKEY 2
|
||||
@@ -69,11 +71,11 @@ const OPTIONS pkeyutl_options[] = {
|
||||
{"inkey", OPT_INKEY, 's', "Input private key file"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
{"peerkey", OPT_PEERKEY, 's', "Peer key file used in key derivation"},
|
||||
{"peerform", OPT_PEERFORM, 'E', "Peer key format - default PEM"},
|
||||
{"peerform", OPT_PEERFORM, 'E', "Peer key format (DER/PEM/P12/ENGINE)"},
|
||||
{"certin", OPT_CERTIN, '-', "Input is a cert with a public key"},
|
||||
{"rev", OPT_REV, '-', "Reverse the order of the input buffer"},
|
||||
{"sigfile", OPT_SIGFILE, '<', "Signature file (verify operation only)"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Private key format - default PEM"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"},
|
||||
|
||||
OPT_SECTION("Output"),
|
||||
{"out", OPT_OUT, '>', "Output file - default stdout"},
|
||||
@@ -155,11 +157,11 @@ int pkeyutl_main(int argc, char **argv)
|
||||
passinarg = opt_arg();
|
||||
break;
|
||||
case OPT_PEERFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &peerform))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &peerform))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyform))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_R_CASES:
|
||||
@@ -517,7 +519,7 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||
break;
|
||||
|
||||
case KEY_CERT:
|
||||
x = load_cert(keyfile, keyform, "Certificate");
|
||||
x = load_cert(keyfile, FORMAT_UNDEF, "Certificate");
|
||||
if (x) {
|
||||
pkey = X509_get_pubkey(x);
|
||||
X509_free(x);
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
|
||||
DEFINE_STACK_OF_CSTRING()
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_V = 100, OPT_VV, OPT_VVV
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
# include <openssl/pem.h>
|
||||
# include <openssl/x509.h>
|
||||
|
||||
DEFINE_STACK_OF(X509_INFO)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
# ifndef PATH_MAX
|
||||
# define PATH_MAX 4096
|
||||
|
||||
+3
-1
@@ -32,6 +32,8 @@
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
|
||||
DEFINE_STACK_OF(CONF_VALUE)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#define BITS "default_bits"
|
||||
#define KEYFILE "default_keyfile"
|
||||
@@ -135,7 +137,7 @@ const OPTIONS req_options[] = {
|
||||
|
||||
OPT_SECTION("Keys and Signing"),
|
||||
{"key", OPT_KEY, 's', "Private key to use"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Key file format"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Key file format (ENGINE, other values ignored)"},
|
||||
{"pubkey", OPT_PUBKEY, '-', "Output public key"},
|
||||
{"keyout", OPT_KEYOUT, '>', "File to send the key to"},
|
||||
{"passin", OPT_PASSIN, 's', "Private key password source"},
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ const OPTIONS rsa_options[] = {
|
||||
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, 's', "Input file"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format, one of DER PEM"},
|
||||
{"inform", OPT_INFORM, 'f', "Input format (DER/PEM/P12/ENGINE"},
|
||||
{"pubin", OPT_PUBIN, '-', "Expect a public key in input file"},
|
||||
{"RSAPublicKey_in", OPT_RSAPUBKEY_IN, '-', "Input is an RSAPublicKey"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
|
||||
+1
-3
@@ -1,5 +1,4 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
|
||||
MIISKAIBAAKCBAEAiQ2f1X6Bte1DKD0OoCBKEikzPW+5w3oXk3WwnE97Wxzy6wJZ
|
||||
ebbZC3CZKKBnJeBMrysPf+lK+9+fP6Vm8bp1wvbcSIA59BDrX6irFSuM/bdnkbuF
|
||||
MFlDjt+uVrxwoyqfPi2IPot1HQg3l5mdyBqcTWvbOnU2L9HZxJfPUCjfzdTMPrMY
|
||||
@@ -62,7 +61,7 @@ JH1/Qx7C/mTAMRsN5SkOthnGq0djCNWfPv/3JV0H67Uf5krFlnwLebrgfTYoPPdo
|
||||
yO7iBUNJzv6Qh22malLp4P8gzACkD7DGlSTnoB5cLwcjmDGg+i9WrUBbOiVTeQfZ
|
||||
kOj1o+Tz35ndpq/DDUVlqliB9krcxva+QHeJPH53EGI+YVg1nD+s/vUDZ3mQMGX9
|
||||
DQou2L8uU6RnWNv/BihGcL8QvS4Ty6QyPOUPpD3zc70JQAEcQk9BxQNaELgJX0IN
|
||||
22cYn22tYvElew9G41OpDqzBRcfbdJmKXQ2HcroShutYJQRGUpAXHk24fy6JVkIU
|
||||
2cYUn22tYvElew9G41OpDqzBRcfbdJmKXQ2HcroShutYJQRGUpAXHk24fy6JVkIU
|
||||
ojF5U6cwextMja1ZIIZgh9eugIRUeIE7319nQNDzuXWjRCcoBLA25P7wnpHWDRpz
|
||||
D9ovXCIvdja74lL5psqobV6L5+fbLPkSgXoImKR0LQKCAgAIC9Jk8kxumCyIVGCP
|
||||
PeM5Uby9M3GMuKrfYsn0Y5e97+kSJF1dpojTodBgR2KQar6eVrvXt+8uZCcIjfx8
|
||||
@@ -98,4 +97,3 @@ TwEgE67iOb2iIoUpon/NyP4LesMzvdpsu2JFlfz13PmmQ34mFI7tWvOb3NA5DP3c
|
||||
rMlMLtKfp2w8HlMZpsUlToNCx6CI+tJrohzcs3BAVAbjFAXRKWGijB1rxwyDdHPv
|
||||
I+/wJTNaRNPQ1M0SwtEL/zJd21y3KSPn4eL+GP3efhlDSjtlDvZqkdAUsU8=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
+3
-3
@@ -48,7 +48,7 @@ const OPTIONS rsautl_options[] = {
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, '<', "Input file"},
|
||||
{"inkey", OPT_INKEY, 's', "Input key"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Private key format - default PEM"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"},
|
||||
{"pubin", OPT_PUBIN, '-', "Input is an RSA public"},
|
||||
{"certin", OPT_CERTIN, '-', "Input is a cert carrying an RSA public key"},
|
||||
{"rev", OPT_REV, '-', "Reverse the order of the input buffer"},
|
||||
@@ -98,7 +98,7 @@ int rsautl_main(int argc, char **argv)
|
||||
ret = 0;
|
||||
goto end;
|
||||
case OPT_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyformat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_IN:
|
||||
@@ -194,7 +194,7 @@ int rsautl_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case KEY_CERT:
|
||||
x = load_cert(keyfile, keyformat, "Certificate");
|
||||
x = load_cert(keyfile, FORMAT_UNDEF, "Certificate");
|
||||
if (x) {
|
||||
pkey = X509_get_pubkey(x);
|
||||
X509_free(x);
|
||||
|
||||
+11
-27
@@ -56,6 +56,12 @@ typedef unsigned int u_int;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
DEFINE_STACK_OF(X509_NAME)
|
||||
DEFINE_STACK_OF(SCT)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#undef BUFSIZZ
|
||||
#define BUFSIZZ 1024*8
|
||||
#define S_CLIENT_IRC_READ_TIMEOUT 8
|
||||
@@ -92,27 +98,6 @@ static int restore_errno(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void do_ssl_shutdown(SSL *ssl)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do {
|
||||
/* We only do unidirectional shutdown */
|
||||
ret = SSL_shutdown(ssl);
|
||||
if (ret < 0) {
|
||||
switch (SSL_get_error(ssl, ret)) {
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
case SSL_ERROR_WANT_ASYNC:
|
||||
case SSL_ERROR_WANT_ASYNC_JOB:
|
||||
/* We just do busy waiting. Nothing clever */
|
||||
continue;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
} while (ret < 0);
|
||||
}
|
||||
|
||||
/* Default PSK identity and key */
|
||||
static char *psk_identity = "Client_identity";
|
||||
|
||||
@@ -651,12 +636,12 @@ const OPTIONS s_client_options[] = {
|
||||
OPT_SECTION("Identity"),
|
||||
{"cert", OPT_CERT, '<', "Client certificate file to use"},
|
||||
{"certform", OPT_CERTFORM, 'F',
|
||||
"Client certificate file format (PEM or DER) PEM default"},
|
||||
"Client certificate file format (PEM/DER/P12); has no effect"},
|
||||
{"cert_chain", OPT_CERT_CHAIN, '<',
|
||||
"Client certificate chain file (in PEM format)"},
|
||||
{"build_chain", OPT_BUILD_CHAIN, '-', "Build client certificate chain"},
|
||||
{"key", OPT_KEY, 's', "Private key file to use; default is: -cert file"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Key format (PEM, DER or engine) PEM default"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Key format (ENGINE, other values ignored)"},
|
||||
{"pass", OPT_PASS, 's', "Private key file pass phrase source"},
|
||||
{"verify", OPT_VERIFY, 'p', "Turn on peer certificate verification"},
|
||||
{"nameopt", OPT_NAMEOPT, 's', "Certificate subject/issuer name printing options"},
|
||||
@@ -1159,7 +1144,7 @@ int s_client_main(int argc, char **argv)
|
||||
sess_in = opt_arg();
|
||||
break;
|
||||
case OPT_CERTFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &cert_format))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &cert_format))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_CRLFORM:
|
||||
@@ -1393,7 +1378,7 @@ int s_client_main(int argc, char **argv)
|
||||
fallback_scsv = 1;
|
||||
break;
|
||||
case OPT_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &key_format))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &key_format))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_PASS:
|
||||
@@ -3152,8 +3137,7 @@ int s_client_main(int argc, char **argv)
|
||||
OPENSSL_clear_free(cbuf, BUFSIZZ);
|
||||
OPENSSL_clear_free(sbuf, BUFSIZZ);
|
||||
OPENSSL_clear_free(mbuf, BUFSIZZ);
|
||||
if (proxypass != NULL)
|
||||
OPENSSL_clear_free(proxypass, strlen(proxypass));
|
||||
clear_free(proxypass);
|
||||
release_engine(e);
|
||||
BIO_free(bio_c_out);
|
||||
bio_c_out = NULL;
|
||||
|
||||
+31
-16
@@ -60,6 +60,12 @@ typedef unsigned int u_int;
|
||||
#endif
|
||||
#include "internal/sockets.h"
|
||||
|
||||
DEFINE_STACK_OF(X509_EXTENSION)
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(SSL_CIPHER)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
static int not_resumable_sess_cb(SSL *s, int is_forward_secure);
|
||||
static int sv_body(int s, int stype, int prot, unsigned char *context);
|
||||
static int www_body(int s, int stype, int prot, unsigned char *context);
|
||||
@@ -755,7 +761,7 @@ typedef enum OPTION_choice {
|
||||
OPT_SRTP_PROFILES, OPT_KEYMATEXPORT, OPT_KEYMATEXPORTLEN,
|
||||
OPT_KEYLOG_FILE, OPT_MAX_EARLY, OPT_RECV_MAX_EARLY, OPT_EARLY_DATA,
|
||||
OPT_S_NUM_TICKETS, OPT_ANTI_REPLAY, OPT_NO_ANTI_REPLAY, OPT_SCTP_LABEL_BUG,
|
||||
OPT_HTTP_SERVER_BINMODE,
|
||||
OPT_HTTP_SERVER_BINMODE, OPT_NOCANAMES,
|
||||
OPT_R_ENUM,
|
||||
OPT_S_ENUM,
|
||||
OPT_V_ENUM,
|
||||
@@ -807,7 +813,7 @@ const OPTIONS s_server_options[] = {
|
||||
{"cert2", OPT_CERT2, '<',
|
||||
"Certificate file to use for servername; default is" TEST_CERT2},
|
||||
{"certform", OPT_CERTFORM, 'F',
|
||||
"Server certificate file format (PEM or DER) PEM default"},
|
||||
"Server certificate file format (PEM/DER/P12); has no effect"},
|
||||
{"cert_chain", OPT_CERT_CHAIN, '<',
|
||||
"Server certificate chain file in PEM format"},
|
||||
{"build_chain", OPT_BUILD_CHAIN, '-', "Build server certificate chain"},
|
||||
@@ -817,19 +823,18 @@ const OPTIONS s_server_options[] = {
|
||||
"Private key file to use; default is -cert file or else" TEST_CERT},
|
||||
{"key2", OPT_KEY2, '<',
|
||||
"-Private Key file to use for servername if not in -cert2"},
|
||||
{"keyform", OPT_KEYFORM, 'f',
|
||||
"Key format (PEM, DER or ENGINE) PEM default"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Key format (ENGINE, other values ignored)"},
|
||||
{"pass", OPT_PASS, 's', "Private key file pass phrase source"},
|
||||
{"dcert", OPT_DCERT, '<',
|
||||
"Second server certificate file to use (usually for DSA)"},
|
||||
{"dcertform", OPT_DCERTFORM, 'F',
|
||||
"Second server certificate file format (PEM or DER) PEM default"},
|
||||
"Second server certificate file format (PEM/DER/P12); has no effect"},
|
||||
{"dcert_chain", OPT_DCERT_CHAIN, '<',
|
||||
"second server certificate chain file in PEM format"},
|
||||
{"dkey", OPT_DKEY, '<',
|
||||
"Second private key file to use (usually for DSA)"},
|
||||
{"dkeyform", OPT_DKEYFORM, 'F',
|
||||
"Second key file format (PEM, DER or ENGINE) PEM default"},
|
||||
"Second key file format (ENGINE, other values ignored)"},
|
||||
{"dpass", OPT_DPASS, 's', "Second private key file pass phrase source"},
|
||||
{"dhparam", OPT_DHPARAM, '<', "DH parameters file to use"},
|
||||
{"servername", OPT_SERVERNAME, 's',
|
||||
@@ -946,6 +951,8 @@ const OPTIONS s_server_options[] = {
|
||||
{"anti_replay", OPT_ANTI_REPLAY, '-', "Switch on anti-replay protection (default)"},
|
||||
{"no_anti_replay", OPT_NO_ANTI_REPLAY, '-', "Switch off anti-replay protection"},
|
||||
{"http_server_binmode", OPT_HTTP_SERVER_BINMODE, '-', "opening files in binary mode when acting as http server (-WWW and -HTTP)"},
|
||||
{"no_ca_names", OPT_NOCANAMES, '-',
|
||||
"Disable TLS Extension CA Names"},
|
||||
{"stateless", OPT_STATELESS, '-', "Require TLSv1.3 cookies"},
|
||||
#ifndef OPENSSL_NO_SSL3
|
||||
{"ssl3", OPT_SSL3, '-', "Just talk SSLv3"},
|
||||
@@ -1083,6 +1090,7 @@ int s_server_main(int argc, char *argv[])
|
||||
const char *keylog_file = NULL;
|
||||
int max_early_data = -1, recv_max_early_data = -1;
|
||||
char *psksessf = NULL;
|
||||
int no_ca_names = 0;
|
||||
#ifndef OPENSSL_NO_SCTP
|
||||
int sctp_label_bug = 0;
|
||||
#endif
|
||||
@@ -1237,14 +1245,14 @@ int s_server_main(int argc, char *argv[])
|
||||
s_serverinfo_file = opt_arg();
|
||||
break;
|
||||
case OPT_CERTFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_cert_format))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_cert_format))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_KEY:
|
||||
s_key_file = opt_arg();
|
||||
break;
|
||||
case OPT_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &s_key_format))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_key_format))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_PASS:
|
||||
@@ -1259,14 +1267,14 @@ int s_server_main(int argc, char *argv[])
|
||||
#endif
|
||||
break;
|
||||
case OPT_DCERTFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_dcert_format))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_dcert_format))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_DCERT:
|
||||
s_dcert_file = opt_arg();
|
||||
break;
|
||||
case OPT_DKEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &s_dkey_format))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_dkey_format))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_DPASS:
|
||||
@@ -1568,7 +1576,9 @@ int s_server_main(int argc, char *argv[])
|
||||
session_id_prefix = opt_arg();
|
||||
break;
|
||||
case OPT_ENGINE:
|
||||
engine = setup_engine(opt_arg(), 1);
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
engine = setup_engine(opt_arg(), s_debug);
|
||||
#endif
|
||||
break;
|
||||
case OPT_R_CASES:
|
||||
if (!opt_rand(o))
|
||||
@@ -1649,6 +1659,9 @@ int s_server_main(int argc, char *argv[])
|
||||
case OPT_HTTP_SERVER_BINMODE:
|
||||
http_server_binmode = 1;
|
||||
break;
|
||||
case OPT_NOCANAMES:
|
||||
no_ca_names = 1;
|
||||
break;
|
||||
case OPT_SENDFILE:
|
||||
#ifndef OPENSSL_NO_KTLS
|
||||
use_sendfile = 1;
|
||||
@@ -1878,7 +1891,6 @@ int s_server_main(int argc, char *argv[])
|
||||
}
|
||||
BIO_printf(bio_err, "id_prefix '%s' set.\n", session_id_prefix);
|
||||
}
|
||||
SSL_CTX_set_quiet_shutdown(ctx, 1);
|
||||
if (exc != NULL)
|
||||
ssl_ctx_set_excert(ctx, exc);
|
||||
|
||||
@@ -1895,6 +1907,10 @@ int s_server_main(int argc, char *argv[])
|
||||
SSL_CTX_set_mode(ctx, SSL_MODE_ASYNC);
|
||||
}
|
||||
|
||||
if (no_ca_names) {
|
||||
SSL_CTX_set_options(ctx, SSL_OP_DISABLE_TLSEXT_CA_NAMES);
|
||||
}
|
||||
|
||||
if (max_send_fragment > 0
|
||||
&& !SSL_CTX_set_max_send_fragment(ctx, max_send_fragment)) {
|
||||
BIO_printf(bio_err, "%s: Max send fragment size %u is out of permitted range\n",
|
||||
@@ -1976,7 +1992,6 @@ int s_server_main(int argc, char *argv[])
|
||||
}
|
||||
BIO_printf(bio_err, "id_prefix '%s' set.\n", session_id_prefix);
|
||||
}
|
||||
SSL_CTX_set_quiet_shutdown(ctx2, 1);
|
||||
if (exc != NULL)
|
||||
ssl_ctx_set_excert(ctx2, exc);
|
||||
|
||||
@@ -2764,7 +2779,7 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
|
||||
err:
|
||||
if (con != NULL) {
|
||||
BIO_printf(bio_s_out, "shutting down SSL\n");
|
||||
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
|
||||
do_ssl_shutdown(con);
|
||||
SSL_free(con);
|
||||
}
|
||||
BIO_printf(bio_s_out, "CONNECTION CLOSED\n");
|
||||
@@ -3433,7 +3448,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context)
|
||||
}
|
||||
end:
|
||||
/* make sure we re-use sessions */
|
||||
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
|
||||
do_ssl_shutdown(con);
|
||||
|
||||
err:
|
||||
OPENSSL_free(buf);
|
||||
@@ -3587,7 +3602,7 @@ static int rev_body(int s, int stype, int prot, unsigned char *context)
|
||||
}
|
||||
end:
|
||||
/* make sure we re-use sessions */
|
||||
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
|
||||
do_ssl_shutdown(con);
|
||||
|
||||
err:
|
||||
|
||||
|
||||
+7
-4
@@ -19,6 +19,9 @@
|
||||
#include <openssl/x509_vfy.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
static int save_certs(char *signerfile, STACK_OF(X509) *signers);
|
||||
static int smime_cb(int ok, X509_STORE_CTX *ctx);
|
||||
|
||||
@@ -60,7 +63,7 @@ const OPTIONS smime_options[] = {
|
||||
"Output format SMIME (default), PEM or DER"},
|
||||
{"inkey", OPT_INKEY, 's',
|
||||
"Input private key (if not signer or recipient)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Input private key format (PEM or ENGINE)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Input private key format (ENGINE, other values ignored)"},
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
||||
#endif
|
||||
@@ -426,7 +429,7 @@ int smime_main(int argc, char **argv)
|
||||
if (encerts == NULL)
|
||||
goto end;
|
||||
while (*argv != NULL) {
|
||||
cert = load_cert(*argv, FORMAT_PEM,
|
||||
cert = load_cert(*argv, FORMAT_UNDEF,
|
||||
"recipient certificate file");
|
||||
if (cert == NULL)
|
||||
goto end;
|
||||
@@ -445,7 +448,7 @@ int smime_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (recipfile != NULL && (operation == SMIME_DECRYPT)) {
|
||||
if ((recip = load_cert(recipfile, FORMAT_PEM,
|
||||
if ((recip = load_cert(recipfile, FORMAT_UNDEF,
|
||||
"recipient certificate file")) == NULL) {
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
@@ -545,7 +548,7 @@ int smime_main(int argc, char **argv)
|
||||
for (i = 0; i < sk_OPENSSL_STRING_num(sksigners); i++) {
|
||||
signerfile = sk_OPENSSL_STRING_value(sksigners, i);
|
||||
keyfile = sk_OPENSSL_STRING_value(skkeys, i);
|
||||
signer = load_cert(signerfile, FORMAT_PEM,
|
||||
signer = load_cert(signerfile, FORMAT_UNDEF,
|
||||
"signer certificate");
|
||||
if (signer == NULL)
|
||||
goto end;
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ const OPTIONS spkac_options[] = {
|
||||
OPT_SECTION("Input"),
|
||||
{"in", OPT_IN, '<', "Input file"},
|
||||
{"key", OPT_KEY, '<', "Create SPKAC using private key"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Private key file format - default PEM (PEM, DER, or ENGINE)"},
|
||||
{"keyform", OPT_KEYFORM, 'f', "Private key file format (ENGINE, other values ignored)"},
|
||||
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
|
||||
{"challenge", OPT_CHALLENGE, 's', "Challenge string"},
|
||||
{"spkac", OPT_SPKAC, 's', "Alternative SPKAC name"},
|
||||
|
||||
+5
-1
@@ -18,6 +18,10 @@
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
DEFINE_STACK_OF(X509)
|
||||
DEFINE_STACK_OF(X509_CRL)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
static int cb(int ok, X509_STORE_CTX *ctx);
|
||||
static int check(X509_STORE *ctx, const char *file,
|
||||
STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
|
||||
@@ -252,7 +256,7 @@ static int check(X509_STORE *ctx, const char *file,
|
||||
STACK_OF(X509) *chain = NULL;
|
||||
int num_untrusted;
|
||||
|
||||
x = load_cert(file, FORMAT_PEM, "certificate file");
|
||||
x = load_cert(file, FORMAT_UNDEF, "certificate file");
|
||||
if (x == NULL)
|
||||
goto end;
|
||||
|
||||
|
||||
+14
-10
@@ -28,6 +28,10 @@
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
|
||||
DEFINE_STACK_OF(ASN1_OBJECT)
|
||||
DEFINE_STACK_OF(X509_EXTENSION)
|
||||
DEFINE_STACK_OF_STRING()
|
||||
|
||||
#undef POSTFIX
|
||||
#define POSTFIX ".srl"
|
||||
#define DEF_DAYS 30
|
||||
@@ -74,13 +78,13 @@ const OPTIONS x509_options[] = {
|
||||
#endif
|
||||
|
||||
{"inform", OPT_INFORM, 'f',
|
||||
"Input format - default PEM (one of DER or PEM)"},
|
||||
"CSR input format (DER or PEM) - default PEM"},
|
||||
{"in", OPT_IN, '<', "Input file - default stdin"},
|
||||
{"passin", OPT_PASSIN, 's', "Private key password/pass-phrase source"},
|
||||
{"outform", OPT_OUTFORM, 'f',
|
||||
"Output format - default PEM (one of DER or PEM)"},
|
||||
"Output format (DER or PEM) - default PEM"},
|
||||
{"out", OPT_OUT, '>', "Output file - default stdout"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Private key format - default PEM"},
|
||||
{"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"},
|
||||
{"req", OPT_REQ, '-', "Input is a certificate request, sign and output"},
|
||||
{"vfyopt", OPT_VFYOPT, 's', "Verification parameter in n:v form"},
|
||||
|
||||
@@ -148,8 +152,8 @@ const OPTIONS x509_options[] = {
|
||||
{"extfile", OPT_EXTFILE, '<', "File with X509V3 extensions to add"},
|
||||
OPT_R_OPTIONS,
|
||||
OPT_PROV_OPTIONS,
|
||||
{"CAform", OPT_CAFORM, 'F', "CA format - default PEM"},
|
||||
{"CAkeyform", OPT_CAKEYFORM, 'E', "CA key format - default PEM"},
|
||||
{"CAform", OPT_CAFORM, 'F', "CA cert format (PEM/DER/P12); has no effect"},
|
||||
{"CAkeyform", OPT_CAKEYFORM, 'E', "CA key format (ENGINE, other values ignored)"},
|
||||
{"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"},
|
||||
{"CAcreateserial", OPT_CACREATESERIAL, '-',
|
||||
"Create serial number file if it does not exist"},
|
||||
@@ -224,7 +228,7 @@ int x509_main(int argc, char **argv)
|
||||
ret = 0;
|
||||
goto end;
|
||||
case OPT_INFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &informat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_IN:
|
||||
@@ -235,15 +239,15 @@ int x509_main(int argc, char **argv)
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_KEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyformat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_CAFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &CAformat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &CAformat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_CAKEYFORM:
|
||||
if (!opt_format(opt_arg(), OPT_FMT_PDE, &CAkeyformat))
|
||||
if (!opt_format(opt_arg(), OPT_FMT_ANY, &CAkeyformat))
|
||||
goto opthelp;
|
||||
break;
|
||||
case OPT_OUT:
|
||||
@@ -627,7 +631,7 @@ int x509_main(int argc, char **argv)
|
||||
if (!X509_set_pubkey(x, fkey != NULL ? fkey : X509_REQ_get0_pubkey(req)))
|
||||
goto end;
|
||||
} else {
|
||||
x = load_cert(infile, informat, "Certificate");
|
||||
x = load_cert(infile, FORMAT_UNDEF, "Certificate");
|
||||
if (x == NULL)
|
||||
goto end;
|
||||
if (fkey != NULL && !X509_set_pubkey(x, fkey))
|
||||
|
||||
Reference in New Issue
Block a user