From 1530ef3ec56f6a921ba9728489daa472456a3e8e Mon Sep 17 00:00:00 2001 From: Steven Valdez Date: Thu, 30 Nov 2017 12:02:42 -0500 Subject: [PATCH] Add early data input from file. Change-Id: I93a54e7a67acddb196ed53ce7fe49c718553948d Reviewed-on: https://boringssl-review.googlesource.com/23604 Reviewed-by: Steven Valdez Commit-Queue: Steven Valdez CQ-Verified: CQ bot account: commit-bot@chromium.org --- tool/client.cc | 18 +++++++++++++++--- tool/generate_ed25519.cc | 8 -------- tool/internal.h | 8 ++++++++ tool/server.cc | 8 -------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/tool/client.cc b/tool/client.cc index 57e1b6e6..fa279ae5 100644 --- a/tool/client.cc +++ b/tool/client.cc @@ -122,7 +122,8 @@ static const struct argument kArguments[] = { }, { "-early-data", kOptionalArgument, "Enable early data. The argument to " - "this flag is the early data to send.", + "this flag is the early data to send or if it starts with '@', the " + "file to read from for early data.", }, { "-tls13-variant", kOptionalArgument, @@ -299,8 +300,19 @@ static bool DoConnection(SSL_CTX *ctx, } if (args_map.count("-early-data") != 0 && SSL_in_early_data(ssl.get())) { - int ed_size = args_map["-early-data"].size(); - int ssl_ret = SSL_write(ssl.get(), args_map["-early-data"].data(), ed_size); + std::string early_data = args_map["-early-data"]; + if (early_data.size() > 0 && early_data[0] == '@') { + const char *filename = early_data.c_str() + 1; + std::vector data; + ScopedFILE f(fopen(filename, "rb")); + if (f == nullptr || !ReadAll(&data, f.get())) { + fprintf(stderr, "Error reading %s.\n", filename); + return false; + } + early_data = std::string(data.begin(), data.end()); + } + int ed_size = early_data.size(); + int ssl_ret = SSL_write(ssl.get(), early_data.data(), ed_size); if (ssl_ret <= 0) { int ssl_err = SSL_get_error(ssl.get(), ssl_ret); fprintf(stderr, "Error while writing: %d\n", ssl_err); diff --git a/tool/generate_ed25519.cc b/tool/generate_ed25519.cc index 35b57b99..6499dbea 100644 --- a/tool/generate_ed25519.cc +++ b/tool/generate_ed25519.cc @@ -21,14 +21,6 @@ #include "internal.h" -struct FileCloser { - void operator()(FILE *file) { - fclose(file); - } -}; - -using ScopedFILE = std::unique_ptr; - static const struct argument kArguments[] = { { "-out-public", kRequiredArgument, "The file to write the public key to", diff --git a/tool/internal.h b/tool/internal.h index a6c8ecab..b626270f 100644 --- a/tool/internal.h +++ b/tool/internal.h @@ -44,6 +44,14 @@ OPENSSL_MSVC_PRAGMA(warning(pop)) #define BORINGSSL_WRITE write #endif +struct FileCloser { + void operator()(FILE *file) { + fclose(file); + } +}; + +using ScopedFILE = std::unique_ptr; + enum ArgumentType { kRequiredArgument, kOptionalArgument, diff --git a/tool/server.cc b/tool/server.cc index 63d77e9a..99638852 100644 --- a/tool/server.cc +++ b/tool/server.cc @@ -91,14 +91,6 @@ static const struct argument kArguments[] = { }, }; -struct FileCloser { - void operator()(FILE *file) { - fclose(file); - } -}; - -using ScopedFILE = std::unique_ptr; - static bool LoadOCSPResponse(SSL_CTX *ctx, const char *filename) { ScopedFILE f(fopen(filename, "rb")); std::vector data;