summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-08-17 18:51:47 +0000
committertb <>2022-08-17 18:51:47 +0000
commitc54903f2a71d453922361378bf5be43319fa74f0 (patch)
treee275d061be29fbe1483246fb3bb20e5c0c413f0a
parent1c5609b103eb8a5e47488306e9b34ff2021b41fa (diff)
downloadopenbsd-c54903f2a71d453922361378bf5be43319fa74f0.tar.gz
openbsd-c54903f2a71d453922361378bf5be43319fa74f0.tar.bz2
openbsd-c54903f2a71d453922361378bf5be43319fa74f0.zip
Implement the SSL_CTRL_GET_SHARED_GROUP control
This implements SSL_get_shared_{curve,group}() in a bug-compatible fashion with OpenSSL. This is your average OpenSSL-style overloaded parameter API where n >= 0 means "return the n-th shared group's NID" (as if anyone possibly ever cared about the case n > 0) and n == -1 means "return the number of shared groups". There is also an undocumented case n == -2 for Suite B profile support which falls back to n == 0 in case Suite B profile support is disabled, so n == -2 is the same as n == 0 in LibreSSL. The API also returns 0 for error, which is indistinguishable from a count of 0 shared groups but coincides with NID_undef. Contrary to claims in the documentation, the API doesn't actually return -1 for clients, rather it returns 0. Obviously this entire exercise is pretty useless, but since somebody exposed it because they could and someone else used it because they could we need to provide it. ok jsing
-rw-r--r--src/lib/libssl/s3_lib.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
index 2726744357..e93298c2db 100644
--- a/src/lib/libssl/s3_lib.c
+++ b/src/lib/libssl/s3_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_lib.c,v 1.236 2022/08/17 07:39:19 jsing Exp $ */ 1/* $OpenBSD: s3_lib.c,v 1.237 2022/08/17 18:51:47 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1656,6 +1656,39 @@ ssl3_clear(SSL *s)
1656} 1656}
1657 1657
1658long 1658long
1659_SSL_get_shared_group(SSL *s, long n)
1660{
1661 size_t count;
1662 int nid;
1663
1664 /* OpenSSL document that they return -1 for clients. They return 0. */
1665 if (!s->server)
1666 return 0;
1667
1668 if (n == -1) {
1669 if (!tls1_count_shared_groups(s, &count))
1670 return 0;
1671
1672 if (count > LONG_MAX)
1673 count = LONG_MAX;
1674
1675 return count;
1676 }
1677
1678 /* Undocumented special case added for Suite B profile support. */
1679 if (n == -2)
1680 n = 0;
1681
1682 if (n < 0)
1683 return 0;
1684
1685 if (!tls1_get_shared_group_by_index(s, n, &nid))
1686 return NID_undef;
1687
1688 return nid;
1689}
1690
1691long
1659_SSL_get_peer_tmp_key(SSL *s, EVP_PKEY **key) 1692_SSL_get_peer_tmp_key(SSL *s, EVP_PKEY **key)
1660{ 1693{
1661 EVP_PKEY *pkey = NULL; 1694 EVP_PKEY *pkey = NULL;
@@ -2075,6 +2108,9 @@ ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
2075 case SSL_CTRL_SET_GROUPS_LIST: 2108 case SSL_CTRL_SET_GROUPS_LIST:
2076 return SSL_set1_groups_list(s, parg); 2109 return SSL_set1_groups_list(s, parg);
2077 2110
2111 case SSL_CTRL_GET_SHARED_GROUP:
2112 return _SSL_get_shared_group(s, larg);
2113
2078 /* XXX - rename to SSL_CTRL_GET_PEER_TMP_KEY and remove server check. */ 2114 /* XXX - rename to SSL_CTRL_GET_PEER_TMP_KEY and remove server check. */
2079 case SSL_CTRL_GET_SERVER_TMP_KEY: 2115 case SSL_CTRL_GET_SERVER_TMP_KEY:
2080 if (s->server != 0) 2116 if (s->server != 0)