/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 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
#include <openssl/ssl.h>
#include <openssl/evp.h>
+
+#ifdef __VMS
+# pragma names save
+# pragma names as_is,shortened
+#endif
+
#include "../ssl/ssl_locl.h"
#include "../ssl/record/record_locl.h"
+#ifdef __VMS
+# pragma names restore
+#endif
+
#include "testutil.h"
-#include "test_main.h"
/*
* Based on the test vectors provided in:
static RECORD_DATA refdata[] = {
{
+ /*
+ * Server: EncryptedExtensions, Certificate, CertificateVerify and
+ * Finished
+ */
{
"0800001e001c000a00140012001d001700180019010001010102010301040000"
"00000b0001b9000001b50001b0308201ac30820115a003020102020102300d06"
"0000000000000000"
},
{
+ /* Client: Finished */
{
"1400002078367856d3c8cc4e0a95eb98906ca7a48bd3cc7029f48bd4ae0dc91a"
"b903ca8916","",""
"0000000000000000"
},
{
+ /* Server: NewSessionTicket */
{
"040000a60002a3004abe594b00924e535321cadc96238da09caf9b02fecafdd6"
"5e3e418f03e43772cf512ed8066100503b1c08abbbf298a9d138ce821dd12fe1"
"0000000000000000"
},
{
+ /* Client: Application Data */
{
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
"202122232425262728292a2b2c2d2e2f303117","",""
"0000000000000000"
},
{
+ /* Server: Application Data */
{
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
"202122232425262728292a2b2c2d2e2f303117","",""
"0000000000000001"
},
{
+ /* Client: CloseNotify */
{
"010015","",""
},
"0000000000000001"
},
{
+ /* Server: CloseNotify */
{
"010015","",""
},
else
refd = multihexstr2buf(recd->plaintext, &refdatalen);
- if (refd == NULL) {
- fprintf(stderr, "Failed to get reference data\n");
- goto err;
- }
-
- if (rec->length != refdatalen) {
- fprintf(stderr, "Unexpected length\n");
+ if (!TEST_ptr(refd)) {
+ TEST_info("Failed to get reference data");
goto err;
}
- if (memcmp(rec->data, refd, refdatalen) != 0) {
- fprintf(stderr, "Data does not match\n");
+ if (!TEST_mem_eq(rec->data, rec->length, refd, refdatalen))
goto err;
- }
ret = 1;
return ret;
}
+#define TLS13_AES_128_GCM_SHA256_BYTES ((const unsigned char *)"\x13\x01")
+
static int test_tls13_encryption(void)
{
SSL_CTX *ctx = NULL;
rec.data = NULL;
ctx = SSL_CTX_new(TLS_method());
- if (ctx == NULL) {
- fprintf(stderr, "Failed creating SSL_CTX\n");
+ if (!TEST_ptr(ctx)) {
+ TEST_info("Failed creating SSL_CTX");
goto err;
}
s = SSL_new(ctx);
- if (s == NULL) {
- fprintf(stderr, "Failed creating SSL\n");
+ if (!TEST_ptr(s)) {
+ TEST_info("Failed creating SSL");
goto err;
}
s->enc_read_ctx = EVP_CIPHER_CTX_new();
+ if (!TEST_ptr(s->enc_read_ctx))
+ goto err;
+
s->enc_write_ctx = EVP_CIPHER_CTX_new();
- if (s->enc_read_ctx == NULL || s->enc_write_ctx == NULL) {
- fprintf(stderr, "Failed creating EVP_CIPHER_CTX\n");
+ if (!TEST_ptr(s->enc_write_ctx))
+ goto err;
+
+ s->s3->tmp.new_cipher = SSL_CIPHER_find(s, TLS13_AES_128_GCM_SHA256_BYTES);
+ if (!TEST_ptr(s->s3->tmp.new_cipher)) {
+ TEST_info("Failed to find cipher");
goto err;
}
ivlen = EVP_CIPHER_iv_length(ciph);
if (!load_record(&rec, &refdata[ctr], &key, s->read_iv, ivlen,
RECORD_LAYER_get_read_sequence(&s->rlayer))) {
- fprintf(stderr, "Failed loading key into EVP_CIPHER_CTX\n");
+ TEST_error("Failed loading key into EVP_CIPHER_CTX");
goto err;
}
if (EVP_CipherInit_ex(s->enc_write_ctx, ciph, NULL, key, NULL, 1) <= 0
|| EVP_CipherInit_ex(s->enc_read_ctx, ciph, NULL, key, NULL, 0)
<= 0) {
- fprintf(stderr, "Failed loading key into EVP_CIPHER_CTX\n");
+ TEST_error("Failed loading key into EVP_CIPHER_CTX\n");
goto err;
}
/* Encrypt it */
- if (tls13_enc(s, &rec, 1, 1) != 1) {
- fprintf(stderr, "Failed to encrypt record %"OSSLzu"\n", ctr);
+ if (!TEST_size_t_eq(tls13_enc(s, &rec, 1, 1), 1)) {
+ TEST_info("Failed to encrypt record %zu", ctr);
goto err;
}
- if (!test_record(&rec, &refdata[ctr], 1)) {
- fprintf(stderr, "Record %"OSSLzu" encryption test failed\n", ctr);
+ if (!TEST_true(test_record(&rec, &refdata[ctr], 1))) {
+ TEST_info("Record %zu encryption test failed", ctr);
goto err;
}
/* Decrypt it */
- if (tls13_enc(s, &rec, 1, 0) != 1) {
- fprintf(stderr, "Failed to decrypt record %"OSSLzu"\n", ctr);
+ if (!TEST_int_eq(tls13_enc(s, &rec, 1, 0), 1)) {
+ TEST_info("Failed to decrypt record %zu", ctr);
goto err;
}
- if (!test_record(&rec, &refdata[ctr], 0)) {
- fprintf(stderr, "Record %"OSSLzu" decryption test failed\n", ctr);
+ if (!TEST_true(test_record(&rec, &refdata[ctr], 0))) {
+ TEST_info("Record %zu decryption test failed", ctr);
goto err;
}
seq = NULL;
}
- fprintf(stderr, "PASS: %"OSSLzu" records tested\n", ctr);
+ TEST_note("PASS: %zu records tested", ctr);
ret = 1;
err: