Latest update

This commit is contained in:
2018-12-12 13:00:30 +09:00
parent 3aaee0f8f9
commit 7cd0ce9c1d
228 changed files with 10180 additions and 7774 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
* https://www.openssl.org/source/license.html
*/
/* Tests for the ANS1_STRING_TABLE_* functions */
/* Tests for the ASN1_STRING_TABLE_* functions */
#include <stdio.h>
#include <string.h>
+1 -1
View File
@@ -287,7 +287,7 @@ static char *pt(const unsigned char *p, char buf[DATA_BUF_SIZE])
{
char *ret;
int i;
static char *f = "0123456789ABCDEF";
static const char *f = "0123456789ABCDEF";
ret = &(buf[0]);
for (i = 0; i < 8; i++) {
+8 -7
View File
@@ -44,8 +44,9 @@ static void display_engine_list(void)
static int test_engines(void)
{
ENGINE *block[NUMTOADD];
char *eid[NUMTOADD];
char *ename[NUMTOADD];
char buf[256];
const char *id, *name;
ENGINE *ptr;
int loop;
int to_return = 0;
@@ -138,12 +139,12 @@ static int test_engines(void)
TEST_info("About to beef up the engine-type list");
for (loop = 0; loop < NUMTOADD; loop++) {
sprintf(buf, "id%d", loop);
id = OPENSSL_strdup(buf);
eid[loop] = OPENSSL_strdup(buf);
sprintf(buf, "Fake engine type %d", loop);
name = OPENSSL_strdup(buf);
ename[loop] = OPENSSL_strdup(buf);
if (!TEST_ptr(block[loop] = ENGINE_new())
|| !TEST_true(ENGINE_set_id(block[loop], id))
|| !TEST_true(ENGINE_set_name(block[loop], name)))
|| !TEST_true(ENGINE_set_id(block[loop], eid[loop]))
|| !TEST_true(ENGINE_set_name(block[loop], ename[loop])))
goto end;
}
for (loop = 0; loop < NUMTOADD; loop++) {
@@ -162,8 +163,8 @@ static int test_engines(void)
ENGINE_free(ptr);
}
for (loop = 0; loop < NUMTOADD; loop++) {
OPENSSL_free((void *)ENGINE_get_id(block[loop]));
OPENSSL_free((void *)ENGINE_get_name(block[loop]));
OPENSSL_free(eid[loop]);
OPENSSL_free(ename[loop]);
}
to_return = 1;
+42 -27
View File
@@ -21,6 +21,7 @@
#include "testutil.h"
#include "evp_test.h"
#define AAD_NUM 4
typedef struct evp_test_method_st EVP_TEST_METHOD;
@@ -457,9 +458,9 @@ typedef struct cipher_data_st {
size_t plaintext_len;
unsigned char *ciphertext;
size_t ciphertext_len;
/* GCM, CCM and OCB only */
unsigned char *aad;
size_t aad_len;
/* GCM, CCM, OCB and SIV only */
unsigned char *aad[AAD_NUM];
size_t aad_len[AAD_NUM];
unsigned char *tag;
size_t tag_len;
} CIPHER_DATA;
@@ -484,6 +485,7 @@ static int cipher_test_init(EVP_TEST *t, const char *alg)
m = EVP_CIPHER_mode(cipher);
if (m == EVP_CIPH_GCM_MODE
|| m == EVP_CIPH_OCB_MODE
|| m == EVP_CIPH_SIV_MODE
|| m == EVP_CIPH_CCM_MODE)
cdat->aead = m;
else if (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)
@@ -497,13 +499,15 @@ static int cipher_test_init(EVP_TEST *t, const char *alg)
static void cipher_test_cleanup(EVP_TEST *t)
{
int i;
CIPHER_DATA *cdat = t->data;
OPENSSL_free(cdat->key);
OPENSSL_free(cdat->iv);
OPENSSL_free(cdat->ciphertext);
OPENSSL_free(cdat->plaintext);
OPENSSL_free(cdat->aad);
for (i = 0; i < AAD_NUM; i++)
OPENSSL_free(cdat->aad[i]);
OPENSSL_free(cdat->tag);
}
@@ -511,6 +515,7 @@ static int cipher_test_parse(EVP_TEST *t, const char *keyword,
const char *value)
{
CIPHER_DATA *cdat = t->data;
int i;
if (strcmp(keyword, "Key") == 0)
return parse_bin(value, &cdat->key, &cdat->key_len);
@@ -521,8 +526,13 @@ static int cipher_test_parse(EVP_TEST *t, const char *keyword,
if (strcmp(keyword, "Ciphertext") == 0)
return parse_bin(value, &cdat->ciphertext, &cdat->ciphertext_len);
if (cdat->aead) {
if (strcmp(keyword, "AAD") == 0)
return parse_bin(value, &cdat->aad, &cdat->aad_len);
if (strcmp(keyword, "AAD") == 0) {
for (i = 0; i < AAD_NUM; i++) {
if (cdat->aad[i] == NULL)
return parse_bin(value, &cdat->aad[i], &cdat->aad_len[i]);
}
return 0;
}
if (strcmp(keyword, "Tag") == 0)
return parse_bin(value, &cdat->tag, &cdat->tag_len);
}
@@ -545,7 +555,7 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
CIPHER_DATA *expected = t->data;
unsigned char *in, *expected_out, *tmp = NULL;
size_t in_len, out_len, donelen = 0;
int ok = 0, tmplen, chunklen, tmpflen;
int ok = 0, tmplen, chunklen, tmpflen, i;
EVP_CIPHER_CTX *ctx = NULL;
t->err = "TEST_FAILURE";
@@ -647,32 +657,36 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
goto err;
}
}
if (expected->aad) {
if (expected->aad[0] != NULL) {
t->err = "AAD_SET_ERROR";
if (!frag) {
if (!EVP_CipherUpdate(ctx, NULL, &chunklen, expected->aad,
expected->aad_len))
goto err;
for (i = 0; expected->aad[i] != NULL; i++) {
if (!EVP_CipherUpdate(ctx, NULL, &chunklen, expected->aad[i],
expected->aad_len[i]))
goto err;
}
} else {
/*
* Supply the AAD in chunks less than the block size where possible
*/
if (expected->aad_len > 0) {
if (!EVP_CipherUpdate(ctx, NULL, &chunklen, expected->aad, 1))
goto err;
donelen++;
}
if (expected->aad_len > 2) {
if (!EVP_CipherUpdate(ctx, NULL, &chunklen,
expected->aad + donelen,
expected->aad_len - 2))
goto err;
donelen += expected->aad_len - 2;
}
if (expected->aad_len > 1
for (i = 0; expected->aad[i] != NULL; i++) {
if (expected->aad_len[i] > 0) {
if (!EVP_CipherUpdate(ctx, NULL, &chunklen, expected->aad[i], 1))
goto err;
donelen++;
}
if (expected->aad_len[i] > 2) {
if (!EVP_CipherUpdate(ctx, NULL, &chunklen,
expected->aad[i] + donelen,
expected->aad_len[i] - 2))
goto err;
donelen += expected->aad_len[i] - 2;
}
if (expected->aad_len[i] > 1
&& !EVP_CipherUpdate(ctx, NULL, &chunklen,
expected->aad + donelen, 1))
goto err;
expected->aad[i] + donelen, 1))
goto err;
}
}
}
EVP_CIPHER_CTX_set_padding(ctx, 0);
@@ -798,10 +812,11 @@ static int cipher_test_run(EVP_TEST *t)
if (out_misalign == 1 && frag == 0) {
/*
* XTS, CCM and Wrap modes have special requirements about input
* XTS, SIV, CCM and Wrap modes have special requirements about input
* lengths so we don't fragment for those
*/
if (cdat->aead == EVP_CIPH_CCM_MODE
|| EVP_CIPHER_mode(cdat->cipher) == EVP_CIPH_SIV_MODE
|| EVP_CIPHER_mode(cdat->cipher) == EVP_CIPH_XTS_MODE
|| EVP_CIPHER_mode(cdat->cipher) == EVP_CIPH_WRAP_MODE)
break;
+21 -25
View File
@@ -27,54 +27,50 @@
# ifndef OPENSSL_NO_MD5
static struct test_st {
unsigned char key[16];
const char key[16];
int key_len;
unsigned char data[64];
const unsigned char data[64];
int data_len;
unsigned char *digest;
const char *digest;
} test[8] = {
{
"", 0, "More text test vectors to stuff up EBCDIC machines :-)", 54,
(unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86",
"e9139d1e6ee064ef8cf514fc7dc83e86",
},
{
{
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
}, 16, "Hi There", 8,
(unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d",
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
16, "Hi There", 8,
"9294727a3638bb1c13f48ef8158bfc9d",
},
{
"Jefe", 4, "what do ya want for nothing?", 28,
(unsigned char *)"750c783e6ab0b503eaa86e310a5db738",
"750c783e6ab0b503eaa86e310a5db738",
},
{
{
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
}, 16, {
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
16, {
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
}, 50, (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6",
}, 50, "56be34521d144c88dbb8c733f0e8b3f6",
},
{
"", 0, "My test data", 12,
(unsigned char *)"61afdecb95429ef494d61fdee15990cabf0826fc"
"61afdecb95429ef494d61fdee15990cabf0826fc"
},
{
"", 0, "My test data", 12,
(unsigned char *)"2274b195d90ce8e03406f4b526a47e0787a88a65479938f1a5baa3ce0f079776"
"2274b195d90ce8e03406f4b526a47e0787a88a65479938f1a5baa3ce0f079776"
},
{
"123456", 6, "My test data", 12,
(unsigned char *)"bab53058ae861a7f191abe2d0145cbb123776a6369ee3f9d79ce455667e411dd"
"bab53058ae861a7f191abe2d0145cbb123776a6369ee3f9d79ce455667e411dd"
},
{
"12345", 5, "My test data again", 18,
(unsigned char *)"a12396ceddd2a85f4c656bc1e0aa50c78cffde3e"
"a12396ceddd2a85f4c656bc1e0aa50c78cffde3e"
}
};
# endif
@@ -98,7 +94,7 @@ static int test_hmac_md5(int idx)
test[idx].data, test[idx].data_len, NULL, NULL),
MD5_DIGEST_LENGTH);
if (!TEST_str_eq(p, (char *)test[idx].digest))
if (!TEST_str_eq(p, test[idx].digest))
return 0;
return 1;
@@ -149,7 +145,7 @@ static int test_hmac_run(void)
goto err;
p = pt(buf, len);
if (!TEST_str_eq(p, (char *)test[4].digest))
if (!TEST_str_eq(p, test[4].digest))
goto err;
if (!TEST_false(HMAC_Init_ex(ctx, NULL, 0, EVP_sha256(), NULL)))
@@ -162,7 +158,7 @@ static int test_hmac_run(void)
goto err;
p = pt(buf, len);
if (!TEST_str_eq(p, (char *)test[5].digest))
if (!TEST_str_eq(p, test[5].digest))
goto err;
if (!TEST_true(HMAC_Init_ex(ctx, test[6].key, test[6].key_len, NULL, NULL))
@@ -170,7 +166,7 @@ static int test_hmac_run(void)
|| !TEST_true(HMAC_Final(ctx, buf, &len)))
goto err;
p = pt(buf, len);
if (!TEST_str_eq(p, (char *)test[6].digest))
if (!TEST_str_eq(p, test[6].digest))
goto err;
ret = 1;
@@ -187,7 +183,7 @@ static int test_hmac_single_shot(void)
/* Test single-shot with an empty key. */
p = pt(HMAC(EVP_sha1(), NULL, 0, test[4].data, test[4].data_len,
NULL, NULL), SHA_DIGEST_LENGTH);
if (!TEST_str_eq(p, (char *)test[4].digest))
if (!TEST_str_eq(p, test[4].digest))
return 0;
return 1;
@@ -214,7 +210,7 @@ static int test_hmac_copy(void)
goto err;
p = pt(buf, len);
if (!TEST_str_eq(p, (char *)test[7].digest))
if (!TEST_str_eq(p, test[7].digest))
goto err;
ret = 1;
+2 -2
View File
@@ -25,7 +25,7 @@ static const unsigned char c[8] = { 0x11, 0xFB, 0xED, 0x2B, 0x01, 0x98, 0x6D, 0x
static unsigned char out[80];
static const char text[] = "Hello to all people out there";
static const unsigned char text[] = "Hello to all people out there";
static const unsigned char cfb_key[16] = {
0xe1, 0xf0, 0xc3, 0xd2, 0xa5, 0xb4, 0x87, 0x96,
@@ -74,7 +74,7 @@ static int test_idea_cbc(void)
IDEA_set_encrypt_key(k, &key);
IDEA_set_decrypt_key(&key, &dkey);
memcpy(iv, k, sizeof(iv));
IDEA_cbc_encrypt((unsigned char *)text, out, text_len, &key, iv, 1);
IDEA_cbc_encrypt(text, out, text_len, &key, iv, 1);
memcpy(iv, k, sizeof(iv));
IDEA_cbc_encrypt(out, out, IDEA_BLOCK, &dkey, iv, 0);
IDEA_cbc_encrypt(&out[8], &out[8], text_len - 8, &dkey, iv, 0);
+1 -1
View File
@@ -16,7 +16,7 @@ setup("test_evp");
my @files = ( "evpciph.txt", "evpdigest.txt", "evpencod.txt", "evpkdf.txt",
"evpmac.txt", "evppbe.txt", "evppkey.txt", "evppkey_ecc.txt",
"evpcase.txt" );
"evpcase.txt", "evpaessiv.txt" );
plan tests => scalar(@files);
@@ -0,0 +1,44 @@
#
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (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
# Tests start with one of these keywords
# Cipher Decrypt Derive Digest Encoding KDF MAC PBE
# PrivPubKeyPair Sign Verify VerifyRecover
# and continue until a blank line. Lines starting with a pound sign,
# like this prolog, are ignored.
Title = RFC5297 AES-SIV
Cipher = aes-128-siv
Key = fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
AAD = 101112131415161718191a1b1c1d1e1f2021222324252627
Tag = 85632d07c6e8f37f950acd320a2ecc93
Plaintext = 112233445566778899aabbccddee
Ciphertext = 40c02b9690c4dc04daef7f6afe5c
Cipher = aes-128-siv
Key = 7f7e7d7c7b7a79787776757473727170404142434445464748494a4b4c4d4e4f
AAD = 00112233445566778899aabbccddeeffdeaddadadeaddadaffeeddccbbaa99887766554433221100
AAD = 102030405060708090a0
AAD = 09f911029d74e35bd84156c5635688c0
Tag = 7bdb6e3b432667eb06f4d14bff2fbd0f
Plaintext = 7468697320697320736f6d6520706c61696e7465787420746f20656e6372797074207573696e67205349562d414553
Ciphertext = cb900f2fddbe404326601965c889bf17dba77ceb094fa663b7a3f748ba8af829ea64ad544a272e9c485b62a3fd5c0d
Cipher = aes-192-siv
Key = fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfefffffefdfcfbfaf9f8f7f6f5f4f3f2f1f0
AAD = 101112131415161718191a1b1c1d1e1f2021222324252627
Tag = 89e869b93256785154f0963962fe0740
Plaintext = 112233445566778899aabbccddee
Ciphertext = eff356e42dec1f4febded36642f2
Cipher = aes-256-siv
Key = fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfefff0f1f2f3f4f5f6f7f8f9fafbfcfdfefffffefdfcfbfaf9f8f7f6f5f4f3f2f1f0
AAD = 101112131415161718191a1b1c1d1e1f2021222324252627
Tag = 724dfb2eaf94dbb19b0ba3a299a0801e
Plaintext = 112233445566778899aabbccddee
Ciphertext = f3b05a55498ec2552690b89810e4
@@ -17817,6 +17817,13 @@ Key = ED448-1-PUBLIC-Raw
Input = ""
Output = 533a37f6bbe457251f023c0d88f976ae2dfb504a843e34d2074fd823d41a591f2b233f034f628281f2fd7a22ddd47d7828c59bd0a21bfd3980ff0d2028d4b18a9df63e006c5d1c2d345b925d8dc00b4104852db99ac5c7cdda8530a113a0f4dbb61149f05a7363268c71d95808ff2e652600
#Signature malelability test.
#Same as the verify operation above but with the order added to s
OneShotDigestVerify = NULL
Key = ED448-1-PUBLIC-Raw
Input = ""
Output = 533a37f6bbe457251f023c0d88f976ae2dfb504a843e34d2074fd823d41a591f2b233f034f628281f2fd7a22ddd47d7828c59bd0a21bfd3980f25278d3667403c14bcec5f9cfde9955ebc8333c0ae78fc86e518317c5c7cdda8530a113a0f4dbb61149f05a7363268c71d95808ff2e656600
Result = VERIFY_ERROR
# Key generation tests
KeyGen = rsaEncryption
+193
View File
@@ -22,6 +22,7 @@
#include "testutil.h"
#include "testutil/output.h"
#include "internal/nelem.h"
#include "internal/ktls.h"
#include "../ssl/ssl_locl.h"
#ifndef OPENSSL_NO_TLS1_3
@@ -656,6 +657,192 @@ static int execute_test_large_message(const SSL_METHOD *smeth,
return testresult;
}
#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_KTLS)
/* sock must be connected */
static int ktls_chk_platform(int sock)
{
if (!ktls_enable(sock))
return 0;
return 1;
}
static int ping_pong_query(SSL *clientssl, SSL *serverssl, int cfd, int sfd)
{
static char count = 1;
unsigned char cbuf[16000] = {0};
unsigned char sbuf[16000];
size_t err = 0;
char crec_wseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
char crec_wseq_after[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
char srec_wseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
char srec_wseq_after[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
char srec_rseq_before[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
char srec_rseq_after[TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE];
cbuf[0] = count++;
memcpy(crec_wseq_before, &clientssl->rlayer.write_sequence,
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
memcpy(srec_wseq_before, &serverssl->rlayer.write_sequence,
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
memcpy(srec_rseq_before, &serverssl->rlayer.read_sequence,
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
if (!TEST_true(SSL_write(clientssl, cbuf, sizeof(cbuf)) == sizeof(cbuf)))
goto end;
while ((err = SSL_read(serverssl, &sbuf, sizeof(sbuf))) != sizeof(sbuf)) {
if (SSL_get_error(serverssl, err) != SSL_ERROR_WANT_READ) {
goto end;
}
}
if (!TEST_true(SSL_write(serverssl, sbuf, sizeof(sbuf)) == sizeof(sbuf)))
goto end;
while ((err = SSL_read(clientssl, &cbuf, sizeof(cbuf))) != sizeof(cbuf)) {
if (SSL_get_error(clientssl, err) != SSL_ERROR_WANT_READ) {
goto end;
}
}
memcpy(crec_wseq_after, &clientssl->rlayer.write_sequence,
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
memcpy(srec_wseq_after, &serverssl->rlayer.write_sequence,
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
memcpy(srec_rseq_after, &serverssl->rlayer.read_sequence,
TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
/* verify the payload */
if (!TEST_mem_eq(cbuf, sizeof(cbuf), sbuf, sizeof(sbuf)))
goto end;
/* ktls is used then kernel sequences are used instead of OpenSSL sequences */
if (clientssl->mode & SSL_MODE_NO_KTLS_TX) {
if (!TEST_mem_ne(crec_wseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
crec_wseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
goto end;
} else {
if (!TEST_mem_eq(crec_wseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
crec_wseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
goto end;
}
if (serverssl->mode & SSL_MODE_NO_KTLS_TX) {
if (!TEST_mem_ne(srec_wseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
srec_wseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
goto end;
} else {
if (!TEST_mem_eq(srec_wseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
srec_wseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
goto end;
}
if (!TEST_mem_ne(srec_rseq_before, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE,
srec_rseq_after, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE))
goto end;
return 1;
end:
return 0;
}
static int execute_test_ktls(int cis_ktls_tx, int sis_ktls_tx)
{
SSL_CTX *cctx = NULL, *sctx = NULL;
SSL *clientssl = NULL, *serverssl = NULL;
int testresult = 0;
int cfd, sfd;
if (!TEST_true(create_test_sockets(&cfd, &sfd)))
goto end;
/* Skip this test if the platform does not support ktls */
if (!ktls_chk_platform(cfd))
return 1;
/* Create a session based on SHA-256 */
if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
TLS_client_method(),
TLS1_2_VERSION, TLS1_2_VERSION,
&sctx, &cctx, cert, privkey))
|| !TEST_true(SSL_CTX_set_cipher_list(cctx,
"AES128-GCM-SHA256"))
|| !TEST_true(create_ssl_objects2(sctx, cctx, &serverssl,
&clientssl, sfd, cfd)))
goto end;
if (!cis_ktls_tx) {
if (!TEST_true(SSL_set_mode(clientssl, SSL_MODE_NO_KTLS_TX)))
goto end;
}
if (!sis_ktls_tx) {
if (!TEST_true(SSL_set_mode(serverssl, SSL_MODE_NO_KTLS_TX)))
goto end;
}
if (!TEST_true(create_ssl_connection(serverssl, clientssl,
SSL_ERROR_NONE)))
goto end;
if (!cis_ktls_tx) {
if (!TEST_false(BIO_get_ktls_send(clientssl->wbio)))
goto end;
} else {
if (!TEST_true(BIO_get_ktls_send(clientssl->wbio)))
goto end;
}
if (!sis_ktls_tx) {
if (!TEST_false(BIO_get_ktls_send(serverssl->wbio)))
goto end;
} else {
if (!TEST_true(BIO_get_ktls_send(serverssl->wbio)))
goto end;
}
if (!TEST_true(ping_pong_query(clientssl, serverssl, cfd, sfd)))
goto end;
testresult = 1;
end:
if (clientssl) {
SSL_shutdown(clientssl);
SSL_free(clientssl);
}
if (serverssl) {
SSL_shutdown(serverssl);
SSL_free(serverssl);
}
SSL_CTX_free(sctx);
SSL_CTX_free(cctx);
serverssl = clientssl = NULL;
return testresult;
}
static int test_ktls_client_server(void)
{
return execute_test_ktls(1, 1);
}
static int test_ktls_no_client_server(void)
{
return execute_test_ktls(0, 1);
}
static int test_ktls_client_no_server(void)
{
return execute_test_ktls(1, 0);
}
static int test_ktls_no_client_no_server(void)
{
return execute_test_ktls(0, 0);
}
#endif
static int test_large_message_tls(void)
{
return execute_test_large_message(TLS_server_method(), TLS_client_method(),
@@ -5869,6 +6056,12 @@ int setup_tests(void)
#endif
}
#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_KTLS)
ADD_TEST(test_ktls_client_server);
ADD_TEST(test_ktls_no_client_server);
ADD_TEST(test_ktls_client_no_server);
ADD_TEST(test_ktls_no_client_no_server);
#endif
ADD_TEST(test_large_message_tls);
ADD_TEST(test_large_message_tls_read_ahead);
#ifndef OPENSSL_NO_DTLS
+121
View File
@@ -16,6 +16,14 @@
#ifdef OPENSSL_SYS_UNIX
# include <unistd.h>
#ifndef OPENSSL_NO_KTLS
# include <netinet/in.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <unistd.h>
# include <fcntl.h>
#endif
static ossl_inline void ossl_sleep(unsigned int millis) {
usleep(millis * 1000);
@@ -655,6 +663,119 @@ int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
#define MAXLOOPS 1000000
#ifndef OPENSSL_NO_KTLS
static int set_nb(int fd)
{
int flags;
flags = fcntl(fd,F_GETFL,0);
if (flags == -1)
return flags;
flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
return flags;
}
int create_test_sockets(int *cfd, int *sfd)
{
struct sockaddr_in sin;
const char *host = "127.0.0.1";
int cfd_connected = 0, ret = 0;
socklen_t slen = sizeof(sin);
int afd = -1;
*cfd = -1;
*sfd = -1;
memset ((char *) &sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(host);
afd = socket(AF_INET, SOCK_STREAM, 0);
if (afd < 0)
return 0;
if (bind(afd, (struct sockaddr*)&sin, sizeof(sin)) < 0)
goto out;
if (getsockname(afd, (struct sockaddr*)&sin, &slen) < 0)
goto out;
if (listen(afd, 1) < 0)
goto out;
*cfd = socket(AF_INET, SOCK_STREAM, 0);
if (*cfd < 0)
goto out;
if (set_nb(afd) == -1)
goto out;
while (*sfd == -1 || !cfd_connected ) {
*sfd = accept(afd, NULL, 0);
if (*sfd == -1 && errno != EAGAIN)
goto out;
if (!cfd_connected && connect(*cfd, (struct sockaddr*)&sin, sizeof(sin)) < 0)
goto out;
else
cfd_connected = 1;
}
if (set_nb(*cfd) == -1 || set_nb(*sfd) == -1)
goto out;
ret = 1;
goto success;
out:
if (*cfd != -1)
close(*cfd);
if (*sfd != -1)
close(*sfd);
success:
if (afd != -1)
close(afd);
return ret;
}
#else
int create_test_sockets(int *cfd, int *sfd)
{
return 0;
}
#endif
int create_ssl_objects2(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
SSL **cssl, int sfd, int cfd)
{
SSL *serverssl = NULL, *clientssl = NULL;
BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;
if (*sssl != NULL)
serverssl = *sssl;
else if (!TEST_ptr(serverssl = SSL_new(serverctx)))
goto error;
if (*cssl != NULL)
clientssl = *cssl;
else if (!TEST_ptr(clientssl = SSL_new(clientctx)))
goto error;
if (!TEST_ptr(s_to_c_bio = BIO_new_socket(sfd, BIO_NOCLOSE))
|| !TEST_ptr(c_to_s_bio = BIO_new_socket(cfd, BIO_NOCLOSE)))
goto error;
SSL_set_bio(clientssl, c_to_s_bio, c_to_s_bio);
SSL_set_bio(serverssl, s_to_c_bio, s_to_c_bio);
*sssl = serverssl;
*cssl = clientssl;
return 1;
error:
SSL_free(serverssl);
SSL_free(clientssl);
BIO_free(s_to_c_bio);
BIO_free(c_to_s_bio);
return 0;
}
/*
* NOTE: Transfers control of the BIOs - this function will free them on error
*/
+3
View File
@@ -19,6 +19,9 @@ int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio);
int create_bare_ssl_connection(SSL *serverssl, SSL *clientssl, int want);
int create_ssl_objects2(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
SSL **cssl, int sfd, int cfd);
int create_test_sockets(int *cfd, int *sfd);
int create_ssl_connection(SSL *serverssl, SSL *clientssl, int want);
void shutdown_ssl_connection(SSL *serverssl, SSL *clientssl);
+1 -1
View File
@@ -99,7 +99,7 @@ static int gcd(int a, int b)
return a;
}
void setup_test_framework()
void setup_test_framework(void)
{
char *TAP_levels = getenv("HARNESS_OSSL_LEVEL");
char *test_seed = getenv("OPENSSL_TEST_RAND_ORDER");
+12 -11
View File
@@ -31,9 +31,9 @@ static void test_diff_header(const char *left, const char *right)
static void test_string_null_empty(const char *m, char c)
{
if (m == NULL)
test_printf_stderr("% 4s %c NULL\n", "", c);
test_printf_stderr("%4s %c NULL\n", "", c);
else
test_printf_stderr("% 4u:%c ''\n", 0u, c);
test_printf_stderr("%4u:%c ''\n", 0u, c);
}
static void test_fail_string_common(const char *prefix, const char *file,
@@ -94,18 +94,18 @@ static void test_fail_string_common(const char *prefix, const char *file,
bdiff[i] = '\0';
}
if (n1 == n2 && !diff) {
test_printf_stderr("% 4u: '%s'\n", cnt, n2 > n1 ? b2 : b1);
test_printf_stderr("%4u: '%s'\n", cnt, n2 > n1 ? b2 : b1);
} else {
if (cnt == 0 && (m1 == NULL || *m1 == '\0'))
test_string_null_empty(m1, '-');
else if (n1 > 0)
test_printf_stderr("% 4u:- '%s'\n", cnt, b1);
test_printf_stderr("%4u:- '%s'\n", cnt, b1);
if (cnt == 0 && (m2 == NULL || *m2 == '\0'))
test_string_null_empty(m2, '+');
else if (n2 > 0)
test_printf_stderr("% 4u:+ '%s'\n", cnt, b2);
test_printf_stderr("%4u:+ '%s'\n", cnt, b2);
if (diff && i > 0)
test_printf_stderr("% 4s %s\n", "", bdiff);
test_printf_stderr("%4s %s\n", "", bdiff);
}
m1 += n1;
m2 += n2;
@@ -206,6 +206,7 @@ static int convert_bn_memory(const unsigned char *in, size_t bytes,
{
int n = bytes * 2, i;
char *p = out, *q = NULL;
const char *r;
if (bn != NULL && !BN_is_zero(bn)) {
hex_convert_memory(in, bytes, out, BN_OUTPUT_SIZE);
@@ -248,10 +249,10 @@ static int convert_bn_memory(const unsigned char *in, size_t bytes,
}
*p = '\0';
if (bn == NULL)
q = "NULL";
r = "NULL";
else
q = BN_is_negative(bn) ? "-0" : "0";
strcpy(p - strlen(q), q);
r = BN_is_negative(bn) ? "-0" : "0";
strcpy(p - strlen(r), r);
return 0;
}
@@ -409,7 +410,7 @@ void test_output_bignum(const char *name, const BIGNUM *bn)
static void test_memory_null_empty(const unsigned char *m, char c)
{
if (m == NULL)
test_printf_stderr("% 4s %c%s\n", "", c, "NULL");
test_printf_stderr("%4s %c%s\n", "", c, "NULL");
else
test_printf_stderr("%04x %c%s\n", 0u, c, "empty");
}
@@ -493,7 +494,7 @@ static void test_fail_memory_common(const char *prefix, const char *file,
else if (n2 > 0)
test_printf_stderr("%04x:+%s\n", cnt, b2);
if (diff && i > 0)
test_printf_stderr("% 4s %s\n", "", bdiff);
test_printf_stderr("%4s %s\n", "", bdiff);
}
m1 += n1;
m2 += n2;
+1 -1
View File
@@ -25,7 +25,7 @@ static void check_arg_usage(void)
for (i = 0; i < n; i++)
if (!arg_used[i+1])
test_printf_stderr("Warning ignored command-line argument %d: %s\n",
test_printf_stderr("Warning ignored command-line argument %zu: %s\n",
i, args[i+1]);
if (i < arg_count)
test_printf_stderr("Warning arguments %zu and later unchecked\n", i);
+29 -5
View File
@@ -10,8 +10,25 @@
#ifndef HEADER_TU_OUTPUT_H
# define HEADER_TU_OUTPUT_H
#include <stdarg.h>
# include <stdarg.h>
# define ossl_test__attr__(x)
# if defined(__GNUC__) && defined(__STDC_VERSION__) \
&& !defined(__APPLE__)
/*
* Because we support the 'z' modifier, which made its appearance in C99,
* we can't use __attribute__ with pre C99 dialects.
*/
# if __STDC_VERSION__ >= 199901L
# undef ossl_test__attr__
# define ossl_test__attr__ __attribute__
# if __GNUC__*10 + __GNUC_MINOR__ >= 44
# define ossl_test__printf__ __gnu_printf__
# else
# define ossl_test__printf__ __printf__
# endif
# endif
# endif
/*
* The basic I/O functions used internally by the test framework. These
* can be overridden when needed. Note that if one is, then all must be.
@@ -19,14 +36,21 @@
void test_open_streams(void);
void test_close_streams(void);
/* The following ALL return the number of characters written */
int test_vprintf_stdout(const char *fmt, va_list ap);
int test_vprintf_stderr(const char *fmt, va_list ap);
int test_vprintf_stdout(const char *fmt, va_list ap)
ossl_test__attr__((__format__(ossl_test__printf__, 1, 0)));
int test_vprintf_stderr(const char *fmt, va_list ap)
ossl_test__attr__((__format__(ossl_test__printf__, 1, 0)));
/* These return failure or success */
int test_flush_stdout(void);
int test_flush_stderr(void);
/* Commodity functions. There's no need to override these */
int test_printf_stdout(const char *fmt, ...);
int test_printf_stderr(const char *fmt, ...);
int test_printf_stdout(const char *fmt, ...)
ossl_test__attr__((__format__(ossl_test__printf__, 1, 2)));
int test_printf_stderr(const char *fmt, ...)
ossl_test__attr__((__format__(ossl_test__printf__, 1, 2)));
# undef ossl_test__printf__
# undef ossl_test__attr__
#endif /* HEADER_TU_OUTPUT_H */
+2 -1
View File
@@ -86,7 +86,8 @@ static char *strip_spaces(char *p)
int test_readstanza(STANZA *s)
{
PAIR *pp = s->pairs;
char *p, *equals, *key, *value;
char *p, *equals, *key;
const char *value;
for (s->numpairs = 0; BIO_gets(s->fp, s->buff, sizeof(s->buff)); ) {
s->curr++;
+2 -1
View File
@@ -93,13 +93,14 @@ static int write_string(BIO *b, const char *buf, size_t n)
*/
static int tap_write_ex(BIO *b, const char *buf, size_t size, size_t *in_size)
{
static char empty[] = "";
BIO *next = BIO_next(b);
size_t i;
int j;
for (i = 0; i < size; i++) {
if (BIO_get_data(b) == NULL) {
BIO_set_data(b, "");
BIO_set_data(b, empty);
for (j = 0; j < subtest_level(); j++)
if (!write_string(next, " ", 1))
goto err;
+1 -1
View File
@@ -420,7 +420,7 @@ int test_BN_abs_eq_word(const char *file, int line, const char *bns,
static const char *print_time(const ASN1_TIME *t)
{
return t == NULL ? "<null>" : (char *)ASN1_STRING_get0_data(t);
return t == NULL ? "<null>" : (const char *)ASN1_STRING_get0_data(t);
}
#define DEFINE_TIME_T_COMPARISON(opname, op) \