|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#ifdef OPENSSL_NO_CT
|
|
Packit Service |
084de1 |
# error "CT is disabled"
|
|
Packit Service |
084de1 |
#endif
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <openssl/ct.h>
|
|
Packit Service |
084de1 |
#include <openssl/err.h>
|
|
Packit Service |
084de1 |
#include <time.h>
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include "ct_local.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Number of seconds in the future that an SCT timestamp can be, by default,
|
|
Packit Service |
084de1 |
* without being considered invalid. This is added to time() when setting a
|
|
Packit Service |
084de1 |
* default value for CT_POLICY_EVAL_CTX.epoch_time_in_ms.
|
|
Packit Service |
084de1 |
* It can be overridden by calling CT_POLICY_EVAL_CTX_set_time().
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
static const time_t SCT_CLOCK_DRIFT_TOLERANCE = 300;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (ctx == NULL) {
|
|
Packit Service |
084de1 |
CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* time(NULL) shouldn't ever fail, so don't bother checking for -1. */
|
|
Packit Service |
084de1 |
ctx->epoch_time_in_ms = (uint64_t)(time(NULL) + SCT_CLOCK_DRIFT_TOLERANCE) *
|
|
Packit Service |
084de1 |
1000;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return ctx;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
if (ctx == NULL)
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
X509_free(ctx->cert);
|
|
Packit Service |
084de1 |
X509_free(ctx->issuer);
|
|
Packit Service |
084de1 |
OPENSSL_free(ctx);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
if (!X509_up_ref(cert))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
ctx->cert = cert;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
if (!X509_up_ref(issuer))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
ctx->issuer = issuer;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
|
|
Packit Service |
084de1 |
CTLOG_STORE *log_store)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->log_store = log_store;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->epoch_time_in_ms = time_in_ms;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return ctx->cert;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return ctx->issuer;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return ctx->log_store;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return ctx->epoch_time_in_ms;
|
|
Packit Service |
084de1 |
}
|