diff options
author | beck <> | 2021-11-20 01:10:49 +0000 |
---|---|---|
committer | beck <> | 2021-11-20 01:10:49 +0000 |
commit | 945f084e2204432f02dc67409d640c082c7d12b1 (patch) | |
tree | 09562d0baf42f60ea370c64468465708195ec887 /src/lib/libcrypto/ct/ct_log.c | |
parent | 3d755921799d0394eade3c0043ddc31a5a71be7c (diff) | |
download | openbsd-945f084e2204432f02dc67409d640c082c7d12b1.tar.gz openbsd-945f084e2204432f02dc67409d640c082c7d12b1.tar.bz2 openbsd-945f084e2204432f02dc67409d640c082c7d12b1.zip |
Make these files compile - not hooked up to build yet.
ok jsing@ tb@
Diffstat (limited to 'src/lib/libcrypto/ct/ct_log.c')
-rw-r--r-- | src/lib/libcrypto/ct/ct_log.c | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/src/lib/libcrypto/ct/ct_log.c b/src/lib/libcrypto/ct/ct_log.c index ee44de2bfc..1eca056b89 100644 --- a/src/lib/libcrypto/ct/ct_log.c +++ b/src/lib/libcrypto/ct/ct_log.c | |||
@@ -16,7 +16,8 @@ | |||
16 | #include <openssl/evp.h> | 16 | #include <openssl/evp.h> |
17 | #include <openssl/safestack.h> | 17 | #include <openssl/safestack.h> |
18 | 18 | ||
19 | #include "internal/cryptlib.h" | 19 | #include "cryptlib.h" |
20 | |||
20 | 21 | ||
21 | /* | 22 | /* |
22 | * Information about a CT log server. | 23 | * Information about a CT log server. |
@@ -52,23 +53,23 @@ static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void); | |||
52 | * Deletes a CT log store load context. | 53 | * Deletes a CT log store load context. |
53 | * Does not delete any of the fields. | 54 | * Does not delete any of the fields. |
54 | */ | 55 | */ |
55 | static void ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX* ctx); | 56 | static void ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX *ctx); |
56 | 57 | ||
57 | static CTLOG_STORE_LOAD_CTX * | 58 | static CTLOG_STORE_LOAD_CTX * |
58 | ctlog_store_load_ctx_new(void) | 59 | ctlog_store_load_ctx_new(void) |
59 | { | 60 | { |
60 | CTLOG_STORE_LOAD_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); | 61 | CTLOG_STORE_LOAD_CTX *ctx = calloc(1, sizeof(*ctx)); |
61 | 62 | ||
62 | if (ctx == NULL) | 63 | if (ctx == NULL) |
63 | CTerr(CT_F_CTLOG_STORE_LOAD_CTX_NEW, ERR_R_MALLOC_FAILURE); | 64 | CTerror(ERR_R_MALLOC_FAILURE); |
64 | 65 | ||
65 | return ctx; | 66 | return ctx; |
66 | } | 67 | } |
67 | 68 | ||
68 | static void | 69 | static void |
69 | ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX* ctx) | 70 | ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX *ctx) |
70 | { | 71 | { |
71 | OPENSSL_free(ctx); | 72 | free(ctx); |
72 | } | 73 | } |
73 | 74 | ||
74 | /* Converts a log's public key into a SHA256 log ID */ | 75 | /* Converts a log's public key into a SHA256 log ID */ |
@@ -80,24 +81,24 @@ ct_v1_log_id_from_pkey(EVP_PKEY *pkey, unsigned char log_id[CT_V1_HASHLEN]) | |||
80 | int pkey_der_len = i2d_PUBKEY(pkey, &pkey_der); | 81 | int pkey_der_len = i2d_PUBKEY(pkey, &pkey_der); |
81 | 82 | ||
82 | if (pkey_der_len <= 0) { | 83 | if (pkey_der_len <= 0) { |
83 | CTerr(CT_F_CT_V1_LOG_ID_FROM_PKEY, CT_R_LOG_KEY_INVALID); | 84 | CTerror(CT_R_LOG_KEY_INVALID); |
84 | goto err; | 85 | goto err; |
85 | } | 86 | } |
86 | 87 | ||
87 | SHA256(pkey_der, pkey_der_len, log_id); | 88 | SHA256(pkey_der, pkey_der_len, log_id); |
88 | ret = 1; | 89 | ret = 1; |
89 | err: | 90 | err: |
90 | OPENSSL_free(pkey_der); | 91 | free(pkey_der); |
91 | return ret; | 92 | return ret; |
92 | } | 93 | } |
93 | 94 | ||
94 | CTLOG_STORE * | 95 | CTLOG_STORE * |
95 | CTLOG_STORE_new(void) | 96 | CTLOG_STORE_new(void) |
96 | { | 97 | { |
97 | CTLOG_STORE *ret = OPENSSL_zalloc(sizeof(*ret)); | 98 | CTLOG_STORE *ret = calloc(1, sizeof(*ret)); |
98 | 99 | ||
99 | if (ret == NULL) { | 100 | if (ret == NULL) { |
100 | CTerr(CT_F_CTLOG_STORE_NEW, ERR_R_MALLOC_FAILURE); | 101 | CTerror(ERR_R_MALLOC_FAILURE); |
101 | return NULL; | 102 | return NULL; |
102 | } | 103 | } |
103 | 104 | ||
@@ -106,8 +107,8 @@ CTLOG_STORE_new(void) | |||
106 | goto err; | 107 | goto err; |
107 | 108 | ||
108 | return ret; | 109 | return ret; |
109 | err: | 110 | err: |
110 | OPENSSL_free(ret); | 111 | free(ret); |
111 | return NULL; | 112 | return NULL; |
112 | } | 113 | } |
113 | 114 | ||
@@ -116,24 +117,25 @@ CTLOG_STORE_free(CTLOG_STORE *store) | |||
116 | { | 117 | { |
117 | if (store != NULL) { | 118 | if (store != NULL) { |
118 | sk_CTLOG_pop_free(store->logs, CTLOG_free); | 119 | sk_CTLOG_pop_free(store->logs, CTLOG_free); |
119 | OPENSSL_free(store); | 120 | free(store); |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | static int | 124 | static int |
124 | ctlog_new_from_conf(CTLOG **ct_log, const CONF *conf, const char *section) | 125 | ctlog_new_from_conf(CTLOG **ct_log, const CONF *conf, const char *section) |
125 | { | 126 | { |
126 | const char *description = NCONF_get_string(conf, section, "description"); | 127 | const char *description = NCONF_get_string(conf, section, |
128 | "description"); | ||
127 | char *pkey_base64; | 129 | char *pkey_base64; |
128 | 130 | ||
129 | if (description == NULL) { | 131 | if (description == NULL) { |
130 | CTerr(CT_F_CTLOG_NEW_FROM_CONF, CT_R_LOG_CONF_MISSING_DESCRIPTION); | 132 | CTerror(CT_R_LOG_CONF_MISSING_DESCRIPTION); |
131 | return 0; | 133 | return 0; |
132 | } | 134 | } |
133 | 135 | ||
134 | pkey_base64 = NCONF_get_string(conf, section, "key"); | 136 | pkey_base64 = NCONF_get_string(conf, section, "key"); |
135 | if (pkey_base64 == NULL) { | 137 | if (pkey_base64 == NULL) { |
136 | CTerr(CT_F_CTLOG_NEW_FROM_CONF, CT_R_LOG_CONF_MISSING_KEY); | 138 | CTerror(CT_R_LOG_CONF_MISSING_KEY); |
137 | return 0; | 139 | return 0; |
138 | } | 140 | } |
139 | 141 | ||
@@ -143,12 +145,7 @@ ctlog_new_from_conf(CTLOG **ct_log, const CONF *conf, const char *section) | |||
143 | int | 145 | int |
144 | CTLOG_STORE_load_default_file(CTLOG_STORE *store) | 146 | CTLOG_STORE_load_default_file(CTLOG_STORE *store) |
145 | { | 147 | { |
146 | const char *fpath = ossl_safe_getenv(CTLOG_FILE_EVP); | 148 | return CTLOG_STORE_load_file(store, CTLOG_FILE); |
147 | |||
148 | if (fpath == NULL) | ||
149 | fpath = CTLOG_FILE; | ||
150 | |||
151 | return CTLOG_STORE_load_file(store, fpath); | ||
152 | } | 149 | } |
153 | 150 | ||
154 | /* | 151 | /* |
@@ -170,12 +167,12 @@ ctlog_store_load_log(const char *log_name, int log_name_len, void *arg) | |||
170 | if (log_name == NULL) | 167 | if (log_name == NULL) |
171 | return 1; | 168 | return 1; |
172 | 169 | ||
173 | tmp = OPENSSL_strndup(log_name, log_name_len); | 170 | tmp = strndup(log_name, log_name_len); |
174 | if (tmp == NULL) | 171 | if (tmp == NULL) |
175 | goto mem_err; | 172 | goto mem_err; |
176 | 173 | ||
177 | ret = ctlog_new_from_conf(&ct_log, load_ctx->conf, tmp); | 174 | ret = ctlog_new_from_conf(&ct_log, load_ctx->conf, tmp); |
178 | OPENSSL_free(tmp); | 175 | free(tmp); |
179 | 176 | ||
180 | if (ret < 0) { | 177 | if (ret < 0) { |
181 | /* Propagate any internal error */ | 178 | /* Propagate any internal error */ |
@@ -192,9 +189,9 @@ ctlog_store_load_log(const char *log_name, int log_name_len, void *arg) | |||
192 | } | 189 | } |
193 | return 1; | 190 | return 1; |
194 | 191 | ||
195 | mem_err: | 192 | mem_err: |
196 | CTLOG_free(ct_log); | 193 | CTLOG_free(ct_log); |
197 | CTerr(CT_F_CTLOG_STORE_LOAD_LOG, ERR_R_MALLOC_FAILURE); | 194 | CTerror(ERR_R_MALLOC_FAILURE); |
198 | return -1; | 195 | return -1; |
199 | } | 196 | } |
200 | 197 | ||
@@ -213,24 +210,24 @@ CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file) | |||
213 | goto end; | 210 | goto end; |
214 | 211 | ||
215 | if (NCONF_load(load_ctx->conf, file, NULL) <= 0) { | 212 | if (NCONF_load(load_ctx->conf, file, NULL) <= 0) { |
216 | CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID); | 213 | CTerror(CT_R_LOG_CONF_INVALID); |
217 | goto end; | 214 | goto end; |
218 | } | 215 | } |
219 | 216 | ||
220 | enabled_logs = NCONF_get_string(load_ctx->conf, NULL, "enabled_logs"); | 217 | enabled_logs = NCONF_get_string(load_ctx->conf, NULL, "enabled_logs"); |
221 | if (enabled_logs == NULL) { | 218 | if (enabled_logs == NULL) { |
222 | CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID); | 219 | CTerror(CT_R_LOG_CONF_INVALID); |
223 | goto end; | 220 | goto end; |
224 | } | 221 | } |
225 | 222 | ||
226 | if (!CONF_parse_list(enabled_logs, ',', 1, ctlog_store_load_log, load_ctx) || | 223 | if (!CONF_parse_list(enabled_logs, ',', 1, ctlog_store_load_log, load_ctx) || |
227 | load_ctx->invalid_log_entries > 0) { | 224 | load_ctx->invalid_log_entries > 0) { |
228 | CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID); | 225 | CTerror(CT_R_LOG_CONF_INVALID); |
229 | goto end; | 226 | goto end; |
230 | } | 227 | } |
231 | 228 | ||
232 | ret = 1; | 229 | ret = 1; |
233 | end: | 230 | end: |
234 | NCONF_free(load_ctx->conf); | 231 | NCONF_free(load_ctx->conf); |
235 | ctlog_store_load_ctx_free(load_ctx); | 232 | ctlog_store_load_ctx_free(load_ctx); |
236 | return ret; | 233 | return ret; |
@@ -244,16 +241,16 @@ end: | |||
244 | CTLOG * | 241 | CTLOG * |
245 | CTLOG_new(EVP_PKEY *public_key, const char *name) | 242 | CTLOG_new(EVP_PKEY *public_key, const char *name) |
246 | { | 243 | { |
247 | CTLOG *ret = OPENSSL_zalloc(sizeof(*ret)); | 244 | CTLOG *ret = calloc(1, sizeof(*ret)); |
248 | 245 | ||
249 | if (ret == NULL) { | 246 | if (ret == NULL) { |
250 | CTerr(CT_F_CTLOG_NEW, ERR_R_MALLOC_FAILURE); | 247 | CTerror(ERR_R_MALLOC_FAILURE); |
251 | return NULL; | 248 | return NULL; |
252 | } | 249 | } |
253 | 250 | ||
254 | ret->name = OPENSSL_strdup(name); | 251 | ret->name = strdup(name); |
255 | if (ret->name == NULL) { | 252 | if (ret->name == NULL) { |
256 | CTerr(CT_F_CTLOG_NEW, ERR_R_MALLOC_FAILURE); | 253 | CTerror(ERR_R_MALLOC_FAILURE); |
257 | goto err; | 254 | goto err; |
258 | } | 255 | } |
259 | 256 | ||
@@ -272,9 +269,9 @@ void | |||
272 | CTLOG_free(CTLOG *log) | 269 | CTLOG_free(CTLOG *log) |
273 | { | 270 | { |
274 | if (log != NULL) { | 271 | if (log != NULL) { |
275 | OPENSSL_free(log->name); | 272 | free(log->name); |
276 | EVP_PKEY_free(log->public_key); | 273 | EVP_PKEY_free(log->public_key); |
277 | OPENSSL_free(log); | 274 | free(log); |
278 | } | 275 | } |
279 | } | 276 | } |
280 | 277 | ||
@@ -301,8 +298,8 @@ CTLOG_get0_public_key(const CTLOG *log) | |||
301 | * Given a log ID, finds the matching log. | 298 | * Given a log ID, finds the matching log. |
302 | * Returns NULL if no match found. | 299 | * Returns NULL if no match found. |
303 | */ | 300 | */ |
304 | const CTLOG | 301 | const CTLOG * |
305 | *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store, const uint8_t *log_id, | 302 | CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store, const uint8_t *log_id, |
306 | size_t log_id_len) | 303 | size_t log_id_len) |
307 | { | 304 | { |
308 | int i; | 305 | int i; |