diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-03-16 13:11:30 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-13 17:16:19 +0700 |
commit | 931368e3fbf4611ed717f7cfe47bc884c4409876 (patch) | |
tree | 63ef941b75667dbea1f74b32321fe06ffa29191c /crypto/src/tls/TlsExtensionsUtilities.cs | |
parent | RFC 9146: Add registry entries (diff) | |
download | BouncyCastle.NET-ed25519-931368e3fbf4611ed717f7cfe47bc884c4409876.tar.xz |
RFC 9146: connection_id extension negotiation
Diffstat (limited to '')
-rw-r--r-- | crypto/src/tls/TlsExtensionsUtilities.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crypto/src/tls/TlsExtensionsUtilities.cs b/crypto/src/tls/TlsExtensionsUtilities.cs index 836c1b506..bc4ca2714 100644 --- a/crypto/src/tls/TlsExtensionsUtilities.cs +++ b/crypto/src/tls/TlsExtensionsUtilities.cs @@ -64,6 +64,12 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> + public static void AddConnectionIDExtension(IDictionary<int, byte[]> extensions, byte[] connectionID) + { + extensions[ExtensionType.connection_id] = CreateConnectionIDExtension(connectionID); + } + + /// <exception cref="IOException"/> public static void AddCookieExtension(IDictionary<int, byte[]> extensions, byte[] cookie) { extensions[ExtensionType.cookie] = CreateCookieExtension(cookie); @@ -317,6 +323,13 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> + public static byte[] GetConnectionIDExtension(IDictionary<int, byte[]> extensions) + { + byte[] extensionData = TlsUtilities.GetExtensionData(extensions, ExtensionType.connection_id); + return extensionData == null ? null : ReadConnectionIDExtension(extensionData); + } + + /// <exception cref="IOException"/> public static byte[] GetCookieExtension(IDictionary<int, byte[]> extensions) { byte[] extensionData = TlsUtilities.GetExtensionData(extensions, ExtensionType.cookie); @@ -631,6 +644,15 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> + public static byte[] CreateConnectionIDExtension(byte[] connectionID) + { + if (connectionID == null) + throw new TlsFatalAlert(AlertDescription.internal_error); + + return TlsUtilities.EncodeOpaque8(connectionID); + } + + /// <exception cref="IOException"/> public static byte[] CreateCookieExtension(byte[] cookie) { if (TlsUtilities.IsNullOrEmpty(cookie) || cookie.Length >= (1 << 16)) @@ -1059,6 +1081,12 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> + public static byte[] ReadConnectionIDExtension(byte[] extensionData) + { + return TlsUtilities.DecodeOpaque8(extensionData); + } + + /// <exception cref="IOException"/> public static byte[] ReadCookieExtension(byte[] extensionData) { return TlsUtilities.DecodeOpaque16(extensionData, 1); |