Latest update.

This commit is contained in:
2020-01-17 19:45:12 +09:00
parent 016df9f433
commit 0f7abb4eb6
1100 changed files with 47785 additions and 16292 deletions
-3
View File
@@ -3,8 +3,6 @@
# This is mostly being used for generation of certificate requests.
#
RANDFILE = ./.rnd
####################################################################
[ req ]
default_bits = 2048
@@ -43,7 +41,6 @@ certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/cakey.pem# The private key
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = v3_ca # The extensions to add to the cert
-2
View File
@@ -4,8 +4,6 @@
#
# hacked by iang to do DH certs - CA
RANDFILE = ./.rnd
####################################################################
[ req ]
distinguished_name = req_distinguished_name
-2
View File
@@ -4,8 +4,6 @@
#
# hacked by iang to do DSA certs - CA
RANDFILE = ./.rnd
####################################################################
[ req ]
distinguished_name = req_distinguished_name
-2
View File
@@ -4,8 +4,6 @@
#
# create RSA certs - CA
RANDFILE = ./.rnd
####################################################################
[ req ]
distinguished_name = req_distinguished_name
-3
View File
@@ -3,8 +3,6 @@
# This config is used by the Time Stamp Authority tests.
#
RANDFILE = ./.rnd
# Extra OBJECT IDENTIFIER info:
oid_section = new_oids
@@ -32,7 +30,6 @@ new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
private_key = $dir/private/cakey.pem# The private key
RANDFILE = $dir/private/.rand # private random number file
default_days = 365 # how long to certify for
default_md = sha256 # which md to use.
-2
View File
@@ -3,8 +3,6 @@
# This is mostly being used for generation of certificate requests.
#
RANDFILE = ./.rnd
####################################################################
[ req ]
default_bits = 2048
-2
View File
@@ -3,8 +3,6 @@
# This is mostly being used for generation of certificate requests.
#
RANDFILE = ./.rnd
####################################################################
[ req ]
default_bits = 2048
+4 -1
View File
@@ -27,7 +27,10 @@ The number {nn} is (somewhat loosely) grouped as follows:
20-24 openssl commands (some otherwise not tested)
25-29 certificate forms, generation and verification
30-35 engine and evp
60-79 APIs
60-79 APIs:
60 X509 subsystem
61 BIO subsystem
65 CMP subsystem
70 PACKET layer
80-89 "larger" protocols (CA, CMS, OCSP, SSL, TSA)
90-98 misc
-2
View File
@@ -4,8 +4,6 @@
#
# hacked by iang to do DSA certs - Server
RANDFILE = ./.rnd
####################################################################
[ req ]
distinguished_name = req_distinguished_name
-2
View File
@@ -4,8 +4,6 @@
#
# create RSA certs - Server
RANDFILE = ./.rnd
####################################################################
[ req ]
distinguished_name = req_distinguished_name
-1
View File
@@ -3,7 +3,6 @@
# This is mostly being used for generation of certificate requests.
#
RANDFILE = ./.rnd
CN2 = Brother 2
####################################################################
+2 -2
View File
@@ -28,7 +28,7 @@ static unsigned char t_invalid_zero[] = {
0x02, 0x00 /* INTEGER tag + length */
};
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
/* LONG case ************************************************************* */
typedef struct {
@@ -162,7 +162,7 @@ static int test_uint64(void)
int setup_tests(void)
{
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
ADD_TEST(test_long);
#endif
ADD_TEST(test_int32);
+3 -3
View File
@@ -179,7 +179,7 @@ typedef struct {
ENCDEC_DATA(-1, -1), \
ENCDEC_DATA(0, ASN1_LONG_UNDEF)
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
/***** LONG ******************************************************************/
typedef struct {
@@ -824,7 +824,7 @@ static int test_intern(const TEST_PACKAGE *package)
return fail == 0;
}
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
static int test_long_32bit(void)
{
return test_intern(&long_test_package_32bit);
@@ -858,7 +858,7 @@ static int test_uint64(void)
int setup_tests(void)
{
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
ADD_TEST(test_long_32bit);
ADD_TEST(test_long_64bit);
#endif
+60
View File
@@ -320,6 +320,65 @@ static int test_table_compare(int idx)
return TEST_int_eq(ASN1_TIME_compare(&td->t1, &td->t2), td->result);
}
static int test_time_dup(void)
{
int ret = 0;
ASN1_TIME *asn1_time = NULL;
ASN1_TIME *asn1_time_dup = NULL;
ASN1_TIME *asn1_gentime = NULL;
asn1_time = ASN1_TIME_adj(NULL, time(NULL), 0, 0);
if (asn1_time == NULL) {
TEST_info("Internal error.");
goto err;
}
asn1_gentime = ASN1_TIME_to_generalizedtime(asn1_time, NULL);
if (asn1_gentime == NULL) {
TEST_info("Internal error.");
goto err;
}
asn1_time_dup = ASN1_TIME_dup(asn1_time);
if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
TEST_info("ASN1_TIME_dup() failed.");
goto err;
}
if (!TEST_int_eq(ASN1_TIME_compare(asn1_time, asn1_time_dup), 0)) {
TEST_info("ASN1_TIME_dup() duplicated non-identical value.");
goto err;
}
ASN1_STRING_free(asn1_time_dup);
asn1_time_dup = ASN1_UTCTIME_dup(asn1_time);
if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
TEST_info("ASN1_UTCTIME_dup() failed.");
goto err;
}
if (!TEST_int_eq(ASN1_TIME_compare(asn1_time, asn1_time_dup), 0)) {
TEST_info("ASN1_UTCTIME_dup() duplicated non-identical UTCTIME value.");
goto err;
}
ASN1_STRING_free(asn1_time_dup);
asn1_time_dup = ASN1_GENERALIZEDTIME_dup(asn1_gentime);
if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
TEST_info("ASN1_GENERALIZEDTIME_dup() failed.");
goto err;
}
if (!TEST_int_eq(ASN1_TIME_compare(asn1_gentime, asn1_time_dup), 0)) {
TEST_info("ASN1_GENERALIZEDTIME_dup() dup'ed non-identical value.");
goto err;
}
ret = 1;
err:
ASN1_STRING_free(asn1_time);
ASN1_STRING_free(asn1_gentime);
ASN1_STRING_free(asn1_time_dup);
return ret;
}
int setup_tests(void)
{
/*
@@ -354,5 +413,6 @@ int setup_tests(void)
#endif
}
ADD_ALL_TESTS(test_table_compare, OSSL_NELEM(tbl_compare_testdata));
ADD_TEST(test_time_dup);
return 1;
}
+1 -4
View File
@@ -312,10 +312,7 @@ int main(int argc, char **argv)
fprintf(stderr,
"OpenSSL build is not ASYNC capable - skipping async tests\n");
} else {
CRYPTO_set_mem_debug(1);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
if ( !test_ASYNC_init_thread()
if (!test_ASYNC_init_thread()
|| !test_ASYNC_callback_status()
|| !test_ASYNC_start_job()
|| !test_ASYNC_get_current_job()
+3 -2
View File
@@ -8,9 +8,10 @@
*/
/*
* This has been a quickly hacked 'ideatest.c'. When I add tests for other
* RC2 modes, more of the code will be uncommented.
* BF low level APIs are deprecated for public use, but still ok for internal
* use.
*/
#include "internal/deprecated.h"
#include <stdio.h>
#include <string.h>
-7
View File
@@ -221,13 +221,6 @@ finish:
return ok;
}
int global_init(void)
{
CRYPTO_set_mem_debug(1);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
return 1;
}
int setup_tests(void)
{
ADD_TEST(test_bio_memleak);
+267
View File
@@ -0,0 +1,267 @@
/*
* Copyright 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <stdarg.h>
#include <openssl/bio.h>
#include <openssl/safestack.h>
#include "opt.h"
static BIO *bio_in = NULL;
static BIO *bio_out = NULL;
static BIO *bio_err = NULL;
/*-
* This program sets up a chain of BIO_f_filter() on top of bio_out, how
* many is governed by the user through -n. It allows the user to set the
* indentation for each individual filter using -i and -p. Then it reads
* text from bio_in and prints it out through the BIO chain.
*
* The filter index is counted from the source/sink, i.e. index 0 is closest
* to it.
*
* Example:
*
* $ echo foo | ./bio_prefix_text -n 2 -i 1:32 -p 1:FOO -i 0:3
* FOO foo
* ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* | |
* | +------ 32 spaces from filter 1
* +-------------------------- 3 spaces from filter 0
*/
static size_t amount = 0;
static BIO **chain = NULL;
typedef enum OPTION_choice {
OPT_ERR = -1,
OPT_EOF = 0,
OPT_AMOUNT,
OPT_INDENT,
OPT_PREFIX
} OPTION_CHOICE;
static const OPTIONS options[] = {
{ "n", OPT_AMOUNT, 'p', "Amount of BIO_f_prefix() filters" },
/*
* idx is the index to the BIO_f_filter chain(), where 0 is closest
* to the source/sink BIO. If idx isn't given, 0 is assumed
*/
{ "i", OPT_INDENT, 's', "Indentation in form '[idx:]indent'" },
{ "p", OPT_PREFIX, 's', "Prefix in form '[idx:]prefix'" },
{ NULL }
};
int opt_printf_stderr(const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = BIO_vprintf(bio_err, fmt, ap);
va_end(ap);
return ret;
}
static int run_pipe(void)
{
char buf[4096];
while (!BIO_eof(bio_in)) {
size_t bytes_in;
size_t bytes_out;
if (!BIO_read_ex(bio_in, buf, sizeof(buf), &bytes_in))
return 0;
bytes_out = 0;
while (bytes_out < bytes_in) {
size_t bytes;
if (!BIO_write_ex(chain[amount - 1], buf, bytes_in, &bytes))
return 0;
bytes_out += bytes;
}
}
return 1;
}
static int setup_bio_chain(const char *progname)
{
BIO *next = NULL;
size_t n = amount;
chain = OPENSSL_zalloc(sizeof(*chain) * n);
if (chain != NULL) {
size_t i;
next = bio_out;
BIO_up_ref(next); /* Protection against freeing */
for (i = 0; n > 0; i++, n--) {
BIO *curr = BIO_new(BIO_f_prefix());
if (curr == NULL)
goto err;
chain[i] = BIO_push(curr, next);
if (chain[i] == NULL)
goto err;
next = chain[i];
}
}
return chain != NULL;
err:
/* Free the chain we built up */
BIO_free_all(next);
OPENSSL_free(chain);
return 0;
}
static void cleanup(void)
{
if (chain != NULL) {
BIO_free_all(chain[amount - 1]);
OPENSSL_free(chain);
}
BIO_free_all(bio_in);
BIO_free_all(bio_out);
BIO_free_all(bio_err);
}
static int setup(void)
{
OPTION_CHOICE o;
char *arg;
char *colon;
char *endptr;
size_t idx, indent;
const char *progname = opt_getprog();
bio_in = BIO_new_fp(stdin, BIO_NOCLOSE | BIO_FP_TEXT);
bio_out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
#ifdef __VMS
bio_out = BIO_push(BIO_new(BIO_f_linebuffer()), bio_out);
bio_err = BIO_push(BIO_new(BIO_f_linebuffer()), bio_err);
#endif
OPENSSL_assert(bio_in != NULL);
OPENSSL_assert(bio_out != NULL);
OPENSSL_assert(bio_err != NULL);
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
case OPT_AMOUNT:
arg = opt_arg();
amount = strtoul(arg, &endptr, 10);
if (endptr[0] != '\0') {
BIO_printf(bio_err,
"%s: -n argument isn't a decimal number: %s",
progname, arg);
return 0;
}
if (amount < 1) {
BIO_printf(bio_err, "%s: must set up at least one filter",
progname);
return 0;
}
if (!setup_bio_chain(progname)) {
BIO_printf(bio_err, "%s: failed setting up filter chain",
progname);
return 0;
}
break;
case OPT_INDENT:
if (chain == NULL) {
BIO_printf(bio_err, "%s: -i given before -n", progname);
return 0;
}
arg = opt_arg();
colon = strchr(arg, ':');
idx = 0;
if (colon != NULL) {
idx = strtoul(arg, &endptr, 10);
if (endptr[0] != ':') {
BIO_printf(bio_err,
"%s: -i index isn't a decimal number: %s",
progname, arg);
return 0;
}
colon++;
} else {
colon = arg;
}
indent = strtoul(colon, &endptr, 10);
if (endptr[0] != '\0') {
BIO_printf(bio_err,
"%s: -i value isn't a decimal number: %s",
progname, arg);
return 0;
}
if (idx >= amount) {
BIO_printf(bio_err, "%s: index (%zu) not within range 0..%zu",
progname, idx, amount - 1);
return 0;
}
if (!BIO_set_indent(chain[idx], (long)indent)) {
BIO_printf(bio_err, "%s: failed setting indentation: %s",
progname, arg);
return 0;
}
break;
case OPT_PREFIX:
if (chain == NULL) {
BIO_printf(bio_err, "%s: -p given before -n", progname);
return 0;
}
arg = opt_arg();
colon = strchr(arg, ':');
idx = 0;
if (colon != NULL) {
idx = strtoul(arg, &endptr, 10);
if (endptr[0] != ':') {
BIO_printf(bio_err,
"%s: -p index isn't a decimal number: %s",
progname, arg);
return 0;
}
colon++;
} else {
colon = arg;
}
if (idx >= amount) {
BIO_printf(bio_err, "%s: index (%zu) not within range 0..%zu",
progname, idx, amount - 1);
return 0;
}
if (!BIO_set_prefix(chain[idx], colon)) {
BIO_printf(bio_err, "%s: failed setting prefix: %s",
progname, arg);
return 0;
}
break;
default:
case OPT_ERR:
return 0;
}
}
return 1;
}
int main(int argc, char **argv)
{
int rv = EXIT_SUCCESS;
opt_init(argc, argv, options);
rv = (setup() && run_pipe()) ? EXIT_SUCCESS : EXIT_FAILURE;
cleanup();
return rv;
}
+285 -1
View File
@@ -2054,7 +2054,7 @@ static int test_rand_range(void)
n_success += test_rand_range_single(i);
if (TEST_int_ge(n_success, binomial_critical))
return 1;
TEST_note("This test is expeced to fail by chance 0.01%% of the time.");
TEST_note("This test is expected to fail by chance 0.01%% of the time.");
return 0;
}
@@ -2484,6 +2484,288 @@ static int test_gcd_prime(void)
return st;
}
typedef struct mod_exp_test_st
{
const char *base;
const char *exp;
const char *mod;
const char *res;
} MOD_EXP_TEST;
static const MOD_EXP_TEST ModExpTests[] = {
/* original test vectors for rsaz_512_sqr bug, by OSS-Fuzz */
{
"1166180238001879113042182292626169621106255558914000595999312084"
"4627946820899490684928760491249738643524880720584249698100907201"
"002086675047927600340800371",
"8000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"
"00000000",
"1340780792684523720980737645613191762604395855615117867483316354"
"3294276330515137663421134775482798690129946803802212663956180562"
"088664022929883876655300863",
"8243904058268085430037326628480645845409758077568738532059032482"
"8294114415890603594730158120426756266457928475330450251339773498"
"26758407619521544102068438"
},
{
"4974270041410803822078866696159586946995877618987010219312844726"
"0284386121835740784990869050050504348861513337232530490826340663"
"197278031692737429054",
"4974270041410803822078866696159586946995877428188754995041148539"
"1663243362592271353668158565195557417149981094324650322556843202"
"946445882670777892608",
"1340780716511420227215592830971452482815377482627251725537099028"
"4429769497230131760206012644403029349547320953206103351725462999"
"947509743623340557059752191",
"5296244594780707015616522701706118082963369547253192207884519362"
"1767869984947542695665420219028522815539559194793619684334900442"
"49304558011362360473525933"
},
/* test vectors for rsaz_512_srq bug, with rcx/rbx=1 */
{ /* between first and second iteration */
"5148719036160389201525610950887605325980251964889646556085286545"
"3931548809178823413169359635978762036512397113080988070677858033"
"36463909753993540214027190",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between second and third iteration */
"8908340854353752577419678771330460827942371434853054158622636544"
"8151360109722890949471912566649465436296659601091730745087014189"
"2672764191218875181826063",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between third and fourth iteration */
"3427446396505596330634350984901719674479522569002785244080234738"
"4288743635435746136297299366444548736533053717416735379073185344"
"26985272974404612945608761",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between fourth and fifth iteration */
"3472743044917564564078857826111874560045331237315597383869652985"
"6919870028890895988478351133601517365908445058405433832718206902"
"4088133164805266956353542",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between fifth and sixth iteration */
"3608632990153469264412378349742339216742409743898601587274768025"
"0110772032985643555192767717344946174122842255204082586753499651"
"14483434992887431333675068",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between sixth and seventh iteration */
"8455374370234070242910508226941981520235709767260723212165264877"
"8689064388017521524568434328264431772644802567028663962962025746"
"9283458217850119569539086",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between seventh and eighth iteration */
"5155371529688532178421209781159131443543419764974688878527112131"
"7446518205609427412336183157918981038066636807317733319323257603"
"04416292040754017461076359",
"1005585594745694782468051874865438459560952436544429503329267108"
"2791323022555160232601405723625177570767523893639864538140315412"
"108959927459825236754563832",
"1005585594745694782468051874865438459560952436544429503329267108"
"2791323022555160232601405723625177570767523893639864538140315412"
"108959927459825236754563833",
"1"
},
/* test vectors for rsaz_512_srq bug, with rcx/rbx=2 */
{ /* between first and second iteration */
"3155666506033786929967309937640790361084670559125912405342594979"
"4345142818528956285490897841406338022378565972533508820577760065"
"58494345853302083699912572",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between second and third iteration */
"3789819583801342198190405714582958759005991915505282362397087750"
"4213544724644823098843135685133927198668818185338794377239590049"
"41019388529192775771488319",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between third and forth iteration */
"4695752552040706867080542538786056470322165281761525158189220280"
"4025547447667484759200742764246905647644662050122968912279199065"
"48065034299166336940507214",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between forth and fifth iteration */
"2159140240970485794188159431017382878636879856244045329971239574"
"8919691133560661162828034323196457386059819832804593989740268964"
"74502911811812651475927076",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between fifth and sixth iteration */
"5239312332984325668414624633307915097111691815000872662334695514"
"5436533521392362443557163429336808208137221322444780490437871903"
"99972784701334569424519255",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between sixth and seventh iteration */
"1977953647322612860406858017869125467496941904523063466791308891"
"1172796739058531929470539758361774569875505293428856181093904091"
"33788264851714311303725089",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042158",
"6703903964971298549787012499102923063739682910296196688861780721"
"8608820150367734884009371490834517138450159290932430254268769414"
"05973284973216824503042159",
"1"
},
{ /* between seventh and eighth iteration */
"6456987954117763835533395796948878140715006860263624787492985786"
"8514630216966738305923915688821526449499763719943997120302368211"
"04813318117996225041943964",
"1340780792994259709957402499820584612747936582059239337772356144"
"3721764030073546976801874298166903427690031858186486050853753882"
"811946551499689575296532556",
"1340780792994259709957402499820584612747936582059239337772356144"
"3721764030073546976801874298166903427690031858186486050853753882"
"811946551499689575296532557",
"1"
}
};
static int test_mod_exp(int i)
{
const MOD_EXP_TEST *test = &ModExpTests[i];
int res = 0;
BIGNUM* result = NULL;
BIGNUM *base = NULL, *exponent = NULL, *modulo = NULL;
char *s = NULL;
if (!TEST_ptr(result = BN_new())
|| !TEST_true(BN_dec2bn(&base, test->base))
|| !TEST_true(BN_dec2bn(&exponent, test->exp))
|| !TEST_true(BN_dec2bn(&modulo, test->mod)))
goto err;
if (!TEST_int_eq(BN_mod_exp(result, base, exponent, modulo, ctx), 1))
goto err;
if (!TEST_ptr(s = BN_bn2dec(result)))
goto err;
if (!TEST_mem_eq(s, strlen(s), test->res, strlen(test->res)))
goto err;
res = 1;
err:
OPENSSL_free(s);
BN_free(result);
BN_free(base);
BN_free(exponent);
BN_free(modulo);
return res;
}
static int test_mod_exp_consttime(int i)
{
const MOD_EXP_TEST *test = &ModExpTests[i];
int res = 0;
BIGNUM* result = NULL;
BIGNUM *base = NULL, *exponent = NULL, *modulo = NULL;
char *s = NULL;
if (!TEST_ptr(result = BN_new())
|| !TEST_true(BN_dec2bn(&base, test->base))
|| !TEST_true(BN_dec2bn(&exponent, test->exp))
|| !TEST_true(BN_dec2bn(&modulo, test->mod)))
goto err;
BN_set_flags(base, BN_FLG_CONSTTIME);
BN_set_flags(exponent, BN_FLG_CONSTTIME);
BN_set_flags(modulo, BN_FLG_CONSTTIME);
if (!TEST_int_eq(BN_mod_exp(result, base, exponent, modulo, ctx), 1))
goto err;
if (!TEST_ptr(s = BN_bn2dec(result)))
goto err;
if (!TEST_mem_eq(s, strlen(s), test->res, strlen(test->res)))
goto err;
res = 1;
err:
OPENSSL_free(s);
BN_free(result);
BN_free(base);
BN_free(exponent);
BN_free(modulo);
return res;
}
static int file_test_run(STANZA *s)
{
static const FILETEST filetests[] = {
@@ -2621,6 +2903,8 @@ int setup_tests(void)
ADD_ALL_TESTS(test_is_prime, (int)OSSL_NELEM(primes));
ADD_ALL_TESTS(test_not_prime, (int)OSSL_NELEM(not_primes));
ADD_TEST(test_gcd_prime);
ADD_ALL_TESTS(test_mod_exp, (int)OSSL_NELEM(ModExpTests));
ADD_ALL_TESTS(test_mod_exp_consttime, (int)OSSL_NELEM(ModExpTests));
if (stochastic)
ADD_TEST(test_rand_range);
} else {
+92 -51
View File
@@ -6,7 +6,7 @@ SUBDIRS=ossl_shim
# Most of all, ../apps/lib/apps.c needs to be divided in smaller pieces to
# be useful here.
#
# Auxilliary program source (copied from ../apps/build.info)
# Auxiliary program source (copied from ../apps/build.info)
IF[{- $config{target} =~ /^(?:VC-|mingw)/ -}]
# It's called 'init', but doesn't have much 'init' in it...
$AUXLIBAPPSSRC=../apps/lib/win32_init.c
@@ -14,31 +14,32 @@ ENDIF
IF[{- $config{target} =~ /^vms-/ -}]
$AUXLIBAPPSSRC=../apps/lib/vms_term_sock.c ../apps/lib/vms_decc_argv.c
ENDIF
$LIBAPPSSRC=../apps/lib/opt.c ../apps/lib/bf_prefix.c $AUXLIBAPPSSRC
$LIBAPPSSRC=../apps/lib/opt.c $AUXLIBAPPSSRC
IF[{- !$disabled{tests} -}]
LIBS{noinst,has_main}=libtestutil.a
SOURCE[libtestutil.a]=testutil/basic_output.c testutil/output_helpers.c \
testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \
testutil/format_output.c testutil/tap_bio.c \
testutil/test_cleanup.c testutil/main.c testutil/init.c \
testutil/test_cleanup.c testutil/main.c testutil/testutil_init.c \
testutil/options.c testutil/test_options.c \
testutil/apps_mem.c testutil/random.c $LIBAPPSSRC
INCLUDE[libtestutil.a]=../include ../apps/include ..
DEPEND[libtestutil.a]=../libcrypto
PROGRAMS{noinst}=\
confdump \
versions \
aborttest test_test \
sanitytest rsa_complex exdatatest bntest \
ectest ecstresstest ecdsatest gmdifftest pbelutest ideatest \
md2test \
hmactest \
rc2test rc4test rc5test \
destest mdc2test \
dhtest enginetest casttest \
bftest ssltest_old dsatest dsa_no_digest_size_test exptest rsa_test \
evp_test evp_extra_test evp_fetch_prov_test igetest v3nametest v3ext \
dhtest enginetest \
ssltest_old dsatest dsa_no_digest_size_test exptest rsa_test \
evp_pkey_provided_test evp_test evp_extra_test evp_fetch_prov_test \
v3nametest v3ext \
crltest danetest bad_dtls_test lhash_test sparse_array_test \
conf_include_test params_api_test params_conversion_test \
constant_time_test verify_extra_test clienthellotest \
@@ -55,8 +56,13 @@ IF[{- !$disabled{tests} -}]
recordlentest drbgtest drbg_cavs_test sslbuffertest \
time_offset_test pemtest ssl_cert_table_internal_test ciphername_test \
servername_test ocspapitest rsa_mp_test fatalerrtest tls13ccstest \
sysdefaulttest errtest gosttest \
context_internal_test aesgcmtest params_test evp_pkey_dparams_test
sysdefaulttest errtest ssl_ctx_test gosttest \
context_internal_test aesgcmtest params_test evp_pkey_dparams_test \
keymgmt_internal_test
SOURCE[confdump]=confdump.c
INCLUDE[confdump]=../include ../apps/include
DEPEND[confdump]=../libcrypto
SOURCE[versions]=versions.c
INCLUDE[versions]=../include ../apps/include
@@ -109,26 +115,10 @@ IF[{- !$disabled{tests} -}]
INCLUDE[ideatest]=../include ../apps/include
DEPEND[ideatest]=../libcrypto libtestutil.a
SOURCE[md2test]=md2test.c
INCLUDE[md2test]=../include ../apps/include
DEPEND[md2test]=../libcrypto libtestutil.a
SOURCE[hmactest]=hmactest.c
INCLUDE[hmactest]=../include ../apps/include
DEPEND[hmactest]=../libcrypto libtestutil.a
SOURCE[rc2test]=rc2test.c
INCLUDE[rc2test]=../include ../apps/include
DEPEND[rc2test]=../libcrypto libtestutil.a
SOURCE[rc4test]=rc4test.c
INCLUDE[rc4test]=../include ../apps/include
DEPEND[rc4test]=../libcrypto libtestutil.a
SOURCE[rc5test]=rc5test.c
INCLUDE[rc5test]=../include ../apps/include
DEPEND[rc5test]=../libcrypto libtestutil.a
SOURCE[destest]=destest.c
INCLUDE[destest]=../include ../apps/include
DEPEND[destest]=../libcrypto libtestutil.a
@@ -145,14 +135,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[enginetest]=../include ../apps/include
DEPEND[enginetest]=../libcrypto libtestutil.a
SOURCE[casttest]=casttest.c
INCLUDE[casttest]=../include ../apps/include
DEPEND[casttest]=../libcrypto libtestutil.a
SOURCE[bftest]=bftest.c
INCLUDE[bftest]=../include ../apps/include
DEPEND[bftest]=../libcrypto libtestutil.a
SOURCE[ssltest_old]=ssltest_old.c
INCLUDE[ssltest_old]=.. ../include ../apps/include
DEPEND[ssltest_old]=../libcrypto ../libssl
@@ -175,7 +157,7 @@ IF[{- !$disabled{tests} -}]
SOURCE[rsa_mp_test]=rsa_mp_test.c
INCLUDE[rsa_mp_test]=../include ../apps/include
DEPEND[rsa_mp_test]=../libcrypto libtestutil.a
DEPEND[rsa_mp_test]=../libcrypto.a libtestutil.a
SOURCE[fatalerrtest]=fatalerrtest.c ssltestlib.c
INCLUDE[fatalerrtest]=../include ../apps/include
@@ -203,9 +185,26 @@ IF[{- !$disabled{tests} -}]
DEFINE[evp_extra_test]=NO_FIPS_MODULE
ENDIF
SOURCE[igetest]=igetest.c
INCLUDE[igetest]=../include ../apps/include
DEPEND[igetest]=../libcrypto libtestutil.a
SOURCE[evp_pkey_provided_test]=evp_pkey_provided_test.c
INCLUDE[evp_pkey_provided_test]=../include ../apps/include
DEPEND[evp_pkey_provided_test]=../libcrypto libtestutil.a
IF[{- !$disabled{"deprecated"}
|| (defined $config{"api"} && $config{"api"} < 30000) -}]
PROGRAMS{noinst}=igetest bftest casttest
SOURCE[igetest]=igetest.c
INCLUDE[igetest]=../include ../apps/include
DEPEND[igetest]=../libcrypto libtestutil.a
SOURCE[bftest]=bftest.c
INCLUDE[bftest]=../include ../apps/include
DEPEND[bftest]=../libcrypto libtestutil.a
SOURCE[casttest]=casttest.c
INCLUDE[casttest]=../include ../apps/include
DEPEND[casttest]=../libcrypto libtestutil.a
ENDIF
SOURCE[v3nametest]=v3nametest.c
INCLUDE[v3nametest]=../include ../apps/include
@@ -434,12 +433,12 @@ IF[{- !$disabled{tests} -}]
INCLUDE[shlibloadtest]=../include ../apps/include ../crypto/include
ENDIF
IF[{- $disabled{shared} -}]
PROGRAMS{noinst}=cipher_overhead_test
SOURCE[cipher_overhead_test]=cipher_overhead_test.c
INCLUDE[cipher_overhead_test]=.. ../include ../apps/include
DEPEND[cipher_overhead_test]=../libcrypto ../libssl libtestutil.a
ENDIF
# cipher_overhead_test uses internal symbols, so it must be linked with
# the static libraries
PROGRAMS{noinst}=cipher_overhead_test
SOURCE[cipher_overhead_test]=cipher_overhead_test.c
INCLUDE[cipher_overhead_test]=.. ../include ../apps/include
DEPEND[cipher_overhead_test]=../libcrypto.a ../libssl.a libtestutil.a
SOURCE[uitest]=uitest.c ../apps/lib/apps_ui.c
INCLUDE[uitest]=.. ../include ../apps/include
@@ -470,7 +469,8 @@ IF[{- !$disabled{tests} -}]
DEPEND[conf_include_test]=../libcrypto libtestutil.a
IF[{- !$disabled{cmp} -}]
PROGRAMS{noinst}=cmp_asn_test cmp_ctx_test
PROGRAMS{noinst}=cmp_asn_test cmp_ctx_test cmp_status_test cmp_hdr_test \
cmp_protect_test cmp_msg_test
ENDIF
SOURCE[cmp_asn_test]=cmp_asn_test.c cmp_testlib.c
@@ -481,6 +481,22 @@ IF[{- !$disabled{tests} -}]
INCLUDE[cmp_ctx_test]=.. ../include ../apps/include
DEPEND[cmp_ctx_test]=../libcrypto.a libtestutil.a
SOURCE[cmp_hdr_test]=cmp_hdr_test.c cmp_testlib.c
INCLUDE[cmp_hdr_test]=.. ../include ../apps/include
DEPEND[cmp_hdr_test]=../libcrypto.a libtestutil.a
SOURCE[cmp_status_test]=cmp_status_test.c cmp_testlib.c
INCLUDE[cmp_status_test]=.. ../include ../apps/include
DEPEND[cmp_status_test]=../libcrypto.a libtestutil.a
SOURCE[cmp_protect_test]=cmp_protect_test.c cmp_testlib.c
INCLUDE[cmp_protect_test]=.. ../include ../apps/include
DEPEND[cmp_protect_test]=../libcrypto.a libtestutil.a
SOURCE[cmp_msg_test]=cmp_msg_test.c cmp_testlib.c
INCLUDE[cmp_msg_test]=.. ../include ../apps/include
DEPEND[cmp_msg_test]=../libcrypto.a libtestutil.a
# Internal test programs. These are essentially a collection of internal
# test routines. Some of them need to reach internal symbols that aren't
# available through the shared library (at least on Linux, Solaris, Windows
@@ -565,6 +581,18 @@ IF[{- !$disabled{tests} -}]
INCLUDE[sm4_internal_test]=.. ../include ../apps/include ../crypto/include
DEPEND[sm4_internal_test]=../libcrypto.a libtestutil.a
SOURCE[rc2test]=rc2test.c
INCLUDE[rc2test]=../include ../apps/include
DEPEND[rc2test]=../libcrypto.a libtestutil.a
SOURCE[rc4test]=rc4test.c
INCLUDE[rc4test]=../include ../apps/include
DEPEND[rc4test]=../libcrypto.a libtestutil.a
SOURCE[rc5test]=rc5test.c
INCLUDE[rc5test]=../include ../apps/include
DEPEND[rc5test]=../libcrypto.a libtestutil.a
SOURCE[ec_internal_test]=ec_internal_test.c
INCLUDE[ec_internal_test]=../include ../crypto/ec ../apps/include ../crypto/include
DEPEND[ec_internal_test]=../libcrypto.a libtestutil.a
@@ -588,15 +616,19 @@ IF[{- !$disabled{tests} -}]
SOURCE[asn1_dsa_internal_test]=asn1_dsa_internal_test.c
INCLUDE[asn1_dsa_internal_test]=.. ../include ../apps/include ../crypto/include
DEPEND[asn1_dsa_internal_test]=../libcrypto.a libtestutil.a
ENDIF
IF[{- !$disabled{mdc2} -}]
PROGRAMS{noinst}=mdc2_internal_test
ENDIF
SOURCE[keymgmt_internal_test]=keymgmt_internal_test.c
INCLUDE[keymgmt_internal_test]=.. ../include ../apps/include
DEPEND[keymgmt_internal_test]=../libcrypto.a libtestutil.a
SOURCE[mdc2_internal_test]=mdc2_internal_test.c
INCLUDE[mdc2_internal_test]=.. ../include ../apps/include
DEPEND[mdc2_internal_test]=../libcrypto libtestutil.a
IF[{- !$disabled{mdc2} -}]
PROGRAMS{noinst}=mdc2_internal_test
ENDIF
SOURCE[mdc2_internal_test]=mdc2_internal_test.c
INCLUDE[mdc2_internal_test]=.. ../include ../apps/include
DEPEND[mdc2_internal_test]=../libcrypto.a libtestutil.a
ENDIF
PROGRAMS{noinst}=asn1_time_test
SOURCE[asn1_time_test]=asn1_time_test.c
@@ -674,8 +706,17 @@ IF[{- !$disabled{tests} -}]
SOURCE[namemap_internal_test]=namemap_internal_test.c
INCLUDE[namemap_internal_test]=.. ../include ../apps/include
DEPEND[namemap_internal_test]=../libcrypto.a libtestutil.a
PROGRAMS{noinst}=bio_prefix_text
SOURCE[bio_prefix_text]=bio_prefix_text.c $LIBAPPSSRC
INCLUDE[bio_prefix_text]=.. ../include ../apps/include
DEPEND[bio_prefix_text]=../libcrypto
ENDIF
SOURCE[ssl_ctx_test]=ssl_ctx_test.c
INCLUDE[ssl_ctx_test]=../include ../apps/include
DEPEND[ssl_ctx_test]=../libcrypto ../libssl libtestutil.a
{-
use File::Spec::Functions;
use File::Basename;
+6
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* CAST low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+7 -16
View File
@@ -24,21 +24,10 @@ typedef struct test_fixture {
static CMP_ASN_TEST_FIXTURE *set_up(const char *const test_case_name)
{
CMP_ASN_TEST_FIXTURE *fixture;
int setup_ok = 0;
/* Allocate memory owned by the fixture, exit on error */
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
goto err;
return NULL;
fixture->test_case_name = test_case_name;
setup_ok = 1;
err:
if (!setup_ok) {
#ifndef OPENSSL_NO_STDIO
ERR_print_errors_fp(stderr);
#endif
exit(EXIT_FAILURE);
}
return fixture;
}
@@ -51,8 +40,7 @@ static void tear_down(CMP_ASN_TEST_FIXTURE *fixture)
OPENSSL_free(fixture);
}
static int execute_cmp_asn1_get_int_test(CMP_ASN_TEST_FIXTURE *
fixture)
static int execute_cmp_asn1_get_int_test(CMP_ASN_TEST_FIXTURE *fixture)
{
ASN1_INTEGER *asn1integer = ASN1_INTEGER_new();
ASN1_INTEGER_set(asn1integer, 77);
@@ -121,12 +109,15 @@ void cleanup_tests(void)
int setup_tests(void)
{
RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
/* ASN.1 related tests */
ADD_TEST(test_cmp_asn1_get_int);
ADD_TEST(test_ASN1_OCTET_STRING_set);
ADD_TEST(test_ASN1_OCTET_STRING_set_tgt_is_src);
/* TODO make sure that total number of tests (here currently 24) is shown,
also for other cmp_*text.c. Currently the test drivers always show 1. */
/*
* TODO make sure that total number of tests (here currently 24) is shown,
* also for other cmp_*text.c. Currently the test drivers always show 1.
*/
return 1;
}
+66 -57
View File
@@ -29,8 +29,9 @@ static OSSL_CMP_CTX_TEST_FIXTURE *set_up(const char *const test_case_name)
{
OSSL_CMP_CTX_TEST_FIXTURE *fixture;
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))
|| !TEST_ptr(fixture->ctx = OSSL_CMP_CTX_new())) {
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
return NULL;
if (!TEST_ptr(fixture->ctx = OSSL_CMP_CTX_new())) {
tear_down(fixture);
return NULL;
}
@@ -38,7 +39,8 @@ static OSSL_CMP_CTX_TEST_FIXTURE *set_up(const char *const test_case_name)
return fixture;
}
static STACK_OF(X509) *sk_X509_new_1(void) {
static STACK_OF(X509) *sk_X509_new_1(void)
{
STACK_OF(X509) *sk = sk_X509_new_null();
X509 *x = X509_new();
@@ -50,7 +52,8 @@ static STACK_OF(X509) *sk_X509_new_1(void) {
return sk;
}
static void sk_X509_pop_X509_free(STACK_OF(X509) *sk) {
static void sk_X509_pop_X509_free(STACK_OF(X509) *sk)
{
sk_X509_pop_free(sk, X509_free);
}
@@ -74,7 +77,6 @@ static int execute_CTX_reinit_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
|| !OSSL_CMP_CTX_set1_transactionID(ctx, bytes)
|| !OSSL_CMP_CTX_set1_senderNonce(ctx, bytes)
|| !ossl_cmp_ctx_set1_recipNonce(ctx, bytes))
goto err;
if (!TEST_true(OSSL_CMP_CTX_reinit(ctx)))
@@ -334,7 +336,7 @@ static int execute_CTX_##SETN##_##GETN##_##FIELD( \
CMP_CTX *ctx = fixture->ctx; \
int (*set_fn)(CMP_CTX *ctx, TYPE) = \
(int (*)(CMP_CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
/* need type cast in above assignment because TYPE arg sometimes is const */ \
/* need type cast in above assignment because TYPE arg sometimes is const */ \
TYPE (*get_fn)(const CMP_CTX *ctx) = OSSL_CMP_CTX_##GETN##_##FIELD; \
TYPE val1_to_free = NEW; \
TYPE val1 = val1_to_free; \
@@ -466,17 +468,20 @@ static int test_CTX_##SETN##_##GETN##_##FIELD(void) \
return result; \
}
static char *char_new(void) {
static char *char_new(void)
{
return OPENSSL_strdup("test");
}
static void char_free(char *val) {
static void char_free(char *val)
{
OPENSSL_free(val);
}
#define EMPTY_SK_X509(x) ((x) == NULL || sk_X509_num(x) == 0)
static X509_STORE *X509_STORE_new_1(void) {
static X509_STORE *X509_STORE_new_1(void)
{
X509_STORE *store = X509_STORE_new();
if (store != NULL)
@@ -496,24 +501,24 @@ static X509_STORE *X509_STORE_new_1(void) {
#define DEFINE_SET_GET_TEST(OSSL_CMP, CTX, N, M, DUP, FIELD, TYPE) \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, DUP, FIELD, \
TYPE*, NULL, IS_0, TYPE##_new(), TYPE##_free)
TYPE*, NULL, IS_0, TYPE##_new(), TYPE##_free)
#define DEFINE_SET_GET_SK_TEST_DEFAULT(OSSL_CMP, CTX, N, M, FIELD, ELEM_TYPE, \
DEFAULT, NEW, FREE) \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, 1, FIELD, \
STACK_OF(ELEM_TYPE)*, NULL, DEFAULT, NEW, FREE)
STACK_OF(ELEM_TYPE)*, NULL, DEFAULT, NEW, FREE)
#define DEFINE_SET_GET_SK_TEST(OSSL_CMP, CTX, N, M, FIELD, T) \
DEFINE_SET_GET_SK_TEST_DEFAULT(OSSL_CMP, CTX, N, M, FIELD, T, \
IS_0, sk_##T##_new_null(), sk_##T##_free)
IS_0, sk_##T##_new_null(), sk_##T##_free)
#define DEFINE_SET_GET_SK_X509_TEST(OSSL_CMP, CTX, N, M, FNAME) \
DEFINE_SET_GET_SK_TEST_DEFAULT(OSSL_CMP, CTX, N, M, FNAME, X509, \
EMPTY_SK_X509, \
sk_X509_new_1(), sk_X509_pop_X509_free)
EMPTY_SK_X509, \
sk_X509_new_1(), sk_X509_pop_X509_free)
#define DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, N, M, DUP, FIELD, TYPE, \
DEFAULT) \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, DUP, FIELD, \
TYPE*, NULL, DEFAULT, TYPE##_new(), TYPE##_free)
TYPE*, NULL, DEFAULT, TYPE##_new(), TYPE##_free)
#define DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, N, DUP, FIELD, TYPE, DEFAULT) \
static TYPE *OSSL_CMP_CTX_get0_##FIELD(const CMP_CTX *ctx) \
{ \
@@ -529,27 +534,26 @@ static X509_STORE *X509_STORE_new_1(void) {
return ctx == NULL ? ERR(NULL) : ctx->FIELD; \
} \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get0, 1, FIELD, \
STACK_OF(TYPE)*, NULL, IS_0, \
sk_##TYPE##_new_null(), sk_##TYPE##_free)
STACK_OF(TYPE)*, NULL, IS_0, \
sk_##TYPE##_new_null(), sk_##TYPE##_free)
#define DEFINE_SET_CB_TEST(FIELD) \
static OSSL_cmp_##FIELD##_t \
OSSL_CMP_CTX_get_##FIELD(const CMP_CTX *ctx) \
static OSSL_cmp_##FIELD##_t OSSL_CMP_CTX_get_##FIELD(const CMP_CTX *ctx) \
{ \
if (ctx == NULL) \
CMPerr(0, CMP_R_NULL_ARGUMENT); \
return ctx == NULL ? NULL /* cannot use ERR(NULL) here */ : ctx->FIELD;\
} \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, FIELD, \
OSSL_cmp_##FIELD##_t, NULL, IS_0, \
test_##FIELD, DROP)
OSSL_cmp_##FIELD##_t, NULL, IS_0, \
test_##FIELD, DROP)
#define DEFINE_SET_GET_P_VOID_TEST(FIELD) \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, FIELD, void*, \
NULL, IS_0, ((void *)1), DROP)
NULL, IS_0, ((void *)1), DROP)
#define DEFINE_SET_GET_INT_TEST_DEFAULT(OSSL_CMP, CTX, FIELD, DEFAULT) \
DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set, get, 0, FIELD, int, -1, \
DEFAULT, 1, DROP)
DEFAULT, 1, DROP)
#define DEFINE_SET_GET_INT_TEST(OSSL_CMP, CTX, FIELD) \
DEFINE_SET_GET_INT_TEST_DEFAULT(OSSL_CMP, CTX, FIELD, IS_NEG)
#define DEFINE_SET_PORT_TEST(FIELD) \
@@ -589,8 +593,9 @@ static X509_STORE *X509_STORE_new_1(void) {
#define push0 0
#define push1 1
#define DEFINE_PUSH_BASE_TEST(PUSHN, DUP, FIELD, ELEM, TYPE, T, \
DEFAULT, NEW, FREE) \
static TYPE sk_top_##FIELD(const CMP_CTX *ctx) { \
DEFAULT, NEW, FREE) \
static TYPE sk_top_##FIELD(const CMP_CTX *ctx) \
{ \
return sk_##T##_value(ctx->FIELD, sk_##T##_num(ctx->FIELD) - 1); \
} \
\
@@ -599,7 +604,9 @@ static int execute_CTX_##PUSHN##_##ELEM(OSSL_CMP_CTX_TEST_FIXTURE *fixture) \
CMP_CTX *ctx = fixture->ctx; \
int (*push_fn)(CMP_CTX *ctx, TYPE) = \
(int (*)(CMP_CTX *ctx, TYPE))OSSL_CMP_CTX_##PUSHN##_##ELEM; \
/* need type cast in above assignment because TYPE arg sometimes is const */ \
/* \
* need type cast in above assignment because TYPE arg sometimes is const \
*/ \
int n_elem = sk_##T##_num(ctx->FIELD); \
STACK_OF(TYPE) field_read; \
TYPE val1_to_free = NEW; \
@@ -695,7 +702,7 @@ static int test_CTX_##PUSHN##_##ELEM(void) \
#define DEFINE_PUSH_TEST(N, DUP, FIELD, ELEM, TYPE) \
DEFINE_PUSH_BASE_TEST(push##N, DUP, FIELD, ELEM, TYPE*, TYPE, \
IS_0, TYPE##_new(), TYPE##_free)
IS_0, TYPE##_new(), TYPE##_free)
void cleanup_tests(void)
{
@@ -703,9 +710,9 @@ void cleanup_tests(void)
}
DEFINE_SET_GET_ARG_FN(set, get, option, 16, int)
/* option == OSSL_CMP_OPT_IGNORE_KEYUSAGE */
/* option == OSSL_CMP_OPT_IGNORE_KEYUSAGE */
DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, option_16, int, -1, IS_0, \
1 /* true */, DROP)
1 /* true */, DROP)
#ifndef OPENSSL_NO_TRACE
DEFINE_SET_CB_TEST(log_cb)
@@ -725,8 +732,8 @@ DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, srvCert, X509)
DEFINE_SET_TEST(ossl_cmp, ctx, 0, 0, validatedSrvCert, X509)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, expected_sender, X509_NAME)
DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set0, get0, 0, trustedStore,
X509_STORE*, NULL,
DEFAULT_STORE, X509_STORE_new_1(), X509_STORE_free)
X509_STORE*, NULL,
DEFAULT_STORE, X509_STORE_new_1(), X509_STORE_free)
DEFINE_SET_GET_SK_X509_TEST(OSSL_CMP, CTX, 1, 0, untrusted_certs)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, clCert, X509)
@@ -740,11 +747,10 @@ DEFINE_SET_GET_TEST(OSSL_CMP, CTX, 0, 0, 0, newPkey_1, EVP_PKEY)
DEFINE_SET_GET_ARG_FN(set0, get0, newPkey, 0, EVP_PKEY*) /* priv == 0 */
DEFINE_SET_GET_TEST(OSSL_CMP, CTX, 0, 0, 0, newPkey_0, EVP_PKEY)
DEFINE_SET_GET1_STR_FN(set1, referenceValue)
DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, 1, referenceValue_str,
char, IS_0)
DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, 1, referenceValue_str, char,
IS_0)
DEFINE_SET_GET1_STR_FN(set1, secretValue)
DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, 1, secretValue_str,
char, IS_0)
DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, 1, secretValue_str, char, IS_0)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, issuer, X509_NAME)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, subjectName, X509_NAME)
#ifdef ISSUE_9504_RESOLVED
@@ -767,8 +773,8 @@ DEFINE_SET_GET_TEST(ossl_cmp, ctx, 0, 0, 0, newCert, X509)
DEFINE_SET_GET_SK_X509_TEST(ossl_cmp, ctx, 1, 1, caPubs)
DEFINE_SET_GET_SK_X509_TEST(ossl_cmp, ctx, 1, 1, extraCertsIn)
DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, transactionID,
ASN1_OCTET_STRING, IS_0)
DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, transactionID, ASN1_OCTET_STRING,
IS_0)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, senderNonce, ASN1_OCTET_STRING)
DEFINE_SET_TEST(ossl_cmp, ctx, 1, 1, recipNonce, ASN1_OCTET_STRING)
@@ -778,9 +784,9 @@ int setup_tests(void)
/* OSSL_CMP_CTX_free() is tested by tear_down() */
ADD_TEST(test_CTX_reinit);
/* various CMP options: */
/* various CMP options: */
ADD_TEST(test_CTX_set_get_option_16);
/* CMP-specific callback for logging and outputting the error queue: */
/* CMP-specific callback for logging and outputting the error queue: */
#ifndef OPENSSL_NO_TRACE
ADD_TEST(test_CTX_set_get_log_cb);
#endif
@@ -792,13 +798,14 @@ int setup_tests(void)
*/
ADD_TEST(test_cmp_ctx_log_cb);
#if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT)
/* also tests OSSL_CMP_CTX_set_log_cb(), OSSL_CMP_print_errors_cb(),
ossl_cmp_add_error_txt(), and the macros
ossl_cmp_add_error_data and ossl_cmp_add_error_line:
*/
/*
* also tests OSSL_CMP_CTX_set_log_cb(), OSSL_CMP_print_errors_cb(),
* ossl_cmp_add_error_txt(), and the macros
* ossl_cmp_add_error_data and ossl_cmp_add_error_line:
*/
ADD_TEST(test_CTX_print_errors);
#endif
/* message transfer: */
/* message transfer: */
ADD_TEST(test_CTX_set1_get0_serverPath);
ADD_TEST(test_CTX_set1_get0_serverName);
ADD_TEST(test_CTX_set_get_serverPort);
@@ -808,29 +815,31 @@ int setup_tests(void)
ADD_TEST(test_CTX_set_get_http_cb_arg);
ADD_TEST(test_CTX_set_get_transfer_cb);
ADD_TEST(test_CTX_set_get_transfer_cb_arg);
/* server authentication: */
/* server authentication: */
ADD_TEST(test_CTX_set1_get0_srvCert);
ADD_TEST(test_CTX_set0_get0_validatedSrvCert);
ADD_TEST(test_CTX_set1_get0_expected_sender);
ADD_TEST(test_CTX_set0_get0_trustedStore);
ADD_TEST(test_CTX_set1_get0_untrusted_certs);
/* client authentication: */
/* client authentication: */
ADD_TEST(test_CTX_set1_get0_clCert);
ADD_TEST(test_CTX_set1_get0_pkey);
/* the following two also test ossl_cmp_asn1_octet_string_set1_bytes(): */
ADD_TEST(test_CTX_set1_get1_referenceValue_str);
ADD_TEST(test_CTX_set1_get1_secretValue_str);
/* CMP message header and extra certificates: */
/* CMP message header and extra certificates: */
ADD_TEST(test_CTX_set1_get0_recipient);
ADD_TEST(test_CTX_push0_geninfo_ITAV);
ADD_TEST(test_CTX_set1_get0_extraCertsOut);
/* certificate template: */
/* certificate template: */
ADD_TEST(test_CTX_set0_get0_newPkey_1);
ADD_TEST(test_CTX_set0_get0_newPkey_0);
ADD_TEST(test_CTX_set1_get0_issuer);
ADD_TEST(test_CTX_set1_get0_subjectName);
#ifdef ISSUE_9504_RESOLVED
/* test currently fails, see https://github.com/openssl/openssl/issues/9504 */
/*
* test currently fails, see https://github.com/openssl/openssl/issues/9504
*/
ADD_TEST(test_CTX_push1_subjectAltName);
#endif
ADD_TEST(test_CTX_set0_get0_reqExtensions);
@@ -838,28 +847,28 @@ int setup_tests(void)
ADD_TEST(test_CTX_push0_policy);
ADD_TEST(test_CTX_set1_get0_oldCert);
#ifdef ISSUE_9504_RESOLVED
/* test currently fails, see https://github.com/openssl/openssl/issues/9504 */
/*
* test currently fails, see https://github.com/openssl/openssl/issues/9504
*/
ADD_TEST(test_CTX_set1_get0_p10CSR);
#endif
/* misc body contents: */
/* misc body contents: */
ADD_TEST(test_CTX_push0_genm_ITAV);
/* certificate confirmation: */
/* certificate confirmation: */
ADD_TEST(test_CTX_set_get_certConf_cb);
ADD_TEST(test_CTX_set_get_certConf_cb_arg);
/* result fetching: */
/* result fetching: */
ADD_TEST(test_CTX_set_get_status);
ADD_TEST(test_CTX_set0_get0_statusString);
ADD_TEST(test_CTX_set_get_failInfoCode);
ADD_TEST(test_CTX_set0_get0_newCert);
ADD_TEST(test_CTX_set1_get1_caPubs);
ADD_TEST(test_CTX_set1_get1_extraCertsIn);
/* exported for testing and debugging purposes: */
/* exported for testing and debugging purposes: */
/* the following three also test ossl_cmp_asn1_octet_string_set1(): */
ADD_TEST(test_CTX_set1_get0_transactionID);
ADD_TEST(test_CTX_set1_get0_senderNonce);
ADD_TEST(test_CTX_set1_get0_recipNonce);
/* TODO ossl_cmp_build_cert_chain() will be tested with cmp_protect.c*/
/* ossl_cmp_build_cert_chain() is tested in cmp_protect.c */
return 1;
}
+472
View File
@@ -0,0 +1,472 @@
/*
* Copyright 2007-2019 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 "cmp_testlib.h"
static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH];
typedef struct test_fixture {
const char *test_case_name;
int expected;
OSSL_CMP_CTX *cmp_ctx;
OSSL_CMP_PKIHEADER *hdr;
} CMP_HDR_TEST_FIXTURE;
static void tear_down(CMP_HDR_TEST_FIXTURE *fixture)
{
OSSL_CMP_PKIHEADER_free(fixture->hdr);
OSSL_CMP_CTX_free(fixture->cmp_ctx);
OPENSSL_free(fixture);
}
static CMP_HDR_TEST_FIXTURE *set_up(const char *const test_case_name)
{
CMP_HDR_TEST_FIXTURE *fixture;
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
return NULL;
fixture->test_case_name = test_case_name;
if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new()))
goto err;
if (!TEST_ptr(fixture->hdr = OSSL_CMP_PKIHEADER_new()))
goto err;
return fixture;
err:
tear_down(fixture);
return NULL;
}
static int execute_HDR_set_get_pvno_test(CMP_HDR_TEST_FIXTURE *fixture)
{
int pvno = 77;
if (!TEST_int_eq(ossl_cmp_hdr_set_pvno(fixture->hdr, pvno), 1))
return 0;
if (!TEST_int_eq(ossl_cmp_hdr_get_pvno(fixture->hdr), pvno))
return 0;
return 1;
}
static int test_HDR_set_get_pvno(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_set_get_pvno_test, tear_down);
return result;
}
#define X509_NAME_ADD(n, rd, s) X509_NAME_add_entry_by_txt((n), (rd), \
MBSTRING_ASC, (unsigned char *)(s), -1, -1, 0)
static int execute_HDR_get0_senderNonce_test(CMP_HDR_TEST_FIXTURE *fixture)
{
X509_NAME *sender = X509_NAME_new();
ASN1_OCTET_STRING *sn;
if (!TEST_ptr(sender))
return 0;
X509_NAME_ADD(sender, "CN", "A common sender name");
if (!TEST_int_eq(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx, sender),
1))
return 0;
if (!TEST_int_eq(ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr),
1))
return 0;
sn = ossl_cmp_hdr_get0_senderNonce(fixture->hdr);
if (!TEST_int_eq(ASN1_OCTET_STRING_cmp(fixture->cmp_ctx->senderNonce, sn),
0))
return 0;
X509_NAME_free(sender);
return 1;
}
static int test_HDR_get0_senderNonce(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_get0_senderNonce_test, tear_down);
return result;
}
static int execute_HDR_set1_sender_test(CMP_HDR_TEST_FIXTURE *fixture)
{
X509_NAME *x509name = X509_NAME_new();
if (!TEST_ptr(x509name))
return 0;
X509_NAME_ADD(x509name, "CN", "A common sender name");
if (!TEST_int_eq(ossl_cmp_hdr_set1_sender(fixture->hdr, x509name), 1))
return 0;
if (!TEST_int_eq(fixture->hdr->sender->type, GEN_DIRNAME))
return 0;
if (!TEST_int_eq(
X509_NAME_cmp(fixture->hdr->sender->d.directoryName, x509name), 0))
return 0;
X509_NAME_free(x509name);
return 1;
}
static int test_HDR_set1_sender(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_set1_sender_test, tear_down);
return result;
}
static int execute_HDR_set1_recipient_test(CMP_HDR_TEST_FIXTURE *fixture)
{
X509_NAME *x509name = X509_NAME_new();
if (!TEST_ptr(x509name))
return 0;
X509_NAME_ADD(x509name, "CN", "A common recipient name");
if (!TEST_int_eq(ossl_cmp_hdr_set1_recipient(fixture->hdr, x509name), 1))
return 0;
if (!TEST_int_eq(fixture->hdr->recipient->type, GEN_DIRNAME))
return 0;
if (!TEST_int_eq(
X509_NAME_cmp(fixture->hdr->recipient->d.directoryName, x509name),0))
return 0;
X509_NAME_free(x509name);
return 1;
}
static int test_HDR_set1_recipient(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_set1_recipient_test, tear_down);
return result;
}
static int execute_HDR_update_messageTime_test(CMP_HDR_TEST_FIXTURE *fixture)
{
struct tm hdrtm;
time_t hdrtime, before, after, now;
now = time(NULL);
before = mktime(gmtime(&now));
if (!TEST_true(ossl_cmp_hdr_update_messageTime(fixture->hdr)))
return 0;
if (!TEST_true(ASN1_TIME_to_tm(fixture->hdr->messageTime, &hdrtm)))
return 0;
hdrtime = mktime(&hdrtm);
if (!TEST_true(before <= hdrtime))
return 0;
now = time(NULL);
after = mktime(gmtime(&now));
return TEST_true(hdrtime <= after);
}
static int test_HDR_update_messageTime(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_update_messageTime_test, tear_down);
return result;
}
static int execute_HDR_set1_senderKID_test(CMP_HDR_TEST_FIXTURE *fixture)
{
ASN1_OCTET_STRING* senderKID = ASN1_OCTET_STRING_new();
if (!TEST_ptr(senderKID))
return 0;
if (!TEST_int_eq(ASN1_OCTET_STRING_set(senderKID, rand_data,
sizeof(rand_data)), 1))
return 0;
if (!TEST_int_eq(ossl_cmp_hdr_set1_senderKID(fixture->hdr, senderKID), 1))
return 0;
if (!TEST_int_eq(
ASN1_OCTET_STRING_cmp(fixture->hdr->senderKID, senderKID), 0))
return 0;
ASN1_OCTET_STRING_free(senderKID);
return 1;
}
static int test_HDR_set1_senderKID(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_set1_senderKID_test, tear_down);
return result;
}
static int execute_HDR_push0_freeText_test(CMP_HDR_TEST_FIXTURE *fixture)
{
ASN1_UTF8STRING* text = ASN1_UTF8STRING_new();
if (!TEST_ptr(text))
return 0;
if (!ASN1_STRING_set(text, "A free text", -1))
return 0;
if (!TEST_int_eq(
ossl_cmp_hdr_push0_freeText(fixture->hdr, text), 1))
return 0;
if (!TEST_true(text == sk_ASN1_UTF8STRING_value(
fixture->hdr->freeText, 0)))
return 0;
return 1;
}
static int test_HDR_push0_freeText(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_push0_freeText_test, tear_down);
return result;
}
static int execute_HDR_push1_freeText_test(CMP_HDR_TEST_FIXTURE *fixture)
{
ASN1_UTF8STRING* text = ASN1_UTF8STRING_new();
if (!TEST_ptr(text))
return 0;
if (!ASN1_STRING_set(text, "A free text", -1))
return 0;
if (!TEST_int_eq(
ossl_cmp_hdr_push1_freeText(fixture->hdr, text), 1))
return 0;
if (!TEST_int_eq(ASN1_STRING_cmp(
sk_ASN1_UTF8STRING_value(fixture->hdr->freeText, 0), text), 0))
return 0;
ASN1_UTF8STRING_free(text);
return 1;
}
static int test_HDR_push1_freeText(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_push1_freeText_test, tear_down);
return result;
}
static int
execute_HDR_generalInfo_push0_item_test(CMP_HDR_TEST_FIXTURE *fixture)
{
OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new();
if (!TEST_ptr(itav))
return 0;
if (!TEST_int_eq(
ossl_cmp_hdr_generalInfo_push0_item(fixture->hdr, itav), 1))
return 0;
if (!TEST_true(itav == sk_OSSL_CMP_ITAV_value(
fixture->hdr->generalInfo, 0)))
return 0;
return 1;
}
static int test_HDR_generalInfo_push0_item(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_generalInfo_push0_item_test, tear_down);
return result;
}
static int
execute_HDR_generalInfo_push1_items_test(CMP_HDR_TEST_FIXTURE *fixture)
{
const char oid[] = "1.2.3.4";
char buf[20];
OSSL_CMP_ITAV *itav;
STACK_OF(OSSL_CMP_ITAV) *itavs = NULL;
ASN1_INTEGER *asn1int = ASN1_INTEGER_new();
ASN1_TYPE *val = ASN1_TYPE_new();
if (!TEST_ptr(asn1int))
return 0;
if (!TEST_ptr(val))
return 0;
ASN1_INTEGER_set(asn1int, 88);
ASN1_TYPE_set(val, V_ASN1_INTEGER, asn1int);
itav = OSSL_CMP_ITAV_create(OBJ_txt2obj(oid, 1), val);
OSSL_CMP_ITAV_push0_stack_item(&itavs, itav);
if (!TEST_int_eq(
ossl_cmp_hdr_generalInfo_push1_items(fixture->hdr, itavs), 1))
return 0;
OBJ_obj2txt(buf, sizeof(buf), OSSL_CMP_ITAV_get0_type(
sk_OSSL_CMP_ITAV_value(fixture->hdr->generalInfo, 0)), 0);
if (!TEST_int_eq(memcmp(oid, buf, sizeof(oid)), 0))
return 0;
if (!TEST_int_eq(ASN1_TYPE_cmp(itav->infoValue.other,
OSSL_CMP_ITAV_get0_value(
sk_OSSL_CMP_ITAV_value(fixture->hdr->generalInfo, 0))), 0))
return 0;
sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free);
return 1;
}
static int test_HDR_generalInfo_push1_items(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_HDR_generalInfo_push1_items_test, tear_down);
return result;
}
static int
execute_HDR_set_and_check_implicitConfirm_test(CMP_HDR_TEST_FIXTURE
* fixture)
{
return TEST_false(ossl_cmp_hdr_check_implicitConfirm(fixture->hdr))
&& TEST_true(ossl_cmp_hdr_set_implicitConfirm(fixture->hdr))
&& TEST_true(ossl_cmp_hdr_check_implicitConfirm(fixture->hdr));
}
static int test_HDR_set_and_check_implicit_confirm(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
EXECUTE_TEST(execute_HDR_set_and_check_implicitConfirm_test, tear_down);
return result;
}
static int execute_HDR_init_test(CMP_HDR_TEST_FIXTURE *fixture)
{
ASN1_OCTET_STRING *header_nonce = NULL;
ASN1_OCTET_STRING *ctx_nonce = NULL;
int res = 0;
if (!TEST_int_eq(fixture->expected,
ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr)))
goto err;
if (fixture->expected != 0) {
if (!TEST_int_eq(ossl_cmp_hdr_get_pvno(fixture->hdr), OSSL_CMP_PVNO)
|| !TEST_true(0 == ASN1_OCTET_STRING_cmp(
ossl_cmp_hdr_get0_senderNonce(fixture->hdr),
fixture->cmp_ctx->senderNonce))
|| !TEST_true(0 == ASN1_OCTET_STRING_cmp(
OSSL_CMP_HDR_get0_transactionID(fixture->hdr),
fixture->cmp_ctx->transactionID)))
goto err;
header_nonce = OSSL_CMP_HDR_get0_recipNonce(fixture->hdr);
ctx_nonce = fixture->cmp_ctx->recipNonce;
if (ctx_nonce != NULL
&& (!TEST_ptr(header_nonce)
|| !TEST_int_eq(0, ASN1_OCTET_STRING_cmp(header_nonce,
ctx_nonce))))
goto err;
}
res = 1;
err:
return res;
}
static int test_HDR_init(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
unsigned char ref[CMP_TEST_REFVALUE_LENGTH];
fixture->expected = 1;
if (!TEST_int_eq(1, RAND_bytes(ref, sizeof(ref)))
|| !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
ref, sizeof(ref)))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_HDR_init_test, tear_down);
return result;
}
static int test_HDR_init_with_subject(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
X509_NAME *subject = NULL;
fixture->expected = 1;
if (!TEST_ptr(subject = X509_NAME_new())
|| !TEST_true(X509_NAME_ADD(subject, "CN", "Common Name"))
|| !TEST_true(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx,
subject))) {
tear_down(fixture);
fixture = NULL;
}
X509_NAME_free(subject);
EXECUTE_TEST(execute_HDR_init_test, tear_down);
return result;
}
static int test_HDR_init_no_ref_no_subject(void)
{
SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up);
fixture->expected = 0;
EXECUTE_TEST(execute_HDR_init_test, tear_down);
return result;
}
void cleanup_tests(void)
{
return;
}
int setup_tests(void)
{
RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
/* Message header tests */
ADD_TEST(test_HDR_set_get_pvno);
ADD_TEST(test_HDR_get0_senderNonce);
ADD_TEST(test_HDR_set1_sender);
ADD_TEST(test_HDR_set1_recipient);
ADD_TEST(test_HDR_update_messageTime);
ADD_TEST(test_HDR_set1_senderKID);
ADD_TEST(test_HDR_push0_freeText);
/* indirectly tests ossl_cmp_pkifreetext_push_str(): */
ADD_TEST(test_HDR_push1_freeText);
ADD_TEST(test_HDR_generalInfo_push0_item);
ADD_TEST(test_HDR_generalInfo_push1_items);
ADD_TEST(test_HDR_set_and_check_implicit_confirm);
/* also tests public function OSSL_CMP_HDR_get0_transactionID(): */
/* also tests public function OSSL_CMP_HDR_get0_recipNonce(): */
/* also tests internal function ossl_cmp_hdr_get_pvno(): */
ADD_TEST(test_HDR_init);
ADD_TEST(test_HDR_init_with_subject);
ADD_TEST(test_HDR_init_no_ref_no_subject);
/*
* TODO make sure that total number of tests (here currently 24) is shown,
* also for other cmp_*text.c. Currently the test drivers always show 1.
*/
return 1;
}
+577
View File
@@ -0,0 +1,577 @@
/*
* Copyright 2007-2019 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 "cmp_testlib.h"
static const char *server_cert_f;
static const char *pkcs10_f;
typedef struct test_fixture {
const char *test_case_name;
OSSL_CMP_CTX *cmp_ctx;
/* for msg create tests */
int bodytype;
int err_code;
/* for certConf */
int fail_info;
/* for protection tests */
OSSL_CMP_MSG *msg;
int expected;
/* for error and response messages */
OSSL_CMP_PKISI *si;
} CMP_MSG_TEST_FIXTURE;
static unsigned char ref[CMP_TEST_REFVALUE_LENGTH];
static void tear_down(CMP_MSG_TEST_FIXTURE *fixture)
{
OSSL_CMP_CTX_free(fixture->cmp_ctx);
OSSL_CMP_MSG_free(fixture->msg);
OSSL_CMP_PKISI_free(fixture->si);
OPENSSL_free(fixture);
}
#define SET_OPT_UNPROTECTED_SEND(ctx, val) \
OSSL_CMP_CTX_set_option((ctx), OSSL_CMP_OPT_UNPROTECTED_SEND, (val))
static CMP_MSG_TEST_FIXTURE *set_up(const char *const test_case_name)
{
CMP_MSG_TEST_FIXTURE *fixture;
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
return NULL;
fixture->test_case_name = test_case_name;
if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new())
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))
|| !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
ref, sizeof(ref)))) {
tear_down(fixture);
return NULL;
}
return fixture;
}
static EVP_PKEY *newkey = NULL;
static X509 *cert = NULL;
#define EXECUTE_MSG_CREATION_TEST(expr) \
do { \
OSSL_CMP_MSG *msg = NULL; \
int good = fixture->expected != 0 ? \
TEST_ptr(msg = (expr)) && TEST_true(valid_asn1_encoding(msg)) : \
TEST_ptr_null(msg = (expr)); \
\
OSSL_CMP_MSG_free(msg); \
return good; \
} while (0)
/*-
* The following tests call a cmp message creation function.
* if fixture->expected != 0:
* returns 1 if the message is created and syntactically correct.
* if fixture->expected == 0
* returns 1 if message creation returns NULL
*/
static int execute_certreq_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_certReq_new(fixture->cmp_ctx,
fixture->bodytype,
fixture->err_code));
}
static int execute_errormsg_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_error_new(fixture->cmp_ctx, fixture->si,
fixture->err_code,
NULL /* fixture->free_text */,
0));
}
static int execute_rr_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_rr_new(fixture->cmp_ctx));
}
static int execute_certconf_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_certConf_new
(fixture->cmp_ctx, fixture->fail_info, NULL));
}
static int execute_genm_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_genm_new(fixture->cmp_ctx));
}
static int execute_pollreq_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_pollReq_new(fixture->cmp_ctx, 4711));
}
static int execute_pkimessage_create_test(CMP_MSG_TEST_FIXTURE *fixture)
{
EXECUTE_MSG_CREATION_TEST(ossl_cmp_msg_create
(fixture->cmp_ctx, fixture->bodytype));
}
static int set1_newPkey(OSSL_CMP_CTX *ctx, EVP_PKEY* pkey)
{
if (!EVP_PKEY_up_ref(pkey))
return 0;
if (!OSSL_CMP_CTX_set0_newPkey(ctx, 1, pkey)) {
EVP_PKEY_free(pkey);
return 0;
}
return 1;
}
static int test_cmp_create_ir_protection_set(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
OSSL_CMP_CTX *ctx = fixture->cmp_ctx;
unsigned char secret[16];
fixture->bodytype = OSSL_CMP_PKIBODY_IR;
fixture->err_code = -1;
fixture->expected = 1;
if (!TEST_int_eq(1, RAND_bytes(secret, sizeof(secret)))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(ctx, 0))
|| !TEST_true(set1_newPkey(ctx, newkey))
|| !TEST_true(OSSL_CMP_CTX_set1_secretValue(ctx, secret,
sizeof(secret)))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_ir_protection_fails(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_IR;
fixture->err_code = -1;
fixture->expected = 0;
if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, newkey))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
|| !TEST_true(OSSL_CMP_CTX_set1_clCert(fixture->cmp_ctx, cert))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_cr_without_key(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_CR;
fixture->err_code = -1;
fixture->expected = 0;
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_cr(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_CR;
fixture->err_code = -1;
fixture->expected = 1;
if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_certreq_with_invalid_bodytype(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_RR;
fixture->err_code = -1;
fixture->expected = 0;
if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_p10cr(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
OSSL_CMP_CTX *ctx = fixture->cmp_ctx;
X509_REQ *p10cr = NULL;
fixture->bodytype = OSSL_CMP_PKIBODY_P10CR;
fixture->err_code = CMP_R_ERROR_CREATING_P10CR;
fixture->expected = 1;
if (!TEST_ptr(p10cr = load_csr(pkcs10_f))
|| !TEST_true(set1_newPkey(ctx, newkey))
|| !TEST_true(OSSL_CMP_CTX_set1_p10CSR(ctx, p10cr))) {
tear_down(fixture);
fixture = NULL;
}
X509_REQ_free(p10cr);
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_p10cr_null(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_P10CR;
fixture->err_code = CMP_R_ERROR_CREATING_P10CR;
fixture->expected = 0;
if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_kur(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_KUR;
fixture->err_code = -1;
fixture->expected = 1;
if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))
|| !TEST_true(OSSL_CMP_CTX_set1_oldCert(fixture->cmp_ctx, cert))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_kur_without_oldcert(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->bodytype = OSSL_CMP_PKIBODY_KUR;
fixture->err_code = -1;
fixture->expected = 0;
if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certreq_create_test, tear_down);
return result;
}
static int test_cmp_create_certconf(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->fail_info = 0;
fixture->expected = 1;
if (!TEST_true(ossl_cmp_ctx_set0_newCert(fixture->cmp_ctx,
X509_dup(cert)))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certconf_create_test, tear_down);
return result;
}
static int test_cmp_create_certconf_badAlg(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_badAlg;
fixture->expected = 1;
if (!TEST_true(ossl_cmp_ctx_set0_newCert(fixture->cmp_ctx,
X509_dup(cert)))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certconf_create_test, tear_down);
return result;
}
static int test_cmp_create_certconf_fail_info_max(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_MAX;
fixture->expected = 1;
if (!TEST_true(ossl_cmp_ctx_set0_newCert(fixture->cmp_ctx,
X509_dup(cert)))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_certconf_create_test, tear_down);
return result;
}
static int test_cmp_create_error_msg(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->si = ossl_cmp_statusinfo_new(OSSL_CMP_PKISTATUS_rejection,
OSSL_CMP_PKIFAILUREINFO_systemFailure,
NULL);
fixture->err_code = -1;
fixture->expected = 1; /* Expected: Message creation is successful */
if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_errormsg_create_test, tear_down);
return result;
}
static int test_cmp_create_pollreq(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->expected = 1;
EXECUTE_TEST(execute_pollreq_create_test, tear_down);
return result;
}
static int test_cmp_create_rr(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->expected = 1;
if (!TEST_true(OSSL_CMP_CTX_set1_oldCert(fixture->cmp_ctx, cert))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_rr_create_test, tear_down);
return result;
}
static int test_cmp_create_genm(void)
{
OSSL_CMP_ITAV *iv = NULL;
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
fixture->expected = 1;
iv = OSSL_CMP_ITAV_create(OBJ_nid2obj(NID_id_it_implicitConfirm), NULL);
if (!TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))
|| !TEST_ptr(iv)
|| !TEST_true(OSSL_CMP_CTX_push0_genm_ITAV(fixture->cmp_ctx, iv))) {
OSSL_CMP_ITAV_free(iv);
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_genm_create_test, tear_down);
return result;
}
static int execute_certrep_create(CMP_MSG_TEST_FIXTURE *fixture)
{
OSSL_CMP_CERTREPMESSAGE *crepmsg = OSSL_CMP_CERTREPMESSAGE_new();
OSSL_CMP_CERTRESPONSE *read_cresp, *cresp = OSSL_CMP_CERTRESPONSE_new();
EVP_PKEY *privkey;
X509 *certfromresp = NULL;
int res = 0;
if (crepmsg == NULL || cresp == NULL)
goto err;
if (!ASN1_INTEGER_set(cresp->certReqId, 99))
goto err;
if ((cresp->certifiedKeyPair = OSSL_CMP_CERTIFIEDKEYPAIR_new()) == NULL)
goto err;
cresp->certifiedKeyPair->certOrEncCert->type =
OSSL_CMP_CERTORENCCERT_CERTIFICATE;
if ((cresp->certifiedKeyPair->certOrEncCert->value.certificate =
X509_dup(cert)) == NULL
|| !sk_OSSL_CMP_CERTRESPONSE_push(crepmsg->response, cresp))
goto err;
cresp = NULL;
read_cresp = ossl_cmp_certrepmessage_get0_certresponse(crepmsg, 99);
if (!TEST_ptr(read_cresp))
goto err;
if (!TEST_ptr_null(ossl_cmp_certrepmessage_get0_certresponse(crepmsg, 88)))
goto err;
privkey = OSSL_CMP_CTX_get0_newPkey(fixture->cmp_ctx, 1); /* may be NULL */
certfromresp = ossl_cmp_certresponse_get1_certificate(privkey, read_cresp);
if (certfromresp == NULL || !TEST_int_eq(X509_cmp(cert, certfromresp), 0))
goto err;
res = 1;
err:
X509_free(certfromresp);
OSSL_CMP_CERTRESPONSE_free(cresp);
OSSL_CMP_CERTREPMESSAGE_free(crepmsg);
return res;
}
static int test_cmp_create_certrep(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
EXECUTE_TEST(execute_certrep_create, tear_down);
return result;
}
static int execute_rp_create(CMP_MSG_TEST_FIXTURE *fixture)
{
OSSL_CMP_PKISI *si = ossl_cmp_statusinfo_new(33, 44, "a text");
X509_NAME *issuer = X509_NAME_new();
ASN1_INTEGER *serial = ASN1_INTEGER_new();
OSSL_CRMF_CERTID *cid = NULL;
OSSL_CMP_MSG *rpmsg = NULL;
int res = 0;
if (si == NULL || issuer == NULL || serial == NULL)
goto err;
if (!X509_NAME_add_entry_by_txt(issuer, "CN", MBSTRING_ASC,
(unsigned char*)"The Issuer", -1, -1, 0)
|| !ASN1_INTEGER_set(serial, 99)
|| (cid = OSSL_CRMF_CERTID_gen(issuer, serial)) == NULL
|| (rpmsg = ossl_cmp_rp_new(fixture->cmp_ctx, si, cid, 1)) == NULL)
goto err;
if (!TEST_ptr(ossl_cmp_revrepcontent_get_CertId(rpmsg->body->value.rp, 0)))
goto err;
if (!TEST_ptr(ossl_cmp_revrepcontent_get_pkistatusinfo(rpmsg->body->value.rp,
0)))
goto err;
res = 1;
err:
ASN1_INTEGER_free(serial);
X509_NAME_free(issuer);
OSSL_CRMF_CERTID_free(cid);
OSSL_CMP_PKISI_free(si);
OSSL_CMP_MSG_free(rpmsg);
return res;
}
static int test_cmp_create_rp(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
EXECUTE_TEST(execute_rp_create, tear_down);
return result;
}
static int execute_pollrep_create(CMP_MSG_TEST_FIXTURE *fixture)
{
OSSL_CMP_MSG *pollrep;
int res = 0;
pollrep = ossl_cmp_pollRep_new(fixture->cmp_ctx, 77, 2000);
if (!TEST_ptr(pollrep))
return 0;
if (!TEST_ptr(ossl_cmp_pollrepcontent_get0_pollrep(
pollrep->body->value.pollRep, 77)))
goto err;
if (!TEST_ptr_null(ossl_cmp_pollrepcontent_get0_pollrep(
pollrep->body->value.pollRep, 88)))
goto err;
res = 1;
err:
OSSL_CMP_MSG_free(pollrep);
return res;
}
static int test_cmp_create_pollrep(void)
{
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
EXECUTE_TEST(execute_pollrep_create, tear_down);
return result;
}
static int test_cmp_pkimessage_create(int bodytype)
{
X509_REQ *p10cr = NULL;
SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up);
switch (fixture->bodytype = bodytype) {
case OSSL_CMP_PKIBODY_P10CR:
fixture->expected = 1;
if (!TEST_true(OSSL_CMP_CTX_set1_p10CSR(fixture->cmp_ctx,
p10cr = load_csr(pkcs10_f)))) {
tear_down(fixture);
fixture = NULL;
}
X509_REQ_free(p10cr);
break;
case OSSL_CMP_PKIBODY_IR:
case OSSL_CMP_PKIBODY_IP:
case OSSL_CMP_PKIBODY_CR:
case OSSL_CMP_PKIBODY_CP:
case OSSL_CMP_PKIBODY_KUR:
case OSSL_CMP_PKIBODY_KUP:
case OSSL_CMP_PKIBODY_RR:
case OSSL_CMP_PKIBODY_RP:
case OSSL_CMP_PKIBODY_PKICONF:
case OSSL_CMP_PKIBODY_GENM:
case OSSL_CMP_PKIBODY_GENP:
case OSSL_CMP_PKIBODY_ERROR:
case OSSL_CMP_PKIBODY_CERTCONF:
case OSSL_CMP_PKIBODY_POLLREQ:
case OSSL_CMP_PKIBODY_POLLREP:
fixture->expected = 1;
break;
default:
fixture->expected = 0;
break;
}
EXECUTE_TEST(execute_pkimessage_create_test, tear_down);
return result;
}
void cleanup_tests(void)
{
EVP_PKEY_free(newkey);
X509_free(cert);
}
int setup_tests(void)
{
if (!TEST_ptr(server_cert_f = test_get_argument(0))
|| !TEST_ptr(pkcs10_f = test_get_argument(1))) {
TEST_error("usage: cmp_msg_test server.crt pkcs10.der\n");
return 0;
}
if (!TEST_ptr(newkey = gen_rsa())
|| !TEST_ptr(cert = load_pem_cert(server_cert_f))
|| !TEST_int_eq(1, RAND_bytes(ref, sizeof(ref)))) {
cleanup_tests();
return 0;
}
/* Message creation tests */
ADD_TEST(test_cmp_create_certreq_with_invalid_bodytype);
ADD_TEST(test_cmp_create_ir_protection_fails);
ADD_TEST(test_cmp_create_ir_protection_set);
ADD_TEST(test_cmp_create_error_msg);
ADD_TEST(test_cmp_create_certconf);
ADD_TEST(test_cmp_create_certconf_badAlg);
ADD_TEST(test_cmp_create_certconf_fail_info_max);
ADD_TEST(test_cmp_create_kur);
ADD_TEST(test_cmp_create_kur_without_oldcert);
ADD_TEST(test_cmp_create_cr);
ADD_TEST(test_cmp_create_cr_without_key);
ADD_TEST(test_cmp_create_p10cr);
ADD_TEST(test_cmp_create_p10cr_null);
ADD_TEST(test_cmp_create_pollreq);
ADD_TEST(test_cmp_create_rr);
ADD_TEST(test_cmp_create_rp);
ADD_TEST(test_cmp_create_genm);
ADD_TEST(test_cmp_create_certrep);
ADD_TEST(test_cmp_create_pollrep);
ADD_ALL_TESTS_NOSUBTEST(test_cmp_pkimessage_create,
OSSL_CMP_PKIBODY_POLLREP + 1);
return 1;
}
+517
View File
@@ -0,0 +1,517 @@
/*
* Copyright 2007-2019 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 "cmp_testlib.h"
static const char *ir_protected_f;
static const char *ir_unprotected_f;
static const char *ip_PBM_f;
typedef struct test_fixture {
const char *test_case_name;
OSSL_CMP_CTX *cmp_ctx;
/* for protection tests */
OSSL_CMP_MSG *msg;
OSSL_CMP_PKISI *si; /* for error and response messages */
ASN1_OCTET_STRING *secret;
EVP_PKEY *privkey;
EVP_PKEY *pubkey;
unsigned char *mem;
int memlen;
X509 *cert;
STACK_OF(X509) *certs;
STACK_OF(X509) *chain;
int callback_arg;
int expected;
} CMP_PROTECT_TEST_FIXTURE;
static void tear_down(CMP_PROTECT_TEST_FIXTURE *fixture)
{
OSSL_CMP_CTX_free(fixture->cmp_ctx);
OSSL_CMP_MSG_free(fixture->msg);
ASN1_OCTET_STRING_free(fixture->secret);
OSSL_CMP_PKISI_free(fixture->si);
OPENSSL_free(fixture->mem);
sk_X509_free(fixture->certs);
sk_X509_free(fixture->chain);
OPENSSL_free(fixture);
}
static CMP_PROTECT_TEST_FIXTURE *set_up(const char *const test_case_name)
{
CMP_PROTECT_TEST_FIXTURE *fixture;
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
return NULL;
fixture->test_case_name = test_case_name;
if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new())) {
tear_down(fixture);
return NULL;
}
return fixture;
}
static EVP_PKEY *loadedprivkey = NULL;
static EVP_PKEY *loadedpubkey = NULL;
static EVP_PKEY *loadedkey = NULL;
static X509 *cert = NULL;
static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH];
static OSSL_CMP_MSG *ir_unprotected, *ir_protected;
static X509 *endentity1 = NULL, *endentity2 = NULL,
*root = NULL, *intermediate = NULL;
static int execute_calc_protection_fails_test(CMP_PROTECT_TEST_FIXTURE *fixture)
{
ASN1_BIT_STRING *protection =
ossl_cmp_calc_protection(fixture->msg, fixture->secret,
fixture->privkey);
int res = TEST_ptr_null(protection);
ASN1_BIT_STRING_free(protection);
return res;
}
static int execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE *fixture)
{
ASN1_BIT_STRING *protection =
ossl_cmp_calc_protection(fixture->msg, fixture->secret, NULL);
int res = TEST_ptr(protection)
&& TEST_true(ASN1_STRING_cmp(protection, fixture->msg->protection) == 0);
ASN1_BIT_STRING_free(protection);
return res;
}
/*
* This function works similarly to parts of CMP_verify_signature in cmp_vfy.c,
* but without the need for a OSSL_CMP_CTX or a X509 certificate
*/
static int verify_signature(OSSL_CMP_MSG *msg,
ASN1_BIT_STRING *protection,
EVP_PKEY *pkey, int digest_nid)
{
CMP_PROTECTEDPART prot_part;
unsigned char *prot_part_der = NULL;
int len;
EVP_MD_CTX *ctx = NULL;
const EVP_MD *digest = EVP_get_digestbynid(digest_nid);
int res;
prot_part.header = OSSL_CMP_MSG_get0_header(msg);
prot_part.body = msg->body;
res =
TEST_int_ge(len = i2d_CMP_PROTECTEDPART(&prot_part, &prot_part_der), 0)
&& TEST_ptr(ctx = EVP_MD_CTX_new())
&& TEST_true(EVP_DigestVerifyInit(ctx, NULL, digest, NULL, pkey))
&& TEST_int_eq(EVP_DigestVerify(ctx, protection->data,
protection->length,
prot_part_der, len), 1);
/* cleanup */
EVP_MD_CTX_free(ctx);
OPENSSL_free(prot_part_der);
return res;
}
/* Calls OSSL_CMP_calc_protection and compares and verifies signature */
static int execute_calc_protection_signature_test(CMP_PROTECT_TEST_FIXTURE *
fixture)
{
ASN1_BIT_STRING *protection =
ossl_cmp_calc_protection(fixture->msg, NULL, fixture->privkey);
int ret = (TEST_ptr(protection)
&& TEST_true(ASN1_STRING_cmp(protection,
fixture->msg->protection) == 0)
&& TEST_true(verify_signature(fixture->msg, protection,
fixture->pubkey,
fixture->cmp_ctx->digest)));
ASN1_BIT_STRING_free(protection);
return ret;
}
static int test_cmp_calc_protection_no_key_no_secret(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f))
|| !TEST_ptr(fixture->msg->header->protectionAlg =
X509_ALGOR_new() /* no specific alg needed here */)) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_calc_protection_fails_test, tear_down);
return result;
}
static int test_cmp_calc_protection_pkey(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->pubkey = loadedpubkey;
fixture->privkey = loadedprivkey;
if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_calc_protection_signature_test, tear_down);
return result;
}
static int test_cmp_calc_protection_pbmac(void)
{
unsigned char sec_insta[] = { 'i', 'n', 's', 't', 'a' };
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
if (!TEST_ptr(fixture->secret = ASN1_OCTET_STRING_new())
|| !TEST_true(ASN1_OCTET_STRING_set
(fixture->secret, sec_insta, sizeof(sec_insta)))
|| !TEST_ptr(fixture->msg = load_pkimsg(ip_PBM_f))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_calc_protection_pbmac_test, tear_down);
return result;
}
static int execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE *fixture)
{
return TEST_int_eq(fixture->expected,
ossl_cmp_msg_protect(fixture->cmp_ctx, fixture->msg));
}
#define SET_OPT_UNPROTECTED_SEND(ctx, val) \
OSSL_CMP_CTX_set_option((ctx), OSSL_CMP_OPT_UNPROTECTED_SEND, (val))
static int test_MSG_protect_unprotected_request(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->expected = 1;
if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_MSG_protect_test, tear_down);
return result;
}
static int test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key(void)
{
const size_t size = sizeof(rand_data) / 2;
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->expected = 1;
if (!TEST_ptr(fixture->msg =
OSSL_CMP_MSG_dup(ir_unprotected))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
/*
* Use half of the 16 bytes of random input
* for each reference and secret value
*/
|| !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
rand_data, size))
|| !TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
rand_data + size,
size))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_MSG_protect_test, tear_down);
return result;
}
static int test_MSG_protect_with_certificate_and_key(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->expected = 1;
if (!TEST_ptr(fixture->msg =
OSSL_CMP_MSG_dup(ir_unprotected))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
|| !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedkey))
|| !TEST_true(OSSL_CMP_CTX_set1_clCert(fixture->cmp_ctx, cert))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_MSG_protect_test, tear_down);
return result;
}
static int test_MSG_protect_certificate_based_without_cert(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
OSSL_CMP_CTX *ctx = fixture->cmp_ctx;
fixture->expected = 0;
if (!TEST_ptr(fixture->msg =
OSSL_CMP_MSG_dup(ir_unprotected))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(ctx, 0))
|| !TEST_true(OSSL_CMP_CTX_set0_newPkey(ctx, 1, loadedkey))) {
tear_down(fixture);
fixture = NULL;
}
EVP_PKEY_up_ref(loadedkey);
EXECUTE_TEST(execute_MSG_protect_test, tear_down);
return result;
}
static int test_MSG_protect_no_key_no_secret(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->expected = 0;
if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
|| !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_MSG_protect_test, tear_down);
return result;
}
static int execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE *fixture)
{
return TEST_true(ossl_cmp_msg_add_extraCerts(fixture->cmp_ctx,
fixture->msg));
}
static int test_MSG_add_extraCerts(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_protected))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_MSG_add_extraCerts_test, tear_down);
return result;
}
static int execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE *fixture)
{
STACK_OF(X509) *result = NULL;
int ret = 0;
if (TEST_ptr(result = ossl_cmp_build_cert_chain(fixture->certs,
fixture->cert))) {
/* Check whether chain built is equal to the expected one */
ret = TEST_int_eq(0, STACK_OF_X509_cmp(result, fixture->chain));
sk_X509_pop_free(result, X509_free);
}
return ret;
}
static int test_cmp_build_cert_chain(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->cert = endentity2;
if (!TEST_ptr(fixture->certs = sk_X509_new_null())
|| !TEST_ptr(fixture->chain = sk_X509_new_null())
|| !TEST_true(sk_X509_push(fixture->certs, endentity1))
|| !TEST_true(sk_X509_push(fixture->certs, root))
|| !TEST_true(sk_X509_push(fixture->certs, intermediate))
|| !TEST_true(sk_X509_push(fixture->chain, endentity2))
|| !TEST_true(sk_X509_push(fixture->chain, intermediate))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
return result;
}
static int test_cmp_build_cert_chain_missing_intermediate(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->cert = endentity2;
if (!TEST_ptr(fixture->certs = sk_X509_new_null())
|| !TEST_ptr(fixture->chain = sk_X509_new_null())
|| !TEST_true(sk_X509_push(fixture->certs, endentity1))
|| !TEST_true(sk_X509_push(fixture->certs, root))
|| !TEST_true(sk_X509_push(fixture->chain, endentity2))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
return result;
}
static int test_cmp_build_cert_chain_missing_root(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->cert = endentity2;
if (!TEST_ptr(fixture->certs = sk_X509_new_null())
|| !TEST_ptr(fixture->chain = sk_X509_new_null())
|| !TEST_true(sk_X509_push(fixture->certs, endentity1))
|| !TEST_true(sk_X509_push(fixture->certs, intermediate))
|| !TEST_true(sk_X509_push(fixture->chain, endentity2))
|| !TEST_true(sk_X509_push(fixture->chain, intermediate))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
return result;
}
static int test_cmp_build_cert_chain_no_certs(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->cert = endentity2;
if (!TEST_ptr(fixture->certs = sk_X509_new_null())
|| !TEST_ptr(fixture->chain = sk_X509_new_null())
|| !TEST_true(sk_X509_push(fixture->chain, endentity2))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
return result;
}
static int execute_X509_STORE_test(CMP_PROTECT_TEST_FIXTURE *fixture)
{
X509_STORE *store = X509_STORE_new();
STACK_OF(X509) *sk = NULL;
int res = 0;
if (!TEST_true(ossl_cmp_X509_STORE_add1_certs(store,
fixture->certs,
fixture->callback_arg)))
goto err;
sk = ossl_cmp_X509_STORE_get1_certs(store);
if (!TEST_int_eq(0, STACK_OF_X509_cmp(sk, fixture->chain)))
goto err;
res = 1;
err:
X509_STORE_free(store);
sk_X509_pop_free(sk, X509_free);
return res;
}
static int test_X509_STORE(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->callback_arg = 0; /* self-signed allowed */
if (!TEST_ptr(fixture->certs = sk_X509_new_null())
|| !sk_X509_push(fixture->certs, endentity1)
|| !sk_X509_push(fixture->certs, endentity2)
|| !sk_X509_push(fixture->certs, root)
|| !sk_X509_push(fixture->certs, intermediate)
|| !TEST_ptr(fixture->chain = sk_X509_dup(fixture->certs))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_X509_STORE_test, tear_down);
return result;
}
static int test_X509_STORE_only_self_signed(void)
{
SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
fixture->certs = sk_X509_new_null();
fixture->chain = sk_X509_new_null();
fixture->callback_arg = 1; /* only self-signed */
if (!TEST_true(sk_X509_push(fixture->certs, endentity1))
|| !TEST_true(sk_X509_push(fixture->certs, endentity2))
|| !TEST_true(sk_X509_push(fixture->certs, root))
|| !TEST_true(sk_X509_push(fixture->certs, intermediate))
|| !TEST_true(sk_X509_push(fixture->chain, root))) {
tear_down(fixture);
fixture = NULL;
}
EXECUTE_TEST(execute_X509_STORE_test, tear_down);
return result;
}
void cleanup_tests(void)
{
EVP_PKEY_free(loadedprivkey);
EVP_PKEY_free(loadedpubkey);
EVP_PKEY_free(loadedkey);
X509_free(cert);
X509_free(endentity1);
X509_free(endentity2);
X509_free(root);
X509_free(intermediate);
OSSL_CMP_MSG_free(ir_protected);
OSSL_CMP_MSG_free(ir_unprotected);
}
int setup_tests(void)
{
char *server_f;
char *server_key_f;
char *server_cert_f;
char *endentity1_f;
char *endentity2_f;
char *root_f;
char *intermediate_f;
RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
if (!TEST_ptr(server_f = test_get_argument(0))
|| !TEST_ptr(ir_protected_f = test_get_argument(1))
|| !TEST_ptr(ir_unprotected_f = test_get_argument(2))
|| !TEST_ptr(ip_PBM_f = test_get_argument(3))
|| !TEST_ptr(server_cert_f = test_get_argument(4))
|| !TEST_ptr(server_key_f = test_get_argument(5))
|| !TEST_ptr(endentity1_f = test_get_argument(6))
|| !TEST_ptr(endentity2_f = test_get_argument(7))
|| !TEST_ptr(root_f = test_get_argument(8))
|| !TEST_ptr(intermediate_f = test_get_argument(9))) {
TEST_error("usage: cmp_protect_test server.pem "
"IR_protected.der IR_unprotected.der IP_PBM.der "
"server.crt server.pem"
"EndEntity1.crt EndEntity2.crt "
"Root_CA.crt Intermediate_CA.crt\n");
return 0;
}
if (!TEST_ptr(loadedkey = load_pem_key(server_key_f))
|| !TEST_ptr(cert = load_pem_cert(server_cert_f)))
return 0;
if (!TEST_ptr(loadedprivkey = load_pem_key(server_f)))
return 0;
if (TEST_true(EVP_PKEY_up_ref(loadedprivkey)))
loadedpubkey = loadedprivkey;
if (!TEST_ptr(ir_protected = load_pkimsg(ir_protected_f))
|| !TEST_ptr(ir_unprotected = load_pkimsg(ir_unprotected_f)))
return 0;
if (!TEST_ptr(endentity1 = load_pem_cert(endentity1_f))
|| !TEST_ptr(endentity2 = load_pem_cert(endentity2_f))
|| !TEST_ptr(root = load_pem_cert(root_f))
|| !TEST_ptr(intermediate = load_pem_cert(intermediate_f)))
return 0;
if (!TEST_int_eq(1, RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH)))
return 0;
/* Message protection tests */
ADD_TEST(test_cmp_calc_protection_no_key_no_secret);
ADD_TEST(test_cmp_calc_protection_pkey);
ADD_TEST(test_cmp_calc_protection_pbmac);
ADD_TEST(test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key);
ADD_TEST(test_MSG_protect_with_certificate_and_key);
ADD_TEST(test_MSG_protect_certificate_based_without_cert);
ADD_TEST(test_MSG_protect_unprotected_request);
ADD_TEST(test_MSG_protect_no_key_no_secret);
ADD_TEST(test_MSG_add_extraCerts);
ADD_TEST(test_cmp_build_cert_chain);
ADD_TEST(test_cmp_build_cert_chain_missing_root);
ADD_TEST(test_cmp_build_cert_chain_missing_intermediate);
ADD_TEST(test_cmp_build_cert_chain_no_certs);
ADD_TEST(test_X509_STORE);
ADD_TEST(test_X509_STORE_only_self_signed);
return 1;
}
+111
View File
@@ -0,0 +1,111 @@
/*
* Copyright 2007-2019 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 "cmp_testlib.h"
typedef struct test_fixture {
const char *test_case_name;
int pkistatus;
const char *str; /* Not freed by tear_down */
const char *text; /* Not freed by tear_down */
int pkifailure;
} CMP_STATUS_TEST_FIXTURE;
static CMP_STATUS_TEST_FIXTURE *set_up(const char *const test_case_name)
{
CMP_STATUS_TEST_FIXTURE *fixture;
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
return NULL;
fixture->test_case_name = test_case_name;
return fixture;
}
static void tear_down(CMP_STATUS_TEST_FIXTURE *fixture)
{
OPENSSL_free(fixture);
}
/*
* Tests PKIStatusInfo creation and get-functions
*/
static int execute_PKISI_test(CMP_STATUS_TEST_FIXTURE *fixture)
{
OSSL_CMP_PKISI *si = NULL;
int status;
ASN1_UTF8STRING *statusString = NULL;
int res = 0, i;
if (!TEST_ptr(si = ossl_cmp_statusinfo_new(fixture->pkistatus,
fixture->pkifailure,
fixture->text)))
goto end;
status = ossl_cmp_pkisi_get_pkistatus(si);
if (!TEST_int_eq(fixture->pkistatus, status)
|| !TEST_str_eq(fixture->str, ossl_cmp_PKIStatus_to_string(status)))
goto end;
if (!TEST_ptr(statusString =
sk_ASN1_UTF8STRING_value(ossl_cmp_pkisi_get0_statusstring(si),
0))
|| !TEST_str_eq(fixture->text, (char *)statusString->data))
goto end;
if (!TEST_int_eq(fixture->pkifailure,
ossl_cmp_pkisi_get_pkifailureinfo(si)))
goto end;
for (i = 0; i <= OSSL_CMP_PKIFAILUREINFO_MAX; i++)
if (!TEST_int_eq((fixture->pkifailure >> i) & 1,
ossl_cmp_pkisi_pkifailureinfo_check(si, i)))
goto end;
res = 1;
end:
OSSL_CMP_PKISI_free(si);
return res;
}
static int test_PKISI(void)
{
SETUP_TEST_FIXTURE(CMP_STATUS_TEST_FIXTURE, set_up);
fixture->pkistatus = OSSL_CMP_PKISTATUS_revocationNotification;
fixture->str = "PKIStatus: revocation notification - a revocation of the cert has occurred";
fixture->text = "this is an additional text describing the failure";
fixture->pkifailure = OSSL_CMP_CTX_FAILINFO_unsupportedVersion |
OSSL_CMP_CTX_FAILINFO_badDataFormat;
EXECUTE_TEST(execute_PKISI_test, tear_down);
return result;
}
void cleanup_tests(void)
{
return;
}
int setup_tests(void)
{
/*-
* this tests all of:
* ossl_cmp_statusinfo_new()
* ossl_cmp_pkisi_get_pkistatus()
* ossl_cmp_PKIStatus_to_string()
* ossl_cmp_pkisi_get0_statusstring()
* ossl_cmp_pkisi_get_pkifailureinfo()
* ossl_cmp_pkisi_pkifailureinfo_check()
*/
ADD_TEST(test_PKISI);
return 1;
}
+8
View File
@@ -40,6 +40,14 @@ X509 *load_pem_cert(const char *file)
return cert;
}
OSSL_CMP_MSG *load_pkimsg(const char *file)
{
OSSL_CMP_MSG *msg;
(void)TEST_ptr((msg = ossl_cmp_msg_load(file)));
return msg;
}
X509_REQ *load_csr(const char *file)
{
X509_REQ *csr = NULL;
+2 -1
View File
@@ -16,7 +16,7 @@
# include <openssl/pem.h>
# include <openssl/rand.h>
#include "../crypto/cmp/cmp_local.h"
# include "../crypto/cmp/cmp_local.h"
# include "testutil.h"
@@ -25,6 +25,7 @@
EVP_PKEY *load_pem_key(const char *file);
X509 *load_pem_cert(const char *file);
X509_REQ *load_csr(const char *file);
OSSL_CMP_MSG *load_pkimsg(const char *file);
int valid_asn1_encoding(const OSSL_CMP_MSG *msg);
EVP_PKEY *gen_rsa(void);
int STACK_OF_X509_cmp(const STACK_OF(X509) *sk1, const STACK_OF(X509) *sk2);
-7
View File
@@ -90,13 +90,6 @@ static int test_load_config(void)
return 0;
}
/* verify whether RANDFILE is set correctly */
str = NCONF_get_string(conf, "", "RANDFILE");
if (!TEST_ptr(str) || !TEST_str_eq(str, "./.rnd")) {
TEST_note("RANDFILE incorrect");
return 0;
}
/* verify whether CA_default/default_days is set */
val = 0;
if (!TEST_int_eq(NCONF_get_number(conf, "CA_default", "default_days", &val), 1)
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright 1999-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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <string.h>
#include <openssl/bio.h>
#include <openssl/conf.h>
#include <openssl/safestack.h>
#include <openssl/err.h>
static STACK_OF(OPENSSL_CSTRING) *section_names = NULL;
static void collect_section_name(CONF_VALUE *v)
{
/* A section is a CONF_VALUE with name == NULL */
if (v->name == NULL)
sk_OPENSSL_CSTRING_push(section_names, v->section);
}
static int section_name_cmp(OPENSSL_CSTRING const *a, OPENSSL_CSTRING const *b)
{
return strcmp(*a, *b);
}
static void collect_all_sections(const CONF *cnf)
{
section_names = sk_OPENSSL_CSTRING_new(section_name_cmp);
lh_CONF_VALUE_doall(cnf->data, collect_section_name);
sk_OPENSSL_CSTRING_sort(section_names);
}
static void dump_section(const char *name, const CONF *cnf)
{
STACK_OF(CONF_VALUE) *sect = NCONF_get_section(cnf, name);
int i;
printf("[ %s ]\n", name);
for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
CONF_VALUE *cv = sk_CONF_VALUE_value(sect, i);
printf("%s = %s\n", cv->name, cv->value);
}
}
int main(int argc, char **argv)
{
long eline;
CONF *conf = NCONF_new(NCONF_default());
int ret = 1;
if (conf != NULL && NCONF_load(conf, argv[1], &eline)) {
int i;
collect_all_sections(conf);
for (i = 0; i < sk_OPENSSL_CSTRING_num(section_names); i++) {
dump_section(sk_OPENSSL_CSTRING_value(section_names, i), conf);
}
sk_OPENSSL_CSTRING_free(section_names);
ret = 0;
} else {
ERR_print_errors_fp(stderr);
}
NCONF_free(conf);
return ret;
}
+1 -1
View File
@@ -393,7 +393,7 @@ static int run_tlsatest(void)
if (!TEST_ptr(f = BIO_new_file(tlsafile, "r"))
|| !TEST_ptr(ctx = SSL_CTX_new(TLS_client_method()))
|| !TEST_int_gt(SSL_CTX_dane_enable(ctx), 0)
|| !TEST_true(SSL_CTX_load_verify_locations(ctx, CAfile, NULL))
|| !TEST_true(SSL_CTX_load_verify_file(ctx, CAfile))
|| !TEST_int_gt(SSL_CTX_dane_mtype_set(ctx, EVP_sha512(), 2, 1),
0)
|| !TEST_int_gt(SSL_CTX_dane_mtype_set(ctx, EVP_sha256(), 1, 2),
+1 -1
View File
@@ -589,7 +589,7 @@ static void unhook_drbg(RAND_DRBG *drbg)
HOOK_CTX *ctx = get_hook_ctx(drbg);
drbg->get_entropy = ctx->get_entropy;
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DRBG, drbg, &drbg->ex_data);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RAND_DRBG, drbg, &drbg->ex_data);
}
/* Resets the given hook context */
+101
View File
@@ -2348,6 +2348,106 @@ err:
EC_KEY_free(key);
return ret;
}
/*
* Helper for ec_point_hex2point_test
*
* Self-tests EC_POINT_point2hex() against EC_POINT_hex2point() for the given
* (group,P) pair.
*
* If P is NULL use point at infinity.
*/
static ossl_inline
int ec_point_hex2point_test_helper(const EC_GROUP *group, const EC_POINT *P,
point_conversion_form_t form,
BN_CTX *bnctx)
{
int ret = 0;
EC_POINT *Q = NULL, *Pinf = NULL;
char *hex = NULL;
if (P == NULL) {
/* If P is NULL use point at infinity. */
if (!TEST_ptr(Pinf = EC_POINT_new(group))
|| !TEST_true(EC_POINT_set_to_infinity(group, Pinf)))
goto err;
P = Pinf;
}
if (!TEST_ptr(hex = EC_POINT_point2hex(group, P, form, bnctx))
|| !TEST_ptr(Q = EC_POINT_hex2point(group, hex, NULL, bnctx))
|| !TEST_int_eq(0, EC_POINT_cmp(group, Q, P, bnctx)))
goto err;
/*
* The next check is most likely superfluous, as EC_POINT_cmp should already
* cover this.
* Nonetheless it increases the test coverage for EC_POINT_is_at_infinity,
* so we include it anyway!
*/
if (Pinf != NULL
&& !TEST_true(EC_POINT_is_at_infinity(group, Q)))
goto err;
ret = 1;
err:
EC_POINT_free(Pinf);
OPENSSL_free(hex);
EC_POINT_free(Q);
return ret;
}
/*
* This test self-validates EC_POINT_hex2point() and EC_POINT_point2hex()
*/
static int ec_point_hex2point_test(int id)
{
int ret = 0, nid;
EC_GROUP *group = NULL;
const EC_POINT *G = NULL;
EC_POINT *P = NULL;
BN_CTX * bnctx = NULL;
/* Do some setup */
nid = curves[id].nid;
if (!TEST_ptr(bnctx = BN_CTX_new())
|| !TEST_ptr(group = EC_GROUP_new_by_curve_name(nid))
|| !TEST_ptr(G = EC_GROUP_get0_generator(group))
|| !TEST_ptr(P = EC_POINT_dup(G, group)))
goto err;
if (!TEST_true(ec_point_hex2point_test_helper(group, P,
POINT_CONVERSION_COMPRESSED,
bnctx))
|| !TEST_true(ec_point_hex2point_test_helper(group, NULL,
POINT_CONVERSION_COMPRESSED,
bnctx))
|| !TEST_true(ec_point_hex2point_test_helper(group, P,
POINT_CONVERSION_UNCOMPRESSED,
bnctx))
|| !TEST_true(ec_point_hex2point_test_helper(group, NULL,
POINT_CONVERSION_UNCOMPRESSED,
bnctx))
|| !TEST_true(ec_point_hex2point_test_helper(group, P,
POINT_CONVERSION_HYBRID,
bnctx))
|| !TEST_true(ec_point_hex2point_test_helper(group, NULL,
POINT_CONVERSION_HYBRID,
bnctx)))
goto err;
ret = 1;
err:
EC_POINT_free(P);
EC_GROUP_free(group);
BN_CTX_free(bnctx);
return ret;
}
#endif /* OPENSSL_NO_EC */
int setup_tests(void)
@@ -2377,6 +2477,7 @@ int setup_tests(void)
ADD_ALL_TESTS(check_named_curve_lookup_test, crv_len);
ADD_ALL_TESTS(check_ec_key_field_public_range_test, crv_len);
ADD_ALL_TESTS(check_named_curve_from_ecparameters, crv_len);
ADD_ALL_TESTS(ec_point_hex2point_test, crv_len);
#endif /* OPENSSL_NO_EC */
return 1;
}
+182 -29
View File
@@ -22,6 +22,7 @@
#include <openssl/provider.h>
#include <openssl/core_names.h>
#include <openssl/dsa.h>
#include <openssl/dh.h>
#include "testutil.h"
#include "internal/nelem.h"
#include "crypto/evp.h"
@@ -88,6 +89,7 @@ static const unsigned char kExampleRSAKeyDER[] = {
* kExampleDSAKeyDER is a DSA private key in ASN.1, DER format. Of course, you
* should never use this key anywhere but in an example.
*/
#ifndef OPENSSL_NO_DSA
static const unsigned char kExampleDSAKeyDER[] = {
0x30, 0x82, 0x01, 0xba, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0x9a,
0x05, 0x6d, 0x33, 0xcd, 0x5d, 0x78, 0xa1, 0xbb, 0xcb, 0x7d, 0x5b, 0x8d,
@@ -128,6 +130,7 @@ static const unsigned char kExampleDSAKeyDER[] = {
0xf1, 0x8c, 0x82, 0x97, 0xf2, 0xf4, 0x19, 0xba, 0x2b, 0xf3, 0x16, 0xbe,
0x40, 0x48
};
#endif
/*
* kExampleBadRSAKeyDER is an RSA private key in ASN.1, DER format. The private
@@ -422,6 +425,7 @@ end:
return ret;
}
#ifndef OPENSSL_NO_DSA
static EVP_PKEY *load_example_dsa_key(void)
{
EVP_PKEY *ret = NULL;
@@ -445,7 +449,23 @@ end:
return ret;
}
#endif
static EVP_PKEY *load_example_hmac_key(void)
{
EVP_PKEY *pkey = NULL;
unsigned char key[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
};
pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL, key, sizeof(key));
if (!TEST_ptr(pkey))
return NULL;
return pkey;
}
static int test_EVP_Enveloped(void)
{
@@ -491,10 +511,15 @@ err:
}
/*
* Test 0: Standard calls to EVP_DigestSignInit/Update/Final (RSA)
* Test 1: Standard calls to EVP_DigestSignInit/Update/Final (DSA)
* Test 2: Use an MD BIO to do the Update calls instead (RSA)
* Test 3: Use an MD BIO to do the Update calls instead (DSA)
* Test 0: Standard calls to EVP_DigestSignInit/Update/Final (Implicit fetch digest, RSA)
* Test 1: Standard calls to EVP_DigestSignInit/Update/Final (Implicit fetch digest, DSA)
* Test 2: Standard calls to EVP_DigestSignInit/Update/Final (Implicit fetch digest, HMAC)
* Test 3: Standard calls to EVP_DigestSignInit/Update/Final (Explicit fetch digest, RSA)
* Test 4: Standard calls to EVP_DigestSignInit/Update/Final (Explicit fetch digest, DSA)
* Test 5: Standard calls to EVP_DigestSignInit/Update/Final (Explicit fetch diegst, HMAC)
* Test 6: Use an MD BIO to do the Update calls instead (RSA)
* Test 7: Use an MD BIO to do the Update calls instead (DSA)
* Test 8: Use an MD BIO to do the Update calls instead (HMAC)
*/
static int test_EVP_DigestSignInit(int tst)
{
@@ -506,8 +531,10 @@ static int test_EVP_DigestSignInit(int tst)
EVP_MD_CTX *a_md_ctx = NULL, *a_md_ctx_verify = NULL;
BIO *mdbio = NULL, *membio = NULL;
size_t written;
const EVP_MD *md;
EVP_MD *mdexp = NULL;
if (tst >= 2) {
if (tst >= 6) {
membio = BIO_new(BIO_s_mem());
mdbio = BIO_new(BIO_f_md());
if (!TEST_ptr(membio) || !TEST_ptr(mdbio))
@@ -521,18 +548,31 @@ static int test_EVP_DigestSignInit(int tst)
goto out;
}
if (tst == 0 || tst == 2) {
if (tst == 0 || tst == 3 || tst == 6) {
if (!TEST_ptr(pkey = load_example_rsa_key()))
goto out;
} else {
} else if (tst == 1 || tst == 4 || tst == 7) {
#ifndef OPENSSL_NO_DSA
if (!TEST_ptr(pkey = load_example_dsa_key()))
goto out;
#else
ret = 1;
goto out;
#endif
} else {
if (!TEST_ptr(pkey = load_example_hmac_key()))
goto out;
}
if (!TEST_true(EVP_DigestSignInit(md_ctx, NULL, EVP_sha256(), NULL, pkey)))
if (tst >= 3 && tst <= 5)
md = mdexp = EVP_MD_fetch(NULL, "SHA256", NULL);
else
md = EVP_sha256();
if (!TEST_true(EVP_DigestSignInit(md_ctx, NULL, md, NULL, pkey)))
goto out;
if (tst >= 2) {
if (tst >= 6) {
if (!BIO_write_ex(mdbio, kMsg, sizeof(kMsg), &written))
goto out;
} else {
@@ -542,34 +582,39 @@ static int test_EVP_DigestSignInit(int tst)
/* Determine the size of the signature. */
if (!TEST_true(EVP_DigestSignFinal(md_ctx, NULL, &sig_len))
|| !TEST_size_t_eq(sig_len, (size_t)EVP_PKEY_size(pkey)))
|| !TEST_size_t_le(sig_len, (size_t)EVP_PKEY_size(pkey)))
goto out;
if (!TEST_ptr(sig = OPENSSL_malloc(sig_len))
|| !TEST_true(EVP_DigestSignFinal(md_ctx, sig, &sig_len)))
goto out;
if (tst >= 2) {
if (tst >= 6) {
if (!TEST_int_gt(BIO_reset(mdbio), 0)
|| !TEST_int_gt(BIO_get_md_ctx(mdbio, &md_ctx_verify), 0))
goto out;
}
/* Ensure that the signature round-trips. */
if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, EVP_sha256(),
NULL, pkey)))
goto out;
if (tst >= 2) {
if (!BIO_write_ex(mdbio, kMsg, sizeof(kMsg), &written))
/*
* Ensure that the signature round-trips (Verification isn't supported for
* HMAC via EVP_DigestVerify*)
*/
if (tst != 2 && tst != 5 && tst != 8) {
if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, md,
NULL, pkey)))
goto out;
} else {
if (!TEST_true(EVP_DigestVerifyUpdate(md_ctx_verify, kMsg,
sizeof(kMsg))))
if (tst >= 6) {
if (!TEST_true(BIO_write_ex(mdbio, kMsg, sizeof(kMsg), &written)))
goto out;
} else {
if (!TEST_true(EVP_DigestVerifyUpdate(md_ctx_verify, kMsg,
sizeof(kMsg))))
goto out;
}
if (!TEST_true(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len)))
goto out;
}
if (!TEST_true(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len)))
goto out;
ret = 1;
@@ -580,6 +625,7 @@ static int test_EVP_DigestSignInit(int tst)
EVP_MD_CTX_free(a_md_ctx_verify);
EVP_PKEY_free(pkey);
OPENSSL_free(sig);
EVP_MD_free(mdexp);
return ret;
}
@@ -1237,10 +1283,8 @@ static int test_EVP_PKEY_CTX_get_set_params(void)
/* Initialise a sign operation */
ctx = EVP_PKEY_CTX_new(pkey, NULL);
dsaimpl = EVP_SIGNATURE_fetch(NULL, "DSA", NULL);
if (!TEST_ptr(ctx)
|| !TEST_ptr(dsaimpl)
|| !TEST_int_gt(EVP_PKEY_sign_init_ex(ctx, dsaimpl), 0))
|| !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0))
goto err;
/*
@@ -1299,8 +1343,7 @@ static int test_EVP_PKEY_CTX_get_set_params(void)
*/
mdctx = EVP_MD_CTX_new();
if (!TEST_ptr(mdctx)
|| !TEST_true(EVP_DigestSignInit_ex(mdctx, NULL, "SHA1", NULL,
pkey, dsaimpl)))
|| !TEST_true(EVP_DigestSignInit_ex(mdctx, NULL, "SHA1", NULL, pkey)))
goto err;
/*
@@ -1341,9 +1384,112 @@ static int test_EVP_PKEY_CTX_get_set_params(void)
}
#endif
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
static int test_decrypt_null_chunks(void)
{
EVP_CIPHER_CTX* ctx = NULL;
const unsigned char key[32] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1
};
unsigned char iv[12] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b
};
unsigned char msg[] = "It was the best of times, it was the worst of times";
unsigned char ciphertext[80];
unsigned char plaintext[80];
/* We initialise tmp to a non zero value on purpose */
int ctlen, ptlen, tmp = 99;
int ret = 0;
const int enc_offset = 10, dec_offset = 20;
if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())
|| !TEST_true(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL,
key, iv))
|| !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &ctlen, msg,
enc_offset))
/* Deliberate add a zero length update */
|| !TEST_true(EVP_EncryptUpdate(ctx, ciphertext + ctlen, &tmp, NULL,
0))
|| !TEST_int_eq(tmp, 0)
|| !TEST_true(EVP_EncryptUpdate(ctx, ciphertext + ctlen, &tmp,
msg + enc_offset,
sizeof(msg) - enc_offset))
|| !TEST_int_eq(ctlen += tmp, sizeof(msg))
|| !TEST_true(EVP_EncryptFinal(ctx, ciphertext + ctlen, &tmp))
|| !TEST_int_eq(tmp, 0))
goto err;
/* Deliberately initialise tmp to a non zero value */
tmp = 99;
if (!TEST_true(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, key,
iv))
|| !TEST_true(EVP_DecryptUpdate(ctx, plaintext, &ptlen, ciphertext,
dec_offset))
/*
* Deliberately add a zero length update. We also deliberately do
* this at a different offset than for encryption.
*/
|| !TEST_true(EVP_DecryptUpdate(ctx, plaintext + ptlen, &tmp, NULL,
0))
|| !TEST_int_eq(tmp, 0)
|| !TEST_true(EVP_DecryptUpdate(ctx, plaintext + ptlen, &tmp,
ciphertext + dec_offset,
ctlen - dec_offset))
|| !TEST_int_eq(ptlen += tmp, sizeof(msg))
|| !TEST_true(EVP_DecryptFinal(ctx, plaintext + ptlen, &tmp))
|| !TEST_int_eq(tmp, 0)
|| !TEST_mem_eq(msg, sizeof(msg), plaintext, ptlen))
goto err;
ret = 1;
err:
EVP_CIPHER_CTX_free(ctx);
return ret;
}
#endif /* !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) */
#ifndef OPENSSL_NO_DH
static int test_EVP_PKEY_set1_DH(void)
{
DH *x942dh, *pkcs3dh;
EVP_PKEY *pkey1, *pkey2;
int ret = 0;
x942dh = DH_get_2048_256();
pkcs3dh = DH_new_by_nid(NID_ffdhe2048);
pkey1 = EVP_PKEY_new();
pkey2 = EVP_PKEY_new();
if (!TEST_ptr(x942dh)
|| !TEST_ptr(pkcs3dh)
|| !TEST_ptr(pkey1)
|| !TEST_ptr(pkey2))
goto err;
if(!TEST_true(EVP_PKEY_set1_DH(pkey1, x942dh))
|| !TEST_int_eq(EVP_PKEY_id(pkey1), EVP_PKEY_DHX))
goto err;
if(!TEST_true(EVP_PKEY_set1_DH(pkey2, pkcs3dh))
|| !TEST_int_eq(EVP_PKEY_id(pkey2), EVP_PKEY_DH))
goto err;
ret = 1;
err:
EVP_PKEY_free(pkey1);
EVP_PKEY_free(pkey2);
DH_free(x942dh);
DH_free(pkcs3dh);
return ret;
}
#endif
int setup_tests(void)
{
ADD_ALL_TESTS(test_EVP_DigestSignInit, 4);
ADD_ALL_TESTS(test_EVP_DigestSignInit, 9);
ADD_TEST(test_EVP_DigestVerifyInit);
ADD_TEST(test_EVP_Enveloped);
ADD_ALL_TESTS(test_d2i_AutoPrivateKey, OSSL_NELEM(keydata));
@@ -1373,5 +1519,12 @@ int setup_tests(void)
#ifndef OPENSSL_NO_DSA
ADD_TEST(test_EVP_PKEY_CTX_get_set_params);
#endif
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
ADD_TEST(test_decrypt_null_chunks);
#endif
#ifndef OPENSSL_NO_DH
ADD_TEST(test_EVP_PKEY_set1_DH);
#endif
return 1;
}
+42
View File
@@ -297,6 +297,7 @@ static int test_kdf_x963(void)
return ret;
}
#if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_CAMELLIA)
/*
* KBKDF test vectors from RFC 6803 (Camellia Encryption for Kerberos 5)
* section 10.
@@ -421,6 +422,7 @@ static int test_kdf_kbkdf_6803_256(void)
return ret;
}
#endif
/* Two test vectors from RFC 8009 (AES Encryption with HMAC-SHA2 for Kerberos
* 5) appendix A. */
@@ -732,10 +734,49 @@ static int test_kdf_x942_asn1(void)
}
#endif /* OPENSSL_NO_CMS */
static int test_kdf_krb5kdf(void)
{
int ret;
EVP_KDF_CTX *kctx;
OSSL_PARAM params[4], *p = params;
unsigned char out[16];
static unsigned char key[] = {
0x42, 0x26, 0x3C, 0x6E, 0x89, 0xF4, 0xFC, 0x28,
0xB8, 0xDF, 0x68, 0xEE, 0x09, 0x79, 0x9F, 0x15
};
static unsigned char constant[] = {
0x00, 0x00, 0x00, 0x02, 0x99
};
static const unsigned char expected[sizeof(out)] = {
0x34, 0x28, 0x0A, 0x38, 0x2B, 0xC9, 0x27, 0x69,
0xB2, 0xDA, 0x2F, 0x9E, 0xF0, 0x66, 0x85, 0x4B
};
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER,
(char *)"AES-128-CBC",
sizeof("AES-128-CBC"));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, key,
sizeof(key));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_CONSTANT,
constant, sizeof(constant));
*p = OSSL_PARAM_construct_end();
ret =
TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_KRB5KDF))
&& TEST_true(EVP_KDF_CTX_set_params(kctx, params))
&& TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0)
&& TEST_mem_eq(out, sizeof(out), expected, sizeof(expected));
EVP_KDF_CTX_free(kctx);
return ret;
}
int setup_tests(void)
{
#if !defined(OPENSSL_NO_CMAC) && !defined(OPENSSL_NO_CAMELLIA)
ADD_TEST(test_kdf_kbkdf_6803_128);
ADD_TEST(test_kdf_kbkdf_6803_256);
#endif
ADD_TEST(test_kdf_kbkdf_8009_prf1);
ADD_TEST(test_kdf_kbkdf_8009_prf2);
ADD_TEST(test_kdf_get_kdf);
@@ -753,5 +794,6 @@ int setup_tests(void)
#ifndef OPENSSL_NO_CMS
ADD_TEST(test_kdf_x942_asn1);
#endif
ADD_TEST(test_kdf_krb5kdf);
return 1;
}
+206
View File
@@ -0,0 +1,206 @@
/*
* Copyright 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/serializer.h>
#include <openssl/provider.h>
#include <openssl/params.h>
#include <openssl/core_names.h>
#include "internal/nelem.h"
#include "crypto/evp.h" /* For the internal API */
#include "testutil.h"
static int test_print_key_using_pem(const EVP_PKEY *pk)
{
if (!TEST_true(EVP_PKEY_print_private(bio_out, pk, 0, NULL))
/* Public key in PEM form */
|| !TEST_true(PEM_write_bio_PUBKEY(bio_out, pk))
/* Unencrypted private key in PEM form */
|| !TEST_true(PEM_write_bio_PrivateKey(bio_out, pk,
NULL, NULL, 0, NULL, NULL))
/* Encrypted private key in PEM form */
|| !TEST_true(PEM_write_bio_PrivateKey(bio_out, pk, EVP_aes_256_cbc(),
(unsigned char *)"pass", 4,
NULL, NULL)))
return 0;
return 1;
}
static int test_print_key_using_serializer(const EVP_PKEY *pk)
{
const char *pq = OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ;
OSSL_SERIALIZER_CTX *ctx = NULL;
int ret = 1;
/* Make a context, it's valid for several prints */
TEST_note("Setting up a OSSL_SERIALIZER context with passphrase");
if (!TEST_ptr(ctx = OSSL_SERIALIZER_CTX_new_by_EVP_PKEY(pk, pq))
/* Check that this operation is supported */
|| !TEST_ptr(OSSL_SERIALIZER_CTX_get_serializer(ctx))
/* Set a passphrase to be used later */
|| !TEST_true(OSSL_SERIALIZER_CTX_set_passphrase(ctx,
(unsigned char *)"pass",
4)))
goto err;
/* Use no cipher. This should give us an unencrypted PEM */
TEST_note("Displaying PEM with no encryption");
if (!TEST_true(OSSL_SERIALIZER_to_bio(ctx, bio_out)))
ret = 0;
/* Use a valid cipher name */
TEST_note("Displaying PEM encrypted with AES-256-CBC");
if (!TEST_true(OSSL_SERIALIZER_CTX_set_cipher(ctx, "AES-256-CBC", NULL))
|| !TEST_true(OSSL_SERIALIZER_to_bio(ctx, bio_out)))
ret = 0;
/* Use an invalid cipher name, which should generate no output */
TEST_note("NOT Displaying PEM encrypted with (invalid) FOO");
if (!TEST_false(OSSL_SERIALIZER_CTX_set_cipher(ctx, "FOO", NULL))
|| !TEST_false(OSSL_SERIALIZER_to_bio(ctx, bio_out)))
ret = 0;
/* Clear the cipher. This should give us an unencrypted PEM again */
TEST_note("Displaying PEM with encryption cleared (no encryption)");
if (!TEST_true(OSSL_SERIALIZER_CTX_set_cipher(ctx, NULL, NULL))
|| !TEST_true(OSSL_SERIALIZER_to_bio(ctx, bio_out)))
ret = 0;
err:
OSSL_SERIALIZER_CTX_free(ctx);
return ret;
}
/* Array indexes used in test_fromdata_rsa */
#define N 0
#define E 1
#define D 2
#define P 3
#define Q 4
#define DP 5
#define DQ 6
#define QINV 7
static int test_fromdata_rsa(void)
{
int ret = 0;
EVP_PKEY_CTX *ctx = NULL;
EVP_PKEY *pk = NULL;
/*
* 32-bit RSA key, extracted from this command,
* executed with OpenSSL 1.0.2:
*
* openssl genrsa 32 | openssl rsa -text
*/
static unsigned long key_numbers[] = {
0xbc747fc5, /* N */
0x10001, /* E */
0x7b133399, /* D */
0xe963, /* P */
0xceb7, /* Q */
0x8599, /* DP */
0xbd87, /* DQ */
0xcc3b, /* QINV */
};
OSSL_PARAM fromdata_params[] = {
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_N, &key_numbers[N]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_E, &key_numbers[E]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_D, &key_numbers[D]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_FACTOR, &key_numbers[P]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_FACTOR, &key_numbers[Q]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_EXPONENT, &key_numbers[DP]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_EXPONENT, &key_numbers[DQ]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_RSA_COEFFICIENT, &key_numbers[QINV]),
OSSL_PARAM_END
};
if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL)))
goto err;
if (!TEST_true(EVP_PKEY_key_fromdata_init(ctx))
|| !TEST_true(EVP_PKEY_fromdata(ctx, &pk, fromdata_params))
|| !TEST_int_eq(EVP_PKEY_bits(pk), 32)
|| !TEST_int_eq(EVP_PKEY_security_bits(pk), 8)
|| !TEST_int_eq(EVP_PKEY_size(pk), 4))
goto err;
ret = test_print_key_using_pem(pk)
| test_print_key_using_serializer(pk);
err:
EVP_PKEY_free(pk);
EVP_PKEY_CTX_free(ctx);
return ret;
}
#ifndef OPENSSL_NO_DH
/* Array indexes used in test_fromdata_dh */
#define PRIV_KEY 0
#define PUB_KEY 1
#define FFC_P 2
#define FFC_G 3
static int test_fromdata_dh(void)
{
int ret = 0;
EVP_PKEY_CTX *ctx = NULL;
EVP_PKEY *pk = NULL;
/*
* 32-bit DH key, extracted from this command,
* executed with OpenSSL 1.0.2:
*
* openssl dhparam -out dhp.pem 32
* openssl genpkey -paramfile dhp.pem | openssl pkey -text
*/
static unsigned long key_numbers[] = {
0x666c2b06, /* priv-key */
0x6fa6de50, /* pub-key */
0x8bb45f53, /* P */
0x2, /* G */
};
OSSL_PARAM fromdata_params[] = {
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_DH_PRIV_KEY, &key_numbers[PRIV_KEY]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_DH_PUB_KEY, &key_numbers[PUB_KEY]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_FFC_P, &key_numbers[FFC_P]),
OSSL_PARAM_ulong(OSSL_PKEY_PARAM_FFC_G, &key_numbers[FFC_G]),
OSSL_PARAM_END
};
if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL)))
goto err;
if (!TEST_true(EVP_PKEY_key_fromdata_init(ctx))
|| !TEST_true(EVP_PKEY_fromdata(ctx, &pk, fromdata_params))
|| !TEST_int_eq(EVP_PKEY_bits(pk), 32)
|| !TEST_int_eq(EVP_PKEY_security_bits(pk), 0) /* Missing Q */
|| !TEST_int_eq(EVP_PKEY_size(pk), 4))
goto err;
ret = test_print_key_using_pem(pk)
| test_print_key_using_serializer(pk);
err:
EVP_PKEY_free(pk);
EVP_PKEY_CTX_free(ctx);
return ret;
}
#endif
int setup_tests(void)
{
ADD_TEST(test_fromdata_rsa);
#ifndef OPENSSL_NO_DH
ADD_TEST(test_fromdata_dh);
#endif
return 1;
}
+33 -10
View File
@@ -621,12 +621,15 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
unsigned char *in, *expected_out, *tmp = NULL;
size_t in_len, out_len, donelen = 0;
int ok = 0, tmplen, chunklen, tmpflen, i;
EVP_CIPHER_CTX *ctx_base = NULL;
EVP_CIPHER_CTX *ctx = NULL;
t->err = "TEST_FAILURE";
if (!TEST_ptr(ctx_base = EVP_CIPHER_CTX_new()))
goto err;
if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()))
goto err;
EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
EVP_CIPHER_CTX_set_flags(ctx_base, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
if (enc) {
in = expected->plaintext;
in_len = expected->plaintext_len;
@@ -663,18 +666,18 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
in = memcpy(tmp + out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +
inp_misalign, in, in_len);
}
if (!EVP_CipherInit_ex(ctx, expected->cipher, NULL, NULL, NULL, enc)) {
if (!EVP_CipherInit_ex(ctx_base, expected->cipher, NULL, NULL, NULL, enc)) {
t->err = "CIPHERINIT_ERROR";
goto err;
}
if (expected->iv) {
if (expected->aead) {
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
if (!EVP_CIPHER_CTX_ctrl(ctx_base, EVP_CTRL_AEAD_SET_IVLEN,
expected->iv_len, 0)) {
t->err = "INVALID_IV_LENGTH";
goto err;
}
} else if (expected->iv_len != (size_t)EVP_CIPHER_CTX_iv_length(ctx)) {
} else if (expected->iv_len != (size_t)EVP_CIPHER_CTX_iv_length(ctx_base)) {
t->err = "INVALID_IV_LENGTH";
goto err;
}
@@ -693,7 +696,7 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
tag = expected->tag;
}
if (tag || expected->aead != EVP_CIPH_GCM_MODE) {
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
if (!EVP_CIPHER_CTX_ctrl(ctx_base, EVP_CTRL_AEAD_SET_TAG,
expected->tag_len, tag))
goto err;
}
@@ -702,25 +705,25 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
if (expected->rounds > 0) {
int rounds = (int)expected->rounds;
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, rounds, NULL)) {
if (!EVP_CIPHER_CTX_ctrl(ctx_base, EVP_CTRL_SET_RC5_ROUNDS, rounds, NULL)) {
t->err = "INVALID_ROUNDS";
goto err;
}
}
if (!EVP_CIPHER_CTX_set_key_length(ctx, expected->key_len)) {
if (!EVP_CIPHER_CTX_set_key_length(ctx_base, expected->key_len)) {
t->err = "INVALID_KEY_LENGTH";
goto err;
}
if (expected->key_bits > 0) {
int bits = (int)expected->key_bits;
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, bits, NULL)) {
if (!EVP_CIPHER_CTX_ctrl(ctx_base, EVP_CTRL_SET_RC2_KEY_BITS, bits, NULL)) {
t->err = "INVALID KEY BITS";
goto err;
}
}
if (!EVP_CipherInit_ex(ctx, NULL, NULL, expected->key, expected->iv, -1)) {
if (!EVP_CipherInit_ex(ctx_base, NULL, NULL, expected->key, expected->iv, -1)) {
t->err = "KEY_SET_ERROR";
goto err;
}
@@ -729,11 +732,20 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
if (expected->iv != NULL
&& (EVP_CIPHER_flags(expected->cipher) & EVP_CIPH_CUSTOM_IV) == 0
&& !TEST_mem_eq(expected->iv, expected->iv_len,
EVP_CIPHER_CTX_iv(ctx), expected->iv_len)) {
EVP_CIPHER_CTX_iv(ctx_base), expected->iv_len)) {
t->err = "INVALID_IV";
goto err;
}
/* Test that the cipher dup functions correctly if it is supported */
if (EVP_CIPHER_CTX_copy(ctx, ctx_base)) {
EVP_CIPHER_CTX_free(ctx_base);
ctx_base = NULL;
} else {
EVP_CIPHER_CTX_free(ctx);
ctx = ctx_base;
}
if (expected->aead == EVP_CIPH_CCM_MODE) {
if (!EVP_CipherUpdate(ctx, NULL, &tmplen, NULL, out_len)) {
t->err = "CCM_PLAINTEXT_LENGTH_SET_ERROR";
@@ -840,6 +852,8 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
ok = 1;
err:
OPENSSL_free(tmp);
if (ctx != ctx_base)
EVP_CIPHER_CTX_free(ctx_base);
EVP_CIPHER_CTX_free(ctx);
return ok;
}
@@ -2116,6 +2130,15 @@ static int kdf_test_ctrl(EVP_TEST *t, EVP_KDF_CTX *kctx,
if (nid != NID_undef && EVP_get_digestbynid(nid) == NULL)
t->skip = 1;
}
if (p != NULL && strcmp(name, "cipher") == 0) {
/* If p has an OID and lookup fails assume disabled algorithm */
int nid = OBJ_sn2nid(p);
if (nid == NID_undef)
nid = OBJ_ln2nid(p);
if (nid != NID_undef && EVP_get_cipherbynid(nid) == NULL)
t->skip = 1;
}
OPENSSL_free(name);
return 1;
}
+21
View File
@@ -169,6 +169,27 @@ static int test_hmac_run(void)
if (!TEST_str_eq(p, test[6].digest))
goto err;
/* Test reusing a key */
if (!TEST_true(HMAC_Init_ex(ctx, NULL, 0, NULL, NULL))
|| !TEST_true(HMAC_Update(ctx, test[6].data, test[6].data_len))
|| !TEST_true(HMAC_Final(ctx, buf, &len)))
goto err;
p = pt(buf, len);
if (!TEST_str_eq(p, test[6].digest))
goto err;
/*
* Test reusing a key where the digest is provided again but is the same as
* last time
*/
if (!TEST_true(HMAC_Init_ex(ctx, NULL, 0, EVP_sha256(), NULL))
|| !TEST_true(HMAC_Update(ctx, test[6].data, test[6].data_len))
|| !TEST_true(HMAC_Final(ctx, buf, &len)))
goto err;
p = pt(buf, len);
if (!TEST_str_eq(p, test[6].digest))
goto err;
ret = 1;
err:
HMAC_CTX_free(ctx);
+5 -2
View File
@@ -7,6 +7,9 @@
* https://www.openssl.org/source/license.html
*/
/* The AES_ige_* functions are deprecated, so we suppress warnings about them */
#define OPENSSL_SUPPRESS_DEPRECATED
#include <openssl/crypto.h>
#include <openssl/aes.h>
#include <openssl/rand.h>
@@ -15,7 +18,7 @@
#include "internal/nelem.h"
#include "testutil.h"
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
# define TEST_SIZE 128
# define BIG_TEST_SIZE 10240
@@ -438,7 +441,7 @@ static int test_bi_ige_garble3(void)
int setup_tests(void)
{
#if !OPENSSL_API_3
#ifndef OPENSSL_NO_DEPRECATED_3_0
RAND_bytes(rkey, sizeof(rkey));
RAND_bytes(rkey2, sizeof(rkey2));
RAND_bytes(plaintext, sizeof(plaintext));
+260
View File
@@ -0,0 +1,260 @@
/*
* Copyright 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/provider.h>
#include <openssl/core_names.h>
#include "internal/core.h"
#include "internal/nelem.h"
#include "crypto/evp.h" /* For the internal API */
#include "testutil.h"
typedef struct {
OPENSSL_CTX *ctx1;
OSSL_PROVIDER *prov1;
OPENSSL_CTX *ctx2;
OSSL_PROVIDER *prov2;
} FIXTURE;
static void tear_down(FIXTURE *fixture)
{
if (fixture != NULL) {
OSSL_PROVIDER_unload(fixture->prov1);
OSSL_PROVIDER_unload(fixture->prov2);
OPENSSL_CTX_free(fixture->ctx1);
OPENSSL_CTX_free(fixture->ctx2);
OPENSSL_free(fixture);
}
}
static FIXTURE *set_up(const char *testcase_name)
{
FIXTURE *fixture;
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))
|| !TEST_ptr(fixture->ctx1 = OPENSSL_CTX_new())
|| !TEST_ptr(fixture->prov1 = OSSL_PROVIDER_load(fixture->ctx1,
"default"))
|| !TEST_ptr(fixture->ctx2 = OPENSSL_CTX_new())
|| !TEST_ptr(fixture->prov2 = OSSL_PROVIDER_load(fixture->ctx2,
"default"))) {
tear_down(fixture);
return NULL;
}
return fixture;
}
/* Array indexes */
#define N 0
#define E 1
#define D 2
#define P 3
#define Q 4
#define F3 5 /* Extra factor */
#define DP 6
#define DQ 7
#define E3 8 /* Extra exponent */
#define QINV 9
#define C3 10 /* Extra coefficient */
/*
* We have to do this because OSSL_PARAM_get_ulong() can't handle params
* holding data that isn't exactly sizeof(uint32_t) or sizeof(uint64_t),
* and because the other end deals with BIGNUM, the resulting param might
* be any size. In this particular test, we know that the expected data
* fits within an unsigned long, and we want to get the data in that form
* to make testing of values easier.
*/
static int get_ulong_via_BN(const OSSL_PARAM *p, unsigned long *goal)
{
BIGNUM *n = NULL;
int ret = 1; /* Ever so hopeful */
if (!TEST_true(OSSL_PARAM_get_BN(p, &n))
|| !TEST_true(BN_bn2nativepad(n, (unsigned char *)goal, sizeof(*goal))))
ret = 0;
BN_free(n);
return ret;
}
static int export_cb(const OSSL_PARAM *params, void *arg)
{
unsigned long *keydata = arg;
const OSSL_PARAM *p = NULL;
int factors_idx;
int exponents_idx;
int coefficients_idx;
int ret = 1; /* Ever so hopeful */
if (keydata == NULL)
return 0;
if (!TEST_ptr(p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N))
|| !TEST_true(get_ulong_via_BN(p, &keydata[N]))
|| !TEST_ptr(p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E))
|| !TEST_true(get_ulong_via_BN(p, &keydata[E]))
|| !TEST_ptr(p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D))
|| !TEST_true(get_ulong_via_BN(p, &keydata[D])))
ret = 0;
for (p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR),
factors_idx = P;
p != NULL && factors_idx <= F3;
p = OSSL_PARAM_locate_const(p + 1, OSSL_PKEY_PARAM_RSA_FACTOR),
factors_idx++)
if (!TEST_true(get_ulong_via_BN(p, &keydata[factors_idx])))
ret = 0;
for (p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_EXPONENT),
exponents_idx = DP;
p != NULL && exponents_idx <= E3;
p = OSSL_PARAM_locate_const(p + 1, OSSL_PKEY_PARAM_RSA_EXPONENT),
exponents_idx++)
if (!TEST_true(get_ulong_via_BN(p, &keydata[exponents_idx])))
ret = 0;
for (p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_COEFFICIENT),
coefficients_idx = QINV;
p != NULL && coefficients_idx <= C3;
p = OSSL_PARAM_locate_const(p + 1, OSSL_PKEY_PARAM_RSA_COEFFICIENT),
coefficients_idx++)
if (!TEST_true(get_ulong_via_BN(p, &keydata[coefficients_idx])))
ret = 0;
if (!TEST_int_le(factors_idx, F3)
|| !TEST_int_le(exponents_idx, E3)
|| !TEST_int_le(coefficients_idx, C3))
ret = 0;
return ret;
}
static int test_pass_rsa(FIXTURE *fixture)
{
size_t i;
int ret = 0;
RSA *rsa = NULL;
BIGNUM *bn1 = NULL, *bn2 = NULL, *bn3 = NULL;
EVP_PKEY *pk = NULL;
EVP_KEYMGMT *km1 = NULL, *km2 = NULL;
void *provdata = NULL;
/*
* 32-bit RSA key, extracted from this command,
* executed with OpenSSL 1.0.2:
*
* openssl genrsa 32 | openssl rsa -text
*/
static BN_ULONG expected[] = {
0xbc747fc5, /* N */
0x10001, /* E */
0x7b133399, /* D */
0xe963, /* P */
0xceb7, /* Q */
0, /* F3 */
0x8599, /* DP */
0xbd87, /* DQ */
0, /* E3 */
0xcc3b, /* QINV */
0, /* C3 */
0 /* Extra, should remain zero */
};
static unsigned long keydata[OSSL_NELEM(expected)] = { 0, };
if (!TEST_ptr(rsa = RSA_new()))
goto err;
if (!TEST_ptr(bn1 = BN_new())
|| !TEST_true(BN_set_word(bn1, expected[N]))
|| !TEST_ptr(bn2 = BN_new())
|| !TEST_true(BN_set_word(bn2, expected[E]))
|| !TEST_ptr(bn3 = BN_new())
|| !TEST_true(BN_set_word(bn3, expected[D]))
|| !TEST_true(RSA_set0_key(rsa, bn1, bn2, bn3)))
goto err;
if (!TEST_ptr(bn1 = BN_new())
|| !TEST_true(BN_set_word(bn1, expected[P]))
|| !TEST_ptr(bn2 = BN_new())
|| !TEST_true(BN_set_word(bn2, expected[Q]))
|| !TEST_true(RSA_set0_factors(rsa, bn1, bn2)))
goto err;
if (!TEST_ptr(bn1 = BN_new())
|| !TEST_true(BN_set_word(bn1, expected[DP]))
|| !TEST_ptr(bn2 = BN_new())
|| !TEST_true(BN_set_word(bn2, expected[DQ]))
|| !TEST_ptr(bn3 = BN_new())
|| !TEST_true(BN_set_word(bn3, expected[QINV]))
|| !TEST_true(RSA_set0_crt_params(rsa, bn1, bn2, bn3)))
goto err;
bn1 = bn2 = bn3 = NULL;
if (!TEST_ptr(pk = EVP_PKEY_new())
|| !TEST_true(EVP_PKEY_assign_RSA(pk, rsa)))
goto err;
rsa = NULL;
if (!TEST_ptr(km1 = EVP_KEYMGMT_fetch(fixture->ctx1, "RSA", NULL))
|| !TEST_ptr(km2 = EVP_KEYMGMT_fetch(fixture->ctx2, "RSA", NULL))
|| !TEST_ptr_ne(km1, km2))
goto err;
if (!TEST_ptr(evp_keymgmt_export_to_provider(pk, km1, 0))
|| !TEST_ptr(provdata = evp_keymgmt_export_to_provider(pk, km2, 0)))
goto err;
if (!TEST_true(evp_keymgmt_exportkey(km2, provdata, &export_cb, keydata)))
goto err;
/*
* At this point, the hope is that keydata will have all the numbers
* from the key.
*/
for (i = 0; i < OSSL_NELEM(expected); i++) {
int rv = TEST_int_eq(expected[i], keydata[i]);
if (!rv)
TEST_info("i = %zu", i);
else
ret++;
}
ret = (ret == OSSL_NELEM(expected));
err:
RSA_free(rsa);
BN_free(bn1);
BN_free(bn2);
BN_free(bn3);
EVP_PKEY_free(pk);
EVP_KEYMGMT_free(km1);
EVP_KEYMGMT_free(km2);
return ret;
}
static int (*tests[])(FIXTURE *) = {
test_pass_rsa
};
static int test_pass_key(int n)
{
SETUP_TEST_FIXTURE(FIXTURE, set_up);
EXECUTE_TEST(tests[n], tear_down);
return result;
}
int setup_tests(void)
{
ADD_ALL_TESTS(test_pass_key, 1);
return 1;
}
-81
View File
@@ -1,81 +0,0 @@
/*
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <openssl/provider.h>
#include "internal/nelem.h"
#include "testutil.h"
static OSSL_PROVIDER *prov = NULL;
#ifndef OPENSSL_NO_MD2
# include <openssl/evp.h>
# include <openssl/md2.h>
# ifdef CHARSET_EBCDIC
# include <openssl/ebcdic.h>
# endif
static char *test[] = {
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
};
static char *ret[] = {
"8350e5a3e24c153df2275c9f80692773",
"32ec01ec4a6dac72c0ab96fb34c0b5d1",
"da853b0d3f88d99b30283a69e6ded6bb",
"ab4f496bfb2a530b219ff33031fe06b0",
"4e8ddff3650292ab5a4108c3aa47940b",
"da33def2a42df13975352846c30338cd",
"d5976f79d83d3a0dc9806c3c66f3efd8",
};
static int test_md2(int n)
{
char buf[80];
unsigned char md[MD2_DIGEST_LENGTH];
int i;
if (!TEST_true(EVP_Digest((unsigned char *)test[n], strlen(test[n]),
md, NULL, EVP_md2(), NULL)))
return 0;
for (i = 0; i < MD2_DIGEST_LENGTH; i++)
sprintf(&(buf[i * 2]), "%02x", md[i]);
if (!TEST_str_eq(buf, ret[n]))
return 0;
return 1;
}
#endif
int global_init(void)
{
prov = OSSL_PROVIDER_load(NULL, "legacy");
return prov != NULL;
}
void cleanup_tests(void)
{
OSSL_PROVIDER_unload(prov);
}
int setup_tests(void)
{
#ifndef OPENSSL_NO_MD2
ADD_ALL_TESTS(test_md2, OSSL_NELEM(test));
#endif
return 1;
}
+6
View File
@@ -9,6 +9,12 @@
/* Internal tests for the mdc2 module */
/*
* MDC2 low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <stdio.h>
#include <string.h>
+6
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* MDC2 low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <string.h>
#include <openssl/provider.h>
#include <openssl/params.h>
+27 -24
View File
@@ -13,44 +13,47 @@
#include "testutil.h"
/* __has_feature is a clang-ism, while __SANITIZE_ADDRESS__ is a gcc-ism */
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
# define __SANITIZE_ADDRESS__ 1
# endif
#endif
/* If __SANITIZE_ADDRESS__ isn't defined, define it to be false */
#ifndef __SANITIZE_ADDRESS__
# define __SANITIZE_ADDRESS__ 0
#endif
/*
* We use a proper main function here instead of the custom main from the
* test framework because the CRYPTO_mem_leaks_fp function cannot be called
* a second time without trying to use a null pointer. The test framework
* calls this function as part of its close down.
*
* A work around is to call putenv("OPENSSL_DEBUG_MEMORY=0"); before exiting
* but that is worse than avoiding the test framework's main.
* test framework to avoid CRYPTO_mem_leaks stuff.
*/
int main(int argc, char *argv[])
{
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
char *p;
#if __SANITIZE_ADDRESS__
int exitcode = EXIT_SUCCESS;
#else
/*
* When we don't sanitize, we set the exit code to what we would expect
* to get when we are sanitizing. This makes it easy for wrapper scripts
* to detect that we get the result we expect.
*/
int exitcode = EXIT_FAILURE;
#endif
char *lost;
int noleak;
p = getenv("OPENSSL_DEBUG_MEMORY");
if (p != NULL && strcmp(p, "on") == 0)
CRYPTO_set_mem_debug(1);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
lost = OPENSSL_malloc(3);
if (!TEST_ptr(lost))
return EXIT_FAILURE;
strcpy(lost, "ab");
if (argv[1] && strcmp(argv[1], "freeit") == 0) {
OPENSSL_free(lost);
lost = NULL;
exitcode = EXIT_SUCCESS;
}
noleak = CRYPTO_mem_leaks_fp(stderr);
/* If -1 return value something bad happened */
if (!TEST_int_ne(noleak, -1))
return EXIT_FAILURE;
return TEST_int_eq(lost != NULL, noleak == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
#else
return EXIT_SUCCESS;
#endif
lost = NULL;
return exitcode;
}
+6
View File
@@ -9,6 +9,12 @@
/* Internal tests for the modes module */
/*
* This file uses the low level AES functions (which are deprecated for
* non-internal use) in order to test the modes code
*/
#include "internal/deprecated.h"
#include <stdio.h>
#include <string.h>
+106 -5
View File
@@ -7,6 +7,7 @@
* https://www.openssl.org/source/license.html
*/
#include <openssl/evp.h>
#include "internal/namemap.h"
#include "testutil.h"
@@ -17,15 +18,15 @@
static int test_namemap(OSSL_NAMEMAP *nm)
{
int num1 = ossl_namemap_add(nm, 0, NAME1);
int num2 = ossl_namemap_add(nm, 0, NAME2);
int num3 = ossl_namemap_add(nm, num1, ALIAS1);
int num4 = ossl_namemap_add(nm, 0, ALIAS1_UC);
int num1 = ossl_namemap_add_name(nm, 0, NAME1);
int num2 = ossl_namemap_add_name(nm, 0, NAME2);
int num3 = ossl_namemap_add_name(nm, num1, ALIAS1);
int num4 = ossl_namemap_add_name(nm, 0, ALIAS1_UC);
int check1 = ossl_namemap_name2num(nm, NAME1);
int check2 = ossl_namemap_name2num(nm, NAME2);
int check3 = ossl_namemap_name2num(nm, ALIAS1);
int check4 = ossl_namemap_name2num(nm, ALIAS1_UC);
int false1 = ossl_namemap_name2num(nm, "foo");
int false1 = ossl_namemap_name2num(nm, "cookie");
return TEST_int_ne(num1, 0)
&& TEST_int_ne(num2, 0)
@@ -55,9 +56,109 @@ static int test_namemap_stored(void)
&& test_namemap(nm);
}
/*
* Test that EVP_get_digestbyname() will use the namemap when it can't find
* entries in the legacy method database.
*/
static int test_digestbyname(void)
{
int id;
OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
const EVP_MD *sha256, *foo;
id = ossl_namemap_add_name(nm, 0, "SHA256");
if (!TEST_int_ne(id, 0))
return 0;
if (!TEST_int_eq(ossl_namemap_add_name(nm, id, "foo"), id))
return 0;
sha256 = EVP_get_digestbyname("SHA256");
if (!TEST_ptr(sha256))
return 0;
foo = EVP_get_digestbyname("foo");
if (!TEST_ptr_eq(sha256, foo))
return 0;
return 1;
}
/*
* Test that EVP_get_cipherbyname() will use the namemap when it can't find
* entries in the legacy method database.
*/
static int test_cipherbyname(void)
{
int id;
OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
const EVP_CIPHER *aes128, *bar;
id = ossl_namemap_add_name(nm, 0, "AES-128-CBC");
if (!TEST_int_ne(id, 0))
return 0;
if (!TEST_int_eq(ossl_namemap_add_name(nm, id, "bar"), id))
return 0;
aes128 = EVP_get_cipherbyname("AES-128-CBC");
if (!TEST_ptr(aes128))
return 0;
bar = EVP_get_cipherbyname("bar");
if (!TEST_ptr_eq(aes128, bar))
return 0;
return 1;
}
/*
* Test that EVP_CIPHER_is_a() responds appropriately, even for ciphers that
* are entirely legacy.
*/
static int test_cipher_is_a(void)
{
EVP_CIPHER *fetched = EVP_CIPHER_fetch(NULL, "AES-256-CCM", NULL);
int rv = 1;
if (!TEST_ptr_ne(fetched, NULL))
return 0;
if (!TEST_true(EVP_CIPHER_is_a(fetched, "id-aes256-CCM"))
|| !TEST_false(EVP_CIPHER_is_a(fetched, "AES-128-GCM")))
rv = 0;
if (!TEST_true(EVP_CIPHER_is_a(EVP_aes_256_gcm(), "AES-256-GCM"))
|| !TEST_false(EVP_CIPHER_is_a(EVP_aes_256_gcm(), "AES-128-CCM")))
rv = 0;
EVP_CIPHER_free(fetched);
return rv;
}
/*
* Test that EVP_MD_is_a() responds appropriately, even for MDs that are
* entirely legacy.
*/
static int test_digest_is_a(void)
{
EVP_MD *fetched = EVP_MD_fetch(NULL, "SHA2-512", NULL);
int rv = 1;
if (!TEST_ptr_ne(fetched, NULL))
return 0;
if (!TEST_true(EVP_MD_is_a(fetched, "SHA512"))
|| !TEST_false(EVP_MD_is_a(fetched, "SHA1")))
rv = 0;
if (!TEST_true(EVP_MD_is_a(EVP_sha256(), "SHA2-256"))
|| !TEST_false(EVP_MD_is_a(EVP_sha256(), "SHA3-256")))
rv = 0;
EVP_MD_free(fetched);
return rv;
}
int setup_tests(void)
{
ADD_TEST(test_namemap_independent);
ADD_TEST(test_namemap_stored);
ADD_TEST(test_digestbyname);
ADD_TEST(test_cipherbyname);
ADD_TEST(test_digest_is_a);
ADD_TEST(test_cipher_is_a);
return 1;
}
+2 -2
View File
@@ -288,8 +288,8 @@ static unsigned PskClientCallback(SSL *ssl, const char *hint,
return 0;
}
BUF_strlcpy(out_identity, config->psk_identity.c_str(),
max_identity_len);
OPENSSL_strlcpy(out_identity, config->psk_identity.c_str(),
max_identity_len);
memcpy(out_psk, config->psk.data(), config->psk.size());
return config->psk.size();
}
+1 -1
View File
@@ -548,7 +548,7 @@ static int test_param_construct(void)
if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "bignum"))
|| !TEST_ptr(bn = BN_lebin2bn(bn_val, (int)sizeof(bn_val), NULL))
|| !TEST_true(OSSL_PARAM_set_BN(cp, bn))
|| !TEST_size_t_eq(cp->return_size, sizeof(bn_val)))
|| !TEST_size_t_eq(cp->data_size, cp->return_size))
goto err;
/* Match the return size to avoid trailing garbage bytes */
cp->data_size = cp->return_size;
+16 -5
View File
@@ -28,6 +28,15 @@ static int add_property_names(const char *n, ...)
return res;
}
static int up_ref(void *p)
{
return 1;
}
static void down_ref(void *p)
{
}
static int test_property_string(void)
{
OSSL_METHOD_STORE *store;
@@ -242,7 +251,7 @@ static int test_register_deregister(void)
for (i = 0; i < OSSL_NELEM(impls); i++)
if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid,
impls[i].prop, impls[i].impl,
NULL, NULL))) {
&up_ref, &down_ref))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
@@ -310,7 +319,7 @@ static int test_property(void)
for (i = 0; i < OSSL_NELEM(impls); i++)
if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid,
impls[i].prop, impls[i].impl,
NULL, NULL))) {
&up_ref, &down_ref))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
@@ -350,10 +359,12 @@ static int test_query_cache_stochastic(void)
v[i] = 2 * i;
BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
if (!TEST_true(ossl_method_store_add(store, NULL, i, buf, "abc",
NULL, NULL))
|| !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i))
&up_ref, &down_ref))
|| !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i,
&up_ref, &down_ref))
|| !TEST_true(ossl_method_store_cache_set(store, i, "n=1234",
"miss"))) {
"miss", &up_ref,
&down_ref))) {
TEST_note("iteration %d", i);
goto err;
}
+6
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* RC2 low level APIs are deprecated for public use, but still ok for internal
* use.
*/
#include "internal/deprecated.h"
#include "internal/nelem.h"
#include "testutil.h"
+6
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* RC4 low level APIs are deprecated for public use, but still ok for internal
* use.
*/
#include "internal/deprecated.h"
#include <string.h>
#include "internal/nelem.h"
+6
View File
@@ -7,6 +7,12 @@
* https://www.openssl.org/source/license.html
*/
/*
* RC5 low level APIs are deprecated for public use, but still ok for internal
* use.
*/
#include "internal/deprecated.h"
#include <string.h>
#include "internal/nelem.h"
+18
View File
@@ -0,0 +1,18 @@
#! /usr/bin/env perl
# Copyright 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
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use strict;
use OpenSSL::Test qw(:DEFAULT bldtop_dir);
use OpenSSL::Test::Simple;
use OpenSSL::Test::Utils;
setup("test_internal_provider");
$ENV{OPENSSL_MODULES} = bldtop_dir("test");
simple_test("test_internal_keymgmt", "keymgmt_internal_test");
+5 -2
View File
@@ -41,8 +41,11 @@ sub testordinals
#Some ordinals can be repeated, e.g. if one is VMS and another is !VMS
$newqual = $tokens[4];
$newqual =~ s/!//g;
if ($cnt > $tokens[1]
|| ($cnt == $tokens[1] && ($qualifier ne $newqual
my $number = $tokens[1];
$number = $cnt + 1 if $number eq '?';
$number = $cnt if $number eq '?+';
if ($cnt > $number
|| ($cnt == $number && ($qualifier ne $newqual
|| $qualifier eq ""))) {
print STDERR "Invalid ordinal detected: ".$tokens[1]."\n";
$ret = 0;
+33 -12
View File
@@ -24,24 +24,24 @@ use platform;
plan skip_all => "Test only supported in a fips build" if disabled("fips");
plan tests => 6;
plan tests => 9;
my $infile = bldtop_file('providers', platform->dso('fips'));
$ENV{OPENSSL_MODULES} = bldtop_dir("providers");
#fail if no module name
# fail if no module name
ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module',
'-provider_name', 'fips',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install'])),
"fipinstall fail");
"fipsinstall fail");
# fail to Verify if the configuration file is missing
# fail to verify if the configuration file is missing
ok(!run(app(['openssl', 'fipsinstall', '-in', 'dummy.tmp', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install', '-verify'])),
"fipinstall verify fail");
"fipsinstall verify fail");
# output a fips.conf file containing mac data
@@ -49,25 +49,46 @@ ok(run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install'])),
"fipinstall");
"fipsinstall");
# Verify the fips.conf file
# verify the fips.conf file
ok(run(app(['openssl', 'fipsinstall', '-in', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install', '-verify'])),
"fipinstall verify");
"fipsinstall verify");
# Fail to Verify the fips.conf file if a different key is used
# fail to verify the fips.conf file if a different key is used
ok(!run(app(['openssl', 'fipsinstall', '-in', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:01',
'-section_name', 'fips_install', '-verify'])),
"fipinstall verify fail bad key");
"fipsinstall verify fail bad key");
# Fail to Verify the fips.conf file if a different mac digest is used
# fail to verify the fips.conf file if a different mac digest is used
ok(!run(app(['openssl', 'fipsinstall', '-in', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA512', '-macopt', 'hexkey:00',
'-section_name', 'fips_install', '-verify'])),
"fipinstall verify fail incorrect digest");
"fipsinstall verify fail incorrect digest");
# corrupt the module hmac
ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install', '-corrupt_desc', 'HMAC'])),
"fipsinstall fails when the module integrity is corrupted");
# corrupt the first digest
ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install', '-corrupt_desc', 'SHA1'])),
"fipsinstall fails when the digest result is corrupted");
# corrupt another digest
ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_install', '-corrupt_desc', 'SHA3'])),
"fipsinstall fails when the digest result is corrupted");
+41
View File
@@ -0,0 +1,41 @@
#! /usr/bin/env perl
# Copyright 2017-2018 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
use strict;
use warnings;
use OpenSSL::Test qw(:DEFAULT data_file);
use OpenSSL::Test::Utils;
use File::Compare qw(compare_text);
setup('test_conf');
my %input_result = (
'dollarid_on.conf' => 'dollarid_on.txt',
'dollarid_off.conf' => 'dollarid_off.txt',
);
plan skip_all => 'This is unsupported for cross compiled configurations'
if config('CROSS_COMPILE');
plan tests => 2 * scalar(keys %input_result);
foreach (sort keys %input_result) {
SKIP: {
my $input_path = data_file($_);
my $expected_path = data_file($input_result{$_});
my $result_path = "test_conf-$_-stdout";
skip "Problem dumping $_", 1
unless ok(run(test([ 'confdump', $input_path ],
stdout => $result_path)),
"dumping $_");
is(compare_text($result_path, $expected_path), 0,
"comparing the dump of $_ with $input_result{$_}");
}
}
@@ -0,0 +1,5 @@
.pragma dollarid:off
bar = 0
foo = $bar
cookie = ${foo}
@@ -0,0 +1,4 @@
[ default ]
bar = 0
foo = 0
cookie = 0
@@ -0,0 +1,5 @@
.pragma dollarid:on
bar = 0
foo$bar = 1
cookie = ${foo$bar}
@@ -0,0 +1,4 @@
[ default ]
bar = 0
foo$bar = 1
cookie = 1
+1
View File
@@ -32,6 +32,7 @@ my %cert_expected = (
"cert-256line.pem" => 1,
"cert-257line.pem" => 1,
"cert-blankline.pem" => 0,
"cert-bom.pem" => 1,
"cert-comment.pem" => 0,
"cert-earlypad.pem" => 0,
"cert-extrapad.pem" => 0,
@@ -0,0 +1,28 @@
-----BEGIN CERTIFICATE-----
MIIEzDCCA7QCCQCgxkRox+YljjANBgkqhkiG9w0BAQsFADCCASYxYzBhBgNVBAgM
WlRoZSBHcmVhdCBTdGF0ZSBvZiBMb25nLVdpbmRlZCBDZXJ0aWZpY2F0ZSBGaWVs
ZCBOYW1lcyBXaGVyZWJ5IHRvIEluY3JlYXNlIHRoZSBPdXRwdXQgU2l6ZTEfMB0G
A1UEBwwWVG9vbWFueWNoYXJhY3RlcnN2aWxsZTFIMEYGA1UECgw/VGhlIEJlbmV2
b2xlbnQgU29jaWV0eSBvZiBMb3F1YWNpb3VzIGFuZCBQbGVvbmFzdGljIFBlcmlw
aHJhc2lzMT0wOwYDVQQLDDRFbmRvcnNlbWVudCBvZiBWb3VjaHNhZmUnZCBFdmlk
ZW50aWFyeSBDZXJ0aWZpY2F0aW9uMRUwEwYDVQQDDAxjZXJ0LmV4YW1wbGUwHhcN
MTcwMjIzMjAyNTM2WhcNMTcwMzI1MjAyNTM2WjCCASYxYzBhBgNVBAgMWlRoZSBH
cmVhdCBTdGF0ZSBvZiBMb25nLVdpbmRlZCBDZXJ0aWZpY2F0ZSBGaWVsZCBOYW1l
cyBXaGVyZWJ5IHRvIEluY3JlYXNlIHRoZSBPdXRwdXQgU2l6ZTEfMB0GA1UEBwwW
VG9vbWFueWNoYXJhY3RlcnN2aWxsZTFIMEYGA1UECgw/VGhlIEJlbmV2b2xlbnQg
U29jaWV0eSBvZiBMb3F1YWNpb3VzIGFuZCBQbGVvbmFzdGljIFBlcmlwaHJhc2lz
MT0wOwYDVQQLDDRFbmRvcnNlbWVudCBvZiBWb3VjaHNhZmUnZCBFdmlkZW50aWFy
eSBDZXJ0aWZpY2F0aW9uMRUwEwYDVQQDDAxjZXJ0LmV4YW1wbGUwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7MOIrqH+ZIJiZdroKMrelKMSvvRKg2MEg
j/sx9TaHHqrKys4AiL4Rq/ybQEigFC6G8mpZWbBrU+vN2SLr1ZsPftCHIY12LF56
0WLYTYNqDgF5BdCZCrjJ2hhN+XwML2tgYdWioV/Eey8SJSqUskf03MpcwnLbVfSp
hwmowqNfiEFFqPBCf7E8IVarGWctbMpvlMbAM5owhMev/Ccmqqt81NFkb1WVejvN
5v/JKv243/Xedf4I7ZJv7zKeswoP9piFzWHXCd9SIVzWqF77u/crHufIhoEa7NkZ
hSC2aosQF619iKnfk0nqWaLDJ182CCXkHERoQC7q9X2IGLDLoA0XAgMBAAEwDQYJ
KoZIhvcNAQELBQADggEBAKbtLx+YlCGRCBmYn3dfYF+BIvK/b/e0DKNhDKhb4s9J
ywlJ4qnAB48tgPx0q+ZB+EdMYRqCwyvXJxEdZ7PsCdUeU6xI2ybkhSdUUfQbYem3
aYRG+yukGzazySQJs8lGqxBlRMFl/FGCg+oSQ/I32eGf8micDskj2zkAJtCkUPHX
30YrWMfOwW1r2xYr2mBNXbNWXJhW/sIg5u8aa9fcALeuQcMXkbsbVoPmC5aLdiVZ
rvUFoJ8DPg0aYYwj64RwU0B5HW/7jKhQ25FgKVAzLGrgYx1DivkM7UQGdWYnU8IA
A8S89gRjGk2hnkeagWas3dxqTTpgJDhprgWzyKa9hII=
-----END CERTIFICATE-----
+10
View File
@@ -6,7 +6,17 @@
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use strict;
use warnings;
use OpenSSL::Test::Simple;
use OpenSSL::Test;
use OpenSSL::Test::Utils;
setup("test_bf");
plan skip_all => "Low-level Blowfish APIs are disabled in this build"
if disabled("deprecated")
&& (!defined config("api") || config("api") >= 30000);
simple_test("test_bf", "bftest", "bf");
+11
View File
@@ -7,6 +7,17 @@
# https://www.openssl.org/source/license.html
use strict;
use warnings;
use OpenSSL::Test::Simple;
use OpenSSL::Test;
use OpenSSL::Test::Utils;
setup("test_cast");
plan skip_all => "Low-level CAST APIs are disabled in this build"
if disabled("deprecated")
&& (!defined config("api") || config("api") >= 30000);
simple_test("test_cast", "casttest", "cast");
+41 -13
View File
@@ -16,23 +16,51 @@ use OpenSSL::Test::Utils;
setup("test_ec");
plan tests => 5;
plan tests => 11;
require_ok(srctop_file('test','recipes','tconversion.pl'));
ok(run(test(["ectest"])), "running ectest");
SKIP: {
skip "Skipping ec conversion test", 3
if disabled("ec");
SKIP: {
skip "Skipping EC conversion test", 3
if disabled("ec");
subtest 'ec conversions -- private key' => sub {
tconversion("ec", srctop_file("test","testec-p256.pem"));
};
subtest 'ec conversions -- private key PKCS#8' => sub {
tconversion("ec", srctop_file("test","testec-p256.pem"), "pkey");
};
subtest 'ec conversions -- public key' => sub {
tconversion("ec", srctop_file("test","testecpub-p256.pem"), "ec", "-pubin", "-pubout");
};
subtest 'EC conversions -- private key' => sub {
tconversion("ec", srctop_file("test","testec-p256.pem"));
};
subtest 'EC conversions -- private key PKCS#8' => sub {
tconversion("ec", srctop_file("test","testec-p256.pem"), "pkey");
};
subtest 'EC conversions -- public key' => sub {
tconversion("ec", srctop_file("test","testecpub-p256.pem"),
"ec", "-pubin", "-pubout");
};
}
SKIP: {
skip "Skipping EdDSA conversion test", 6
if disabled("ec");
subtest 'Ed25519 conversions -- private key' => sub {
tconversion("pkey", srctop_file("test","tested25519.pem"));
};
subtest 'Ed25519 conversions -- private key PKCS#8' => sub {
tconversion("pkey", srctop_file("test","tested25519.pem"), "pkey");
};
subtest 'Ed25519 conversions -- public key' => sub {
tconversion("pkey", srctop_file("test","tested25519pub.pem"),
"pkey", "-pubin", "-pubout");
};
subtest 'Ed448 conversions -- private key' => sub {
tconversion("pkey", srctop_file("test","tested448.pem"));
};
subtest 'Ed448 conversions -- private key PKCS#8' => sub {
tconversion("pkey", srctop_file("test","tested448.pem"), "pkey");
};
subtest 'Ed448 conversions -- public key' => sub {
tconversion("pkey", srctop_file("test","tested448pub.pem"),
"pkey", "-pubin", "-pubout");
};
}
+104
View File
@@ -0,0 +1,104 @@
#! /usr/bin/env perl
# Copyright 2017 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
use strict;
use warnings;
use File::Spec;
use OpenSSL::Test qw/:DEFAULT with srctop_file/;
use OpenSSL::Test::Utils;
setup("test_dgst");
plan tests => 5;
sub tsignverify {
my $testtext = shift;
my $privkey = shift;
my $pubkey = shift;
my $data_to_sign = srctop_file('test', 'README');
my $other_data = srctop_file('test', 'README.external');
plan tests => 4;
ok(run(app(['openssl', 'dgst', '-sign', $privkey,
'-out', 'testdgst.sig',
$data_to_sign])),
$testtext.": Generating signature");
ok(run(app(['openssl', 'dgst', '-prverify', $privkey,
'-signature', 'testdgst.sig',
$data_to_sign])),
$testtext.": Verify signature with private key");
ok(run(app(['openssl', 'dgst', '-verify', $pubkey,
'-signature', 'testdgst.sig',
$data_to_sign])),
$testtext.": Verify signature with public key");
ok(!run(app(['openssl', 'dgst', '-verify', $pubkey,
'-signature', 'testdgst.sig',
$other_data])),
$testtext.": Expect failure verifying mismatching data");
unlink 'testdgst.sig';
}
SKIP: {
skip "RSA is not supported by this OpenSSL build", 1
if disabled("rsa");
subtest "RSA signature generation and verification with `dgst` CLI" => sub {
tsignverify("RSA",
srctop_file("test","testrsa.pem"),
srctop_file("test","testrsapub.pem"));
};
}
SKIP: {
skip "DSA is not supported by this OpenSSL build", 1
if disabled("dsa");
subtest "DSA signature generation and verification with `dgst` CLI" => sub {
tsignverify("DSA",
srctop_file("test","testdsa.pem"),
srctop_file("test","testdsapub.pem"));
};
}
SKIP: {
skip "ECDSA is not supported by this OpenSSL build", 1
if disabled("ec");
subtest "ECDSA signature generation and verification with `dgst` CLI" => sub {
tsignverify("ECDSA",
srctop_file("test","testec-p256.pem"),
srctop_file("test","testecpub-p256.pem"));
};
}
SKIP: {
skip "EdDSA is not supported by this OpenSSL build", 2
if disabled("ec");
skip "EdDSA is not supported with `dgst` CLI", 2;
subtest "Ed25519 signature generation and verification with `dgst` CLI" => sub {
tsignverify("Ed25519",
srctop_file("test","tested25519.pem"),
srctop_file("test","tested25519pub.pem"));
};
subtest "Ed448 signature generation and verification with `dgst` CLI" => sub {
tsignverify("Ed448",
srctop_file("test","tested448.pem"),
srctop_file("test","tested448pub.pem"));
};
}
+2 -2
View File
@@ -30,14 +30,14 @@ my $ciphersstatus = undef;
my @ciphers =
grep(! /wrap|^$|^[^-]/,
(map { split /\s+/ }
run(app([$cmd, "enc", "-ciphers"]),
run(app([$cmd, "enc", "-list"]),
capture => 1, statusvar => \$ciphersstatus)));
plan tests => 2 + scalar @ciphers;
SKIP: {
skip "Problems getting ciphers...", 1 + scalar(@ciphers)
unless ok($ciphersstatus, "Running 'openssl enc -ciphers'");
unless ok($ciphersstatus, "Running 'openssl enc -list'");
unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
diag($!);
skip "Not initialized, skipping...", scalar(@ciphers);
+104 -1
View File
@@ -15,7 +15,7 @@ use OpenSSL::Test::Utils;
setup("test_pkeyutl");
plan tests => 6;
plan tests => 11;
# For the tests below we use the cert itself as the TBS file
@@ -68,3 +68,106 @@ SKIP: {
}
unlink 'signature.dat';
sub tsignverify {
my $testtext = shift;
my $privkey = shift;
my $pubkey = shift;
my @extraopts = @_;
my $data_to_sign = srctop_file('test', 'README');
my $other_data = srctop_file('test', 'README.external');
my $sigfile = 'testpkeyutl.sig';
my @args = ();
plan tests => 4;
@args = ('openssl', 'pkeyutl', '-sign',
'-inkey', $privkey,
'-out', $sigfile,
'-in', $data_to_sign);
push(@args, @extraopts);
ok(run(app([@args])),
$testtext.": Generating signature");
@args = ('openssl', 'pkeyutl', '-verify',
'-inkey', $privkey,
'-sigfile', $sigfile,
'-in', $data_to_sign);
push(@args, @extraopts);
ok(run(app([@args])),
$testtext.": Verify signature with private key");
@args = ('openssl', 'pkeyutl', '-verify',
'-inkey', $pubkey, '-pubin',
'-sigfile', $sigfile,
'-in', $data_to_sign);
push(@args, @extraopts);
ok(run(app([@args])),
$testtext.": Verify signature with public key");
@args = ('openssl', 'pkeyutl', '-verify',
'-inkey', $pubkey, '-pubin',
'-sigfile', $sigfile,
'-in', $other_data);
push(@args, @extraopts);
ok(!run(app([@args])),
$testtext.": Expect failure verifying mismatching data");
unlink $sigfile;
}
SKIP: {
skip "RSA is not supported by this OpenSSL build", 1
if disabled("rsa");
subtest "RSA CLI signature generation and verification" => sub {
tsignverify("RSA",
srctop_file("test","testrsa.pem"),
srctop_file("test","testrsapub.pem"),
"-rawin", "-digest", "sha256");
};
}
SKIP: {
skip "DSA is not supported by this OpenSSL build", 1
if disabled("dsa");
subtest "DSA CLI signature generation and verification" => sub {
tsignverify("DSA",
srctop_file("test","testdsa.pem"),
srctop_file("test","testdsapub.pem"),
"-rawin", "-digest", "sha256");
};
}
SKIP: {
skip "ECDSA is not supported by this OpenSSL build", 1
if disabled("ec");
subtest "ECDSA CLI signature generation and verification" => sub {
tsignverify("ECDSA",
srctop_file("test","testec-p256.pem"),
srctop_file("test","testecpub-p256.pem"),
"-rawin", "-digest", "sha256");
};
}
SKIP: {
skip "EdDSA is not supported by this OpenSSL build", 2
if disabled("ec");
subtest "Ed2559 CLI signature generation and verification" => sub {
tsignverify("Ed25519",
srctop_file("test","tested25519.pem"),
srctop_file("test","tested25519pub.pem"),
"-rawin");
};
subtest "Ed448 CLI signature generation and verification" => sub {
tsignverify("Ed448",
srctop_file("test","tested448.pem"),
srctop_file("test","tested448pub.pem"),
"-rawin");
};
}
+126 -26
View File
@@ -15,14 +15,10 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
setup("test_req");
plan tests => 10;
plan tests => 15;
require_ok(srctop_file('test','recipes','tconversion.pl'));
open RND, ">>", ".rnd";
print RND "string to make the random number generator think it has randomness";
close RND;
# What type of key to generate?
my @req_new;
if (disabled("rsa")) {
@@ -46,15 +42,115 @@ ok(!run(app([@addext_args, "-addext", $val, "-addext", $val2])));
ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3])));
ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3])));
subtest "generating certificate requests with RSA" => sub {
plan tests => 2;
SKIP: {
skip "RSA is not supported by this OpenSSL build", 2
if disabled("rsa");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-out", "testreq.pem", "-utf8",
"-key", srctop_file("test", "testrsa.pem")])),
"Generating request");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout"])),
"Verifying signature on request");
}
};
subtest "generating certificate requests with DSA" => sub {
plan tests => 2;
SKIP: {
skip "DSA is not supported by this OpenSSL build", 2
if disabled("dsa");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-out", "testreq.pem", "-utf8",
"-key", srctop_file("test", "testdsa.pem")])),
"Generating request");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout"])),
"Verifying signature on request");
}
};
subtest "generating certificate requests with ECDSA" => sub {
plan tests => 2;
SKIP: {
skip "ECDSA is not supported by this OpenSSL build", 2
if disabled("ec");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-out", "testreq.pem", "-utf8",
"-key", srctop_file("test", "testec-p256.pem")])),
"Generating request");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout"])),
"Verifying signature on request");
}
};
subtest "generating certificate requests with Ed25519" => sub {
plan tests => 2;
SKIP: {
skip "Ed25519 is not supported by this OpenSSL build", 2
if disabled("ec");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-out", "testreq.pem", "-utf8",
"-key", srctop_file("test", "tested25519.pem")])),
"Generating request");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout"])),
"Verifying signature on request");
}
};
subtest "generating certificate requests with Ed448" => sub {
plan tests => 2;
SKIP: {
skip "Ed448 is not supported by this OpenSSL build", 2
if disabled("ec");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-out", "testreq.pem", "-utf8",
"-key", srctop_file("test", "tested448.pem")])),
"Generating request");
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout"])),
"Verifying signature on request");
}
};
subtest "generating certificate requests" => sub {
plan tests => 2;
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
@req_new, "-out", "testreq.pem"])),
@req_new, "-out", "testreq.pem"])),
"Generating request");
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout"])),
"-verify", "-in", "testreq.pem", "-noout"])),
"Verifying signature on request");
};
@@ -64,24 +160,28 @@ subtest "generating SM2 certificate requests" => sub {
SKIP: {
skip "SM2 is not supported by this OpenSSL build", 4
if disabled("sm2");
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-key", srctop_file("test", "certs", "sm2.key"),
"-sigopt", "sm2_id:1234567812345678",
"-out", "testreq.pem", "-sm3"])),
"Generating SM2 certificate request");
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout",
"-sm2-id", "1234567812345678", "-sm3"])),
"Verifying signature on SM2 certificate request");
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-new", "-key", srctop_file("test", "certs", "sm2.key"),
"-sigopt", "sm2_hex_id:DEADBEEF",
"-out", "testreq.pem", "-sm3"])),
"Generating SM2 certificate request with hex id");
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
ok(run(app(["openssl", "req",
"-config", srctop_file("test", "test.cnf"),
"-verify", "-in", "testreq.pem", "-noout",
"-sm2-hex-id", "DEADBEEF", "-sm3"])),
"Verifying signature on SM2 certificate request");
@@ -91,9 +191,9 @@ subtest "generating SM2 certificate requests" => sub {
my @openssl_args = ("req", "-config", srctop_file("apps", "openssl.cnf"));
run_conversion('req conversions',
"testreq.pem");
"testreq.pem");
run_conversion('req conversions -- testreq2',
srctop_file("test", "testreq2.pem"));
srctop_file("test", "testreq2.pem"));
unlink "testkey.pem", "testreq.pem";
@@ -102,20 +202,20 @@ sub run_conversion {
my $reqfile = shift;
subtest $title => sub {
run(app(["openssl", @openssl_args,
"-in", $reqfile, "-inform", "p",
"-noout", "-text"],
stderr => "req-check.err", stdout => undef));
open DATA, "req-check.err";
SKIP: {
plan skip_all => "skipping req conversion test for $reqfile"
if grep /Unknown Public Key/, map { s/\R//; } <DATA>;
run(app(["openssl", @openssl_args,
"-in", $reqfile, "-inform", "p",
"-noout", "-text"],
stderr => "req-check.err", stdout => undef));
open DATA, "req-check.err";
SKIP: {
plan skip_all => "skipping req conversion test for $reqfile"
if grep /Unknown Public Key/, map { s/\R//; } <DATA>;
tconversion("req", $reqfile, @openssl_args);
}
close DATA;
unlink "req-check.err";
tconversion("req", $reqfile, @openssl_args);
}
close DATA;
unlink "req-check.err";
done_testing();
done_testing();
};
}
+118
View File
@@ -0,0 +1,118 @@
#! /usr/bin/env perl
# Copyright 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
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use strict;
use warnings;
use OpenSSL::Test qw/:DEFAULT with bldtop_file srctop_file cmdstr/;
use OpenSSL::Test::Utils;
setup("test_verify_store");
plan tests => 10;
my $dummycnf = srctop_file("apps", "openssl.cnf");
my $CAkey = "keyCA.ss";
my $CAcert="certCA.ss";
my $CAserial="certCA.srl";
my $CAreq="reqCA.ss";
my $CAconf=srctop_file("test","CAss.cnf");
my $CAreq2="req2CA.ss"; # temp
my $Uconf=srctop_file("test","Uss.cnf");
my $Ukey="keyU.ss";
my $Ureq="reqU.ss";
my $Ucert="certU.ss";
SKIP: {
req( 'make cert request',
qw(-new),
-config => $CAconf,
-out => $CAreq,
-keyout => $CAkey );
skip 'failure', 8 unless
x509( 'convert request into self-signed cert',
qw(-req -CAcreateserial),
-in => $CAreq,
-out => $CAcert,
-signkey => $CAkey,
-days => 30,
-extfile => $CAconf,
-extensions => 'v3_ca' );
skip 'failure', 7 unless
x509( 'convert cert into a cert request',
qw(-x509toreq),
-in => $CAcert,
-out => $CAreq2,
-signkey => $CAkey );
skip 'failure', 6 unless
req( 'verify request 1',
qw(-verify -noout),
-config => $dummycnf,
-in => $CAreq );
skip 'failure', 5 unless
req( 'verify request 2',
qw(-verify -noout),
-config => $dummycnf,
-in => $CAreq2 );
skip 'failure', 4 unless
verify( 'verify signature',
-CAstore => $CAcert,
$CAcert );
skip 'failure', 3 unless
req( 'make a user cert request',
qw(-new),
-config => $Uconf,
-out => $Ureq,
-keyout => $Ukey );
skip 'failure', 2 unless
x509( 'sign user cert request',
qw(-req -CAcreateserial),
-in => $Ureq,
-out => $Ucert,
-CA => $CAcert,
-CAkey => $CAkey,
-CAserial => $CAserial,
-days => 30,
-extfile => $Uconf,
-extensions => 'v3_ee' )
&& verify( undef,
-CAstore => $CAcert,
$Ucert );
skip 'failure', 0 unless
x509( 'Certificate details',
qw( -subject -issuer -startdate -enddate -noout),
-in => $Ucert );
}
sub verify {
my $title = shift;
ok(run(app([qw(openssl verify), @_])), $title);
}
sub req {
my $title = shift;
ok(run(app([qw(openssl req), @_])), $title);
}
sub x509 {
my $title = shift;
ok(run(app([qw(openssl x509), @_])), $title);
}
+11 -3
View File
@@ -33,11 +33,13 @@ push @configs, 'fips.cnf' unless $no_fips;
my @files = qw( evpciph.txt evpdigest.txt );
my @defltfiles = qw( evpencod.txt evpkdf.txt evppkey_kdf.txt evpmac.txt
evppbe.txt evppkey.txt evppkey_ecc.txt evpcase.txt evpaessiv.txt
evpccmcavs.txt );
evppbe.txt evppkey.txt evppkey_ecc.txt evpcase.txt evpccmcavs.txt );
my @ideafiles = qw( evpciph_idea.txt );
push @defltfiles, @ideafiles unless disabled("idea");
my @sivfiles = qw( evpaessiv.txt );
push @defltfiles, @sivfiles unless disabled("siv");
my @castfiles = qw( evpciph_cast5.txt );
push @defltfiles, @castfiles unless disabled("cast");
@@ -62,6 +64,12 @@ push @defltfiles, @rc2files unless disabled("rc2");
my @chachafiles = qw( evpciph_chacha.txt );
push @defltfiles, @chachafiles unless disabled("chacha");
my @bffiles = qw( evpciph_bf.txt );
push @defltfiles, @bffiles unless disabled("bf");
my @bffiles = qw( evpmd_md2.txt );
push @defltfiles, @bffiles unless disabled("md2");
plan tests =>
($no_fips ? 0 : 1) # FIPS install test
+ (scalar(@configs) * scalar(@files))
@@ -78,7 +86,7 @@ unless ($no_fips) {
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_sect'])),
"fipinstall");
"fipsinstall");
}
foreach (@configs) {
+11
View File
@@ -2462,3 +2462,14 @@ AAD = 8008315ebf2e6fe020e8f5eb
Tag = 3615b7f90a651de15da20fb6
Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5
Ciphertext = ff78128ee18ee3cb9fb0d20726a017ff67fbd09d3a4c38aa32f6d306d3fdda378e459b83ed005507449d6cd981a4c1e3ff4193870c276ef09b6317a01a2283206ae4b4be0d0b235422c8abb00122410656b75e1ffc7fb49c0d0c5d6169aa7623610579968037aee8e83fc26264ea866590fd620aa3c0a5f323d953aa7f8defb0d0d60ab5a9de44dbaf8eae74ea3ab5f30594154f405fd630aa4c4d5603efdfa1
# Test that the tag can be set after specifying AAD.
Cipher = ARIA-256-CCM
Availablein = default
Key = 0c5ffd37a11edc42c325287fc0604f2e3e8cd5671a00fe3216aa5eb105783b54
IV = 000020e8f5eb00000000315e
AAD = 8008315ebf2e6fe020e8f5eb
Tag = 3615b7f90a651de15da20fb6
SetTagLate = TRUE
Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5
Ciphertext = ff78128ee18ee3cb9fb0d20726a017ff67fbd09d3a4c38aa32f6d306d3fdda378e459b83ed005507449d6cd981a4c1e3ff4193870c276ef09b6317a01a2283206ae4b4be0d0b235422c8abb00122410656b75e1ffc7fb49c0d0c5d6169aa7623610579968037aee8e83fc26264ea866590fd620aa3c0a5f323d953aa7f8defb0d0d60ab5a9de44dbaf8eae74ea3ab5f30594154f405fd630aa4c4d5603efdfa1
@@ -0,0 +1,68 @@
#
# Copyright 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
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
Title = Self generated BF test vectors
Cipher = BF-ECB
Availablein = default
Key = 000102030405060708090a0b0c0d0e0f
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = 079590e0010626685653b9b6c2a406e0
#Bigger key
Cipher = BF-ECB
Availablein = default
Key = 000102030405060708090a0b0c0d0e0f00000000
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = 7a0fe3734ad4785b49e59296b7861789
Cipher = BF-CBC
Availablein = default
Key = 000102030405060708090a0b0c0d0e0f
IV = 0101010101010101
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = 39c65006742b62a49f7a40ff69749c0a
#Bigger key
Cipher = BF-CBC
Availablein = default
Key = 000102030405060708090a0b0c0d0e0f00000000
IV = 0101010101010101
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = 3a5cefdb91e56e7aab45e7ea562bd465
Cipher = BF-OFB
Availablein = default
Key = 0001020304050607
IV = 0101010101010101
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = 27be8331cdc52dc61724029d302b9358
#Bigger key
Cipher = BF-OFB
Availablein = default
Key = 000102030405060700000000
IV = 0101010101010101
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = f108f229cc1cbe228aa3b2407979289a
Cipher = BF-CFB
Availablein = default
Key = 0001020304050607
IV = 0101010101010101
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = 27be8331cdc52dc675a93625f90f5db4
#Bigger key
Cipher = BF-CFB
Availablein = default
Key = 000102030405060700000000
IV = 0101010101010101
Plaintext = 0f0e0c0d0b0a09080706050403020100
Ciphertext = f108f229cc1cbe2214f00c3a8611cb46
@@ -60,3 +60,8 @@ Key = ebb46227c6cc8b37641910833222772a
Plaintext = 00000000000000000000000000000000
Ciphertext = 720c94b63edf44e131d950ca211a5a30
#Self generated. Long key
Cipher = RC4
Key = ebb46227c6cc8b37641910833222772a00000000
Plaintext = 00000000000000000000000000000000
Ciphertext = 358b23dba47770e72c7ea8ce5bd68da3
@@ -20,6 +20,12 @@ Key = 00000000000000000000000000000000
Plaintext = 000102030405060708090A0B0C0D0E0F
Ciphertext = d9d37019aec1161b27d7ad56b21f0f42
#Self generated. Bigger key.
Cipher = RC5-ECB
Key = 0000000000000000000000000000000000000000
Plaintext = 000102030405060708090A0B0C0D0E0F
Ciphertext = 610084f3e141cbc5455b82e2d56da565
Cipher = RC5-CBC
Key = 00000000000000000000000000000000
IV = 0000000000000000
@@ -32,6 +38,13 @@ IV = 0102030405060708
Plaintext = 000102030405060708090A0B0C0D0E0F
Ciphertext = eeebae12d768ac9e5b3d6072a9c76c65
#Self generated. Bigger key.
Cipher = RC5-CBC
Key = 0102030405060708090A0B0C0D0E0F1000000000
IV = 0102030405060708
Plaintext = 000102030405060708090A0B0C0D0E0F
Ciphertext = af64972111a80ec28871c51dd4bfe8de
Cipher = RC5-OFB
Key = 00000000000000000000000000000000
IV = 0000000000000000
@@ -44,6 +57,13 @@ IV = 0102030405060708
Plaintext = 000102030405060708090A0B0C0D0E0F
Ciphertext = c0ad101b40fc7ffdfc386ea5ecf458b7
#Self generated. Bigger key.
Cipher = RC5-OFB
Key = 0102030405060708090A0B0C0D0E0F1000000000
IV = 0102030405060708
Plaintext = 000102030405060708090A0B0C0D0E0F
Ciphertext = 66ff8fee03d45533dde93632e8f81f6f
Cipher = RC5-CFB
Key = 00000000000000000000000000000000
IV = 0000000000000000
+120
View File
@@ -6523,3 +6523,123 @@ Ctrl.hexsecret = hexsecret:000102030405060708090a0b0c0d0e0f10111213
Ctrl.cekalg = cekalg:id-smime-alg-CMSRC2wrap
Ctrl.hexukm = hexukm:0123456789abcdeffedcba98765432010123456789abcdeffedcba98765432010123456789abcdeffedcba98765432010123456789abcdeffedcba9876543201
Output = 48950c46e0530075403cce72889604e0
Title = KRB5KDF tests (from RFC 3961 test vectors and krb5 sources)
#RFC3961
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:dce06b1f64c857a11c3db57c51899b2cc1791008ce973b92
Ctrl.hexconstant = hexconstant:0000000155
Output = 925179d04591a79b5d3192c4a7e9c289b049c71f6ee604cd
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:5e13d31c70ef765746578531cb51c15bf11ca82c97cee9f2
Ctrl.hexconstant = hexconstant:00000001aa
Output = 9e58e5a146d9942a101c469845d67a20e3c4259ed913f207
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:98e6fd8a04a4b6859b75a176540b9752bad3ecd610a252bc
Ctrl.hexconstant = hexconstant:0000000155
Output = 13fef80d763e94ec6d13fd2ca1d085070249dad39808eabf
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:622aec25a2fe2cad7094680b7c64940280084c1a7cec92b5
Ctrl.hexconstant = hexconstant:00000001aa
Output = f8dfbf04b097e6d9dc0702686bcb3489d91fd9a4516b703e
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:d3f8298ccb166438dcb9b93ee5a7629286a491f838f802fb
Ctrl.hexconstant = hexconstant:6b65726265726f73
Output = 2370da575d2a3da864cebfdc5204d56df779a7df43d9da43
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:c1081649ada74362e6a1459d01dfd30d67c2234c940704da
Ctrl.hexconstant = hexconstant:0000000155
Output = 348057ec98fdc48016161c2a4c7a943e92ae492c989175f7
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:5d154af238f46713155719d55e2f1f790dd661f279a7917c
Ctrl.hexconstant = hexconstant:00000001aa
Output = a8808ac267dada3dcbe9a7c84626fbc761c294b01315e5c1
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:798562e049852f57dc8c343ba17f2ca1d97394efc8adc443
Ctrl.hexconstant = hexconstant:0000000155
Output = c813f88a3be3b334f75425ce9175fbe3c8493b89c8703b49
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:26dce334b545292f2feab9a8701a89a4b99eb9942cecd016
Ctrl.hexconstant = hexconstant:00000001aa
Output = f48ffd6e83f83e7354e694fd252cf83bfe58f7d5ba37ec5d
#Krb5 sources
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:850BB51358548CD05E86768C313E3BFEF7511937DCF72C3E
Ctrl.hexconstant = hexconstant:0000000299
Output = F78C496D16E6C2DAE0E0B6C24057A84C0426AEEF26FD6DCE
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:850BB51358548CD05E86768C313E3BFEF7511937DCF72C3E
Ctrl.hexconstant = hexconstant:00000002AA
Output = 5B5723D0B634CB684C3EBA5264E9A70D52E683231AD3C4CE
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:850BB51358548CD05E86768C313E3BFEF7511937DCF72C3E
Ctrl.hexconstant = hexconstant:0000000255
Output = A77C94980E9B7345A81525C423A737CE67F4CD91B6B3DA45
KDF = KRB5KDF
Ctrl.cipher = cipher:AES-128-CBC
Ctrl.hexkey = hexkey:42263C6E89F4FC28B8DF68EE09799F15
Ctrl.hexconstant = hexconstant:0000000299
Output = 34280A382BC92769B2DA2F9EF066854B
KDF = KRB5KDF
Ctrl.cipher = cipher:AES-128-CBC
Ctrl.hexkey = hexkey:42263C6E89F4FC28B8DF68EE09799F15
Ctrl.hexconstant = hexconstant:00000002AA
Output = 5B14FC4E250E14DDF9DCCF1AF6674F53
KDF = KRB5KDF
Ctrl.cipher = cipher:AES-128-CBC
Ctrl.hexkey = hexkey:42263C6E89F4FC28B8DF68EE09799F15
Ctrl.hexconstant = hexconstant:0000000255
Output = 4ED31063621684F09AE8D89991AF3E8F
KDF = KRB5KDF
Ctrl.cipher = cipher:AES-256-CBC
Ctrl.hexkey = hexkey:FE697B52BC0D3CE14432BA036A92E65BBB52280990A2FA27883998D72AF30161
Ctrl.hexconstant = hexconstant:0000000299
Output = BFAB388BDCB238E9F9C98D6A878304F04D30C82556375AC507A7A852790F4674
KDF = KRB5KDF
Ctrl.cipher = cipher:AES-256-CBC
Ctrl.hexkey = hexkey:FE697B52BC0D3CE14432BA036A92E65BBB52280990A2FA27883998D72AF30161
Ctrl.hexconstant = hexconstant:00000002AA
Output = C7CFD9CD75FE793A586A542D87E0D1396F1134A104BB1A9190B8C90ADA3DDF37
KDF = KRB5KDF
Ctrl.cipher = cipher:AES-256-CBC
Ctrl.hexkey = hexkey:FE697B52BC0D3CE14432BA036A92E65BBB52280990A2FA27883998D72AF30161
Ctrl.hexconstant = hexconstant:0000000255
Output = 97151B4C76945063E2EB0529DC067D97D7BBA90776D8126D91F34F3101AEA8BA
#Same as the first but with no "fixup"
KDF = KRB5KDF
Ctrl.cipher = cipher:DES-EDE3-CBC
Ctrl.hexkey = hexkey:dce06b1f64c857a11c3db57c51899b2cc1791008ce973b92
Ctrl.hexconstant = hexconstant:0000000155
Output = 935079d14490a75c3093c4a6e8c3b049c71e6ee705
@@ -0,0 +1,44 @@
#
# Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
Title = MD2 tests
Digest = MD2
Availablein = legacy
Input =
Output = 8350e5a3e24c153df2275c9f80692773
Digest = MD2
Availablein = legacy
Input = "a"
Output = 32ec01ec4a6dac72c0ab96fb34c0b5d1
Digest = MD2
Availablein = legacy
Input = "abc"
Output = da853b0d3f88d99b30283a69e6ded6bb
Digest = MD2
Availablein = legacy
Input = "message digest"
Output = ab4f496bfb2a530b219ff33031fe06b0
Digest = MD2
Availablein = legacy
Input = "abcdefghijklmnopqrstuvwxyz"
Output = 4e8ddff3650292ab5a4108c3aa47940b
Digest = MD2
Availablein = legacy
Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Output = da33def2a42df13975352846c30338cd
Digest = MD2
Availablein = legacy
Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
Output = d5976f79d83d3a0dc9806c3c66f3efd8
@@ -807,6 +807,8 @@ PublicKeyRaw=Bob-448-PUBLIC-Raw:X448:3eb7a829b0cd20f5bcfc0b599b6feccf6da4627107b
PrivPubKeyPair = Bob-448-Raw:Bob-448-PUBLIC-Raw
PublicKeyRaw=Bob-448-PUBLIC-Raw-NonCanonical:X448:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Derive=Alice-448
PeerKey=Bob-448-PUBLIC
SharedSecret=07fff4181ac6cc95ec1c16a94a0f74d12da232ce40a77552281d282bb60c0b56fd2464c335543936521c24403085d59a449a5037514a879d
@@ -823,6 +825,11 @@ Derive=Bob-448-Raw
PeerKey=Alice-448-PUBLIC-Raw
SharedSecret=07fff4181ac6cc95ec1c16a94a0f74d12da232ce40a77552281d282bb60c0b56fd2464c335543936521c24403085d59a449a5037514a879d
# Self-generated non-canonical
Derive=Alice-448-Raw
PeerKey=Bob-448-PUBLIC-Raw-NonCanonical
SharedSecret=66e2e682b1f8e68c809f1bb3e406bd826921d9c1a5bfbfcbab7ae72feecee63660eabd54934f3382061d17607f581a90bdac917a064959fb
# Illegal sign/verify operations with X448 key
Sign=Alice-448
+1 -1
View File
@@ -53,7 +53,7 @@ unless ($no_fips) {
'-provider_name', 'fips', '-mac_name', 'HMAC',
'-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
'-section_name', 'fips_sect']),
message => "fipinstall"
message => "fipsinstall"
};
push @testdata, (
{ config => srctop_file("test", "fips.cnf"),
@@ -1,5 +1,6 @@
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
# Copyright (c) 2018, Oracle and/or its affiliates. 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
@@ -8,8 +9,5 @@
use OpenSSL::Test::Simple;
use OpenSSL::Test qw/:DEFAULT bldtop_dir/;
setup("test_md2");
simple_test("test_md2", "md2test", "md2");
simple_test("test_evp_pkey_provided", "evp_pkey_provided_test");
+55
View File
@@ -0,0 +1,55 @@
#! /usr/bin/env perl
# Copyright 2017-2018 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
use strict;
use warnings;
use OpenSSL::Test qw(:DEFAULT data_file);
use File::Compare qw(compare_text);
setup('test_bio_prefix');
my %input_result = (
'in1.txt' => [ 'args1.pl', 'out1.txt' ],
'in2.txt' => [ 'args2.pl', 'out2.txt' ],
);
plan tests => 2 * scalar(keys %input_result);
foreach (sort keys %input_result) {
SKIP: {
my $input_path = data_file($_);
my $args_path = data_file($input_result{$_}->[0]);
my $expected_path = data_file($input_result{$_}->[1]);
my $result_path = "test_bio_prefix-$_-stdout";
my @args = do $args_path;
skip "Problem prefixing $_", 1
unless ok(run(test([ 'bio_prefix_text', @args ],
stdin => $input_path, stdout => $result_path)),
"prefixing $_ with args " . join(' ', @args));
is(compare_text($result_path, $expected_path, \&cmp_line), 0,
"comparing the dump of $_ with $expected_path");
}
}
sub cmp_line {
return 0 if scalar @_ == 0;
if (scalar @_ != 2) {
diag "Lines to compare less than 2: ", scalar @_;
return -1;
}
$_[0] =~ s|\R$||;
$_[1] =~ s|\R$||;
my $r = $_[0] cmp $_[1];
diag "Lines differ:\n<: $_[0]\n>: $_[1]\n" unless $r == 0;
return $r;
}
@@ -0,0 +1,6 @@
(
-n => 2,
-i => '1:32',
-p => '1:FOO',
-i => '0:3'
);
@@ -0,0 +1,3 @@
(
-n => 1,
);
@@ -0,0 +1 @@
foo
@@ -0,0 +1 @@
bar
@@ -0,0 +1 @@
FOO foo
@@ -0,0 +1 @@
bar
+22
View File
@@ -0,0 +1,22 @@
#! /usr/bin/env perl
# Copyright 2007-2019 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
use strict;
use OpenSSL::Test qw/:DEFAULT data_file/;
use OpenSSL::Test::Utils;
setup("test_cmp_lib");
plan skip_all => "This test is not supported in a no-cmp build"
if disabled("cmp");
plan tests => 1;
ok(run(test(["cmp_hdr_test"])));
+24
View File
@@ -0,0 +1,24 @@
#! /usr/bin/env perl
# Copyright 2007-2019 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
use strict;
use OpenSSL::Test qw/:DEFAULT data_file/;
use OpenSSL::Test::Utils;
setup("test_cmp_msg");
plan skip_all => "This test is not supported in a no-cmp build"
if disabled("cmp");
plan tests => 1;
ok(run(test(["cmp_msg_test",
data_file("server.crt"),
data_file("pkcs10.der")])));
Binary file not shown.
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICpTCCAY2gAwIBAgIBATANBgkqhkiG9w0BAQUFADAWMRQwEgYDVQQKDAtvcGVu
c3NsX2NtcDAeFw0xNzEyMjAxMzA0MDBaFw0xODEyMjAxMzA0MDBaMBYxFDASBgNV
BAoMC29wZW5zc2xfY21wMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
4ckRrH0UWmIJFj99kBqvCipGjJRAaPkdvWjdDQLglTpI3eZAJHnq0ypW/PZccrWj
o7mxuvAStEYWF+5Jx6ZFmAsC1K0NNebSAZQoLWYZqiOzkfVVpLicMnItNFElfCoh
BzPCYmF5UlC5yp9PSUEfNwPJqDIRMtw+IlVUV3AJw9TJ3uuWq/vWW9r96/gBKKdd
mj/q2gGT8RC6LxEaolTbhfPbHaA1DFpv1WQFb3oAV3Wq14SOZf9bH1olBVsmBMsU
shFEw5MXVrNCv2moM4HtITMyjvZe7eIwHzSzf6dvQjERG6GvZ/i5KOhaqgJCnRKd
HHzijz9cLec5p9NSOuC1OwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQDGUXpFCBkV
WgPrBfZyBwt6VCjWB/e67q4IdcKMfDa4hwSquah1AyXHI0PlC/qitnoSx2+7f7pY
TEOay/3eEPUl1J5tdPF2Vg56Dw8jdhSkMwO7bXKDEE3R6o6jaa4ECgxwQtdGHmNU
A41PgKX76yEXku803ptO39/UR7i7Ye3MbyAmWE+PvixJYUbxd3fqz5fsaJqTCzAy
AT9hrr4uu8J7m3LYaYXo4LVL4jw5UsP5bIYtpmmEBfy9GhpUqH5/LzBNij7y3ziE
T59wHkzawAQDHsBPuCe07DFtlzqWWvaih0TQAw9MZ2tbyK9jt7P80Rqt9CwpM/i9
jQYqSl/ix5hn
-----END CERTIFICATE-----
+35
View File
@@ -0,0 +1,35 @@
#! /usr/bin/env perl
# Copyright 2007-2019 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
use strict;
use OpenSSL::Test qw/:DEFAULT data_file/;
use OpenSSL::Test::Utils;
setup("test_cmp_protect");
plan skip_all => "This test is not supported in a no-cmp build"
if disabled("cmp");
plan skip_all => "This test is not supported in a shared library build on Windows"
if $^O eq 'MSWin32' && !disabled("shared");
plan tests => 1;
ok(run(test(["cmp_protect_test",
data_file("server.pem"),
data_file("IR_protected.der"),
data_file("IR_unprotected.der"),
data_file("IP_PBM.der"),
data_file("server.crt"),
data_file("server.pem"),
data_file("EndEntity1.crt"),
data_file("EndEntity2.crt"),
data_file("Root_CA.crt"),
data_file("Intermediate_CA.crt")])));
@@ -0,0 +1,16 @@
-----BEGIN CERTIFICATE-----
MIICnDCCAYSgAwIBAgIBAzANBgkqhkiG9w0BAQUFADASMRAwDgYDVQQDEwdSb290
IENBMB4XDTE3MTEwODE1NDgwMFoXDTE4MTEwODExMTkwMFowETEPMA0GA1UEAxMG
Q2xpZW50MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtNiWJufEotHe
p6E/4b0laX7K1NRamNoUokLIsq78RoBieBXaGxIdbT6zmhLnLmZdb0UN3v7FUP75
rqPN2yyj3TbS4o5ilh5El8bDDAPhW5lthCddvH/uBziRAM5oIB4xxOumNbgHpLUT
Clh49sdXd4ydYpCTWld5emRouBmMUeP/0EkyWMBIrHGSBxrqtFVRXhxvVHImQv6Z
hIKql7dCVCZbhUtxw6sLxIGL4xlhKoM2o31k4I/9tjZrWSZZ7KAIOlOLrjxZc/bQ
MwvxVUgS+C+iXzhCY8v+N/K37jwtAAk4C1aOGv/VygNcN0C/ynfKSzFmtnfei4+3
6GC7HtFzewIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQB3GYpPSCCYsJM5owKcODr/
I1aJ8jQ+u5jCKjvYLp6Cnbr4AbRXzvKuMyV6UfIAQbrGOxAClvX++5/ZQbhY+TxN
iiUM3yr5yYCLqj4MeYHhJ3gOzcppAO9LQ9V7eA8C830giZMm3cpApFSLP8CpwNUD
W/fgoQfaOae5IYPZdea88Gmt5RVNbtHgVqtm4ifTQo577kfxTeh20s+M6pgYW3/R
vftXy2ITEtk/j3NcRvOyZ7Bu1mAg7wNeUjL+gDWAaxs16LsWsCsUGwfr/Z2Rq1CF
zB0XwIyigkVLDLqDzUShcw0Eb/zYy2KXsxNWA2tb27mw+T+tmmOszpn7JjLrlVks
-----END CERTIFICATE-----
@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB3zCCAZSgAwIBAgIBBjAKBggqhkjOPQQDAzAVMRMwEQYDVQQDEwpad2lzY2hl
bkNBMB4XDTE3MTEwODE2MDUwMFoXDTE4MTEwODExMTkwMFowEjEQMA4GA1UEAxMH
Q2xpZW50MjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALTYlibnxKLR
3qehP+G9JWl+ytTUWpjaFKJCyLKu/EaAYngV2hsSHW0+s5oS5y5mXW9FDd7+xVD+
+a6jzdsso9020uKOYpYeRJfGwwwD4VuZbYQnXbx/7gc4kQDOaCAeMcTrpjW4B6S1
EwpYePbHV3eMnWKQk1pXeXpkaLgZjFHj/9BJMljASKxxkgca6rRVUV4cb1RyJkL+
mYSCqpe3QlQmW4VLccOrC8SBi+MZYSqDNqN9ZOCP/bY2a1kmWeygCDpTi648WXP2
0DML8VVIEvgvol84QmPL/jfyt+48LQAJOAtWjhr/1coDXDdAv8p3yksxZrZ33ouP
t+hgux7Rc3sCAwEAAaMNMAswCQYDVR0TBAIwADAKBggqhkjOPQQDAwM5ADA2AhkA
qASBLwTauET6FGp/EBe7b/99jTyGB861AhkA5ILGkLX4KmjRkTcNxJ3JKB1Sumya
cbqF
-----END CERTIFICATE-----
Binary file not shown.
@@ -0,0 +1 @@
Reference#: 3078Secret Value: insta
@@ -0,0 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIB1jCBv6ADAgECAgEFMA0GCSqGSIb3DQEBDQUAMBIxEDAOBgNVBAMTB1Jvb3Qg
Q0EwHhcNMTcxMTA4MTYwNDAwWhcNMTgxMTA4MTExOTAwWjAVMRMwEQYDVQQDEwpa
d2lzY2hlbkNBMEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAE9bJcmZWj2CmO6aW8
9Qylkj1WgPREf9/s4Z1VYqFODeJnebPXFBLVH/aoGxnds9E9oxAwDjAMBgNVHRME
BTADAQH/MA0GCSqGSIb3DQEBDQUAA4IBAQBwQD4NTIWMMevEsSrBpKjjQEWc81Ct
eXoyAXr/d8wgVyuIZe9C7ekxPQCwowcmONUyeYQv9N2eYpdhkAQuk6DS4+aDR4s7
I6rg5R5CUGGla5NUxM0BKIS3ZIezvEGlP1NFN+HBgJI7ZIIYQ3zDr0EYgo4J7Xvm
5p58pcCZSsbVyKwKs6T+rTzOVVmJ2L1bWzywZEDmzxMkPmA6fP9XtB4Kx/b4oviw
TEQl3Jf9EkBvBkKX2rRJs7aMJo4MwOnE4HHOV5GAQqhGrXltsuXmVfIQPtRN4xlK
oNf/FukI1NcBh4A/iY4PmbyxHYmKy6qjFjng2u2VFtH15HDT4XlLP5gq
-----END CERTIFICATE-----

Some files were not shown because too many files have changed in this diff Show More