2014-08-12 00:51:50 +01:00
|
|
|
/* Copyright (c) 2014, Google Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
|
|
|
|
#include "test_config.h"
|
|
|
|
|
2014-09-30 12:44:15 +01:00
|
|
|
#include <stdio.h>
|
2014-08-12 00:51:50 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2014-08-24 06:25:27 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <openssl/base64.h>
|
2014-08-12 00:51:50 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef bool TestConfig::*BoolMember;
|
|
|
|
typedef std::string TestConfig::*StringMember;
|
|
|
|
|
|
|
|
struct BoolFlag {
|
|
|
|
const char *flag;
|
|
|
|
BoolMember member;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StringFlag {
|
|
|
|
const char *flag;
|
|
|
|
StringMember member;
|
|
|
|
};
|
|
|
|
|
|
|
|
const BoolFlag kBoolFlags[] = {
|
|
|
|
{ "-server", &TestConfig::is_server },
|
2014-08-11 23:43:38 +01:00
|
|
|
{ "-dtls", &TestConfig::is_dtls },
|
2014-08-12 00:51:50 +01:00
|
|
|
{ "-resume", &TestConfig::resume },
|
|
|
|
{ "-fallback-scsv", &TestConfig::fallback_scsv },
|
|
|
|
{ "-require-any-client-certificate",
|
|
|
|
&TestConfig::require_any_client_certificate },
|
|
|
|
{ "-false-start", &TestConfig::false_start },
|
|
|
|
{ "-async", &TestConfig::async },
|
|
|
|
{ "-write-different-record-sizes",
|
|
|
|
&TestConfig::write_different_record_sizes },
|
|
|
|
{ "-cbc-record-splitting", &TestConfig::cbc_record_splitting },
|
|
|
|
{ "-partial-write", &TestConfig::partial_write },
|
|
|
|
{ "-no-tls12", &TestConfig::no_tls12 },
|
|
|
|
{ "-no-tls11", &TestConfig::no_tls11 },
|
|
|
|
{ "-no-tls1", &TestConfig::no_tls1 },
|
|
|
|
{ "-no-ssl3", &TestConfig::no_ssl3 },
|
2014-08-11 23:43:38 +01:00
|
|
|
{ "-cookie-exchange", &TestConfig::cookie_exchange },
|
2014-08-24 08:47:07 +01:00
|
|
|
{ "-shim-writes-first", &TestConfig::shim_writes_first },
|
2014-08-31 05:59:27 +01:00
|
|
|
{ "-tls-d5-bug", &TestConfig::tls_d5_bug },
|
2014-09-24 20:21:44 +01:00
|
|
|
{ "-expect-session-miss", &TestConfig::expect_session_miss },
|
2014-10-11 00:23:43 +01:00
|
|
|
{ "-expect-extended-master-secret",
|
|
|
|
&TestConfig::expect_extended_master_secret },
|
2014-08-12 00:51:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const size_t kNumBoolFlags = sizeof(kBoolFlags) / sizeof(kBoolFlags[0]);
|
|
|
|
|
|
|
|
const StringFlag kStringFlags[] = {
|
|
|
|
{ "-key-file", &TestConfig::key_file },
|
|
|
|
{ "-cert-file", &TestConfig::cert_file },
|
|
|
|
{ "-expect-server-name", &TestConfig::expected_server_name },
|
|
|
|
{ "-advertise-npn", &TestConfig::advertise_npn },
|
|
|
|
{ "-expect-next-proto", &TestConfig::expected_next_proto },
|
|
|
|
{ "-select-next-proto", &TestConfig::select_next_proto },
|
2014-08-24 06:46:07 +01:00
|
|
|
{ "-send-channel-id", &TestConfig::send_channel_id },
|
2014-09-06 17:45:15 +01:00
|
|
|
{ "-host-name", &TestConfig::host_name },
|
2014-09-06 17:58:58 +01:00
|
|
|
{ "-advertise-alpn", &TestConfig::advertise_alpn },
|
|
|
|
{ "-expect-alpn", &TestConfig::expected_alpn },
|
|
|
|
{ "-expect-advertised-alpn", &TestConfig::expected_advertised_alpn },
|
|
|
|
{ "-select-alpn", &TestConfig::select_alpn },
|
2014-08-12 00:51:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const size_t kNumStringFlags = sizeof(kStringFlags) / sizeof(kStringFlags[0]);
|
|
|
|
|
2014-08-24 06:25:27 +01:00
|
|
|
const StringFlag kBase64Flags[] = {
|
|
|
|
{ "-expect-certificate-types", &TestConfig::expected_certificate_types },
|
2014-08-24 06:46:07 +01:00
|
|
|
{ "-expect-channel-id", &TestConfig::expected_channel_id },
|
2014-08-24 06:25:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const size_t kNumBase64Flags = sizeof(kBase64Flags) / sizeof(kBase64Flags[0]);
|
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TestConfig::TestConfig()
|
|
|
|
: is_server(false),
|
2014-08-11 23:43:38 +01:00
|
|
|
is_dtls(false),
|
2014-08-12 00:51:50 +01:00
|
|
|
resume(false),
|
|
|
|
fallback_scsv(false),
|
|
|
|
require_any_client_certificate(false),
|
|
|
|
false_start(false),
|
|
|
|
async(false),
|
|
|
|
write_different_record_sizes(false),
|
|
|
|
cbc_record_splitting(false),
|
|
|
|
partial_write(false),
|
|
|
|
no_tls12(false),
|
|
|
|
no_tls11(false),
|
|
|
|
no_tls1(false),
|
2014-08-11 23:43:38 +01:00
|
|
|
no_ssl3(false),
|
2014-08-24 08:47:07 +01:00
|
|
|
cookie_exchange(false),
|
2014-08-31 05:59:27 +01:00
|
|
|
shim_writes_first(false),
|
2014-09-24 20:21:44 +01:00
|
|
|
tls_d5_bug(false),
|
2014-10-11 00:23:43 +01:00
|
|
|
expect_session_miss(false),
|
|
|
|
expect_extended_master_secret(false) {
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseConfig(int argc, char **argv, TestConfig *out_config) {
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < kNumBoolFlags; j++) {
|
|
|
|
if (strcmp(argv[i], kBoolFlags[j].flag) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j < kNumBoolFlags) {
|
|
|
|
out_config->*(kBoolFlags[j].member) = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < kNumStringFlags; j++) {
|
|
|
|
if (strcmp(argv[i], kStringFlags[j].flag) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j < kNumStringFlags) {
|
|
|
|
i++;
|
|
|
|
if (i >= argc) {
|
|
|
|
fprintf(stderr, "Missing parameter\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
out_config->*(kStringFlags[j].member) = argv[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-24 06:25:27 +01:00
|
|
|
for (j = 0; j < kNumBase64Flags; j++) {
|
|
|
|
if (strcmp(argv[i], kBase64Flags[j].flag) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j < kNumBase64Flags) {
|
|
|
|
i++;
|
|
|
|
if (i >= argc) {
|
|
|
|
fprintf(stderr, "Missing parameter\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
size_t len;
|
|
|
|
if (!EVP_DecodedLength(&len, strlen(argv[i]))) {
|
|
|
|
fprintf(stderr, "Invalid base64: %s\n", argv[i]);
|
|
|
|
}
|
|
|
|
std::unique_ptr<uint8_t[]> decoded(new uint8_t[len]);
|
|
|
|
if (!EVP_DecodeBase64(decoded.get(), &len, len,
|
|
|
|
reinterpret_cast<const uint8_t *>(argv[i]),
|
|
|
|
strlen(argv[i]))) {
|
|
|
|
fprintf(stderr, "Invalid base64: %s\n", argv[i]);
|
|
|
|
}
|
|
|
|
out_config->*(kBase64Flags[j].member) = std::string(
|
|
|
|
reinterpret_cast<const char *>(decoded.get()), len);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
fprintf(stderr, "Unknown argument: %s\n", argv[i]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|