OpenVPN
tls_crypt.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2016-2026 Sentyron B.V. <openvpn@sentyron.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "syshead.h"
28
29#include "argv.h"
30#include "base64.h"
31#include "crypto.h"
32#include "integer.h"
33#include "platform.h"
34#include "run_command.h"
35#include "session_id.h"
36#include "ssl.h"
37#include "buffer.h"
38
39#include "tls_crypt.h"
40
41const char *tls_crypt_v2_cli_pem_name = "OpenVPN tls-crypt-v2 client key";
42const char *tls_crypt_v2_srv_pem_name = "OpenVPN tls-crypt-v2 server key";
43
45static const uint8_t TLS_CRYPT_METADATA_TYPE_USER = 0x00;
47static const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP = 0x01;
48
49static struct key_type
51{
52 return create_kt("AES-256-CTR", "SHA256", "tls-crypt");
53}
54
55unsigned int
60
61void
62tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, const char *key_file,
63 bool key_inline, bool tls_server)
64{
65 const int key_direction = tls_server ? KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE;
66 struct key_type kt = tls_crypt_kt();
67 if (!kt.cipher || !kt.digest)
68 {
69 msg(M_FATAL, "ERROR: --tls-crypt not supported");
70 }
71 crypto_read_openvpn_key(&kt, key, key_file, key_inline, key_direction,
72 "Control Channel Encryption", "tls-crypt", keydata);
73}
74
78static void
79xor_key2(struct key2 *key, const struct key2 *other)
80{
81 ASSERT(key->n == 2 && other->n == 2);
82 for (int k = 0; k < 2; k++)
83 {
84 for (int j = 0; j < MAX_CIPHER_KEY_LENGTH; j++)
85 {
86 key->keys[k].cipher[j] = key->keys[k].cipher[j] ^ other->keys[k].cipher[j];
87 }
88
89 for (int j = 0; j < MAX_HMAC_KEY_LENGTH; j++)
90 {
91 key->keys[k].hmac[j] = key->keys[k].hmac[j] ^ other->keys[k].hmac[j];
92 }
93 }
94}
95
96#if defined(__GNUC__) || defined(__clang__)
97#pragma GCC diagnostic push
98#pragma GCC diagnostic ignored "-Wsign-conversion"
99#endif
100
101bool
103{
104 struct key2 rengokeys;
106 strlen(EXPORT_DYNAMIC_TLS_CRYPT_LABEL), rengokeys.keys,
107 sizeof(rengokeys.keys)))
108 {
109 return false;
110 }
111 rengokeys.n = 2;
112
113 session->tls_wrap_reneg.opt = session->tls_wrap.opt;
114 session->tls_wrap_reneg.mode = TLS_WRAP_CRYPT;
115 session->tls_wrap_reneg.cleanup_key_ctx = true;
116 session->tls_wrap_reneg.work = alloc_buf(BUF_SIZE(&session->opt->frame));
117
118 packet_id_init(&session->tls_wrap_reneg.opt.packet_id, session->opt->replay_window,
119 session->opt->replay_time, "TLS_WRAP_RENEG", session->key_id);
120
121 if (session->tls_wrap.mode == TLS_WRAP_CRYPT || session->tls_wrap.mode == TLS_WRAP_AUTH)
122 {
123 xor_key2(&rengokeys, &session->tls_wrap.original_wrap_keydata);
124 }
125
126 const int key_direction = session->opt->server ? KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE;
127
128 struct key_type kt = tls_crypt_kt();
129
130 init_key_ctx_bi(&session->tls_wrap_reneg.opt.key_ctx_bi, &rengokeys, key_direction, &kt,
131 "dynamic tls-crypt");
132 secure_memzero(&rengokeys, sizeof(rengokeys));
133
134 return true;
135}
136
137
138bool
139tls_crypt_wrap(const struct buffer *src, struct buffer *dst, struct crypto_options *opt)
140{
141 const struct key_ctx *ctx = &opt->key_ctx_bi.encrypt;
142 struct gc_arena gc;
143
144 /* IV, packet-ID and implicit IV required for this mode. */
145 ASSERT(ctx->cipher);
146 ASSERT(ctx->hmac);
148 ASSERT(hmac_ctx_size(ctx->hmac) == 256 / 8);
149
150 gc_init(&gc);
151
152 dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP FROM: %s", format_hex(CBPTR(src), BLEN(src), 80, &gc));
153
154 /* Get packet ID */
155 if (!packet_id_write(&opt->packet_id.send, dst, true, false))
156 {
157 msg(D_CRYPT_ERRORS, "TLS-CRYPT ERROR: packet ID roll over.");
158 goto err;
159 }
160
161 dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP AD: %s", format_hex(CBPTR(dst), BLEN(dst), 0, &gc));
162
163 /* Buffer overflow check */
165 {
167 "TLS-CRYPT WRAP: buffer size error, "
168 "sc=%d so=%d sl=%d dc=%d do=%d dl=%d",
169 src->capacity, src->offset, src->len, dst->capacity, dst->offset, dst->len);
170 goto err;
171 }
172
173 /* Calculate auth tag and synthetic IV */
174 {
175 uint8_t *tag = NULL;
176 hmac_ctx_reset(ctx->hmac);
177 hmac_ctx_update(ctx->hmac, CBPTR(dst), BLEN(dst));
178 hmac_ctx_update(ctx->hmac, CBPTR(src), BLEN(src));
179
181 hmac_ctx_final(ctx->hmac, tag);
182
183 dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP TAG: %s",
184 format_hex(tag, TLS_CRYPT_TAG_SIZE, 0, &gc));
185
186 /* Use the 128 most significant bits of the tag as IV */
187 ASSERT(cipher_ctx_reset(ctx->cipher, tag));
188 }
189
190 /* Encrypt src */
191 {
192 int outlen = 0;
193 ASSERT(cipher_ctx_update(ctx->cipher, BEND(dst), &outlen, CBPTR(src), BLEN(src)));
194 ASSERT(buf_inc_len(dst, outlen));
195 ASSERT(cipher_ctx_final(ctx->cipher, BEND(dst), &outlen));
196 ASSERT(buf_inc_len(dst, outlen));
197 }
198
199 dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP TO: %s", format_hex(BPTR(dst), BLEN(dst), 80, &gc));
200
201 gc_free(&gc);
202 return true;
203
204err:
206 dst->len = 0;
207 gc_free(&gc);
208 return false;
209}
210
211bool
212tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, struct crypto_options *opt)
213{
214 static const char error_prefix[] = "tls-crypt unwrap error";
215 const struct key_ctx *ctx = &opt->key_ctx_bi.decrypt;
216 struct gc_arena gc;
217
218 gc_init(&gc);
219
220 ASSERT(opt);
221 ASSERT(ctx->cipher);
223
224 dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP FROM: %s", format_hex(CBPTR(src), BLEN(src), 80, &gc));
225
226 if (BLENZ(src) < TLS_CRYPT_OFF_CT)
227 {
228 CRYPT_ERROR("packet too short");
229 }
230
231 /* Decrypt cipher text */
232 {
233 int outlen = 0;
234
235 /* Buffer overflow check (should never fail) */
237 {
238 CRYPT_ERROR("potential buffer overflow");
239 }
240
242 {
243 CRYPT_ERROR("cipher reset failed");
244 }
245 if (!cipher_ctx_update(ctx->cipher, BPTR(dst), &outlen, CBPTR(src) + TLS_CRYPT_OFF_CT,
246 BLEN(src) - (int)TLS_CRYPT_OFF_CT))
247 {
248 CRYPT_ERROR("cipher update failed");
249 }
250 ASSERT(buf_inc_len(dst, outlen));
251 if (!cipher_ctx_final(ctx->cipher, BEND(dst), &outlen))
252 {
253 CRYPT_ERROR("cipher final failed");
254 }
255 ASSERT(buf_inc_len(dst, outlen));
256 }
257
258 /* Check authentication */
259 {
260 const uint8_t *tag = CBPTR(src) + TLS_CRYPT_OFF_TAG;
261 uint8_t tag_check[TLS_CRYPT_TAG_SIZE] = { 0 };
262
263 dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP AD: %s",
265 dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP TO: %s",
266 format_hex(CBPTR(dst), BLEN(dst), 80, &gc));
267
268 hmac_ctx_reset(ctx->hmac);
270 hmac_ctx_update(ctx->hmac, CBPTR(dst), BLEN(dst));
271 hmac_ctx_final(ctx->hmac, tag_check);
272
273 if (memcmp_constant_time(tag, tag_check, sizeof(tag_check)))
274 {
275 dmsg(D_CRYPTO_DEBUG, "tag : %s", format_hex(tag, sizeof(tag_check), 0, &gc));
276 dmsg(D_CRYPTO_DEBUG, "tag_check: %s", format_hex(tag_check, sizeof(tag_check), 0, &gc));
277 CRYPT_ERROR("packet authentication failed");
278 }
279 }
280
281 /* Check replay */
282 if (!(opt->flags & CO_IGNORE_PACKET_ID))
283 {
284 struct packet_id_net pin;
285 struct buffer tmp = *src;
287 ASSERT(packet_id_read(&pin, &tmp, true));
288 if (!crypto_check_replay(opt, &pin, 0, error_prefix, &gc))
289 {
290 CRYPT_ERROR("packet replay");
291 }
292 }
293
294 gc_free(&gc);
295 return true;
296
297error_exit:
299 dst->len = 0;
300 gc_free(&gc);
301 return false;
302}
303
304static inline void
305tls_crypt_v2_load_client_key(struct key_ctx_bi *key, const struct key2 *key2, bool tls_server)
306{
307 const int key_direction = tls_server ? KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE;
308 struct key_type kt = tls_crypt_kt();
309 if (!kt.cipher || !kt.digest)
310 {
311 msg(M_FATAL, "ERROR: --tls-crypt-v2 not supported");
312 }
313 init_key_ctx_bi(key, key2, key_direction, &kt, "Control Channel Encryption");
314}
315
316void
317tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key,
318 struct buffer *wkc_buf, const char *key_file, bool key_inline)
319{
321
322 if (!read_pem_key_file(&client_key, tls_crypt_v2_cli_pem_name, key_file, key_inline))
323 {
324 msg(M_FATAL, "ERROR: invalid tls-crypt-v2 client key format");
325 }
326
327 struct key2 key2 = { .n = 2 };
328 if (!buf_read(&client_key, &key2.keys, sizeof(key2.keys)))
329 {
330 msg(M_FATAL, "ERROR: not enough data in tls-crypt-v2 client key");
331 }
332
334 *original_key = key2;
335 secure_memzero(&key2, sizeof(key2));
336
337 *wkc_buf = client_key;
338}
339
340void
341tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, const char *key_file,
342 bool key_inline)
343{
344 struct key srv_key;
345 struct buffer srv_key_buf;
346
347 buf_set_write(&srv_key_buf, (void *)&srv_key, sizeof(srv_key));
348 if (!read_pem_key_file(&srv_key_buf, tls_crypt_v2_srv_pem_name, key_file, key_inline))
349 {
350 msg(M_FATAL, "ERROR: invalid tls-crypt-v2 server key format");
351 }
352
353 struct key_type kt = tls_crypt_kt();
354 if (!kt.cipher || !kt.digest)
355 {
356 msg(M_FATAL, "ERROR: --tls-crypt-v2 not supported");
357 }
358 struct key_parameters srv_key_params;
359
360 key_parameters_from_key(&srv_key_params, &srv_key);
361
362 init_key_ctx(key_ctx, &srv_key_params, &kt, encrypt, "tls-crypt-v2 server key");
363 secure_memzero(&srv_key, sizeof(srv_key));
364 secure_memzero(&srv_key_params, sizeof(srv_key_params));
365}
366
367static bool
368tls_crypt_v2_wrap_client_key(struct buffer *wkc, const struct key2 *src_key,
369 const struct buffer *src_metadata, struct key_ctx *server_key,
370 struct gc_arena *gc)
371{
372 cipher_ctx_t *cipher_ctx = server_key->cipher;
373 struct buffer work =
375
376 /* Calculate auth tag and synthetic IV */
377 uint8_t *tag = buf_write_alloc(&work, TLS_CRYPT_TAG_SIZE);
378 if (!tag)
379 {
380 msg(M_WARN, "ERROR: could not write tag");
381 return false;
382 }
383 const size_t data_len = BLENZ(src_metadata) + sizeof(src_key->keys) + sizeof(uint16_t);
384 const size_t tagged_len = data_len + TLS_CRYPT_TAG_SIZE;
385 const uint16_t net_len = htons((uint16_t)tagged_len);
386 hmac_ctx_t *hmac_ctx = server_key->hmac;
388 hmac_ctx_update(hmac_ctx, (void *)&net_len, sizeof(net_len));
389 hmac_ctx_update(hmac_ctx, (void *)src_key->keys, sizeof(src_key->keys));
390 hmac_ctx_update(hmac_ctx, CBPTR(src_metadata), BLEN(src_metadata));
392
393 dmsg(D_CRYPTO_DEBUG, "TLS-CRYPT WRAP TAG: %s", format_hex(tag, TLS_CRYPT_TAG_SIZE, 0, gc));
394
395 /* Use the 128 most significant bits of the tag as IV */
397
398 /* Overflow check (OpenSSL requires an extra block in the dst buffer) */
399 const size_t padded_len = data_len + cipher_ctx_block_size(cipher_ctx);
400 if (buf_forward_capacity(&work) < padded_len)
401 {
402 msg(M_WARN, "ERROR: could not crypt: insufficient space in dst");
403 return false;
404 }
405
406 /* Encrypt */
407 int outlen = 0;
408 ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, (void *)src_key->keys,
409 sizeof(src_key->keys)));
410 ASSERT(buf_inc_len(&work, outlen));
411 ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, CBPTR(src_metadata),
412 BLEN(src_metadata)));
413 ASSERT(buf_inc_len(&work, outlen));
414 ASSERT(cipher_ctx_final(cipher_ctx, BEND(&work), &outlen));
415 ASSERT(buf_inc_len(&work, outlen));
416 ASSERT(buf_write(&work, &net_len, sizeof(net_len)));
417
418 return buf_copy(wkc, &work);
419}
420
421static bool
422tls_crypt_v2_unwrap_client_key(struct key2 *client_key, struct buffer *metadata,
423 struct buffer wrapped_client_key, struct key_ctx *server_key)
424{
425 const char *error_prefix = __func__;
426 bool ret = false;
427 struct gc_arena gc = gc_new();
428 /* The crypto API requires one extra cipher block of buffer head room when
429 * decrypting, which nicely matches the tag size of WKc. So
430 * TLS_CRYPT_V2_MAX_WKC_LEN is always large enough for the plaintext. */
431 uint8_t plaintext_buf_data[TLS_CRYPT_V2_MAX_WKC_LEN] = { 0 };
432 struct buffer plaintext = { 0 };
433
434 dmsg(D_TLS_DEBUG_MED, "%s: unwrapping client key (len=%d): %s", __func__,
435 BLEN(&wrapped_client_key),
436 format_hex(BPTR(&wrapped_client_key), BLEN(&wrapped_client_key), 0, &gc));
437
438 if (TLS_CRYPT_V2_MAX_WKC_LEN < BLEN(&wrapped_client_key))
439 {
440 CRYPT_ERROR("wrapped client key too big");
441 }
442
443 /* Decrypt client key and metadata */
444 uint16_t net_len = 0;
445 const uint8_t *tag = BPTR(&wrapped_client_key);
446
447 if (BLENZ(&wrapped_client_key) < sizeof(net_len))
448 {
449 CRYPT_ERROR("failed to read length");
450 }
451 memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), sizeof(net_len));
452
453 if (ntohs(net_len) != BLEN(&wrapped_client_key))
454 {
455 dmsg(D_TLS_DEBUG_LOW, "%s: net_len=%u, BLEN=%i", __func__, ntohs(net_len),
456 BLEN(&wrapped_client_key));
457 CRYPT_ERROR("invalid length");
458 }
459
460 buf_inc_len(&wrapped_client_key, -(int)sizeof(net_len));
461
462 if (!buf_advance(&wrapped_client_key, TLS_CRYPT_TAG_SIZE))
463 {
464 CRYPT_ERROR("failed to read tag");
465 }
466
467 if (!cipher_ctx_reset(server_key->cipher, tag))
468 {
469 CRYPT_ERROR("failed to initialize IV");
470 }
471 buf_set_write(&plaintext, plaintext_buf_data, sizeof(plaintext_buf_data));
472 int outlen = 0;
473 if (!cipher_ctx_update(server_key->cipher, BPTR(&plaintext), &outlen, BPTR(&wrapped_client_key),
474 BLEN(&wrapped_client_key)))
475 {
476 CRYPT_ERROR("could not decrypt client key");
477 }
478 ASSERT(buf_inc_len(&plaintext, outlen));
479
480 if (!cipher_ctx_final(server_key->cipher, BEND(&plaintext), &outlen))
481 {
482 CRYPT_ERROR("cipher final failed");
483 }
484 ASSERT(buf_inc_len(&plaintext, outlen));
485
486 /* Check authentication */
487 uint8_t tag_check[TLS_CRYPT_TAG_SIZE] = { 0 };
488 hmac_ctx_reset(server_key->hmac);
489 hmac_ctx_update(server_key->hmac, (void *)&net_len, sizeof(net_len));
490 hmac_ctx_update(server_key->hmac, BPTR(&plaintext), BLEN(&plaintext));
491 hmac_ctx_final(server_key->hmac, tag_check);
492
493 if (memcmp_constant_time(tag, tag_check, sizeof(tag_check)))
494 {
495 dmsg(D_CRYPTO_DEBUG, "tag : %s", format_hex(tag, sizeof(tag_check), 0, &gc));
496 dmsg(D_CRYPTO_DEBUG, "tag_check: %s", format_hex(tag_check, sizeof(tag_check), 0, &gc));
497 msg(D_TLS_DEBUG_LOW, "This might be a client-key that was generated for "
498 "a different tls-crypt-v2 server key");
499 CRYPT_ERROR("client key authentication error");
500 }
501
502 if (BLENZ(&plaintext) < sizeof(client_key->keys))
503 {
504 CRYPT_ERROR("failed to read client key");
505 }
506 memcpy(&client_key->keys, BPTR(&plaintext), sizeof(client_key->keys));
507 ASSERT(buf_advance(&plaintext, sizeof(client_key->keys)));
508 client_key->n = 2;
509
510 if (!buf_copy(metadata, &plaintext))
511 {
512 CRYPT_ERROR("metadata too large for supplied buffer");
513 }
514
515 ret = true;
516error_exit:
517 if (!ret)
518 {
519 secure_memzero(client_key, sizeof(*client_key));
520 }
521 buf_clear(&plaintext);
522 gc_free(&gc);
523 return ret;
524}
525
526#if defined(__GNUC__) || defined(__clang__)
527#pragma GCC diagnostic pop
528#endif
529
530static bool
531tls_crypt_v2_check_client_key_age(const struct buffer *tls_crypt_v2_metadata, int max_days)
532{
533 if (BLENZ(tls_crypt_v2_metadata) < 1 + sizeof(int64_t))
534 {
535 msg(M_WARN, "ERROR: Client key metadata is too small to contain a timestamp.");
536 return false;
537 }
538
539 const uint8_t *metadata = CBPTR(tls_crypt_v2_metadata);
540 if (*metadata != TLS_CRYPT_METADATA_TYPE_TIMESTAMP)
541 {
542 msg(M_WARN, "ERROR: Client key does not have a timestamp.");
543 return false;
544 }
545
546 int64_t timestamp;
547 memcpy(&timestamp, metadata + 1, sizeof(int64_t));
548 timestamp = (int64_t)ntohll((uint64_t)timestamp);
549 int64_t max_age_in_seconds = (int64_t)max_days * 24 * 60 * 60;
550 if (now - timestamp > max_age_in_seconds)
551 {
552 msg(M_WARN, "ERROR: Client key is too old.");
553 return false;
554 }
555 return true;
556}
557
558static bool
559tls_crypt_v2_verify_metadata(const struct buffer *tls_crypt_v2_metadata, const struct tls_options *opt)
560{
561 bool ret = false;
562 struct gc_arena gc = gc_new();
563 const char *tmp_file = NULL;
564
565 struct buffer metadata = *tls_crypt_v2_metadata;
566
567 int metadata_type = buf_read_u8(&metadata);
568 if (metadata_type < 0)
569 {
570 msg(M_WARN, "ERROR: no metadata type");
571 goto cleanup;
572 }
573
574 tmp_file = platform_create_temp_file(opt->tmp_dir, "tls_crypt_v2_metadata_", &gc);
575 if (!tmp_file || !buffer_write_file(tmp_file, &metadata))
576 {
577 msg(M_WARN, "ERROR: could not write metadata to file");
578 goto cleanup;
579 }
580
581 char metadata_type_str[4] = { 0 }; /* Max value: 255 */
582 snprintf(metadata_type_str, sizeof(metadata_type_str), "%i", (uint8_t)metadata_type);
583 struct env_set *es = env_set_create(NULL);
584 setenv_str(es, "script_type", "tls-crypt-v2-verify");
585 setenv_str(es, "metadata_type", metadata_type_str);
586 setenv_str(es, "metadata_file", tmp_file);
587
588 struct argv argv = argv_new();
590 argv_msg_prefix(D_TLS_DEBUG, &argv, "Executing tls-crypt-v2-verify");
591
592 ret = openvpn_run_script(&argv, es, 0, "--tls-crypt-v2-verify");
593
594 argv_free(&argv);
595 env_set_destroy(es);
596
597 if (!platform_unlink(tmp_file))
598 {
599 msg(M_WARN, "WARNING: failed to remove temp file '%s", tmp_file);
600 }
601
602 if (ret)
603 {
604 msg(D_HANDSHAKE, "TLS CRYPT V2 VERIFY SCRIPT OK");
605 }
606 else
607 {
608 msg(D_HANDSHAKE, "TLS CRYPT V2 VERIFY SCRIPT ERROR");
609 }
610
611cleanup:
612 gc_free(&gc);
613 return ret;
614}
615
616bool
618 const struct tls_options *opt)
619{
621 {
622 msg(D_TLS_ERRORS, "Client wants tls-crypt-v2, but no server key present.");
623 return false;
624 }
625
626 msg(D_HANDSHAKE, "Control Channel: using tls-crypt-v2 key");
627
628 struct buffer wrapped_client_key = *buf;
629 uint16_t net_len = 0;
630
631 if (!buf_advance(&wrapped_client_key, 1)
632 || BLENZ(&wrapped_client_key) < 1 + sizeof(net_len))
633 {
634 msg(D_TLS_ERRORS, "Can not read tls-crypt-v2 client key length");
635 return false;
636 }
637 memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), sizeof(net_len));
638
639 uint16_t wkc_len = ntohs(net_len);
640 if (!buf_advance(&wrapped_client_key, BLEN(&wrapped_client_key) - wkc_len))
641 {
642 msg(D_TLS_ERRORS, "Can not locate tls-crypt-v2 client key");
643 return false;
644 }
645
646 /* Check if this context already owns an initialised key */
647 if (ctx->cleanup_key_ctx == true)
648 {
649 /* This might be a harmless resend of the packet but it is better to
650 * just ignore the WKC part than trying to setup tls-crypt keys again.
651 *
652 * A CONTROL_WKC_V1 packets has a normal packet part and an appended
653 * wrapped control key. These are authenticated individually. We already
654 * set up tls-crypt with the wrapped key, so we are ignoring this part
655 * of the message but we return the normal packet part as the normal
656 * part of the message might have been corrupted earlier and discarded
657 * and this is resend. So return the normal part of the packet,
658 * basically transforming the CONTROL_WKC_V1 into a normal CONTROL_V1
659 * packet*/
660 msg(D_TLS_ERRORS, "Control channel security already setup. Ignoring "
661 "wrapped key part of packet.");
662
663 /* Remove client key from buffer so tls-crypt code can unwrap message */
664 ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key))));
665 return true;
666 }
667
668 struct buffer tls_crypt_v2_metadata = alloc_buf(TLS_CRYPT_V2_MAX_METADATA_LEN);
669 if (!tls_crypt_v2_unwrap_client_key(&ctx->original_wrap_keydata, &tls_crypt_v2_metadata,
670 wrapped_client_key, &ctx->tls_crypt_v2_server_key))
671 {
672 msg(D_TLS_ERRORS, "Can not unwrap tls-crypt-v2 client key");
673 goto error;
674 }
675
676 if (opt && opt->tls_crypt_v2_max_age > 0 && !tls_crypt_v2_check_client_key_age(&tls_crypt_v2_metadata, opt->tls_crypt_v2_max_age))
677 {
678 goto error;
679 }
680
681 if (opt && opt->tls_crypt_v2_verify_script && !tls_crypt_v2_verify_metadata(&tls_crypt_v2_metadata, opt))
682 {
683 goto error;
684 }
685 free_buf(&tls_crypt_v2_metadata);
686
687 /* Load the decrypted key */
688 ctx->mode = TLS_WRAP_CRYPT;
689 ctx->cleanup_key_ctx = true;
691 memset(&ctx->opt.key_ctx_bi, 0, sizeof(ctx->opt.key_ctx_bi));
693
694 /* Remove client key from buffer so tls-crypt code can unwrap message */
695 ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key))));
696
697 return true;
698error:
700 free_buf(&tls_crypt_v2_metadata);
701 return false;
702}
703
704void
709
710#if defined(__GNUC__) || defined(__clang__)
711#pragma GCC diagnostic push
712#pragma GCC diagnostic ignored "-Wsign-conversion"
713#endif
714
715void
716tls_crypt_v2_write_client_key_file(const char *filename, const char *b64_metadata,
717 const char *server_key_file, bool server_key_inline)
718{
719 struct gc_arena gc = gc_new();
720 struct key_ctx server_key = { 0 };
721 struct buffer client_key_pem = { 0 };
723 struct key2 client_key = { .n = 2 };
724
725 if (!rand_bytes((void *)client_key.keys, sizeof(client_key.keys)))
726 {
727 msg(M_FATAL, "ERROR: could not generate random key");
728 goto cleanup;
729 }
730 ASSERT(buf_write(&dst, client_key.keys, sizeof(client_key.keys)));
731
732 struct buffer metadata;
733 if (b64_metadata)
734 {
735 size_t b64_length = strlen(b64_metadata);
736 metadata = alloc_buf_gc(OPENVPN_BASE64_DECODED_LENGTH(b64_length) + 1, &gc);
738 int decoded_len = openvpn_base64_decode(b64_metadata, BEND(&metadata), (int)BCAP(&metadata));
739 if (decoded_len < 0)
740 {
741 msg(M_FATAL, "ERROR: failed to base64 decode provided metadata");
742 goto cleanup;
743 }
744 if ((unsigned int)decoded_len > TLS_CRYPT_V2_MAX_METADATA_LEN - 1)
745 {
746 msg(M_FATAL, "ERROR: metadata too long (%d bytes, max %u bytes)", decoded_len,
748 goto cleanup;
749 }
750 ASSERT(buf_inc_len(&metadata, decoded_len));
751 }
752 else
753 {
754 metadata = alloc_buf_gc(1 + sizeof(int64_t), &gc);
755 int64_t timestamp = htonll((uint64_t)now);
757 ASSERT(buf_write(&metadata, &timestamp, sizeof(timestamp)));
758 }
759
760 tls_crypt_v2_init_server_key(&server_key, true, server_key_file, server_key_inline);
761 if (!tls_crypt_v2_wrap_client_key(&dst, &client_key, &metadata, &server_key, &gc))
762 {
763 msg(M_FATAL, "ERROR: could not wrap generated client key");
764 goto cleanup;
765 }
766
767 /* PEM-encode Kc || WKc */
768 if (!crypto_pem_encode(tls_crypt_v2_cli_pem_name, &client_key_pem, &dst, &gc))
769 {
770 msg(M_FATAL, "ERROR: could not PEM-encode client key");
771 goto cleanup;
772 }
773
774 const char *client_file = filename;
775 bool client_inline = false;
776
777 if (!filename || streq(filename, ""))
778 {
779 buf_null_terminate(&client_key_pem);
780 client_file = (const char *)BPTR(&client_key_pem);
781 client_inline = true;
782 printf("%s\n", client_file);
783 }
784 else if (!buffer_write_file(filename, &client_key_pem))
785 {
786 msg(M_FATAL, "ERROR: could not write client key file");
787 goto cleanup;
788 }
789
790 /* Sanity check: load client key (as "client") */
791 struct key_ctx_bi check_client_key;
792 struct buffer check_wrapped_client_key;
793 struct key2 keydata;
794 msg(D_GENKEY, "Testing client-side key loading...");
795 tls_crypt_v2_init_client_key(&check_client_key, &keydata, &check_wrapped_client_key, client_file,
796 client_inline);
797 free_key_ctx_bi(&check_client_key);
798 secure_memzero(&keydata, sizeof(keydata));
799
800 /* Sanity check: unwrap and load client key (as "server") */
801 struct buffer check_metadata = alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN, &gc);
802 struct key2 check_client_key2 = { 0 };
803 free_key_ctx(&server_key);
804 tls_crypt_v2_init_server_key(&server_key, false, server_key_file, server_key_inline);
805 msg(D_GENKEY, "Testing server-side key loading...");
806 ASSERT(tls_crypt_v2_unwrap_client_key(&check_client_key2, &check_metadata,
807 check_wrapped_client_key, &server_key));
808 secure_memzero(&check_client_key2, sizeof(check_client_key2));
809 buf_clear(&check_wrapped_client_key);
810 free_buf(&check_wrapped_client_key);
811
812cleanup:
813 secure_memzero(&client_key, sizeof(client_key));
814 free_key_ctx(&server_key);
815 buf_clear(&client_key_pem);
816 buf_clear(&dst);
817
818 gc_free(&gc);
819}
820
821#if defined(__GNUC__) || defined(__clang__)
822#pragma GCC diagnostic pop
823#endif
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:490
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
void argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix)
Similar to argv_msg() but prefixes the messages being written with a given string.
Definition argv.c:259
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
#define OPENVPN_BASE64_DECODED_LENGTH(base64_length)
Compute the maximal number of bytes encoded in a base64 string.
Definition base64.h:41
void free_buf(struct buffer *buf)
Free the memory allocated for a buffer.
Definition buffer.c:174
void buf_clear(struct buffer *buf)
Zeroise and reset a buffer.
Definition buffer.c:153
bool buffer_write_file(const char *filename, const struct buffer *buf)
Write buffer contents to file.
Definition buffer.c:285
void buf_null_terminate(struct buffer *buf)
Force a null terminator at the end of the buffer content.
Definition buffer.c:509
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
Definition buffer.c:77
struct buffer alloc_buf(size_t size)
Allocate a buffer of the given size.
Definition buffer.c:60
Buffer management functions and garbage collection.
#define BEND(buf)
Return a pointer one past the end of the buffer content.
Definition buffer.h:143
static bool buf_copy(struct buffer *dest, const struct buffer *src)
Copy the content of one buffer to the end of another.
Definition buffer.h:1347
#define BPTR(buf)
Return a pointer to the start of the buffer content.
Definition buffer.h:139
#define streq(x, y)
helper to work around the semantics of the strcmp() return value
Definition buffer.h:1822
static bool buf_inc_len(struct buffer *buf, int inc)
Increase or decrease the length of a buffer.
Definition buffer.h:1119
static void gc_init(struct gc_arena *a)
Initialise a garbage collection arena to an empty state.
Definition buffer.h:1932
static bool buf_safe(const struct buffer *buf, size_t len)
Check whether len bytes can be appended to a buffer.
Definition buffer.h:994
static bool buf_read(struct buffer *src, void *dest, int size)
Read bytes from the front of a buffer into a caller-supplied destination.
Definition buffer.h:1456
static size_t buf_forward_capacity(const struct buffer *buf)
Return the number of bytes that can still be appended to the buffer.
Definition buffer.h:1038
#define CBPTR(buf)
Return a const pointer to the start of the buffer content.
Definition buffer.h:141
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
Definition buffer.h:748
static uint8_t * buf_write_alloc(struct buffer *buf, size_t size)
Reserve space at the end of a buffer for writing.
Definition buffer.h:1189
static bool buf_advance(struct buffer *buf, ssize_t size)
Advance the content start of a buffer, consuming bytes from the front.
Definition buffer.h:1165
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
Definition buffer.h:1239
static void buf_set_write(struct buffer *buf, uint8_t *data, size_t size)
Initialise a buffer with an externally provided writable memory region.
Definition buffer.h:658
static int buf_read_u8(struct buffer *buf)
Read and consume a uint8_t from the front of a buffer.
Definition buffer.h:1495
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
static char * format_hex(const uint8_t *data, size_t size, size_t maxoutput, struct gc_arena *gc)
Format a binary buffer as a hex string with spaces every 4 bytes.
Definition buffer.h:960
#define BCAP(buf)
Return the number of bytes available for appending to the buffer.
Definition buffer.h:161
#define BLENZ(buf)
Return the length of the buffer content as a size_t.
Definition buffer.h:153
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
void free_key_ctx_bi(struct key_ctx_bi *ctx)
Definition crypto.c:1098
void init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const struct key_type *kt, int enc, const char *prefix)
Definition crypto.c:993
bool read_pem_key_file(struct buffer *key, const char *pem_name, const char *key_file, bool key_inline)
Read key material from a PEM encoded files into the key structure.
Definition crypto.c:1842
void write_pem_key_file(const char *filename, const char *pem_name)
Generate a server key with enough randomness to fill a key struct and write to file.
Definition crypto.c:1787
void key_parameters_from_key(struct key_parameters *key_params, const struct key *key)
Converts a struct key representation into a struct key_parameters representation.
Definition crypto.c:1152
void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, int key_direction, const struct key_type *kt, const char *name)
Definition crypto.c:1057
void crypto_read_openvpn_key(const struct key_type *key_type, struct key_ctx_bi *ctx, const char *key_file, bool key_inline, const int key_direction, const char *key_name, const char *opt_name, struct key2 *keydata)
Definition crypto.c:1251
bool crypto_check_replay(struct crypto_options *opt, const struct packet_id_net *pin, uint16_t epoch, const char *error_prefix, struct gc_arena *gc)
Check packet ID for replay, and perform replay administration.
Definition crypto.c:380
void free_key_ctx(struct key_ctx *ctx)
Definition crypto.c:1079
Data Channel Cryptography Module.
#define KEY_DIRECTION_NORMAL
Definition crypto.h:225
#define CO_PACKET_ID_LONG_FORM
Bit-flag indicating whether to use OpenVPN's long packet ID format.
Definition crypto.h:335
#define CRYPT_ERROR(format)
Definition crypto.h:385
#define CO_IGNORE_PACKET_ID
Bit-flag indicating whether to ignore the packet ID of a received packet.
Definition crypto.h:338
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
#define KEY_DIRECTION_INVERSE
Definition crypto.h:226
static struct key_type create_kt(const char *cipher, const char *md, const char *optname)
Creates and validates an instance of struct key_type with the provided algs.
Definition crypto.h:670
void hmac_ctx_update(hmac_ctx_t *ctx, const uint8_t *src, int src_len)
void hmac_ctx_reset(hmac_ctx_t *ctx)
void hmac_ctx_final(hmac_ctx_t *ctx, uint8_t *dst)
int hmac_ctx_size(hmac_ctx_t *ctx)
#define MAX_CIPHER_KEY_LENGTH
void crypto_clear_error(void)
int rand_bytes(uint8_t *output, int len)
Wrapper for secure random number generator.
#define MAX_HMAC_KEY_LENGTH
int cipher_ctx_update(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len, const uint8_t *src, int src_len)
Updates the given cipher context, encrypting data in the source buffer, and placing any complete bloc...
int cipher_ctx_reset(cipher_ctx_t *ctx, const uint8_t *iv_buf)
Resets the given cipher context, setting the IV to the specified value.
unsigned int cipher_ctx_block_size(const cipher_ctx_t *ctx)
Returns the block size of the cipher, in bytes.
int cipher_ctx_final(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len)
Pads the final cipher block using PKCS padding, and output to the destination buffer.
bool crypto_pem_encode(const char *name, struct buffer *dst, const struct buffer *src, struct gc_arena *gc)
Encode binary data as PEM.
struct hmac_ctx hmac_ctx_t
struct cipher_ctx cipher_ctx_t
void env_set_destroy(struct env_set *es)
Definition env_set.c:165
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:305
struct env_set * env_set_create(struct gc_arena *gc)
Definition env_set.c:155
#define D_TLS_DEBUG_LOW
Definition errlevel.h:75
#define D_CRYPTO_DEBUG
Definition errlevel.h:144
#define D_PACKET_CONTENT
Definition errlevel.h:164
#define D_TLS_DEBUG_MED
Definition errlevel.h:153
#define D_CRYPT_ERRORS
Definition errlevel.h:57
#define D_HANDSHAKE
Definition errlevel.h:70
#define D_GENKEY
Definition errlevel.h:77
#define D_TLS_ERRORS
Definition errlevel.h:58
#define D_TLS_DEBUG
Definition errlevel.h:161
#define TLS_CRYPT_V2_MAX_WKC_LEN
Definition tls_crypt.h:96
#define TLS_CRYPT_BLOCK_SIZE
Definition tls_crypt.h:90
bool tls_crypt_v2_extract_client_key(struct buffer *buf, struct tls_wrap_ctx *ctx, const struct tls_options *opt)
Extract a tls-crypt-v2 client key from a P_CONTROL_HARD_RESET_CLIENT_V3 message, and load the key int...
Definition tls_crypt.c:617
void tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, const char *key_file, bool key_inline, bool tls_server)
Initialize a key_ctx_bi structure for use with --tls-crypt.
Definition tls_crypt.c:62
#define TLS_CRYPT_TAG_SIZE
Definition tls_crypt.h:88
void tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, const char *key_file, bool key_inline)
Initialize a tls-crypt-v2 server key (used to encrypt/decrypt client keys).
Definition tls_crypt.c:341
void tls_crypt_v2_write_client_key_file(const char *filename, const char *b64_metadata, const char *server_key_file, bool server_key_inline)
Generate a tls-crypt-v2 client key, and write to file.
Definition tls_crypt.c:716
#define TLS_CRYPT_OFF_PID
Definition tls_crypt.h:92
bool tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, struct crypto_options *opt)
Unwrap a control channel packet (decrypts, authenticates and performs replay checks).
Definition tls_crypt.c:212
#define TLS_CRYPT_OFF_TAG
Definition tls_crypt.h:93
unsigned int tls_crypt_buf_overhead(void)
Returns the maximum overhead (in bytes) added to the destination buffer by tls_crypt_wrap().
Definition tls_crypt.c:56
#define TLS_CRYPT_OFF_CT
Definition tls_crypt.h:94
bool tls_session_generate_dynamic_tls_crypt_key(struct tls_session *session)
Generates a TLS-Crypt key to be used with dynamic tls-crypt using the TLS EKM exporter function.
Definition tls_crypt.c:102
void tls_crypt_v2_write_server_key_file(const char *filename)
Generate a tls-crypt-v2 server key, and write to file.
Definition tls_crypt.c:705
#define TLS_CRYPT_V2_CLIENT_KEY_LEN
Definition tls_crypt.h:97
void tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key, struct buffer *wkc_buf, const char *key_file, bool key_inline)
Initialize a tls-crypt-v2 client key.
Definition tls_crypt.c:317
bool tls_crypt_wrap(const struct buffer *src, struct buffer *dst, struct crypto_options *opt)
Wrap a control channel packet (both authenticates and encrypts the data).
Definition tls_crypt.c:139
#define TLS_CRYPT_V2_MAX_METADATA_LEN
Definition tls_crypt.h:100
#define ntohll(x)
Definition integer.h:36
#define htonll(x)
Definition integer.h:29
#define BUF_SIZE(f)
Definition mtu.h:188
#define M_FATAL
Definition error.h:90
#define dmsg(flags,...)
Definition error.h:164
#define msg(flags,...)
Definition error.h:152
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
time_t now
Definition otime.c:33
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
Definition packet_id.c:96
bool packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form)
Definition packet_id.c:319
bool packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_form, bool prepend)
Write a packet ID to buf, and update the packet ID state.
Definition packet_id.c:382
static unsigned int packet_id_size(bool long_form)
Definition packet_id.h:253
static bool packet_id_initialized(const struct packet_id *pid)
Is this struct packet_id initialized?
Definition packet_id.h:229
const char * platform_create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc)
Create a temporary file in directory, returns the filename of the created file.
Definition platform.c:545
bool platform_unlink(const char *filename)
Definition platform.c:492
static int openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook)
Will run a script and return the exit code of the script if between 0 and 255, -1 otherwise.
Definition run_command.h:89
int openvpn_base64_decode(const char *str, void *data, int size)
Definition base64.c:160
Control Channel SSL/Data channel negotiation module.
#define EXPORT_DYNAMIC_TLS_CRYPT_LABEL
bool key_state_export_keying_material(struct tls_session *session, const char *label, size_t label_size, void *ekm, size_t ekm_size)
Keying Material Exporters [RFC 5705] allows additional keying material to be derived from existing TL...
Definition argv.h:35
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int capacity
Size in bytes of memory allocated by malloc().
Definition buffer.h:72
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
int offset
Offset in bytes of the actual content within the allocated memory.
Definition buffer.h:74
Security parameter state for processing data channel packets.
Definition crypto.h:286
unsigned int flags
Bit-flags determining behavior of security operation functions.
Definition crypto.h:374
struct key_ctx_bi key_ctx_bi
OpenSSL cipher and HMAC contexts for both sending and receiving directions.
Definition crypto.h:287
struct packet_id packet_id
Current packet ID state for both sending and receiving directions.
Definition crypto.h:326
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Container for bidirectional cipher and HMAC key material.
Definition crypto.h:233
int n
The number of key objects stored in the key2.keys array.
Definition crypto.h:234
struct key keys[2]
Two unidirectional sets of key material.
Definition crypto.h:236
Container for two sets of OpenSSL cipher and/or HMAC contexts for both sending and receiving directio...
Definition crypto.h:273
struct key_ctx decrypt
cipher and/or HMAC contexts for receiving direction.
Definition crypto.h:276
struct key_ctx encrypt
Cipher and/or HMAC contexts for sending direction.
Definition crypto.h:274
Container for one set of cipher and/or HMAC contexts.
Definition crypto.h:195
cipher_ctx_t * cipher
Generic cipher context.
Definition crypto.h:196
hmac_ctx_t * hmac
Generic HMAC context.
Definition crypto.h:197
internal structure similar to struct key that holds key information but is not represented on wire an...
Definition crypto.h:156
const char * cipher
const name of the cipher
Definition crypto.h:135
const char * digest
Message digest static parameters.
Definition crypto.h:136
Container for unidirectional cipher and HMAC key material.
Definition crypto.h:145
uint8_t cipher[MAX_CIPHER_KEY_LENGTH]
Key material for cipher operations.
Definition crypto.h:146
uint8_t hmac[MAX_HMAC_KEY_LENGTH]
Key material for HMAC operations.
Definition crypto.h:148
Data structure for describing the packet id that is received/send to the network.
Definition packet_id.h:171
struct packet_id_send send
Definition packet_id.h:180
const char * tmp_dir
Definition ssl_common.h:399
int tls_crypt_v2_max_age
Definition ssl_common.h:388
const char * tls_crypt_v2_verify_script
Definition ssl_common.h:387
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:497
Control channel wrapping (–tls-auth/–tls-crypt) context.
Definition ssl_common.h:276
enum tls_wrap_ctx::@317033145106102005365073042374303036003032271350 mode
Control channel wrapping mode.
bool cleanup_key_ctx
opt.key_ctx_bi is owned by this context
Definition ssl_common.h:288
struct crypto_options opt
Crypto state.
Definition ssl_common.h:283
struct key_ctx tls_crypt_v2_server_key
Decrypts client keys.
Definition ssl_common.h:285
struct key2 original_wrap_keydata
original key data to be xored in to the key for dynamic tls-crypt.
Definition ssl_common.h:298
static int cleanup(void **state)
struct gc_arena gc
Definition test_ssl.c:138
static const uint8_t TLS_CRYPT_METADATA_TYPE_USER
Metadata contains user-specified data.
Definition tls_crypt.c:45
const char * tls_crypt_v2_srv_pem_name
Definition tls_crypt.c:42
static void tls_crypt_v2_load_client_key(struct key_ctx_bi *key, const struct key2 *key2, bool tls_server)
Definition tls_crypt.c:305
static bool tls_crypt_v2_check_client_key_age(const struct buffer *tls_crypt_v2_metadata, int max_days)
Definition tls_crypt.c:531
const char * tls_crypt_v2_cli_pem_name
Definition tls_crypt.c:41
static const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP
Metadata contains a 64-bit unix timestamp in network byte order.
Definition tls_crypt.c:47
static bool tls_crypt_v2_unwrap_client_key(struct key2 *client_key, struct buffer *metadata, struct buffer wrapped_client_key, struct key_ctx *server_key)
Definition tls_crypt.c:422
static bool tls_crypt_v2_wrap_client_key(struct buffer *wkc, const struct key2 *src_key, const struct buffer *src_metadata, struct key_ctx *server_key, struct gc_arena *gc)
Definition tls_crypt.c:368
static bool tls_crypt_v2_verify_metadata(const struct buffer *tls_crypt_v2_metadata, const struct tls_options *opt)
Definition tls_crypt.c:559
static void xor_key2(struct key2 *key, const struct key2 *other)
Will produce key = key XOR other.
Definition tls_crypt.c:79
static struct key_type tls_crypt_kt(void)
Definition tls_crypt.c:50