]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/ct/ct_policy.c
Default CT_POLICY_EVAL_CTX.epoch_time_in_ms to time()
[thirdparty/openssl.git] / crypto / ct / ct_policy.c
1 /*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #ifdef OPENSSL_NO_CT
11 # error "CT is disabled"
12 #endif
13
14 #include <openssl/ct.h>
15 #include <openssl/err.h>
16 #include <time.h>
17
18 #include "ct_locl.h"
19
20 CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)
21 {
22 CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));
23 time_t epoch_time_in_s;
24
25 if (ctx == NULL) {
26 CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);
27 return NULL;
28 }
29
30 // Use the current time if available.
31 time(&epoch_time_in_s);
32 if (epoch_time_in_s != -1)
33 ctx->epoch_time_in_ms = epoch_time_in_s * 1000;
34
35 return ctx;
36 }
37
38 void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx)
39 {
40 if (ctx == NULL)
41 return;
42 X509_free(ctx->cert);
43 X509_free(ctx->issuer);
44 OPENSSL_free(ctx);
45 }
46
47 int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert)
48 {
49 if (!X509_up_ref(cert))
50 return 0;
51 ctx->cert = cert;
52 return 1;
53 }
54
55 int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer)
56 {
57 if (!X509_up_ref(issuer))
58 return 0;
59 ctx->issuer = issuer;
60 return 1;
61 }
62
63 void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
64 CTLOG_STORE *log_store)
65 {
66 ctx->log_store = log_store;
67 }
68
69 void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)
70 {
71 ctx->epoch_time_in_ms = time_in_ms;
72 }
73
74 X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx)
75 {
76 return ctx->cert;
77 }
78
79 X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx)
80 {
81 return ctx->issuer;
82 }
83
84 const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx)
85 {
86 return ctx->log_store;
87 }
88
89 uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx)
90 {
91 return ctx->epoch_time_in_ms;
92 }