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-12-12 23:17:51 +00:00
|
|
|
#include <stdlib.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 {
|
|
|
|
|
2014-12-12 23:17:51 +00:00
|
|
|
template <typename T>
|
|
|
|
struct Flag {
|
2014-08-12 00:51:50 +01:00
|
|
|
const char *flag;
|
2014-12-12 23:17:51 +00:00
|
|
|
T TestConfig::*member;
|
2014-08-12 00:51:50 +01:00
|
|
|
};
|
|
|
|
|
2014-12-12 23:17:51 +00:00
|
|
|
// FindField looks for the flag in |flags| that matches |flag|. If one is found,
|
|
|
|
// it returns a pointer to the corresponding field in |config|. Otherwise, it
|
|
|
|
// returns NULL.
|
|
|
|
template<typename T, size_t N>
|
|
|
|
T *FindField(TestConfig *config, const Flag<T> (&flags)[N], const char *flag) {
|
|
|
|
for (size_t i = 0; i < N; i++) {
|
|
|
|
if (strcmp(flag, flags[i].flag) == 0) {
|
|
|
|
return &(config->*(flags[i].member));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-12 00:51:50 +01:00
|
|
|
|
2014-12-12 23:17:51 +00:00
|
|
|
const Flag<bool> kBoolFlags[] = {
|
2014-08-12 00:51:50 +01:00
|
|
|
{ "-server", &TestConfig::is_server },
|
2014-08-11 23:43:38 +01:00
|
|
|
{ "-dtls", &TestConfig::is_dtls },
|
2014-08-12 00:51:50 +01:00
|
|
|
{ "-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 },
|
2016-05-24 17:31:07 +01:00
|
|
|
{ "-no-tls13", &TestConfig::no_tls13 },
|
2014-08-12 00:51:50 +01:00
|
|
|
{ "-no-tls12", &TestConfig::no_tls12 },
|
|
|
|
{ "-no-tls11", &TestConfig::no_tls11 },
|
|
|
|
{ "-no-tls1", &TestConfig::no_tls1 },
|
|
|
|
{ "-no-ssl3", &TestConfig::no_ssl3 },
|
2016-07-11 18:19:03 +01:00
|
|
|
{ "-enable-channel-id", &TestConfig::enable_channel_id },
|
2014-08-24 08:47:07 +01:00
|
|
|
{ "-shim-writes-first", &TestConfig::shim_writes_first },
|
2014-09-24 20:21:44 +01:00
|
|
|
{ "-expect-session-miss", &TestConfig::expect_session_miss },
|
2016-03-17 21:49:56 +00:00
|
|
|
{ "-decline-alpn", &TestConfig::decline_alpn },
|
2014-10-11 00:23:43 +01:00
|
|
|
{ "-expect-extended-master-secret",
|
|
|
|
&TestConfig::expect_extended_master_secret },
|
2014-11-25 06:55:35 +00:00
|
|
|
{ "-enable-ocsp-stapling", &TestConfig::enable_ocsp_stapling },
|
|
|
|
{ "-enable-signed-cert-timestamps",
|
|
|
|
&TestConfig::enable_signed_cert_timestamps },
|
2015-02-09 00:33:25 +00:00
|
|
|
{ "-implicit-handshake", &TestConfig::implicit_handshake },
|
2015-02-24 06:23:21 +00:00
|
|
|
{ "-use-early-callback", &TestConfig::use_early_callback },
|
|
|
|
{ "-fail-early-callback", &TestConfig::fail_early_callback },
|
2015-02-21 00:04:00 +00:00
|
|
|
{ "-install-ddos-callback", &TestConfig::install_ddos_callback },
|
|
|
|
{ "-fail-ddos-callback", &TestConfig::fail_ddos_callback },
|
|
|
|
{ "-fail-second-ddos-callback", &TestConfig::fail_second_ddos_callback },
|
2016-11-14 13:02:50 +00:00
|
|
|
{ "-fail-cert-callback", &TestConfig::fail_cert_callback },
|
2015-04-03 00:57:35 +01:00
|
|
|
{ "-handshake-never-done", &TestConfig::handshake_never_done },
|
2015-04-03 09:06:36 +01:00
|
|
|
{ "-use-export-context", &TestConfig::use_export_context },
|
2015-06-03 17:57:23 +01:00
|
|
|
{ "-tls-unique", &TestConfig::tls_unique },
|
2015-06-18 23:36:15 +01:00
|
|
|
{ "-expect-ticket-renewal", &TestConfig::expect_ticket_renewal },
|
|
|
|
{ "-expect-no-session", &TestConfig::expect_no_session },
|
2017-10-11 17:29:36 +01:00
|
|
|
{ "-expect-ticket-supports-early-data",
|
|
|
|
&TestConfig::expect_ticket_supports_early_data },
|
2015-06-16 19:16:23 +01:00
|
|
|
{ "-use-ticket-callback", &TestConfig::use_ticket_callback },
|
|
|
|
{ "-renew-ticket", &TestConfig::renew_ticket },
|
2016-12-07 20:29:45 +00:00
|
|
|
{ "-enable-early-data", &TestConfig::enable_early_data },
|
2015-07-31 02:10:13 +01:00
|
|
|
{ "-enable-client-custom-extension",
|
|
|
|
&TestConfig::enable_client_custom_extension },
|
|
|
|
{ "-enable-server-custom-extension",
|
|
|
|
&TestConfig::enable_server_custom_extension },
|
|
|
|
{ "-custom-extension-skip", &TestConfig::custom_extension_skip },
|
|
|
|
{ "-custom-extension-fail-add", &TestConfig::custom_extension_fail_add },
|
2015-08-30 03:56:45 +01:00
|
|
|
{ "-check-close-notify", &TestConfig::check_close_notify },
|
|
|
|
{ "-shim-shuts-down", &TestConfig::shim_shuts_down },
|
2015-08-18 12:21:54 +01:00
|
|
|
{ "-verify-fail", &TestConfig::verify_fail },
|
|
|
|
{ "-verify-peer", &TestConfig::verify_peer },
|
2017-07-01 15:50:56 +01:00
|
|
|
{ "-verify-peer-if-no-obc", &TestConfig::verify_peer_if_no_obc },
|
2015-10-13 00:54:18 +01:00
|
|
|
{ "-expect-verify-result", &TestConfig::expect_verify_result },
|
|
|
|
{ "-renegotiate-once", &TestConfig::renegotiate_once },
|
|
|
|
{ "-renegotiate-freely", &TestConfig::renegotiate_freely },
|
2015-11-03 21:34:10 +00:00
|
|
|
{ "-renegotiate-ignore", &TestConfig::renegotiate_ignore },
|
2018-05-01 22:14:27 +01:00
|
|
|
{ "-forbid-renegotiation-after-handshake",
|
|
|
|
&TestConfig::forbid_renegotiation_after_handshake },
|
2015-11-02 17:11:35 +00:00
|
|
|
{ "-p384-only", &TestConfig::p384_only },
|
2015-12-19 01:55:44 +00:00
|
|
|
{ "-enable-all-curves", &TestConfig::enable_all_curves },
|
2016-03-10 14:15:01 +00:00
|
|
|
{ "-use-old-client-cert-callback",
|
|
|
|
&TestConfig::use_old_client_cert_callback },
|
2016-07-26 23:03:08 +01:00
|
|
|
{ "-send-alert", &TestConfig::send_alert },
|
2016-09-19 18:08:16 +01:00
|
|
|
{ "-peek-then-read", &TestConfig::peek_then_read },
|
2016-09-03 02:35:25 +01:00
|
|
|
{ "-enable-grease", &TestConfig::enable_grease },
|
2016-11-01 23:45:06 +00:00
|
|
|
{ "-use-exporter-between-reads", &TestConfig::use_exporter_between_reads },
|
2017-08-24 07:01:37 +01:00
|
|
|
{ "-retain-only-sha256-client-cert",
|
|
|
|
&TestConfig::retain_only_sha256_client_cert },
|
|
|
|
{ "-expect-sha256-client-cert",
|
|
|
|
&TestConfig::expect_sha256_client_cert },
|
2017-01-02 04:19:22 +00:00
|
|
|
{ "-read-with-unfinished-write", &TestConfig::read_with_unfinished_write },
|
2017-01-03 15:49:28 +00:00
|
|
|
{ "-expect-secure-renegotiation",
|
|
|
|
&TestConfig::expect_secure_renegotiation },
|
|
|
|
{ "-expect-no-secure-renegotiation",
|
|
|
|
&TestConfig::expect_no_secure_renegotiation },
|
2017-01-28 06:39:29 +00:00
|
|
|
{ "-expect-session-id", &TestConfig::expect_session_id },
|
|
|
|
{ "-expect-no-session-id", &TestConfig::expect_no_session_id },
|
2017-01-11 16:34:52 +00:00
|
|
|
{ "-expect-accept-early-data", &TestConfig::expect_accept_early_data },
|
|
|
|
{ "-expect-reject-early-data", &TestConfig::expect_reject_early_data },
|
2017-10-17 20:48:46 +01:00
|
|
|
{ "-expect-no-offer-early-data", &TestConfig::expect_no_offer_early_data },
|
2017-03-26 21:13:51 +01:00
|
|
|
{ "-no-op-extra-handshake", &TestConfig::no_op_extra_handshake },
|
|
|
|
{ "-handshake-twice", &TestConfig::handshake_twice },
|
2017-04-04 18:52:36 +01:00
|
|
|
{ "-allow-unknown-alpn-protos", &TestConfig::allow_unknown_alpn_protos },
|
2017-03-28 21:38:29 +01:00
|
|
|
{ "-enable-ed25519", &TestConfig::enable_ed25519 },
|
2017-07-11 21:13:10 +01:00
|
|
|
{ "-use-custom-verify-callback", &TestConfig::use_custom_verify_callback },
|
2017-12-01 18:05:12 +00:00
|
|
|
{ "-allow-false-start-without-alpn",
|
|
|
|
&TestConfig::allow_false_start_without_alpn },
|
2017-12-18 23:00:23 +00:00
|
|
|
{ "-expect-draft-downgrade", &TestConfig::expect_draft_downgrade },
|
2018-01-26 17:17:53 +00:00
|
|
|
{ "-handoff", &TestConfig::handoff },
|
2018-02-28 21:35:39 +00:00
|
|
|
{ "-expect-dummy-pq-padding", &TestConfig::expect_dummy_pq_padding },
|
2018-04-08 18:59:25 +01:00
|
|
|
{ "-no-rsa-pss-rsae-certs", &TestConfig::no_rsa_pss_rsae_certs },
|
2018-05-11 00:55:02 +01:00
|
|
|
{ "-use-ocsp-callback", &TestConfig::use_ocsp_callback },
|
|
|
|
{ "-set-ocsp-in-callback", &TestConfig::set_ocsp_in_callback },
|
|
|
|
{ "-decline-ocsp-callback", &TestConfig::decline_ocsp_callback },
|
|
|
|
{ "-fail-ocsp-callback", &TestConfig::fail_ocsp_callback },
|
2014-08-12 00:51:50 +01:00
|
|
|
};
|
|
|
|
|
2014-12-12 23:17:51 +00:00
|
|
|
const Flag<std::string> kStringFlags[] = {
|
2017-07-01 00:11:22 +01:00
|
|
|
{ "-write-settings", &TestConfig::write_settings },
|
2014-08-12 00:51:50 +01:00
|
|
|
{ "-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 },
|
2017-03-09 19:56:07 +00:00
|
|
|
{ "-expect-late-alpn", &TestConfig::expected_late_alpn },
|
2014-09-06 17:58:58 +01:00
|
|
|
{ "-expect-advertised-alpn", &TestConfig::expected_advertised_alpn },
|
|
|
|
{ "-select-alpn", &TestConfig::select_alpn },
|
2014-10-27 05:06:24 +00:00
|
|
|
{ "-psk", &TestConfig::psk },
|
|
|
|
{ "-psk-identity", &TestConfig::psk_identity },
|
2014-11-16 00:06:08 +00:00
|
|
|
{ "-srtp-profiles", &TestConfig::srtp_profiles },
|
2015-03-16 19:16:23 +00:00
|
|
|
{ "-cipher", &TestConfig::cipher },
|
2015-04-03 09:06:36 +01:00
|
|
|
{ "-export-label", &TestConfig::export_label },
|
|
|
|
{ "-export-context", &TestConfig::export_context },
|
2016-11-15 01:16:54 +00:00
|
|
|
{ "-expect-peer-cert-file", &TestConfig::expect_peer_cert_file },
|
2017-02-28 21:45:39 +00:00
|
|
|
{ "-use-client-ca-list", &TestConfig::use_client_ca_list },
|
|
|
|
{ "-expect-client-ca-list", &TestConfig::expected_client_ca_list },
|
2017-08-01 23:38:41 +01:00
|
|
|
{ "-expect-msg-callback", &TestConfig::expect_msg_callback },
|
2014-08-12 00:51:50 +01:00
|
|
|
};
|
|
|
|
|
2014-12-12 23:17:51 +00:00
|
|
|
const Flag<std::string> kBase64Flags[] = {
|
2014-08-24 06:25:27 +01:00
|
|
|
{ "-expect-certificate-types", &TestConfig::expected_certificate_types },
|
2014-08-24 06:46:07 +01:00
|
|
|
{ "-expect-channel-id", &TestConfig::expected_channel_id },
|
2017-09-21 23:02:22 +01:00
|
|
|
{ "-token-binding-params", &TestConfig::send_token_binding_params },
|
2014-11-25 06:55:35 +00:00
|
|
|
{ "-expect-ocsp-response", &TestConfig::expected_ocsp_response },
|
|
|
|
{ "-expect-signed-cert-timestamps",
|
|
|
|
&TestConfig::expected_signed_cert_timestamps },
|
2015-08-12 11:47:11 +01:00
|
|
|
{ "-ocsp-response", &TestConfig::ocsp_response },
|
2015-09-09 13:44:55 +01:00
|
|
|
{ "-signed-cert-timestamps", &TestConfig::signed_cert_timestamps },
|
2016-11-01 17:58:25 +00:00
|
|
|
{ "-ticket-key", &TestConfig::ticket_key },
|
2017-12-22 23:50:43 +00:00
|
|
|
{ "-quic-transport-params", &TestConfig::quic_transport_params },
|
|
|
|
{ "-expected-quic-transport-params",
|
|
|
|
&TestConfig::expected_quic_transport_params },
|
2014-08-24 06:25:27 +01:00
|
|
|
};
|
|
|
|
|
2014-12-12 23:17:51 +00:00
|
|
|
const Flag<int> kIntFlags[] = {
|
Use TCP sockets rather than socketpairs in the SSL tests.
This involves more synchronization with child exits as the kernel no longer
closes the pre-created pipes for free, but it works on Windows. As long as
TCP_NODELAY is set, the performance seems comparable. Though it does involve
dealing with graceful socket shutdown. I couldn't get that to work on Windows
without draining the socket; not even SO_LINGER worked. Current (untested)
theory is that Windows refuses to gracefully shutdown a socket if the peer
sends data after we've stopped reading.
cmd.ExtraFiles doesn't work on Windows; it doesn't use fds natively, so you
can't pass fds 4 and 5. (stdin/stdout/stderr are special slots in
CreateProcess.) We can instead use the syscall module directly and mark handles
as inheritable (and then pass the numerical values out-of-band), but that
requires synchronizing all of our shim.Start() calls and assuming no other
thread is spawning a process.
PROC_THREAD_ATTRIBUTE_HANDLE_LIST fixes threading problems, but requires
wrapping more syscalls. exec.Cmd also doesn't let us launch the process
ourselves. Plus it still requires every handle in the list be marked
inheritable, so it doesn't help if some other thread is launching a process
with bInheritHandles TRUE but NOT using PROC_THREAD_ATTRIBUTE_HANDLE_LIST.
(Like Go, though we can take syscall.ForkLock there.)
http://blogs.msdn.com/b/oldnewthing/archive/2011/12/16/10248328.aspx
The more natively Windows option seems to be named pipes, but that too requires
wrapping more system calls. (To be fair, that isn't too painful.) They also
involve a listening server, so we'd still have to synchronize with shim.Wait()
a la net.TCPListener.
Then there's DuplicateHandle, but then we need an out-of-band signal.
All in all, one cross-platform implementation with a TCP sockets seems
simplest.
Change-Id: I38233e309a0fa6814baf61e806732138902347c0
Reviewed-on: https://boringssl-review.googlesource.com/3563
Reviewed-by: Adam Langley <agl@google.com>
2015-02-21 06:54:29 +00:00
|
|
|
{ "-port", &TestConfig::port },
|
2016-08-17 05:51:00 +01:00
|
|
|
{ "-resume-count", &TestConfig::resume_count },
|
2017-09-21 23:02:22 +01:00
|
|
|
{ "-expected-token-binding-param",
|
|
|
|
&TestConfig::expected_token_binding_param },
|
2014-12-12 23:17:51 +00:00
|
|
|
{ "-min-version", &TestConfig::min_version },
|
|
|
|
{ "-max-version", &TestConfig::max_version },
|
2017-07-07 18:17:19 +01:00
|
|
|
{ "-expect-version", &TestConfig::expect_version },
|
2015-01-11 21:29:36 +00:00
|
|
|
{ "-mtu", &TestConfig::mtu },
|
2017-12-08 22:05:06 +00:00
|
|
|
{ "-export-early-keying-material",
|
|
|
|
&TestConfig::export_early_keying_material },
|
2015-04-03 09:06:36 +01:00
|
|
|
{ "-export-keying-material", &TestConfig::export_keying_material },
|
2015-10-13 00:49:00 +01:00
|
|
|
{ "-expect-total-renegotiations", &TestConfig::expect_total_renegotiations },
|
2016-06-21 23:19:24 +01:00
|
|
|
{ "-expect-peer-signature-algorithm",
|
|
|
|
&TestConfig::expect_peer_signature_algorithm },
|
2016-06-30 19:55:33 +01:00
|
|
|
{ "-expect-curve-id", &TestConfig::expect_curve_id },
|
2016-05-11 03:30:28 +01:00
|
|
|
{ "-initial-timeout-duration-ms", &TestConfig::initial_timeout_duration_ms },
|
2016-09-27 00:57:53 +01:00
|
|
|
{ "-max-cert-list", &TestConfig::max_cert_list },
|
2016-10-31 23:20:42 +00:00
|
|
|
{ "-expect-cipher-aes", &TestConfig::expect_cipher_aes },
|
|
|
|
{ "-expect-cipher-no-aes", &TestConfig::expect_cipher_no_aes },
|
2016-11-01 17:39:36 +00:00
|
|
|
{ "-resumption-delay", &TestConfig::resumption_delay },
|
2017-01-06 21:19:28 +00:00
|
|
|
{ "-max-send-fragment", &TestConfig::max_send_fragment },
|
|
|
|
{ "-read-size", &TestConfig::read_size },
|
2017-03-03 20:05:56 +00:00
|
|
|
{ "-expect-ticket-age-skew", &TestConfig::expect_ticket_age_skew },
|
2017-06-13 17:45:25 +01:00
|
|
|
{ "-tls13-variant", &TestConfig::tls13_variant },
|
2017-12-30 16:04:39 +00:00
|
|
|
{ "-dummy-pq-padding-len", &TestConfig::dummy_pq_padding_len },
|
2014-12-12 23:17:51 +00:00
|
|
|
};
|
2014-08-24 06:25:27 +01:00
|
|
|
|
2016-07-14 17:51:01 +01:00
|
|
|
const Flag<std::vector<int>> kIntVectorFlags[] = {
|
|
|
|
{ "-signing-prefs", &TestConfig::signing_prefs },
|
2017-04-14 22:05:40 +01:00
|
|
|
{ "-verify-prefs", &TestConfig::verify_prefs },
|
2016-07-14 17:51:01 +01:00
|
|
|
};
|
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
bool ParseFlag(char *flag, int argc, char **argv, int *i,
|
|
|
|
bool skip, TestConfig *out_config) {
|
|
|
|
bool *bool_field = FindField(out_config, kBoolFlags, flag);
|
|
|
|
if (bool_field != NULL) {
|
|
|
|
if (!skip) {
|
|
|
|
*bool_field = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-09 17:12:58 +01:00
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
std::string *string_field = FindField(out_config, kStringFlags, flag);
|
|
|
|
if (string_field != NULL) {
|
|
|
|
*i = *i + 1;
|
|
|
|
if (*i >= argc) {
|
|
|
|
fprintf(stderr, "Missing parameter\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!skip) {
|
|
|
|
string_field->assign(argv[*i]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-12 00:51:50 +01:00
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
std::string *base64_field = FindField(out_config, kBase64Flags, flag);
|
|
|
|
if (base64_field != NULL) {
|
|
|
|
*i = *i + 1;
|
|
|
|
if (*i >= argc) {
|
|
|
|
fprintf(stderr, "Missing parameter\n");
|
|
|
|
return false;
|
2017-05-09 17:12:58 +01:00
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
size_t len;
|
|
|
|
if (!EVP_DecodedLength(&len, strlen(argv[*i]))) {
|
|
|
|
fprintf(stderr, "Invalid base64: %s\n", argv[*i]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!skip) {
|
|
|
|
base64_field->assign(reinterpret_cast<const char *>(decoded.get()),
|
|
|
|
len);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-09 17:12:58 +01:00
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
int *int_field = FindField(out_config, kIntFlags, flag);
|
|
|
|
if (int_field) {
|
|
|
|
*i = *i + 1;
|
|
|
|
if (*i >= argc) {
|
|
|
|
fprintf(stderr, "Missing parameter\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!skip) {
|
|
|
|
*int_field = atoi(argv[*i]);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-12 00:51:50 +01:00
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
std::vector<int> *int_vector_field =
|
|
|
|
FindField(out_config, kIntVectorFlags, flag);
|
|
|
|
if (int_vector_field) {
|
|
|
|
*i = *i + 1;
|
|
|
|
if (*i >= argc) {
|
|
|
|
fprintf(stderr, "Missing parameter\n");
|
|
|
|
return false;
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
// Each instance of the flag adds to the list.
|
|
|
|
if (!skip) {
|
|
|
|
int_vector_field->push_back(atoi(argv[*i]));
|
2014-12-12 23:17:51 +00:00
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "Unknown argument: %s\n", flag);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char kInit[] = "-on-initial";
|
|
|
|
const char kResume[] = "-on-resume";
|
|
|
|
const char kRetry[] = "-on-retry";
|
2014-12-12 23:17:51 +00:00
|
|
|
|
2017-03-09 19:56:07 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool ParseConfig(int argc, char **argv,
|
|
|
|
TestConfig *out_initial,
|
|
|
|
TestConfig *out_resume,
|
|
|
|
TestConfig *out_retry) {
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
bool skip = false;
|
|
|
|
char *flag = argv[i];
|
|
|
|
if (strncmp(flag, kInit, strlen(kInit)) == 0) {
|
|
|
|
if (!ParseFlag(flag + strlen(kInit), argc, argv, &i, skip, out_initial)) {
|
2014-12-12 23:17:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
} else if (strncmp(flag, kResume, strlen(kResume)) == 0) {
|
|
|
|
if (!ParseFlag(flag + strlen(kResume), argc, argv, &i, skip,
|
|
|
|
out_resume)) {
|
|
|
|
return false;
|
2017-05-09 17:12:58 +01:00
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
} else if (strncmp(flag, kRetry, strlen(kRetry)) == 0) {
|
|
|
|
if (!ParseFlag(flag + strlen(kRetry), argc, argv, &i, skip, out_retry)) {
|
2016-07-14 17:51:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
} else {
|
|
|
|
int i_init = i;
|
|
|
|
int i_resume = i;
|
|
|
|
if (!ParseFlag(flag, argc, argv, &i_init, skip, out_initial) ||
|
|
|
|
!ParseFlag(flag, argc, argv, &i_resume, skip, out_resume) ||
|
|
|
|
!ParseFlag(flag, argc, argv, &i, skip, out_retry)) {
|
|
|
|
return false;
|
2017-05-09 17:12:58 +01:00
|
|
|
}
|
2016-07-14 17:51:01 +01:00
|
|
|
}
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|