Adding function to set the "current time" callback used for DTLS.

This callback is used by BoringSSL tests in order to simulate the time,
so that the tests have repeatable results. This API will allow consumers
of BoringSSL to write the same sort of tests.

Change-Id: I79d72bce5510bbd83c307915cd2cc937579ce948
Reviewed-on: https://boringssl-review.googlesource.com/8200
Reviewed-by: David Benjamin <davidben@google.com>
This commit is contained in:
Taylor Brandstetter 2016-06-08 15:26:59 -07:00 committed by David Benjamin
parent 2e045a980c
commit 9edb2c6055
2 changed files with 15 additions and 1 deletions

View File

@ -2728,6 +2728,13 @@ OPENSSL_EXPORT void SSL_set_msg_callback_arg(SSL *ssl, void *arg);
OPENSSL_EXPORT void SSL_CTX_set_keylog_callback(
SSL_CTX *ctx, void (*cb)(const SSL *ssl, const char *line));
/* SSL_CTX_set_current_time_cb configures a callback to retrieve the current
* time, which should be set in |*out_clock|. This can be used for testing
* purposes; for example, a callback can be configured that returns a time
* set explicitly by the test. */
OPENSSL_EXPORT void SSL_CTX_set_current_time_cb(
SSL_CTX *ctx, void (*cb)(const SSL *ssl, struct timeval *out_clock));
enum ssl_renegotiate_mode_t {
ssl_renegotiate_never = 0,
ssl_renegotiate_once,
@ -3825,7 +3832,8 @@ struct ssl_ctx_st {
void (*keylog_callback)(const SSL *ssl, const char *line);
/* current_time_cb, if not NULL, is the function to use to get the current
* time. It sets |*out_clock| to the current time. */
* time. It sets |*out_clock| to the current time. See
* |SSL_CTX_set_current_time_cb|. */
void (*current_time_cb)(const SSL *ssl, struct timeval *out_clock);
/* quiet_shutdown is true if the connection should not send a close_notify on

View File

@ -2356,6 +2356,12 @@ void SSL_CTX_set_keylog_callback(SSL_CTX *ctx,
ctx->keylog_callback = cb;
}
void SSL_CTX_set_current_time_cb(SSL_CTX *ctx,
void (*cb)(const SSL *ssl,
struct timeval *out_clock)) {
ctx->current_time_cb = cb;
}
static int cbb_add_hex(CBB *cbb, const uint8_t *in, size_t in_len) {
static const char hextable[] = "0123456789abcdef";
uint8_t *out;