2014-07-02 00:53:04 +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. */
|
|
|
|
|
2014-07-31 23:23:51 +01:00
|
|
|
#include <openssl/base.h>
|
|
|
|
|
|
|
|
#if !defined(OPENSSL_WINDOWS)
|
2014-07-02 00:53:04 +01:00
|
|
|
#include <arpa/inet.h>
|
2014-07-23 00:20:02 +01:00
|
|
|
#include <netinet/in.h>
|
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
|
|
|
#include <netinet/tcp.h>
|
2014-07-23 00:20:02 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/socket.h>
|
2014-07-09 14:30:38 +01:00
|
|
|
#include <unistd.h>
|
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
|
|
|
#else
|
|
|
|
#include <io.h>
|
|
|
|
#pragma warning(push, 3)
|
|
|
|
#include <WinSock2.h>
|
|
|
|
#include <WS2tcpip.h>
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
|
|
|
#pragma comment(lib, "Ws2_32.lib")
|
2014-07-31 23:23:51 +01:00
|
|
|
#endif
|
|
|
|
|
2015-01-31 01:08:37 +00:00
|
|
|
#include <string.h>
|
2014-07-31 23:23:51 +01:00
|
|
|
#include <sys/types.h>
|
2014-07-02 00:53:04 +01:00
|
|
|
|
|
|
|
#include <openssl/bio.h>
|
2014-10-27 05:06:24 +00:00
|
|
|
#include <openssl/buf.h>
|
2014-07-09 14:30:38 +01:00
|
|
|
#include <openssl/bytestring.h>
|
2014-07-23 00:20:02 +01:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
2014-08-05 07:28:57 +01:00
|
|
|
#include "async_bio.h"
|
2014-08-11 23:43:38 +01:00
|
|
|
#include "packeted_bio.h"
|
2015-02-09 07:37:18 +00:00
|
|
|
#include "scoped_types.h"
|
2014-08-12 00:51:50 +01:00
|
|
|
#include "test_config.h"
|
2014-08-05 07:28:57 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
#if !defined(OPENSSL_WINDOWS)
|
|
|
|
static int closesocket(int sock) {
|
|
|
|
return close(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintSocketError(const char *func) {
|
|
|
|
perror(func);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void PrintSocketError(const char *func) {
|
|
|
|
fprintf(stderr, "%s: %d\n", func, WSAGetLastError());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int Usage(const char *program) {
|
2015-02-09 07:37:18 +00:00
|
|
|
fprintf(stderr, "Usage: %s [flags...]\n", program);
|
2014-07-23 00:20:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2014-07-02 00:53:04 +01:00
|
|
|
|
2015-02-09 18:03:50 +00:00
|
|
|
struct TestState {
|
|
|
|
TestState() : cert_ready(false), early_callback_called(false) {}
|
2015-02-09 08:13:35 +00:00
|
|
|
|
2015-02-09 08:04:34 +00:00
|
|
|
ScopedEVP_PKEY channel_id;
|
2015-02-09 08:13:35 +00:00
|
|
|
bool cert_ready;
|
2015-02-09 09:28:16 +00:00
|
|
|
ScopedSSL_SESSION session;
|
|
|
|
ScopedSSL_SESSION pending_session;
|
2015-02-09 18:03:50 +00:00
|
|
|
bool early_callback_called;
|
2015-02-09 08:04:34 +00:00
|
|
|
};
|
|
|
|
|
2015-02-09 18:03:50 +00:00
|
|
|
static void TestStateExFree(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
|
|
|
|
int index, long argl, void *argp) {
|
|
|
|
delete ((TestState *)ptr);
|
2015-02-09 08:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int g_config_index = 0;
|
|
|
|
static int g_clock_index = 0;
|
2015-02-09 18:03:50 +00:00
|
|
|
static int g_state_index = 0;
|
2014-08-12 00:51:50 +01:00
|
|
|
|
2014-11-18 01:26:55 +00:00
|
|
|
static bool SetConfigPtr(SSL *ssl, const TestConfig *config) {
|
2015-02-09 08:04:34 +00:00
|
|
|
return SSL_set_ex_data(ssl, g_config_index, (void *)config) == 1;
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TestConfig *GetConfigPtr(SSL *ssl) {
|
2015-02-09 08:04:34 +00:00
|
|
|
return (const TestConfig *)SSL_get_ex_data(ssl, g_config_index);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
static bool SetClockPtr(SSL *ssl, OPENSSL_timeval *clock) {
|
2015-02-09 08:04:34 +00:00
|
|
|
return SSL_set_ex_data(ssl, g_clock_index, (void *)clock) == 1;
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static OPENSSL_timeval *GetClockPtr(SSL *ssl) {
|
2015-02-09 08:04:34 +00:00
|
|
|
return (OPENSSL_timeval *)SSL_get_ex_data(ssl, g_clock_index);
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:03:50 +00:00
|
|
|
static bool SetTestState(SSL *ssl, std::unique_ptr<TestState> async) {
|
|
|
|
if (SSL_set_ex_data(ssl, g_state_index, (void *)async.get()) == 1) {
|
2015-02-09 08:04:34 +00:00
|
|
|
async.release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:03:50 +00:00
|
|
|
static TestState *GetTestState(SSL *ssl) {
|
|
|
|
return (TestState *)SSL_get_ex_data(ssl, g_state_index);
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
static ScopedEVP_PKEY LoadPrivateKey(const std::string &file) {
|
|
|
|
ScopedBIO bio(BIO_new(BIO_s_file()));
|
|
|
|
if (!bio || !BIO_read_filename(bio.get(), file.c_str())) {
|
|
|
|
return nullptr;
|
2014-08-24 06:46:07 +01:00
|
|
|
}
|
2015-02-09 07:37:18 +00:00
|
|
|
ScopedEVP_PKEY pkey(PEM_read_bio_PrivateKey(bio.get(), NULL, NULL, NULL));
|
2014-08-24 06:46:07 +01:00
|
|
|
return pkey;
|
|
|
|
}
|
|
|
|
|
2015-02-09 08:13:35 +00:00
|
|
|
static bool InstallCertificate(SSL *ssl) {
|
|
|
|
const TestConfig *config = GetConfigPtr(ssl);
|
|
|
|
if (!config->key_file.empty() &&
|
|
|
|
!SSL_use_PrivateKey_file(ssl, config->key_file.c_str(),
|
|
|
|
SSL_FILETYPE_PEM)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!config->cert_file.empty() &&
|
|
|
|
!SSL_use_certificate_file(ssl, config->cert_file.c_str(),
|
|
|
|
SSL_FILETYPE_PEM)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int SelectCertificateCallback(const struct ssl_early_callback_ctx *ctx) {
|
2014-08-12 00:51:50 +01:00
|
|
|
const TestConfig *config = GetConfigPtr(ctx->ssl);
|
2015-02-09 18:03:50 +00:00
|
|
|
GetTestState(ctx->ssl)->early_callback_called = true;
|
2014-08-12 00:51:50 +01:00
|
|
|
|
2015-02-24 06:23:21 +00:00
|
|
|
if (!config->expected_server_name.empty()) {
|
|
|
|
const uint8_t *extension_data;
|
|
|
|
size_t extension_len;
|
|
|
|
CBS extension, server_name_list, host_name;
|
|
|
|
uint8_t name_type;
|
|
|
|
|
|
|
|
if (!SSL_early_callback_ctx_extension_get(ctx, TLSEXT_TYPE_server_name,
|
|
|
|
&extension_data,
|
|
|
|
&extension_len)) {
|
|
|
|
fprintf(stderr, "Could not find server_name extension.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-09 14:30:38 +01:00
|
|
|
|
2015-02-24 06:23:21 +00:00
|
|
|
CBS_init(&extension, extension_data, extension_len);
|
|
|
|
if (!CBS_get_u16_length_prefixed(&extension, &server_name_list) ||
|
|
|
|
CBS_len(&extension) != 0 ||
|
|
|
|
!CBS_get_u8(&server_name_list, &name_type) ||
|
|
|
|
name_type != TLSEXT_NAMETYPE_host_name ||
|
|
|
|
!CBS_get_u16_length_prefixed(&server_name_list, &host_name) ||
|
|
|
|
CBS_len(&server_name_list) != 0) {
|
|
|
|
fprintf(stderr, "Could not decode server_name extension.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-09 14:30:38 +01:00
|
|
|
|
2015-02-24 06:23:21 +00:00
|
|
|
if (!CBS_mem_equal(&host_name,
|
|
|
|
(const uint8_t*)config->expected_server_name.data(),
|
|
|
|
config->expected_server_name.size())) {
|
|
|
|
fprintf(stderr, "Server name mismatch.\n");
|
|
|
|
}
|
2014-07-08 22:30:11 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 06:23:21 +00:00
|
|
|
if (config->fail_early_callback) {
|
2014-07-08 22:30:11 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-24 06:23:21 +00:00
|
|
|
// Install the certificate in the early callback.
|
|
|
|
if (config->use_early_callback) {
|
|
|
|
if (config->async) {
|
|
|
|
// Install the certificate asynchronously.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!InstallCertificate(ctx->ssl)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-09 14:30:38 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2014-07-02 00:53:04 +01:00
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int SkipVerify(int preverify_ok, X509_STORE_CTX *store_ctx) {
|
2014-07-12 20:47:52 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int NextProtosAdvertisedCallback(SSL *ssl, const uint8_t **out,
|
|
|
|
unsigned int *out_len, void *arg) {
|
2014-08-12 00:51:50 +01:00
|
|
|
const TestConfig *config = GetConfigPtr(ssl);
|
2015-02-09 17:59:46 +00:00
|
|
|
if (config->advertise_npn.empty()) {
|
2014-07-12 21:18:02 +01:00
|
|
|
return SSL_TLSEXT_ERR_NOACK;
|
2015-02-09 17:59:46 +00:00
|
|
|
}
|
2014-07-12 21:18:02 +01:00
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
*out = (const uint8_t*)config->advertise_npn.data();
|
|
|
|
*out_len = config->advertise_npn.size();
|
2014-07-12 21:18:02 +01:00
|
|
|
return SSL_TLSEXT_ERR_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int NextProtoSelectCallback(SSL* ssl, uint8_t** out, uint8_t* outlen,
|
2015-03-14 05:54:17 +00:00
|
|
|
const uint8_t* in, unsigned inlen, void* arg) {
|
2014-08-12 00:51:50 +01:00
|
|
|
const TestConfig *config = GetConfigPtr(ssl);
|
2015-02-09 17:59:46 +00:00
|
|
|
if (config->select_next_proto.empty()) {
|
2014-07-28 19:52:32 +01:00
|
|
|
return SSL_TLSEXT_ERR_NOACK;
|
2015-02-09 17:59:46 +00:00
|
|
|
}
|
2014-07-28 19:52:32 +01:00
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
*out = (uint8_t*)config->select_next_proto.data();
|
|
|
|
*outlen = config->select_next_proto.size();
|
2014-07-28 19:52:32 +01:00
|
|
|
return SSL_TLSEXT_ERR_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int AlpnSelectCallback(SSL* ssl, const uint8_t** out, uint8_t* outlen,
|
|
|
|
const uint8_t* in, unsigned inlen, void* arg) {
|
2014-09-06 17:58:58 +01:00
|
|
|
const TestConfig *config = GetConfigPtr(ssl);
|
2015-02-09 17:59:46 +00:00
|
|
|
if (config->select_alpn.empty()) {
|
2014-09-06 17:58:58 +01:00
|
|
|
return SSL_TLSEXT_ERR_NOACK;
|
2015-02-09 17:59:46 +00:00
|
|
|
}
|
2014-09-06 17:58:58 +01:00
|
|
|
|
|
|
|
if (!config->expected_advertised_alpn.empty() &&
|
|
|
|
(config->expected_advertised_alpn.size() != inlen ||
|
|
|
|
memcmp(config->expected_advertised_alpn.data(),
|
|
|
|
in, inlen) != 0)) {
|
|
|
|
fprintf(stderr, "bad ALPN select callback inputs\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = (const uint8_t*)config->select_alpn.data();
|
|
|
|
*outlen = config->select_alpn.size();
|
|
|
|
return SSL_TLSEXT_ERR_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static unsigned PskClientCallback(SSL *ssl, const char *hint,
|
|
|
|
char *out_identity,
|
|
|
|
unsigned max_identity_len,
|
|
|
|
uint8_t *out_psk, unsigned max_psk_len) {
|
2014-10-27 05:06:24 +00:00
|
|
|
const TestConfig *config = GetConfigPtr(ssl);
|
|
|
|
|
|
|
|
if (strcmp(hint ? hint : "", config->psk_identity.c_str()) != 0) {
|
|
|
|
fprintf(stderr, "Server PSK hint did not match.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Account for the trailing '\0' for the identity.
|
|
|
|
if (config->psk_identity.size() >= max_identity_len ||
|
|
|
|
config->psk.size() > max_psk_len) {
|
|
|
|
fprintf(stderr, "PSK buffers too small\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUF_strlcpy(out_identity, config->psk_identity.c_str(),
|
|
|
|
max_identity_len);
|
|
|
|
memcpy(out_psk, config->psk.data(), config->psk.size());
|
|
|
|
return config->psk.size();
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static unsigned PskServerCallback(SSL *ssl, const char *identity,
|
|
|
|
uint8_t *out_psk, unsigned max_psk_len) {
|
2014-10-27 05:06:24 +00:00
|
|
|
const TestConfig *config = GetConfigPtr(ssl);
|
|
|
|
|
|
|
|
if (strcmp(identity, config->psk_identity.c_str()) != 0) {
|
|
|
|
fprintf(stderr, "Client PSK identity did not match.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->psk.size() > max_psk_len) {
|
|
|
|
fprintf(stderr, "PSK buffers too small\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(out_psk, config->psk.data(), config->psk.size());
|
|
|
|
return config->psk.size();
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static void CurrentTimeCallback(SSL *ssl, OPENSSL_timeval *out_clock) {
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
*out_clock = *GetClockPtr(ssl);
|
2015-01-26 05:22:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static void ChannelIdCallback(SSL *ssl, EVP_PKEY **out_pkey) {
|
2015-02-09 18:03:50 +00:00
|
|
|
*out_pkey = GetTestState(ssl)->channel_id.release();
|
2015-02-09 08:04:34 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static int CertCallback(SSL *ssl, void *arg) {
|
2015-02-09 18:03:50 +00:00
|
|
|
if (!GetTestState(ssl)->cert_ready) {
|
2015-02-09 08:13:35 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!InstallCertificate(ssl)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static SSL_SESSION *GetSessionCallback(SSL *ssl, uint8_t *data, int len,
|
|
|
|
int *copy) {
|
2015-02-09 18:03:50 +00:00
|
|
|
TestState *async_state = GetTestState(ssl);
|
2015-02-09 09:28:16 +00:00
|
|
|
if (async_state->session) {
|
|
|
|
*copy = 0;
|
|
|
|
return async_state->session.release();
|
|
|
|
} else if (async_state->pending_session) {
|
|
|
|
return SSL_magic_pending_session_ptr();
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-21 00:04:00 +00:00
|
|
|
static int DDoSCallback(const struct ssl_early_callback_ctx *early_context) {
|
|
|
|
const TestConfig *config = GetConfigPtr(early_context->ssl);
|
|
|
|
static int callback_num = 0;
|
|
|
|
|
|
|
|
callback_num++;
|
|
|
|
if (config->fail_ddos_callback ||
|
|
|
|
(config->fail_second_ddos_callback && callback_num == 2)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Connect returns a new socket connected to localhost on |port| or -1 on
|
|
|
|
// error.
|
|
|
|
static int Connect(uint16_t port) {
|
|
|
|
int sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (sock == -1) {
|
|
|
|
PrintSocketError("socket");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int nodelay = 1;
|
|
|
|
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
|
|
|
|
reinterpret_cast<const char*>(&nodelay), sizeof(nodelay)) != 0) {
|
|
|
|
PrintSocketError("setsockopt");
|
|
|
|
closesocket(sock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sockaddr_in sin;
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_port = htons(port);
|
|
|
|
if (!inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr)) {
|
|
|
|
PrintSocketError("inet_pton");
|
|
|
|
closesocket(sock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (connect(sock, reinterpret_cast<const sockaddr*>(&sin),
|
|
|
|
sizeof(sin)) != 0) {
|
|
|
|
PrintSocketError("connect");
|
|
|
|
closesocket(sock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SocketCloser {
|
|
|
|
public:
|
|
|
|
explicit SocketCloser(int sock) : sock_(sock) {}
|
|
|
|
~SocketCloser() {
|
|
|
|
// Half-close and drain the socket before releasing it. This seems to be
|
|
|
|
// necessary for graceful shutdown on Windows. It will also avoid write
|
|
|
|
// failures in the test runner.
|
|
|
|
#if defined(OPENSSL_WINDOWS)
|
|
|
|
shutdown(sock_, SD_SEND);
|
|
|
|
#else
|
|
|
|
shutdown(sock_, SHUT_WR);
|
|
|
|
#endif
|
|
|
|
while (true) {
|
|
|
|
char buf[1024];
|
|
|
|
if (recv(sock_, buf, sizeof(buf), 0) <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closesocket(sock_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int sock_;
|
|
|
|
};
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
static ScopedSSL_CTX SetupCtx(const TestConfig *config) {
|
2015-02-09 07:37:18 +00:00
|
|
|
ScopedSSL_CTX ssl_ctx(SSL_CTX_new(
|
|
|
|
config->is_dtls ? DTLS_method() : TLS_method()));
|
|
|
|
if (!ssl_ctx) {
|
|
|
|
return nullptr;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
|
2014-08-11 23:43:38 +01:00
|
|
|
if (config->is_dtls) {
|
|
|
|
// DTLS needs read-ahead to function on a datagram BIO.
|
|
|
|
//
|
|
|
|
// TODO(davidben): this should not be necessary. DTLS code should only
|
|
|
|
// expect a datagram BIO.
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_CTX_set_read_ahead(ssl_ctx.get(), 1);
|
2014-08-11 23:43:38 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
if (!SSL_CTX_set_ecdh_auto(ssl_ctx.get(), 1)) {
|
|
|
|
return nullptr;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
if (!SSL_CTX_set_cipher_list(ssl_ctx.get(), "ALL")) {
|
|
|
|
return nullptr;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
ScopedDH dh(DH_get_2048_256(NULL));
|
|
|
|
if (!dh || !SSL_CTX_set_tmp_dh(ssl_ctx.get(), dh.get())) {
|
|
|
|
return nullptr;
|
2014-08-02 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 09:28:16 +00:00
|
|
|
if (config->async && config->is_server) {
|
|
|
|
// Disable the internal session cache. To test asynchronous session lookup,
|
|
|
|
// we use an external session cache.
|
|
|
|
SSL_CTX_set_session_cache_mode(
|
|
|
|
ssl_ctx.get(), SSL_SESS_CACHE_BOTH | SSL_SESS_CACHE_NO_INTERNAL);
|
2015-02-09 17:59:46 +00:00
|
|
|
SSL_CTX_sess_set_get_cb(ssl_ctx.get(), GetSessionCallback);
|
2015-02-09 09:28:16 +00:00
|
|
|
} else {
|
|
|
|
SSL_CTX_set_session_cache_mode(ssl_ctx.get(), SSL_SESS_CACHE_BOTH);
|
|
|
|
}
|
2014-07-23 00:20:02 +01:00
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
ssl_ctx->select_certificate_cb = SelectCertificateCallback;
|
2014-07-09 14:30:38 +01:00
|
|
|
|
2014-07-12 21:18:02 +01:00
|
|
|
SSL_CTX_set_next_protos_advertised_cb(
|
2015-02-09 17:59:46 +00:00
|
|
|
ssl_ctx.get(), NextProtosAdvertisedCallback, NULL);
|
2014-09-06 17:58:58 +01:00
|
|
|
if (!config->select_next_proto.empty()) {
|
2015-02-09 17:59:46 +00:00
|
|
|
SSL_CTX_set_next_proto_select_cb(ssl_ctx.get(), NextProtoSelectCallback,
|
2015-02-09 07:37:18 +00:00
|
|
|
NULL);
|
2014-09-06 17:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!config->select_alpn.empty()) {
|
2015-02-09 17:59:46 +00:00
|
|
|
SSL_CTX_set_alpn_select_cb(ssl_ctx.get(), AlpnSelectCallback, NULL);
|
2014-09-06 17:58:58 +01:00
|
|
|
}
|
2014-07-12 21:18:02 +01:00
|
|
|
|
2014-08-24 06:46:07 +01:00
|
|
|
ssl_ctx->tlsext_channel_id_enabled_new = 1;
|
2015-02-09 17:59:46 +00:00
|
|
|
SSL_CTX_set_channel_id_cb(ssl_ctx.get(), ChannelIdCallback);
|
2014-08-24 06:46:07 +01:00
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
ssl_ctx->current_time_cb = CurrentTimeCallback;
|
2015-01-26 05:22:12 +00:00
|
|
|
|
2014-07-23 00:20:02 +01:00
|
|
|
return ssl_ctx;
|
|
|
|
}
|
|
|
|
|
2015-02-20 16:23:42 +00:00
|
|
|
// RetryAsync is called after a failed operation on |ssl| with return code
|
|
|
|
// |ret|. If the operation should be retried, it simulates one asynchronous
|
|
|
|
// event and returns true. Otherwise it returns false. |async| and |clock_delta|
|
|
|
|
// are the AsyncBio and simulated timeout for |ssl|, respectively.
|
|
|
|
static bool RetryAsync(SSL *ssl, int ret, BIO *async,
|
|
|
|
OPENSSL_timeval *clock_delta) {
|
2014-08-05 07:28:57 +01:00
|
|
|
// No error; don't retry.
|
|
|
|
if (ret >= 0) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
|
|
|
|
if (clock_delta->tv_usec != 0 || clock_delta->tv_sec != 0) {
|
|
|
|
// Process the timeout and retry.
|
|
|
|
OPENSSL_timeval *clock = GetClockPtr(ssl);
|
|
|
|
clock->tv_usec += clock_delta->tv_usec;
|
|
|
|
clock->tv_sec += clock->tv_usec / 1000000;
|
|
|
|
clock->tv_usec %= 1000000;
|
|
|
|
clock->tv_sec += clock_delta->tv_sec;
|
|
|
|
memset(clock_delta, 0, sizeof(*clock_delta));
|
|
|
|
|
|
|
|
if (DTLSv1_handle_timeout(ssl) < 0) {
|
|
|
|
printf("Error retransmitting.\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
}
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
}
|
|
|
|
|
2014-08-05 07:28:57 +01:00
|
|
|
// See if we needed to read or write more. If so, allow one byte through on
|
|
|
|
// the appropriate end to maximally stress the state machine.
|
2015-02-09 08:04:34 +00:00
|
|
|
switch (SSL_get_error(ssl, ret)) {
|
|
|
|
case SSL_ERROR_WANT_READ:
|
2015-02-09 17:59:46 +00:00
|
|
|
AsyncBioAllowRead(async, 1);
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
2015-02-09 08:04:34 +00:00
|
|
|
case SSL_ERROR_WANT_WRITE:
|
2015-02-09 17:59:46 +00:00
|
|
|
AsyncBioAllowWrite(async, 1);
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
2015-02-16 08:57:55 +00:00
|
|
|
case SSL_ERROR_WANT_CHANNEL_ID_LOOKUP: {
|
|
|
|
ScopedEVP_PKEY pkey = LoadPrivateKey(GetConfigPtr(ssl)->send_channel_id);
|
|
|
|
if (!pkey) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-16 08:57:55 +00:00
|
|
|
}
|
|
|
|
GetTestState(ssl)->channel_id = std::move(pkey);
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
2015-02-16 08:57:55 +00:00
|
|
|
}
|
2015-02-09 08:13:35 +00:00
|
|
|
case SSL_ERROR_WANT_X509_LOOKUP:
|
2015-02-09 18:03:50 +00:00
|
|
|
GetTestState(ssl)->cert_ready = true;
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
2015-02-09 09:28:16 +00:00
|
|
|
case SSL_ERROR_PENDING_SESSION:
|
2015-02-09 18:03:50 +00:00
|
|
|
GetTestState(ssl)->session =
|
|
|
|
std::move(GetTestState(ssl)->pending_session);
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
2015-02-24 06:23:21 +00:00
|
|
|
case SSL_ERROR_PENDING_CERTIFICATE:
|
|
|
|
// The handshake will resume without a second call to the early callback.
|
|
|
|
return InstallCertificate(ssl);
|
2015-02-09 08:04:34 +00:00
|
|
|
default:
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// DoExchange runs a test SSL exchange against the peer. On success, it returns
|
|
|
|
// true and sets |*out_session| to the negotiated SSL session. If the test is a
|
|
|
|
// resumption attempt, |is_resume| is true and |session| is the session from the
|
|
|
|
// previous exchange.
|
2015-02-20 16:23:42 +00:00
|
|
|
static bool DoExchange(ScopedSSL_SESSION *out_session, SSL_CTX *ssl_ctx,
|
|
|
|
const TestConfig *config, bool is_resume,
|
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
|
|
|
SSL_SESSION *session) {
|
Add DTLS timeout and retransmit tests.
This extends the packet adaptor protocol to send three commands:
type command =
| Packet of []byte
| Timeout of time.Duration
| TimeoutAck
When the shim processes a Timeout in BIO_read, it sends TimeoutAck, fails the
BIO_read, returns out of the SSL stack, advances the clock, calls
DTLSv1_handle_timeout, and continues.
If the Go side sends Timeout right between sending handshake flight N and
reading flight N+1, the shim won't read the Timeout until it has sent flight
N+1 (it only processes packet commands in BIO_read), so the TimeoutAck comes
after N+1. Go then drops all packets before the TimeoutAck, thus dropping one
transmit of flight N+1 without having to actually process the packets to
determine the end of the flight. The shim then sees the updated clock, calls
DTLSv1_handle_timeout, and re-sends flight N+1 for Go to process for real.
When dropping packets, Go checks the epoch and increments sequence numbers so
that we can continue to be strict here. This requires tracking the initial
sequence number of the next epoch.
The final Finished message takes an additional special-case to test. DTLS
triggers retransmits on either a timeout or seeing a stale flight. OpenSSL only
implements the former which should be sufficient (and is necessary) EXCEPT for
the final Finished message. If the peer's final Finished message is lost, it
won't be waiting for a message from us, so it won't time out anything. That
retransmit must be triggered on stale message, so we retransmit the Finished
message in Go.
Change-Id: I3ffbdb1de525beb2ee831b304670a3387877634c
Reviewed-on: https://boringssl-review.googlesource.com/3212
Reviewed-by: Adam Langley <agl@google.com>
2015-01-27 06:09:43 +00:00
|
|
|
OPENSSL_timeval clock = {0}, clock_delta = {0};
|
2015-02-09 07:37:18 +00:00
|
|
|
ScopedSSL ssl(SSL_new(ssl_ctx));
|
|
|
|
if (!ssl) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
if (!SetConfigPtr(ssl.get(), config) ||
|
2015-02-09 08:04:34 +00:00
|
|
|
!SetClockPtr(ssl.get(), &clock) |
|
2015-02-09 18:03:50 +00:00
|
|
|
!SetTestState(ssl.get(), std::unique_ptr<TestState>(new TestState))) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-11-18 01:26:55 +00:00
|
|
|
}
|
2014-08-12 00:51:50 +01:00
|
|
|
|
2015-02-20 21:03:16 +00:00
|
|
|
if (config->fallback_scsv &&
|
|
|
|
!SSL_set_mode(ssl.get(), SSL_MODE_SEND_FALLBACK_SCSV)) {
|
|
|
|
return false;
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
2015-02-24 06:23:21 +00:00
|
|
|
if (!config->use_early_callback) {
|
|
|
|
if (config->async) {
|
|
|
|
// TODO(davidben): Also test |s->ctx->client_cert_cb| on the client.
|
|
|
|
SSL_set_cert_cb(ssl.get(), CertCallback, NULL);
|
|
|
|
} else if (!InstallCertificate(ssl.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
2014-08-12 00:51:50 +01:00
|
|
|
if (config->require_any_client_certificate) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_verify(ssl.get(), SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
|
2015-02-09 17:59:46 +00:00
|
|
|
SkipVerify);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->false_start) {
|
2015-02-17 00:16:46 +00:00
|
|
|
SSL_set_mode(ssl.get(), SSL_MODE_ENABLE_FALSE_START);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->cbc_record_splitting) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_mode(ssl.get(), SSL_MODE_CBC_RECORD_SPLITTING);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->partial_write) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_mode(ssl.get(), SSL_MODE_ENABLE_PARTIAL_WRITE);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->no_tls12) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_NO_TLSv1_2);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->no_tls11) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_NO_TLSv1_1);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->no_tls1) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_NO_TLSv1);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
|
|
|
if (config->no_ssl3) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_NO_SSLv3);
|
2014-08-12 00:51:50 +01:00
|
|
|
}
|
2014-08-31 05:59:27 +01:00
|
|
|
if (config->tls_d5_bug) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_TLS_D5_BUG);
|
2014-08-31 05:59:27 +01:00
|
|
|
}
|
2014-11-08 17:31:52 +00:00
|
|
|
if (config->allow_unsafe_legacy_renegotiation) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION);
|
2014-11-08 17:31:52 +00:00
|
|
|
}
|
2014-08-24 06:46:07 +01:00
|
|
|
if (!config->expected_channel_id.empty()) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_enable_tls_channel_id(ssl.get());
|
2014-08-24 06:46:07 +01:00
|
|
|
}
|
|
|
|
if (!config->send_channel_id.empty()) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_enable_tls_channel_id(ssl.get());
|
2015-02-09 08:04:34 +00:00
|
|
|
if (!config->async) {
|
2015-02-09 17:59:46 +00:00
|
|
|
// The async case will be supplied by |ChannelIdCallback|.
|
2015-02-09 08:04:34 +00:00
|
|
|
ScopedEVP_PKEY pkey = LoadPrivateKey(config->send_channel_id);
|
|
|
|
if (!pkey || !SSL_set1_tls_channel_id(ssl.get(), pkey.get())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 08:04:34 +00:00
|
|
|
}
|
2014-08-24 06:46:07 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 08:57:55 +00:00
|
|
|
if (!config->host_name.empty() &&
|
|
|
|
!SSL_set_tlsext_host_name(ssl.get(), config->host_name.c_str())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-09-06 17:45:15 +01:00
|
|
|
}
|
2015-02-16 08:57:55 +00:00
|
|
|
if (!config->advertise_alpn.empty() &&
|
|
|
|
SSL_set_alpn_protos(ssl.get(),
|
|
|
|
(const uint8_t *)config->advertise_alpn.data(),
|
|
|
|
config->advertise_alpn.size()) != 0) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-09-06 17:58:58 +01:00
|
|
|
}
|
2014-10-27 05:06:24 +00:00
|
|
|
if (!config->psk.empty()) {
|
2015-02-09 17:59:46 +00:00
|
|
|
SSL_set_psk_client_callback(ssl.get(), PskClientCallback);
|
|
|
|
SSL_set_psk_server_callback(ssl.get(), PskServerCallback);
|
2014-10-27 05:06:24 +00:00
|
|
|
}
|
2014-11-25 06:55:35 +00:00
|
|
|
if (!config->psk_identity.empty() &&
|
2015-02-09 07:37:18 +00:00
|
|
|
!SSL_use_psk_identity_hint(ssl.get(), config->psk_identity.c_str())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-10-27 05:06:24 +00:00
|
|
|
}
|
2014-11-25 06:55:35 +00:00
|
|
|
if (!config->srtp_profiles.empty() &&
|
2015-02-09 07:37:18 +00:00
|
|
|
!SSL_set_srtp_profiles(ssl.get(), config->srtp_profiles.c_str())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-11-25 06:55:35 +00:00
|
|
|
}
|
|
|
|
if (config->enable_ocsp_stapling &&
|
2015-02-09 07:37:18 +00:00
|
|
|
!SSL_enable_ocsp_stapling(ssl.get())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-11-25 06:55:35 +00:00
|
|
|
}
|
|
|
|
if (config->enable_signed_cert_timestamps &&
|
2015-02-09 07:37:18 +00:00
|
|
|
!SSL_enable_signed_cert_timestamps(ssl.get())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-11-16 00:06:08 +00:00
|
|
|
}
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_enable_fastradio_padding(ssl.get(), config->fastradio_padding);
|
2014-12-12 23:17:51 +00:00
|
|
|
if (config->min_version != 0) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_min_version(ssl.get(), (uint16_t)config->min_version);
|
2014-12-12 23:17:51 +00:00
|
|
|
}
|
|
|
|
if (config->max_version != 0) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_max_version(ssl.get(), (uint16_t)config->max_version);
|
2014-12-12 23:17:51 +00:00
|
|
|
}
|
2015-01-11 21:29:36 +00:00
|
|
|
if (config->mtu != 0) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_options(ssl.get(), SSL_OP_NO_QUERY_MTU);
|
|
|
|
SSL_set_mtu(ssl.get(), config->mtu);
|
2015-01-11 21:29:36 +00:00
|
|
|
}
|
2015-02-21 00:04:00 +00:00
|
|
|
if (config->install_ddos_callback) {
|
|
|
|
SSL_CTX_set_dos_protection_cb(ssl_ctx, DDoSCallback);
|
|
|
|
}
|
2014-07-02 00:53:04 +01:00
|
|
|
|
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
|
|
|
int sock = Connect(config->port);
|
|
|
|
if (sock == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SocketCloser closer(sock);
|
|
|
|
|
|
|
|
ScopedBIO bio(BIO_new_socket(sock, BIO_NOCLOSE));
|
2015-02-09 07:37:18 +00:00
|
|
|
if (!bio) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-08-05 07:28:57 +01:00
|
|
|
}
|
2014-08-11 23:43:38 +01:00
|
|
|
if (config->is_dtls) {
|
2015-02-09 17:59:46 +00:00
|
|
|
ScopedBIO packeted = PacketedBioCreate(&clock_delta);
|
2015-02-09 07:37:18 +00:00
|
|
|
BIO_push(packeted.get(), bio.release());
|
|
|
|
bio = std::move(packeted);
|
2014-08-11 23:43:38 +01:00
|
|
|
}
|
2015-02-09 07:37:18 +00:00
|
|
|
BIO *async = NULL;
|
2014-08-12 00:51:50 +01:00
|
|
|
if (config->async) {
|
2015-02-09 07:37:18 +00:00
|
|
|
ScopedBIO async_scoped =
|
2015-02-09 17:59:46 +00:00
|
|
|
config->is_dtls ? AsyncBioCreateDatagram() : AsyncBioCreate();
|
2015-02-09 07:37:18 +00:00
|
|
|
BIO_push(async_scoped.get(), bio.release());
|
|
|
|
async = async_scoped.get();
|
|
|
|
bio = std::move(async_scoped);
|
2014-08-05 07:28:57 +01:00
|
|
|
}
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_bio(ssl.get(), bio.get(), bio.get());
|
|
|
|
bio.release(); // SSL_set_bio takes ownership.
|
2014-08-05 07:28:57 +01:00
|
|
|
|
2014-07-23 00:20:02 +01:00
|
|
|
if (session != NULL) {
|
2015-02-09 09:28:16 +00:00
|
|
|
if (!config->is_server) {
|
|
|
|
if (SSL_set_session(ssl.get(), session) != 1) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 09:28:16 +00:00
|
|
|
}
|
|
|
|
} else if (config->async) {
|
|
|
|
// The internal session cache is disabled, so install the session
|
|
|
|
// manually.
|
2015-02-09 18:03:50 +00:00
|
|
|
GetTestState(ssl.get())->pending_session.reset(
|
2015-02-09 09:28:16 +00:00
|
|
|
SSL_SESSION_up_ref(session));
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret;
|
2015-02-09 00:33:25 +00:00
|
|
|
if (config->implicit_handshake) {
|
2014-08-12 00:51:50 +01:00
|
|
|
if (config->is_server) {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_accept_state(ssl.get());
|
2014-08-05 07:28:57 +01:00
|
|
|
} else {
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_connect_state(ssl.get());
|
2014-08-05 07:28:57 +01:00
|
|
|
}
|
2015-02-09 00:33:25 +00:00
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (config->is_server) {
|
2015-02-09 07:37:18 +00:00
|
|
|
ret = SSL_accept(ssl.get());
|
2015-02-09 00:33:25 +00:00
|
|
|
} else {
|
2015-02-09 07:37:18 +00:00
|
|
|
ret = SSL_connect(ssl.get());
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2015-02-09 17:59:46 +00:00
|
|
|
} while (config->async && RetryAsync(ssl.get(), ret, async, &clock_delta));
|
2015-02-09 00:33:25 +00:00
|
|
|
if (ret != 1) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-07-02 23:37:33 +01:00
|
|
|
}
|
2014-07-09 14:30:38 +01:00
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (is_resume &&
|
2015-02-09 07:37:18 +00:00
|
|
|
(!!SSL_session_reused(ssl.get()) == config->expect_session_miss)) {
|
2015-02-09 00:33:25 +00:00
|
|
|
fprintf(stderr, "session was%s reused\n",
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_session_reused(ssl.get()) ? "" : " not");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-07-09 14:30:38 +01:00
|
|
|
}
|
2014-07-02 23:37:33 +01:00
|
|
|
|
2015-02-24 06:23:21 +00:00
|
|
|
if (config->is_server && !GetTestState(ssl.get())->early_callback_called) {
|
|
|
|
fprintf(stderr, "early callback not called\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (!config->expected_server_name.empty()) {
|
|
|
|
const char *server_name =
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_get_servername(ssl.get(), TLSEXT_NAMETYPE_host_name);
|
2015-02-09 00:33:25 +00:00
|
|
|
if (server_name != config->expected_server_name) {
|
|
|
|
fprintf(stderr, "servername mismatch (got %s; want %s)\n",
|
|
|
|
server_name, config->expected_server_name.c_str());
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-07-08 22:30:11 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (!config->expected_certificate_types.empty()) {
|
|
|
|
uint8_t *certificate_types;
|
|
|
|
int num_certificate_types =
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_get0_certificate_types(ssl.get(), &certificate_types);
|
2015-02-09 00:33:25 +00:00
|
|
|
if (num_certificate_types !=
|
|
|
|
(int)config->expected_certificate_types.size() ||
|
|
|
|
memcmp(certificate_types,
|
|
|
|
config->expected_certificate_types.data(),
|
|
|
|
num_certificate_types) != 0) {
|
|
|
|
fprintf(stderr, "certificate types mismatch\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-07-12 21:18:02 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (!config->expected_next_proto.empty()) {
|
|
|
|
const uint8_t *next_proto;
|
|
|
|
unsigned next_proto_len;
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_get0_next_proto_negotiated(ssl.get(), &next_proto, &next_proto_len);
|
2015-02-09 00:33:25 +00:00
|
|
|
if (next_proto_len != config->expected_next_proto.size() ||
|
|
|
|
memcmp(next_proto, config->expected_next_proto.data(),
|
|
|
|
next_proto_len) != 0) {
|
|
|
|
fprintf(stderr, "negotiated next proto mismatch\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-09-06 17:58:58 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (!config->expected_alpn.empty()) {
|
|
|
|
const uint8_t *alpn_proto;
|
|
|
|
unsigned alpn_proto_len;
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_get0_alpn_selected(ssl.get(), &alpn_proto, &alpn_proto_len);
|
2015-02-09 00:33:25 +00:00
|
|
|
if (alpn_proto_len != config->expected_alpn.size() ||
|
|
|
|
memcmp(alpn_proto, config->expected_alpn.data(),
|
|
|
|
alpn_proto_len) != 0) {
|
|
|
|
fprintf(stderr, "negotiated alpn proto mismatch\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-08-24 06:46:07 +01:00
|
|
|
}
|
2015-02-09 00:33:25 +00:00
|
|
|
|
|
|
|
if (!config->expected_channel_id.empty()) {
|
|
|
|
uint8_t channel_id[64];
|
2015-02-09 07:37:18 +00:00
|
|
|
if (!SSL_get_tls_channel_id(ssl.get(), channel_id, sizeof(channel_id))) {
|
2015-02-09 00:33:25 +00:00
|
|
|
fprintf(stderr, "no channel id negotiated\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
|
|
|
if (config->expected_channel_id.size() != 64 ||
|
|
|
|
memcmp(config->expected_channel_id.data(),
|
|
|
|
channel_id, 64) != 0) {
|
|
|
|
fprintf(stderr, "channel id mismatch\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-08-24 06:46:07 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (config->expect_extended_master_secret) {
|
|
|
|
if (!ssl->session->extended_master_secret) {
|
|
|
|
fprintf(stderr, "No EMS for session when expected");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-10-11 00:23:43 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (!config->expected_ocsp_response.empty()) {
|
|
|
|
const uint8_t *data;
|
|
|
|
size_t len;
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_get0_ocsp_response(ssl.get(), &data, &len);
|
2015-02-09 00:33:25 +00:00
|
|
|
if (config->expected_ocsp_response.size() != len ||
|
|
|
|
memcmp(config->expected_ocsp_response.data(), data, len) != 0) {
|
|
|
|
fprintf(stderr, "OCSP response mismatch\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-11-25 06:55:35 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:33:25 +00:00
|
|
|
if (!config->expected_signed_cert_timestamps.empty()) {
|
|
|
|
const uint8_t *data;
|
|
|
|
size_t len;
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_get0_signed_cert_timestamp_list(ssl.get(), &data, &len);
|
2015-02-09 00:33:25 +00:00
|
|
|
if (config->expected_signed_cert_timestamps.size() != len ||
|
|
|
|
memcmp(config->expected_signed_cert_timestamps.data(),
|
|
|
|
data, len) != 0) {
|
|
|
|
fprintf(stderr, "SCT list mismatch\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
2014-11-25 06:55:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 00:29:33 +00:00
|
|
|
if (config->renegotiate) {
|
|
|
|
if (config->async) {
|
2015-02-09 00:33:25 +00:00
|
|
|
fprintf(stderr, "-renegotiate is not supported with -async.\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-02-09 00:33:25 +00:00
|
|
|
}
|
|
|
|
if (config->implicit_handshake) {
|
|
|
|
fprintf(stderr, "-renegotiate is not supported with -implicit-handshake.\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-10-29 00:29:33 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_renegotiate(ssl.get());
|
2014-10-29 00:29:33 +00:00
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
ret = SSL_do_handshake(ssl.get());
|
2014-10-29 00:29:33 +00:00
|
|
|
if (ret != 1) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-10-29 00:29:33 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_set_state(ssl.get(), SSL_ST_ACCEPT);
|
|
|
|
ret = SSL_do_handshake(ssl.get());
|
2014-10-29 00:29:33 +00:00
|
|
|
if (ret != 1) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-10-29 00:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
if (config->write_different_record_sizes) {
|
2014-08-11 23:43:38 +01:00
|
|
|
if (config->is_dtls) {
|
|
|
|
fprintf(stderr, "write_different_record_sizes not supported for DTLS\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-08-11 23:43:38 +01:00
|
|
|
}
|
2014-08-05 23:23:37 +01:00
|
|
|
// This mode writes a number of different record sizes in an attempt to
|
|
|
|
// trip up the CBC record splitting code.
|
|
|
|
uint8_t buf[32769];
|
|
|
|
memset(buf, 0x42, sizeof(buf));
|
|
|
|
static const size_t kRecordSizes[] = {
|
|
|
|
0, 1, 255, 256, 257, 16383, 16384, 16385, 32767, 32768, 32769};
|
|
|
|
for (size_t i = 0; i < sizeof(kRecordSizes) / sizeof(kRecordSizes[0]);
|
|
|
|
i++) {
|
2014-08-05 07:28:57 +01:00
|
|
|
int w;
|
2014-08-05 23:23:37 +01:00
|
|
|
const size_t len = kRecordSizes[i];
|
|
|
|
size_t off = 0;
|
|
|
|
|
|
|
|
if (len > sizeof(buf)) {
|
|
|
|
fprintf(stderr, "Bad kRecordSizes value.\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-08-05 23:23:37 +01:00
|
|
|
}
|
|
|
|
|
2014-08-05 07:28:57 +01:00
|
|
|
do {
|
2015-02-09 07:37:18 +00:00
|
|
|
w = SSL_write(ssl.get(), buf + off, len - off);
|
2014-08-05 23:23:37 +01:00
|
|
|
if (w > 0) {
|
|
|
|
off += (size_t) w;
|
|
|
|
}
|
2015-02-09 17:59:46 +00:00
|
|
|
} while ((config->async && RetryAsync(ssl.get(), w, async, &clock_delta)) ||
|
2014-08-12 00:51:50 +01:00
|
|
|
(w > 0 && off < len));
|
2014-08-05 23:23:37 +01:00
|
|
|
|
|
|
|
if (w < 0 || off != len) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-05 23:23:37 +01:00
|
|
|
} else {
|
2014-08-24 08:47:07 +01:00
|
|
|
if (config->shim_writes_first) {
|
|
|
|
int w;
|
|
|
|
do {
|
2015-02-09 07:37:18 +00:00
|
|
|
w = SSL_write(ssl.get(), "hello", 5);
|
2015-02-09 17:59:46 +00:00
|
|
|
} while (config->async && RetryAsync(ssl.get(), w, async, &clock_delta));
|
2014-08-24 08:47:07 +01:00
|
|
|
}
|
2014-08-05 23:23:37 +01:00
|
|
|
for (;;) {
|
|
|
|
uint8_t buf[512];
|
|
|
|
int n;
|
|
|
|
do {
|
2015-02-09 07:37:18 +00:00
|
|
|
n = SSL_read(ssl.get(), buf, sizeof(buf));
|
2015-02-09 17:59:46 +00:00
|
|
|
} while (config->async && RetryAsync(ssl.get(), n, async, &clock_delta));
|
2015-02-09 07:37:18 +00:00
|
|
|
int err = SSL_get_error(ssl.get(), n);
|
2015-01-22 21:06:11 +00:00
|
|
|
if (err == SSL_ERROR_ZERO_RETURN ||
|
|
|
|
(n == 0 && err == SSL_ERROR_SYSCALL)) {
|
|
|
|
if (n != 0) {
|
|
|
|
fprintf(stderr, "Invalid SSL_get_error output\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-01-22 21:06:11 +00:00
|
|
|
}
|
2015-02-09 17:59:46 +00:00
|
|
|
// Accept shutdowns with or without close_notify.
|
|
|
|
// TODO(davidben): Write tests which distinguish these two cases.
|
2015-01-22 21:06:11 +00:00
|
|
|
break;
|
|
|
|
} else if (err != SSL_ERROR_NONE) {
|
|
|
|
if (n > 0) {
|
|
|
|
fprintf(stderr, "Invalid SSL_get_error output\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-01-22 21:06:11 +00:00
|
|
|
}
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-01-22 21:06:11 +00:00
|
|
|
}
|
2015-02-09 17:59:46 +00:00
|
|
|
// Successfully read data.
|
2015-01-22 21:06:11 +00:00
|
|
|
if (n <= 0) {
|
|
|
|
fprintf(stderr, "Invalid SSL_get_error output\n");
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2015-01-22 21:06:11 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
buf[i] ^= 0xff;
|
|
|
|
}
|
|
|
|
int w;
|
|
|
|
do {
|
2015-02-09 07:37:18 +00:00
|
|
|
w = SSL_write(ssl.get(), buf, n);
|
2015-02-09 17:59:46 +00:00
|
|
|
} while (config->async && RetryAsync(ssl.get(), w, async, &clock_delta));
|
2015-01-22 21:06:11 +00:00
|
|
|
if (w != n) {
|
2015-02-20 16:23:42 +00:00
|
|
|
return false;
|
2014-08-05 23:23:37 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 00:20:02 +01:00
|
|
|
if (out_session) {
|
2015-02-09 07:37:18 +00:00
|
|
|
out_session->reset(SSL_get1_session(ssl.get()));
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
SSL_shutdown(ssl.get());
|
2015-02-20 16:23:42 +00:00
|
|
|
return true;
|
2014-07-02 00:53:04 +01:00
|
|
|
}
|
2014-07-23 00:20:02 +01:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
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
|
|
|
#if defined(OPENSSL_WINDOWS)
|
|
|
|
/* Initialize Winsock. */
|
|
|
|
WORD wsa_version = MAKEWORD(2, 2);
|
|
|
|
WSADATA wsa_data;
|
|
|
|
int wsa_err = WSAStartup(wsa_version, &wsa_data);
|
|
|
|
if (wsa_err != 0) {
|
|
|
|
fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (wsa_data.wVersion != wsa_version) {
|
|
|
|
fprintf(stderr, "Didn't get expected version: %x\n", wsa_data.wVersion);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#else
|
2014-07-23 00:20:02 +01:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2014-07-31 23:23:51 +01:00
|
|
|
#endif
|
2014-07-23 00:20:02 +01:00
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
if (!SSL_library_init()) {
|
|
|
|
return 1;
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|
2015-02-09 08:04:34 +00:00
|
|
|
g_config_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL);
|
|
|
|
g_clock_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL);
|
2015-02-09 18:03:50 +00:00
|
|
|
g_state_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, TestStateExFree);
|
|
|
|
if (g_config_index < 0 || g_clock_index < 0 || g_state_index < 0) {
|
2014-11-19 02:52:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-07-23 00:20:02 +01:00
|
|
|
|
2014-08-12 00:51:50 +01:00
|
|
|
TestConfig config;
|
|
|
|
if (!ParseConfig(argc - 1, argv + 1, &config)) {
|
2015-02-09 17:59:46 +00:00
|
|
|
return Usage(argv[0]);
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 17:59:46 +00:00
|
|
|
ScopedSSL_CTX ssl_ctx = SetupCtx(&config);
|
2015-02-09 07:37:18 +00:00
|
|
|
if (!ssl_ctx) {
|
2014-07-23 00:20:02 +01:00
|
|
|
BIO_print_errors_fp(stdout);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
ScopedSSL_SESSION session;
|
2015-02-20 16:23:42 +00:00
|
|
|
if (!DoExchange(&session, ssl_ctx.get(), &config, false /* is_resume */,
|
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
|
|
|
NULL /* session */)) {
|
2015-02-20 16:23:42 +00:00
|
|
|
BIO_print_errors_fp(stdout);
|
|
|
|
return 1;
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 16:23:42 +00:00
|
|
|
if (config.resume &&
|
|
|
|
!DoExchange(NULL, ssl_ctx.get(), &config, true /* is_resume */,
|
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
|
|
|
session.get())) {
|
2015-02-20 16:23:42 +00:00
|
|
|
BIO_print_errors_fp(stdout);
|
|
|
|
return 1;
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 07:37:18 +00:00
|
|
|
return 0;
|
2014-07-23 00:20:02 +01:00
|
|
|
}
|