Latest update
This commit is contained in:
+34
-15
@@ -1,4 +1,25 @@
|
||||
{- our @apps_openssl_src =
|
||||
# Program init source, that don't have direct linkage with the rest of the
|
||||
# source, and can therefore not be part of a library.
|
||||
IF[{- !$disabled{uplink} -}]
|
||||
$INITSRC=../ms/applink.c
|
||||
ENDIF
|
||||
IF[{- $config{target} =~ /^vms-/ -}]
|
||||
$INITSRC=vms_decc_init.c
|
||||
ENDIF
|
||||
|
||||
# Auxilliary program source
|
||||
IF[{- $config{target} =~ /^(?:VC-|mingw)/ -}]
|
||||
# It's called 'init', but doesn't have much 'init' in it...
|
||||
$AUXLIBAPPSSRC=win32_init.c
|
||||
ENDIF
|
||||
IF[{- $config{target} =~ /^vms-/ -}]
|
||||
$AUXLIBAPPSSRC=vms_term_sock.c vms_decc_argv.c
|
||||
ENDIF
|
||||
|
||||
# Source for the 'openssl' program
|
||||
# We need the perl variable for the DEPEND generator further down.
|
||||
$OPENSSLSRC={-
|
||||
our @opensslsrc =
|
||||
qw(openssl.c
|
||||
asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c dgst.c dhparam.c
|
||||
dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c errstr.c gendsa.c
|
||||
@@ -7,30 +28,28 @@
|
||||
rsautl.c s_client.c s_server.c s_time.c sess_id.c smime.c speed.c
|
||||
spkac.c srp.c ts.c verify.c version.c x509.c rehash.c storeutl.c
|
||||
info.c);
|
||||
our @apps_lib_src =
|
||||
( qw(apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c
|
||||
bf_prefix.c),
|
||||
split(/\s+/, $target{apps_aux_src}) );
|
||||
our @apps_init_src = split(/\s+/, $target{apps_init_src});
|
||||
"" -}
|
||||
join(' ', @opensslsrc); -}
|
||||
# Source for libapps
|
||||
$LIBAPPSSRC=apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \
|
||||
bf_prefix.c
|
||||
|
||||
IF[{- !$disabled{apps} -}]
|
||||
LIBS{noinst}=libapps.a
|
||||
SOURCE[libapps.a]={- join(" ", @apps_lib_src) -}
|
||||
SOURCE[libapps.a]=$LIBAPPSSRC $AUXLIBAPPSSRC
|
||||
INCLUDE[libapps.a]=.. ../include include
|
||||
|
||||
PROGRAMS=openssl
|
||||
SOURCE[openssl]={- join(" ", @apps_init_src) -}
|
||||
SOURCE[openssl]={- join(" ", @apps_openssl_src) -}
|
||||
SOURCE[openssl]=$INITSRC $OPENSSLSRC
|
||||
INCLUDE[openssl]=.. ../include include
|
||||
DEPEND[openssl]=libapps.a ../libssl
|
||||
|
||||
IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-)/ -}]
|
||||
GENERATE[openssl.rc]=../util/mkrc.pl openssl
|
||||
SOURCE[openssl]=openssl.rc
|
||||
ENDIF
|
||||
IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-)/ -}]
|
||||
GENERATE[openssl.rc]=../util/mkrc.pl openssl
|
||||
SOURCE[openssl]=openssl.rc
|
||||
ENDIF
|
||||
|
||||
{- join("\n ", map { (my $x = $_) =~ s|\.c$|.o|; "DEPEND[$x]=progs.h" }
|
||||
@apps_openssl_src) -}
|
||||
@opensslsrc) -}
|
||||
GENERATE[progs.h]=progs.pl $(APPS_OPENSSL)
|
||||
DEPEND[progs.h]=../configdata.pm
|
||||
|
||||
|
||||
@@ -96,7 +96,8 @@ static int certify(X509 **xret, const char *infile, EVP_PKEY *pkey, X509 *x509,
|
||||
const char *enddate,
|
||||
long days, int batch, const char *ext_sect, CONF *conf,
|
||||
int verbose, unsigned long certopt, unsigned long nameopt,
|
||||
int default_op, int ext_copy, int selfsign);
|
||||
int default_op, int ext_copy, int selfsign,
|
||||
unsigned char *sm2_id, size_t sm2idlen);
|
||||
static int certify_cert(X509 **xret, const char *infile, EVP_PKEY *pkey, X509 *x509,
|
||||
const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
|
||||
STACK_OF(CONF_VALUE) *policy, CA_DB *db,
|
||||
@@ -147,7 +148,7 @@ typedef enum OPTION_choice {
|
||||
OPT_INFILES, OPT_SS_CERT, OPT_SPKAC, OPT_REVOKE, OPT_VALID,
|
||||
OPT_EXTENSIONS, OPT_EXTFILE, OPT_STATUS, OPT_UPDATEDB, OPT_CRLEXTS,
|
||||
OPT_RAND_SERIAL,
|
||||
OPT_R_ENUM,
|
||||
OPT_R_ENUM, OPT_SM2ID, OPT_SM2HEXID,
|
||||
/* Do not change the order here; see related case statements below */
|
||||
OPT_CRL_REASON, OPT_CRL_HOLD, OPT_CRL_COMPROMISE, OPT_CRL_CA_COMPROMISE
|
||||
} OPTION_CHOICE;
|
||||
@@ -217,6 +218,12 @@ const OPTIONS ca_options[] = {
|
||||
OPT_R_OPTIONS,
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
{"sm2-id", OPT_SM2ID, 's',
|
||||
"Specify an ID string to verify an SM2 certificate request"},
|
||||
{"sm2-hex-id", OPT_SM2HEXID, 's',
|
||||
"Specify a hex ID string to verify an SM2 certificate request"},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
@@ -262,6 +269,9 @@ int ca_main(int argc, char **argv)
|
||||
REVINFO_TYPE rev_type = REV_NONE;
|
||||
X509_REVOKED *r = NULL;
|
||||
OPTION_CHOICE o;
|
||||
unsigned char *sm2_id = NULL;
|
||||
size_t sm2_idlen = 0;
|
||||
int sm2_free = 0;
|
||||
|
||||
prog = opt_init(argc, argv, ca_options);
|
||||
while ((o = opt_next()) != OPT_EOF) {
|
||||
@@ -425,6 +435,30 @@ opthelp:
|
||||
case OPT_ENGINE:
|
||||
e = setup_engine(opt_arg(), 0);
|
||||
break;
|
||||
case OPT_SM2ID:
|
||||
/* we assume the input is not a hex string */
|
||||
if (sm2_id != NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Use one of the options 'sm2-hex-id' or 'sm2-id'\n");
|
||||
goto end;
|
||||
}
|
||||
sm2_id = (unsigned char *)opt_arg();
|
||||
sm2_idlen = strlen((const char *)sm2_id);
|
||||
break;
|
||||
case OPT_SM2HEXID:
|
||||
/* try to parse the input as hex string first */
|
||||
if (sm2_id != NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Use one of the options 'sm2-hex-id' or 'sm2-id'\n");
|
||||
goto end;
|
||||
}
|
||||
sm2_free = 1;
|
||||
sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||
if (sm2_id == NULL) {
|
||||
BIO_printf(bio_err, "Invalid hex string input\n");
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
end_of_options:
|
||||
@@ -913,7 +947,8 @@ end_of_options:
|
||||
j = certify(&x, infile, pkey, x509p, dgst, sigopts, attribs, db,
|
||||
serial, subj, chtype, multirdn, email_dn, startdate,
|
||||
enddate, days, batch, extensions, conf, verbose,
|
||||
certopt, get_nameopt(), default_op, ext_copy, selfsign);
|
||||
certopt, get_nameopt(), default_op, ext_copy, selfsign,
|
||||
sm2_id, sm2_idlen);
|
||||
if (j < 0)
|
||||
goto end;
|
||||
if (j > 0) {
|
||||
@@ -932,7 +967,8 @@ end_of_options:
|
||||
j = certify(&x, argv[i], pkey, x509p, dgst, sigopts, attribs, db,
|
||||
serial, subj, chtype, multirdn, email_dn, startdate,
|
||||
enddate, days, batch, extensions, conf, verbose,
|
||||
certopt, get_nameopt(), default_op, ext_copy, selfsign);
|
||||
certopt, get_nameopt(), default_op, ext_copy, selfsign,
|
||||
sm2_id, sm2_idlen);
|
||||
if (j < 0)
|
||||
goto end;
|
||||
if (j > 0) {
|
||||
@@ -1230,6 +1266,8 @@ end_of_options:
|
||||
ret = 0;
|
||||
|
||||
end:
|
||||
if (sm2_free)
|
||||
OPENSSL_free(sm2_id);
|
||||
if (ret)
|
||||
ERR_print_errors(bio_err);
|
||||
BIO_free_all(Sout);
|
||||
@@ -1268,7 +1306,8 @@ static int certify(X509 **xret, const char *infile, EVP_PKEY *pkey, X509 *x509,
|
||||
const char *enddate,
|
||||
long days, int batch, const char *ext_sect, CONF *lconf,
|
||||
int verbose, unsigned long certopt, unsigned long nameopt,
|
||||
int default_op, int ext_copy, int selfsign)
|
||||
int default_op, int ext_copy, int selfsign,
|
||||
unsigned char *sm2id, size_t sm2idlen)
|
||||
{
|
||||
X509_REQ *req = NULL;
|
||||
BIO *in = NULL;
|
||||
@@ -1300,6 +1339,25 @@ static int certify(X509 **xret, const char *infile, EVP_PKEY *pkey, X509 *x509,
|
||||
BIO_printf(bio_err, "error unpacking public key\n");
|
||||
goto end;
|
||||
}
|
||||
if (sm2id != NULL) {
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
ASN1_OCTET_STRING *v;
|
||||
|
||||
v = ASN1_OCTET_STRING_new();
|
||||
if (v == NULL) {
|
||||
BIO_printf(bio_err, "error: SM2 ID allocation failed\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!ASN1_OCTET_STRING_set(v, sm2id, sm2idlen)) {
|
||||
BIO_printf(bio_err, "error: setting SM2 ID failed\n");
|
||||
ASN1_OCTET_STRING_free(v);
|
||||
goto end;
|
||||
}
|
||||
|
||||
X509_REQ_set0_sm2_id(req, v);
|
||||
#endif
|
||||
}
|
||||
i = X509_REQ_verify(req, pktmp);
|
||||
pktmp = NULL;
|
||||
if (i < 0) {
|
||||
|
||||
@@ -603,6 +603,14 @@ int cms_main(int argc, char **argv)
|
||||
goto opthelp;
|
||||
}
|
||||
|
||||
if (flags & CMS_CADES) {
|
||||
if (flags & CMS_NOATTR) {
|
||||
BIO_puts(bio_err, "Incompatible options: "
|
||||
"CAdES required signed attributes\n");
|
||||
goto opthelp;
|
||||
}
|
||||
}
|
||||
|
||||
if (operation & SMIME_SIGNERS) {
|
||||
if (keyfile != NULL && signerfile == NULL) {
|
||||
BIO_puts(bio_err, "Illegal -inkey without -signer\n");
|
||||
|
||||
+2
-1
@@ -317,7 +317,8 @@ int opt_int(const char *arg, int *result);
|
||||
int opt_ulong(const char *arg, unsigned long *result);
|
||||
int opt_long(const char *arg, long *result);
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
|
||||
defined(INTMAX_MAX) && defined(UINTMAX_MAX)
|
||||
defined(INTMAX_MAX) && defined(UINTMAX_MAX) && \
|
||||
!defined(OPENSSL_NO_INTTYPES_H)
|
||||
int opt_imax(const char *arg, intmax_t *result);
|
||||
int opt_umax(const char *arg, uintmax_t *result);
|
||||
#else
|
||||
|
||||
+15
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 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
|
||||
@@ -130,11 +130,8 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
|
||||
{
|
||||
int ret = 0;
|
||||
tracedata *trace_data = vdata;
|
||||
union {
|
||||
CRYPTO_THREAD_ID tid;
|
||||
unsigned long ltid;
|
||||
} tid;
|
||||
char buffer[256];
|
||||
char buffer[256], *hex;
|
||||
CRYPTO_THREAD_ID tid;
|
||||
|
||||
switch (cmd) {
|
||||
case OSSL_TRACE_CTRL_BEGIN:
|
||||
@@ -142,11 +139,11 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
|
||||
return 0;
|
||||
trace_data->ingroup = 1;
|
||||
|
||||
tid.ltid = 0;
|
||||
tid.tid = CRYPTO_THREAD_get_current_id();
|
||||
|
||||
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%lx]:%s: ", tid.ltid,
|
||||
OSSL_trace_get_category_name(category));
|
||||
tid = CRYPTO_THREAD_get_current_id();
|
||||
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
||||
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
|
||||
hex, OSSL_trace_get_category_name(category));
|
||||
OPENSSL_free(hex);
|
||||
BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX,
|
||||
strlen(buffer), buffer);
|
||||
break;
|
||||
@@ -216,6 +213,13 @@ static void setup_trace(const char *str)
|
||||
{
|
||||
char *val;
|
||||
|
||||
/*
|
||||
* We add this handler as early as possible to ensure it's executed
|
||||
* as late as possible, i.e. after the TRACE code has done its cleanup
|
||||
* (which happens last in OPENSSL_cleanup).
|
||||
*/
|
||||
atexit(cleanup_trace);
|
||||
|
||||
trace_data_stack = sk_tracedata_new_null();
|
||||
val = OPENSSL_strdup(str);
|
||||
|
||||
@@ -240,7 +244,6 @@ static void setup_trace(const char *str)
|
||||
}
|
||||
|
||||
OPENSSL_free(val);
|
||||
atexit(cleanup_trace);
|
||||
}
|
||||
#endif /* OPENSSL_NO_TRACE */
|
||||
|
||||
|
||||
+3
-2
@@ -15,7 +15,7 @@
|
||||
#include "internal/nelem.h"
|
||||
#include <string.h>
|
||||
#if !defined(OPENSSL_SYS_MSDOS)
|
||||
# include OPENSSL_UNISTD
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -377,7 +377,8 @@ int opt_long(const char *value, long *result)
|
||||
}
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
|
||||
defined(INTMAX_MAX) && defined(UINTMAX_MAX)
|
||||
defined(INTMAX_MAX) && defined(UINTMAX_MAX) && \
|
||||
!defined(OPENSSL_NO_INTTYPES_H)
|
||||
|
||||
/* Parse an intmax_t, put it into *result; return 0 on failure, else 1. */
|
||||
int opt_imax(const char *value, intmax_t *result)
|
||||
|
||||
+1
-1
@@ -838,7 +838,7 @@ static int alg_print(const X509_ALGOR *alg)
|
||||
goto done;
|
||||
}
|
||||
BIO_printf(bio_err, ", Salt length: %d, Cost(N): %ld, "
|
||||
"Block size(r): %ld, Paralelizm(p): %ld",
|
||||
"Block size(r): %ld, Parallelism(p): %ld",
|
||||
ASN1_STRING_length(kdf->salt),
|
||||
ASN1_INTEGER_get(kdf->costParameter),
|
||||
ASN1_INTEGER_get(kdf->blockSize),
|
||||
|
||||
+155
-8
@@ -90,7 +90,7 @@ typedef enum OPTION_choice {
|
||||
OPT_VERIFY, OPT_NODES, OPT_NOOUT, OPT_VERBOSE, OPT_UTF8,
|
||||
OPT_NAMEOPT, OPT_REQOPT, OPT_SUBJ, OPT_SUBJECT, OPT_TEXT, OPT_X509,
|
||||
OPT_MULTIVALUE_RDN, OPT_DAYS, OPT_SET_SERIAL, OPT_ADDEXT, OPT_EXTENSIONS,
|
||||
OPT_REQEXTS, OPT_PRECERT, OPT_MD,
|
||||
OPT_REQEXTS, OPT_PRECERT, OPT_MD, OPT_SM2ID, OPT_SM2HEXID,
|
||||
OPT_R_ENUM
|
||||
} OPTION_CHOICE;
|
||||
|
||||
@@ -145,6 +145,12 @@ const OPTIONS req_options[] = {
|
||||
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
||||
{"keygen_engine", OPT_KEYGEN_ENGINE, 's',
|
||||
"Specify engine to be used for key generation operations"},
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
{"sm2-id", OPT_SM2ID, 's',
|
||||
"Specify an ID string to verify an SM2 certificate request"},
|
||||
{"sm2-hex-id", OPT_SM2HEXID, 's',
|
||||
"Specify a hex ID string to verify an SM2 certificate request"},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
@@ -239,6 +245,9 @@ int req_main(int argc, char **argv)
|
||||
int nodes = 0, newhdr = 0, subject = 0, pubkey = 0, precert = 0;
|
||||
long newkey = -1;
|
||||
unsigned long chtype = MBSTRING_ASC, reqflag = 0;
|
||||
unsigned char *sm2_id = NULL;
|
||||
size_t sm2_idlen = 0;
|
||||
int sm2_free = 0;
|
||||
|
||||
#ifndef OPENSSL_NO_DES
|
||||
cipher = EVP_des_ede3_cbc();
|
||||
@@ -414,6 +423,29 @@ int req_main(int argc, char **argv)
|
||||
goto opthelp;
|
||||
digest = md_alg;
|
||||
break;
|
||||
case OPT_SM2ID:
|
||||
if (sm2_id != NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Use one of the options 'sm2-hex-id' or 'sm2-id'\n");
|
||||
goto end;
|
||||
}
|
||||
sm2_id = (unsigned char *)opt_arg();
|
||||
sm2_idlen = strlen((const char *)sm2_id);
|
||||
break;
|
||||
case OPT_SM2HEXID:
|
||||
if (sm2_id != NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Use one of the options 'sm2-hex-id' or 'sm2-id'\n");
|
||||
goto end;
|
||||
}
|
||||
/* try to parse the input as hex string first */
|
||||
sm2_free = 1;
|
||||
sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||
if (sm2_id == NULL) {
|
||||
BIO_printf(bio_err, "Invalid hex string input\n");
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc = opt_num_rest();
|
||||
@@ -844,6 +876,26 @@ int req_main(int argc, char **argv)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (sm2_id != NULL) {
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
ASN1_OCTET_STRING *v;
|
||||
|
||||
v = ASN1_OCTET_STRING_new();
|
||||
if (v == NULL) {
|
||||
BIO_printf(bio_err, "error: SM2 ID allocation failed\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!ASN1_OCTET_STRING_set(v, sm2_id, sm2_idlen)) {
|
||||
BIO_printf(bio_err, "error: setting SM2 ID failed\n");
|
||||
ASN1_OCTET_STRING_free(v);
|
||||
goto end;
|
||||
}
|
||||
|
||||
X509_REQ_set0_sm2_id(req, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
i = X509_REQ_verify(req, tpubkey);
|
||||
|
||||
if (i < 0) {
|
||||
@@ -881,9 +933,19 @@ int req_main(int argc, char **argv)
|
||||
|
||||
if (text) {
|
||||
if (x509)
|
||||
X509_print_ex(out, x509ss, get_nameopt(), reqflag);
|
||||
ret = X509_print_ex(out, x509ss, get_nameopt(), reqflag);
|
||||
else
|
||||
X509_REQ_print_ex(out, req, get_nameopt(), reqflag);
|
||||
ret = X509_REQ_print_ex(out, req, get_nameopt(), reqflag);
|
||||
|
||||
if (ret == 0) {
|
||||
if (x509)
|
||||
BIO_printf(bio_err, "Error printing certificate\n");
|
||||
else
|
||||
BIO_printf(bio_err, "Error printing certificate request\n");
|
||||
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if (subject) {
|
||||
@@ -942,6 +1004,8 @@ int req_main(int argc, char **argv)
|
||||
}
|
||||
ret = 0;
|
||||
end:
|
||||
if (sm2_free)
|
||||
OPENSSL_free(sm2_id);
|
||||
if (ret) {
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
@@ -1596,14 +1660,58 @@ static int genpkey_cb(EVP_PKEY_CTX *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
static int ec_pkey_is_sm2(EVP_PKEY *pkey)
|
||||
{
|
||||
EC_KEY *eckey = NULL;
|
||||
const EC_GROUP *group = NULL;
|
||||
|
||||
if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)
|
||||
return 1;
|
||||
if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
|
||||
&& (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
|
||||
&& (group = EC_KEY_get0_group(eckey)) != NULL
|
||||
&& EC_GROUP_get_curve_name(group) == NID_sm2)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int do_sign_init(EVP_MD_CTX *ctx, EVP_PKEY *pkey,
|
||||
const EVP_MD *md, STACK_OF(OPENSSL_STRING) *sigopts)
|
||||
{
|
||||
EVP_PKEY_CTX *pkctx = NULL;
|
||||
int i, def_nid;
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
#endif
|
||||
int i, def_nid, ret = 0;
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
goto err;
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (ec_pkey_is_sm2(pkey)) {
|
||||
/* initialize some SM2-specific code */
|
||||
if (!EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2)) {
|
||||
BIO_printf(bio_err, "Internal error.\n");
|
||||
goto err;
|
||||
}
|
||||
pctx = EVP_PKEY_CTX_new(pkey, NULL);
|
||||
if (pctx == NULL) {
|
||||
BIO_printf(bio_err, "memory allocation failure.\n");
|
||||
goto err;
|
||||
}
|
||||
/* set SM2 ID from sig options before calling the real init routine */
|
||||
for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {
|
||||
char *sigopt = sk_OPENSSL_STRING_value(sigopts, i);
|
||||
if (pkey_ctrl_string(pctx, sigopt) <= 0) {
|
||||
BIO_printf(bio_err, "parameter error \"%s\"\n", sigopt);
|
||||
ERR_print_errors(bio_err);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
EVP_MD_CTX_set_pkey_ctx(ctx, pctx);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* EVP_PKEY_get_default_digest_nid() returns 2 if the digest is mandatory
|
||||
* for this algorithm.
|
||||
@@ -1614,16 +1722,23 @@ static int do_sign_init(EVP_MD_CTX *ctx, EVP_PKEY *pkey,
|
||||
md = NULL;
|
||||
}
|
||||
if (!EVP_DigestSignInit(ctx, &pkctx, md, NULL, pkey))
|
||||
return 0;
|
||||
goto err;
|
||||
for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {
|
||||
char *sigopt = sk_OPENSSL_STRING_value(sigopts, i);
|
||||
if (pkey_ctrl_string(pkctx, sigopt) <= 0) {
|
||||
BIO_printf(bio_err, "parameter error \"%s\"\n", sigopt);
|
||||
ERR_print_errors(bio_err);
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (!ret)
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
@@ -1631,10 +1746,20 @@ int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
{
|
||||
int rv;
|
||||
EVP_MD_CTX *mctx = EVP_MD_CTX_new();
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
#endif
|
||||
|
||||
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||
if (rv > 0)
|
||||
rv = X509_sign_ctx(x, mctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
/* only in SM2 case we need to free the pctx explicitly */
|
||||
if (ec_pkey_is_sm2(pkey)) {
|
||||
pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
}
|
||||
#endif
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv > 0 ? 1 : 0;
|
||||
}
|
||||
@@ -1644,9 +1769,20 @@ int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
{
|
||||
int rv;
|
||||
EVP_MD_CTX *mctx = EVP_MD_CTX_new();
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
#endif
|
||||
|
||||
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||
if (rv > 0)
|
||||
rv = X509_REQ_sign_ctx(x, mctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
/* only in SM2 case we need to free the pctx explicitly */
|
||||
if (ec_pkey_is_sm2(pkey)) {
|
||||
pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
}
|
||||
#endif
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv > 0 ? 1 : 0;
|
||||
}
|
||||
@@ -1656,9 +1792,20 @@ int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
{
|
||||
int rv;
|
||||
EVP_MD_CTX *mctx = EVP_MD_CTX_new();
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
#endif
|
||||
|
||||
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||
if (rv > 0)
|
||||
rv = X509_CRL_sign_ctx(x, mctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
/* only in SM2 case we need to free the pctx explicitly */
|
||||
if (ec_pkey_is_sm2(pkey)) {
|
||||
pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
}
|
||||
#endif
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv > 0 ? 1 : 0;
|
||||
}
|
||||
+1
-1
@@ -2395,7 +2395,7 @@ int s_client_main(int argc, char **argv)
|
||||
(void)BIO_flush(fbio);
|
||||
/*
|
||||
* The first line is the HTTP response. According to RFC 7230,
|
||||
* it's formated exactly like this:
|
||||
* it's formatted exactly like this:
|
||||
*
|
||||
* HTTP/d.d ddd Reason text\r\n
|
||||
*/
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <internal/sockets.h>
|
||||
#if !defined(OPENSSL_SYS_MSDOS)
|
||||
# include OPENSSL_UNISTD
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define SSL_CONNECT_NAME "localhost:4433"
|
||||
|
||||
+6
-3
@@ -29,7 +29,7 @@
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/async.h>
|
||||
#if !defined(OPENSSL_SYS_MSDOS)
|
||||
# include OPENSSL_UNISTD
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -1876,7 +1876,7 @@ int speed_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
buflen = lengths[size_num - 1];
|
||||
if (buflen < 36) /* size of random vector in RSA bencmark */
|
||||
if (buflen < 36) /* size of random vector in RSA benchmark */
|
||||
buflen = 36;
|
||||
buflen += MAX_MISALIGNMENT + 1;
|
||||
loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
|
||||
@@ -1985,7 +1985,10 @@ int speed_main(int argc, char **argv)
|
||||
RC2_set_key(&rc2_ks, 16, key16, 128);
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RC5
|
||||
RC5_32_set_key(&rc5_ks, 16, key16, 12);
|
||||
if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
|
||||
BIO_printf(bio_err, "Failed setting RC5 key\n");
|
||||
goto end;
|
||||
}
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_BF
|
||||
BF_set_key(&bf_ks, 16, key16);
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ int storeutl_main(int argc, char *argv[])
|
||||
}
|
||||
/*
|
||||
* If expected wasn't set at this point, it means the map
|
||||
* isn't syncronised with the possible options leading here.
|
||||
* isn't synchronised with the possible options leading here.
|
||||
*/
|
||||
OPENSSL_assert(expected != 0);
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ static TS_REQ *create_query(BIO *data_bio, const char *digest, const EVP_MD *md,
|
||||
ASN1_OBJECT *policy_obj = NULL;
|
||||
ASN1_INTEGER *nonce_asn1 = NULL;
|
||||
|
||||
if (md == NULL && (md = EVP_get_digestbyname("sha1")) == NULL)
|
||||
if (md == NULL && (md = EVP_get_digestbyname("sha256")) == NULL)
|
||||
goto err;
|
||||
if ((ts_req = TS_REQ_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
+10
-1
@@ -169,11 +169,20 @@ int verify_main(int argc, char **argv)
|
||||
v_verbose = 1;
|
||||
break;
|
||||
case OPT_SM2ID:
|
||||
/* we assume the input is not a hex string */
|
||||
if (sm2_id != NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Use one of the options 'sm2-hex-id' or 'sm2-id' \n");
|
||||
goto end;
|
||||
}
|
||||
sm2_id = (unsigned char *)opt_arg();
|
||||
sm2_idlen = strlen((const char *)sm2_id);
|
||||
break;
|
||||
case OPT_SM2HEXID:
|
||||
if (sm2_id != NULL) {
|
||||
BIO_printf(bio_err,
|
||||
"Use one of the options 'sm2-hex-id' or 'sm2-id' \n");
|
||||
goto end;
|
||||
}
|
||||
/* try to parse the input as hex string first */
|
||||
sm2_free = 1;
|
||||
sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||
|
||||
Reference in New Issue
Block a user