diff options
| author | tb <> | 2026-06-08 11:31:29 +0000 |
|---|---|---|
| committer | tb <> | 2026-06-08 11:31:29 +0000 |
| commit | 1091a3721fde40f0f1c76e8cef8455c495204356 (patch) | |
| tree | 687dfa7dd74c8c4d4b385bd3196adc8cf859fd0f /src | |
| parent | fd6e5f52571c6aa5ff9f91091e5ebd8dd2187f13 (diff) | |
| download | openbsd-1091a3721fde40f0f1c76e8cef8455c495204356.tar.gz openbsd-1091a3721fde40f0f1c76e8cef8455c495204356.tar.bz2 openbsd-1091a3721fde40f0f1c76e8cef8455c495204356.zip | |
regress/libssl/unit: add a currently failing test for ECDHE kex
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libssl/unit/Makefile | 5 | ||||
| -rw-r--r-- | src/regress/lib/libssl/unit/ssl_kex.c | 162 |
2 files changed, 166 insertions, 1 deletions
diff --git a/src/regress/lib/libssl/unit/Makefile b/src/regress/lib/libssl/unit/Makefile index edc0d910c4..e571973c33 100644 --- a/src/regress/lib/libssl/unit/Makefile +++ b/src/regress/lib/libssl/unit/Makefile | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.17 2025/10/24 11:44:08 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.18 2026/06/08 11:31:29 tb Exp $ |
| 2 | 2 | ||
| 3 | PROGS += cipher_list | 3 | PROGS += cipher_list |
| 4 | PROGS += ssl_get_shared_ciphers | 4 | PROGS += ssl_get_shared_ciphers |
| 5 | PROGS += ssl_kex | ||
| 5 | PROGS += ssl_methods | 6 | PROGS += ssl_methods |
| 6 | PROGS += ssl_set_alpn_protos | 7 | PROGS += ssl_set_alpn_protos |
| 7 | PROGS += ssl_verify_param | 8 | PROGS += ssl_verify_param |
| @@ -9,6 +10,8 @@ PROGS += ssl_versions | |||
| 9 | PROGS += tls_ext_alpn | 10 | PROGS += tls_ext_alpn |
| 10 | PROGS += tls_prf | 11 | PROGS += tls_prf |
| 11 | 12 | ||
| 13 | REGRESS_EXPECTED_FAILURES += run-regress-ssl_kex | ||
| 14 | |||
| 12 | WARNINGS= Yes | 15 | WARNINGS= Yes |
| 13 | LDADD = ${SSL_INT} -lcrypto | 16 | LDADD = ${SSL_INT} -lcrypto |
| 14 | DPADD = ${LIBSSL} ${LIBCRYPTO} | 17 | DPADD = ${LIBSSL} ${LIBCRYPTO} |
diff --git a/src/regress/lib/libssl/unit/ssl_kex.c b/src/regress/lib/libssl/unit/ssl_kex.c new file mode 100644 index 0000000000..299f1eb3df --- /dev/null +++ b/src/regress/lib/libssl/unit/ssl_kex.c | |||
| @@ -0,0 +1,162 @@ | |||
| 1 | /* $OpenBSD: ssl_kex.c,v 1.1 2026/06/08 11:31:29 tb Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2026 Theo Buehler <tb@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <err.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | |||
| 22 | #include <openssl/ec.h> | ||
| 23 | #include <openssl/objects.h> | ||
| 24 | |||
| 25 | #include "bytestring.h" | ||
| 26 | #include "ssl_local.h" | ||
| 27 | |||
| 28 | static const uint8_t point_at_infinity[] = { | ||
| 29 | 0x00, | ||
| 30 | }; | ||
| 31 | static const size_t point_at_infinity_len = sizeof(point_at_infinity); | ||
| 32 | |||
| 33 | static const uint8_t secp384r1_uncompressed_point[] = { | ||
| 34 | 0x04, 0xca, 0x0e, 0xc0, 0x60, 0xce, 0x24, 0x25, | ||
| 35 | 0xa7, 0x6e, 0xd1, 0x96, 0x69, 0x33, 0x36, 0x04, | ||
| 36 | 0x87, 0x69, 0x36, 0xfd, 0x2a, 0x83, 0x7a, 0x99, | ||
| 37 | 0xad, 0xb7, 0x35, 0xe9, 0x4c, 0x2f, 0x56, 0xfc, | ||
| 38 | 0xee, 0x7e, 0x68, 0x43, 0x90, 0x41, 0xb7, 0x3c, | ||
| 39 | 0x64, 0xd4, 0xec, 0x82, 0xc1, 0xc6, 0xd9, 0x4b, | ||
| 40 | 0x7d, 0xfa, 0xaa, 0x43, 0x46, 0x19, 0x94, 0x7f, | ||
| 41 | 0xb4, 0xe2, 0xa7, 0xbd, 0x75, 0xaf, 0x4d, 0x8f, | ||
| 42 | 0x45, 0xed, 0x3a, 0x8f, 0xef, 0x93, 0x57, 0x50, | ||
| 43 | 0x3f, 0x24, 0xf4, 0xa8, 0x68, 0x22, 0xf8, 0xa3, | ||
| 44 | 0x8c, 0xa9, 0x8b, 0xe8, 0xb9, 0x28, 0xff, 0x9f, | ||
| 45 | 0xcf, 0xcd, 0xac, 0xc1, 0x20, 0x5f, 0x23, 0x07, | ||
| 46 | 0x40, | ||
| 47 | }; | ||
| 48 | static const size_t secp384r1_uncompressed_point_len = | ||
| 49 | sizeof(secp384r1_uncompressed_point); | ||
| 50 | |||
| 51 | static const uint8_t secp384r1_compressed_point[] = { | ||
| 52 | 0x02, 0xca, 0x0e, 0xc0, 0x60, 0xce, 0x24, 0x25, | ||
| 53 | 0xa7, 0x6e, 0xd1, 0x96, 0x69, 0x33, 0x36, 0x04, | ||
| 54 | 0x87, 0x69, 0x36, 0xfd, 0x2a, 0x83, 0x7a, 0x99, | ||
| 55 | 0xad, 0xb7, 0x35, 0xe9, 0x4c, 0x2f, 0x56, 0xfc, | ||
| 56 | 0xee, 0x7e, 0x68, 0x43, 0x90, 0x41, 0xb7, 0x3c, | ||
| 57 | 0x64, 0xd4, 0xec, 0x82, 0xc1, 0xc6, 0xd9, 0x4b, | ||
| 58 | 0x7d, | ||
| 59 | }; | ||
| 60 | static const size_t secp384r1_compressed_point_len = | ||
| 61 | sizeof(secp384r1_compressed_point); | ||
| 62 | |||
| 63 | static const uint8_t secp384r1_hybrid_point[] = { | ||
| 64 | 0x06, 0xca, 0x0e, 0xc0, 0x60, 0xce, 0x24, 0x25, | ||
| 65 | 0xa7, 0x6e, 0xd1, 0x96, 0x69, 0x33, 0x36, 0x04, | ||
| 66 | 0x87, 0x69, 0x36, 0xfd, 0x2a, 0x83, 0x7a, 0x99, | ||
| 67 | 0xad, 0xb7, 0x35, 0xe9, 0x4c, 0x2f, 0x56, 0xfc, | ||
| 68 | 0xee, 0x7e, 0x68, 0x43, 0x90, 0x41, 0xb7, 0x3c, | ||
| 69 | 0x64, 0xd4, 0xec, 0x82, 0xc1, 0xc6, 0xd9, 0x4b, | ||
| 70 | 0x7d, 0xfa, 0xaa, 0x43, 0x46, 0x19, 0x94, 0x7f, | ||
| 71 | 0xb4, 0xe2, 0xa7, 0xbd, 0x75, 0xaf, 0x4d, 0x8f, | ||
| 72 | 0x45, 0xed, 0x3a, 0x8f, 0xef, 0x93, 0x57, 0x50, | ||
| 73 | 0x3f, 0x24, 0xf4, 0xa8, 0x68, 0x22, 0xf8, 0xa3, | ||
| 74 | 0x8c, 0xa9, 0x8b, 0xe8, 0xb9, 0x28, 0xff, 0x9f, | ||
| 75 | 0xcf, 0xcd, 0xac, 0xc1, 0x20, 0x5f, 0x23, 0x07, | ||
| 76 | 0x40, | ||
| 77 | }; | ||
| 78 | static const size_t secp384r1_hybrid_point_len = sizeof(secp384r1_hybrid_point); | ||
| 79 | |||
| 80 | static int | ||
| 81 | ssl_key_share_ecdhe_test(void) | ||
| 82 | { | ||
| 83 | EC_KEY *ecdh = NULL, *ecdh_peer = NULL; | ||
| 84 | uint8_t *shared_key = NULL; | ||
| 85 | size_t shared_key_len = 0; | ||
| 86 | CBS cbs; | ||
| 87 | int nid = NID_secp384r1; | ||
| 88 | int failed = 0; | ||
| 89 | |||
| 90 | if ((ecdh = EC_KEY_new()) == NULL) | ||
| 91 | err(1, NULL); | ||
| 92 | |||
| 93 | if (!ssl_kex_generate_ecdhe_ecp(ecdh, nid)) { | ||
| 94 | fprintf(stderr, "FAIL: failed to generate P-384 key\n"); | ||
| 95 | failed |= 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | CBS_init(&cbs, secp384r1_uncompressed_point, secp384r1_uncompressed_point_len); | ||
| 99 | if ((ecdh_peer = EC_KEY_new()) == NULL) | ||
| 100 | err(1, NULL); | ||
| 101 | if (!ssl_kex_peer_public_ecdhe_ecp(ecdh_peer, nid, &cbs)) { | ||
| 102 | fprintf(stderr, "FAIL: failed to parse uncompressed P-384 point\n"); | ||
| 103 | failed |= 1; | ||
| 104 | } | ||
| 105 | |||
| 106 | if (!ssl_kex_derive_ecdhe_ecp(ecdh, ecdh_peer, &shared_key, &shared_key_len)) { | ||
| 107 | fprintf(stderr, "FAIL: failed to derive shared P-384 key\n"); | ||
| 108 | failed |= 1; | ||
| 109 | } | ||
| 110 | |||
| 111 | EC_KEY_free(ecdh_peer); | ||
| 112 | ecdh_peer = NULL; | ||
| 113 | |||
| 114 | CBS_init(&cbs, point_at_infinity, point_at_infinity_len); | ||
| 115 | if ((ecdh_peer = EC_KEY_new()) == NULL) | ||
| 116 | err(1, NULL); | ||
| 117 | if (ssl_kex_peer_public_ecdhe_ecp(ecdh_peer, nid, &cbs)) { | ||
| 118 | fprintf(stderr, "FAIL: parsed point at infinity\n"); | ||
| 119 | failed |= 1; | ||
| 120 | } | ||
| 121 | |||
| 122 | EC_KEY_free(ecdh_peer); | ||
| 123 | ecdh_peer = NULL; | ||
| 124 | |||
| 125 | CBS_init(&cbs, secp384r1_compressed_point, secp384r1_compressed_point_len); | ||
| 126 | if ((ecdh_peer = EC_KEY_new()) == NULL) | ||
| 127 | err(1, NULL); | ||
| 128 | if (ssl_kex_peer_public_ecdhe_ecp(ecdh_peer, nid, &cbs)) { | ||
| 129 | fprintf(stderr, "FAIL: parsed compressed P-384 point\n"); | ||
| 130 | failed |= 1; | ||
| 131 | } | ||
| 132 | |||
| 133 | EC_KEY_free(ecdh_peer); | ||
| 134 | ecdh_peer = NULL; | ||
| 135 | |||
| 136 | CBS_init(&cbs, secp384r1_hybrid_point, secp384r1_hybrid_point_len); | ||
| 137 | if ((ecdh_peer = EC_KEY_new()) == NULL) | ||
| 138 | err(1, NULL); | ||
| 139 | if (ssl_kex_peer_public_ecdhe_ecp(ecdh_peer, nid, &cbs)) { | ||
| 140 | fprintf(stderr, "FAIL: parsed hybrid P-384 point\n"); | ||
| 141 | failed |= 1; | ||
| 142 | } | ||
| 143 | |||
| 144 | EC_KEY_free(ecdh_peer); | ||
| 145 | ecdh_peer = NULL; | ||
| 146 | |||
| 147 | EC_KEY_free(ecdh); | ||
| 148 | freezero(shared_key, shared_key_len); | ||
| 149 | |||
| 150 | return failed; | ||
| 151 | } | ||
| 152 | |||
| 153 | int | ||
| 154 | main(void) | ||
| 155 | { | ||
| 156 | int failed = 0; | ||
| 157 | |||
| 158 | /* XXX - add DHE and X25519. */ | ||
| 159 | failed |= ssl_key_share_ecdhe_test(); | ||
| 160 | |||
| 161 | return failed; | ||
| 162 | } | ||
