From 1e4884f615b20946411a74e41eb9c6aa65e2d5f3 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Thu, 24 Sep 2015 10:57:52 -0700 Subject: external/boringssl: sync with upstream. This change imports the current version of BoringSSL. The only local change now is that |BORINGSSL_201509| is defined in base.h. This allows this change to be made without (hopefully) breaking the build. This change will need https://android-review.googlesource.com/172744 to be landed afterwards to update a test. Change-Id: I6d1f463f7785a2423bd846305af91c973c326104 --- src/tool/server.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/tool/server.cc') diff --git a/src/tool/server.cc b/src/tool/server.cc index 164d6a5..abc71cf 100644 --- a/src/tool/server.cc +++ b/src/tool/server.cc @@ -35,10 +35,54 @@ static const struct argument kArguments[] = { "Private-key file to use (default is server.pem)", }, { + "-ocsp-response", kOptionalArgument, + "OCSP response file to send", + }, + { "", kOptionalArgument, "", }, }; +static bool LoadOCSPResponse(SSL_CTX *ctx, const char *filename) { + void *data = NULL; + bool ret = false; + size_t bytes_read; + long length; + + FILE *f = fopen(filename, "rb"); + + if (f == NULL || + fseek(f, 0, SEEK_END) != 0) { + goto out; + } + + length = ftell(f); + if (length < 0) { + goto out; + } + + data = malloc(length); + if (data == NULL) { + goto out; + } + rewind(f); + + bytes_read = fread(data, 1, length, f); + if (ferror(f) != 0 || + bytes_read != (size_t)length || + !SSL_CTX_set_ocsp_response(ctx, (uint8_t*)data, bytes_read)) { + goto out; + } + + ret = true; +out: + if (f != NULL) { + fclose(f); + } + free(data); + return ret; +} + bool Server(const std::vector &args) { if (!InitSocketLibrary()) { return false; @@ -74,6 +118,12 @@ bool Server(const std::vector &args) { return false; } + if (args_map.count("-ocsp-response") != 0 && + !LoadOCSPResponse(ctx, args_map["-ocsp-response"].c_str())) { + fprintf(stderr, "Failed to load OCSP response: %s\n", args_map["-ocsp-response"].c_str()); + return false; + } + int sock = -1; if (!Accept(&sock, args_map["-accept"])) { return false; -- cgit v1.1