Add early data input from file.

Change-Id: I93a54e7a67acddb196ed53ce7fe49c718553948d
Reviewed-on: https://boringssl-review.googlesource.com/23604
Reviewed-by: Steven Valdez <svaldez@google.com>
Commit-Queue: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
Steven Valdez 2017-11-30 12:02:42 -05:00 committed by CQ bot account: commit-bot@chromium.org
parent fb535892e5
commit 1530ef3ec5
4 changed files with 23 additions and 19 deletions

View File

@ -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<uint8_t> 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);

View File

@ -21,14 +21,6 @@
#include "internal.h"
struct FileCloser {
void operator()(FILE *file) {
fclose(file);
}
};
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
static const struct argument kArguments[] = {
{
"-out-public", kRequiredArgument, "The file to write the public key to",

View File

@ -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<FILE, FileCloser>;
enum ArgumentType {
kRequiredArgument,
kOptionalArgument,

View File

@ -91,14 +91,6 @@ static const struct argument kArguments[] = {
},
};
struct FileCloser {
void operator()(FILE *file) {
fclose(file);
}
};
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
static bool LoadOCSPResponse(SSL_CTX *ctx, const char *filename) {
ScopedFILE f(fopen(filename, "rb"));
std::vector<uint8_t> data;