diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-28 20:49:58 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-28 20:49:58 +0700 |
commit | dc5029c8650432ae04df78d2ead06a8349176b74 (patch) | |
tree | 306f232f9cf53762ccb427225dee958313b884fd /crypto/test | |
parent | Generics migration in Ocsp, OpenPgp (diff) | |
download | BouncyCastle.NET-ed25519-dc5029c8650432ae04df78d2ead06a8349176b74.tar.xz |
Generics migration in Tls
Diffstat (limited to 'crypto/test')
20 files changed, 120 insertions, 119 deletions
diff --git a/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs b/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs index 9e2679fbb..a91d1dd31 100644 --- a/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs +++ b/crypto/test/src/tls/crypto/test/BcTlsCryptoTest.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using NUnit.Framework; @@ -181,7 +181,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests ImplTestDHDomain(new TlsDHConfig(namedGroup, true)); } - IList groups = new TestTlsDHGroupVerifier().Groups; + var groups = new TestTlsDHGroupVerifier().Groups; foreach (DHGroup dhGroup in groups) { BigInteger p = dhGroup.P, g = dhGroup.G; @@ -782,7 +782,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Tests private class TestTlsDHGroupVerifier : DefaultTlsDHGroupVerifier { - internal IList Groups + internal IList<DHGroup> Groups { get { return m_groups; } } diff --git a/crypto/test/src/tls/test/DtlsTestSuite.cs b/crypto/test/src/tls/test/DtlsTestSuite.cs index 158620fae..2ac1bb532 100644 --- a/crypto/test/src/tls/test/DtlsTestSuite.cs +++ b/crypto/test/src/tls/test/DtlsTestSuite.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using NUnit.Framework; @@ -14,9 +14,9 @@ namespace Org.BouncyCastle.Tls.Tests { } - public static IEnumerable Suite() + public static IEnumerable<TestCaseData> Suite() { - IList testSuite = new ArrayList(); + var testSuite = new List<TestCaseData>(); AddFallbackTests(testSuite); AddVersionTests(testSuite, ProtocolVersion.DTLSv10); @@ -25,7 +25,7 @@ namespace Org.BouncyCastle.Tls.Tests return testSuite; } - private static void AddFallbackTests(IList testSuite) + private static void AddFallbackTests(IList<TestCaseData> testSuite) { { TlsTestConfig c = CreateDtlsTestConfig(ProtocolVersion.DTLSv12); @@ -59,7 +59,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - private static void AddVersionTests(IList testSuite, ProtocolVersion version) + private static void AddVersionTests(IList<TestCaseData> testSuite, ProtocolVersion version) { string prefix = version.ToString() .Replace(" ", "") @@ -112,7 +112,7 @@ namespace Org.BouncyCastle.Tls.Tests c.clientAuth = C.CLIENT_AUTH_VALID; c.clientAuthSigAlg = SignatureAndHashAlgorithm.rsa_pss_rsae_sha256; c.clientAuthSigAlgClaimed = SignatureScheme.GetSignatureAndHashAlgorithm(SignatureScheme.ecdsa_secp256r1_sha256); - c.serverCertReqSigAlgs = new ArrayList(2); + c.serverCertReqSigAlgs = new List<SignatureAndHashAlgorithm>(2); c.serverCertReqSigAlgs.Add(SignatureAndHashAlgorithm.rsa_pss_rsae_sha256); c.serverCertReqSigAlgs.Add( SignatureScheme.GetSignatureAndHashAlgorithm(SignatureScheme.ecdsa_secp256r1_sha256)); @@ -229,7 +229,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - private static void AddTestCase(IList testSuite, TlsTestConfig config, string name) + private static void AddTestCase(IList<TestCaseData> testSuite, TlsTestConfig config, string name) { testSuite.Add(new TestCaseData(config).SetName(name)); } diff --git a/crypto/test/src/tls/test/MockDtlsClient.cs b/crypto/test/src/tls/test/MockDtlsClient.cs index e56f035d1..5feab0c24 100644 --- a/crypto/test/src/tls/test/MockDtlsClient.cs +++ b/crypto/test/src/tls/test/MockDtlsClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -7,7 +8,6 @@ using Org.BouncyCastle.Tls.Crypto.Impl.BC; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Encoders; -using System.Collections; namespace Org.BouncyCastle.Tls.Tests { @@ -103,7 +103,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -111,7 +111,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetClientExtensions(); } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockDtlsServer.cs b/crypto/test/src/tls/test/MockDtlsServer.cs index 28498de07..adfc40db2 100644 --- a/crypto/test/src/tls/test/MockDtlsServer.cs +++ b/crypto/test/src/tls/test/MockDtlsServer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -55,13 +55,13 @@ namespace Org.BouncyCastle.Tls.Tests short[] certificateTypes = new short[]{ ClientCertificateType.rsa_sign, ClientCertificateType.dss_sign, ClientCertificateType.ecdsa_sign }; - IList serverSigAlgs = null; + IList<SignatureAndHashAlgorithm> serverSigAlgs = null; if (TlsUtilities.IsSignatureAlgorithmsExtensionAllowed(m_context.ServerVersion)) { serverSigAlgs = TlsUtilities.GetDefaultSupportedSignatureAlgorithms(m_context); } - IList certificateAuthorities = new ArrayList(); + var certificateAuthorities = new List<X509Name>(); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-dsa.pem").Subject); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-ecdsa.pem").Subject); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-rsa.pem").Subject); @@ -121,7 +121,7 @@ namespace Org.BouncyCastle.Tls.Tests Console.WriteLine("Server 'tls-unique': " + ToHexString(tlsUnique)); } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -129,7 +129,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -137,7 +137,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -153,7 +153,7 @@ namespace Org.BouncyCastle.Tls.Tests protected override TlsCredentialedSigner GetRsaSignerCredentials() { - IList clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; + var clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; return TlsTestUtilities.LoadSignerCredentialsServer(m_context, clientSigAlgs, SignatureAlgorithm.rsa); } diff --git a/crypto/test/src/tls/test/MockPskDtlsClient.cs b/crypto/test/src/tls/test/MockPskDtlsClient.cs index be40be87a..c32dd628b 100644 --- a/crypto/test/src/tls/test/MockPskDtlsClient.cs +++ b/crypto/test/src/tls/test/MockPskDtlsClient.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -108,7 +108,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -116,7 +116,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetClientExtensions(); } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockPskDtlsServer.cs b/crypto/test/src/tls/test/MockPskDtlsServer.cs index d7a161c6f..5bcee9be7 100644 --- a/crypto/test/src/tls/test/MockPskDtlsServer.cs +++ b/crypto/test/src/tls/test/MockPskDtlsServer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Tls.Crypto.Impl.BC; @@ -73,7 +73,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -81,7 +81,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -89,7 +89,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockPskTls13Client.cs b/crypto/test/src/tls/test/MockPskTls13Client.cs index 1ed19e969..6655e8e5e 100644 --- a/crypto/test/src/tls/test/MockPskTls13Client.cs +++ b/crypto/test/src/tls/test/MockPskTls13Client.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Tls.Crypto; @@ -28,9 +28,9 @@ namespace Org.BouncyCastle.Tls.Tests // return new short[] { PskKeyExchangeMode.psk_dhe_ke, PskKeyExchangeMode.psk_ke }; //} - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_1_1); protocolNames.Add(ProtocolName.Http_2_Tls); return protocolNames; @@ -46,13 +46,13 @@ namespace Org.BouncyCastle.Tls.Tests return ProtocolVersion.TLSv13.Only(); } - public override IList GetExternalPsks() + public override IList<TlsPskExternal> GetExternalPsks() { byte[] identity = Strings.ToUtf8ByteArray("client"); TlsSecret key = Crypto.CreateSecret(Strings.ToUtf8ByteArray("TLS_TEST_PSK")); int prfAlgorithm = PrfAlgorithm.tls13_hkdf_sha256; - return TlsUtilities.VectorOfOne(new BasicTlsPskExternal(identity, key, prfAlgorithm)); + return TlsUtilities.VectorOfOne<TlsPskExternal>(new BasicTlsPskExternal(identity, key, prfAlgorithm)); } public override void NotifyAlertRaised(short alertLevel, short alertDescription, string message, @@ -107,7 +107,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -115,7 +115,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetClientExtensions(); } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockPskTls13Server.cs b/crypto/test/src/tls/test/MockPskTls13Server.cs index b084bec99..b013c2710 100644 --- a/crypto/test/src/tls/test/MockPskTls13Server.cs +++ b/crypto/test/src/tls/test/MockPskTls13Server.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Tls.Crypto; @@ -22,9 +22,9 @@ namespace Org.BouncyCastle.Tls.Tests return null; } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_2_Tls); protocolNames.Add(ProtocolName.Http_1_1); return protocolNames; @@ -51,7 +51,7 @@ namespace Org.BouncyCastle.Tls.Tests return serverVersion; } - public override TlsPskExternal GetExternalPsk(IList identities) + public override TlsPskExternal GetExternalPsk(IList<PskIdentity> identities) { byte[] identity = Strings.ToUtf8ByteArray("client"); long obfuscatedTicketAge = 0L; @@ -105,7 +105,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -113,7 +113,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -121,7 +121,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockPskTlsClient.cs b/crypto/test/src/tls/test/MockPskTlsClient.cs index e01dd74df..2a62cfa36 100644 --- a/crypto/test/src/tls/test/MockPskTlsClient.cs +++ b/crypto/test/src/tls/test/MockPskTlsClient.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -27,9 +27,9 @@ namespace Org.BouncyCastle.Tls.Tests this.m_session = session; } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_1_1); protocolNames.Add(ProtocolName.Http_2_Tls); return protocolNames; @@ -63,12 +63,12 @@ namespace Org.BouncyCastle.Tls.Tests + ", " + AlertDescription.GetText(alertDescription)); } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); - IDictionary clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised( + var clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised( base.GetClientExtensions()); { @@ -135,7 +135,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockPskTlsServer.cs b/crypto/test/src/tls/test/MockPskTlsServer.cs index acfa1bc56..4276bbe3e 100644 --- a/crypto/test/src/tls/test/MockPskTlsServer.cs +++ b/crypto/test/src/tls/test/MockPskTlsServer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Tls.Crypto.Impl.BC; @@ -17,9 +17,9 @@ namespace Org.BouncyCastle.Tls.Tests { } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_2_Tls); protocolNames.Add(ProtocolName.Http_1_1); return protocolNames; @@ -81,7 +81,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -89,7 +89,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -97,7 +97,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockSrpTlsClient.cs b/crypto/test/src/tls/test/MockSrpTlsClient.cs index ac7340ca1..5c91124a0 100644 --- a/crypto/test/src/tls/test/MockSrpTlsClient.cs +++ b/crypto/test/src/tls/test/MockSrpTlsClient.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -22,9 +22,9 @@ namespace Org.BouncyCastle.Tls.Tests this.m_session = session; } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_1_1); protocolNames.Add(ProtocolName.Http_2_Tls); return protocolNames; @@ -58,13 +58,12 @@ namespace Org.BouncyCastle.Tls.Tests + ", " + AlertDescription.GetText(alertDescription)); } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); - IDictionary clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised( - base.GetClientExtensions()); + var clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised(base.GetClientExtensions()); { /* @@ -130,7 +129,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockSrpTlsServer.cs b/crypto/test/src/tls/test/MockSrpTlsServer.cs index fc643af89..988be50d8 100644 --- a/crypto/test/src/tls/test/MockSrpTlsServer.cs +++ b/crypto/test/src/tls/test/MockSrpTlsServer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Crypto.Agreement.Srp; @@ -29,9 +29,9 @@ namespace Org.BouncyCastle.Tls.Tests { } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_2_Tls); protocolNames.Add(ProtocolName.Http_1_1); return protocolNames; @@ -93,7 +93,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -101,7 +101,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -109,7 +109,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -119,13 +119,13 @@ namespace Org.BouncyCastle.Tls.Tests protected override TlsCredentialedSigner GetDsaSignerCredentials() { - IList clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; + var clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; return TlsTestUtilities.LoadSignerCredentialsServer(m_context, clientSigAlgs, SignatureAlgorithm.dsa); } protected override TlsCredentialedSigner GetRsaSignerCredentials() { - IList clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; + var clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; return TlsTestUtilities.LoadSignerCredentialsServer(m_context, clientSigAlgs, SignatureAlgorithm.rsa); } diff --git a/crypto/test/src/tls/test/MockTlsClient.cs b/crypto/test/src/tls/test/MockTlsClient.cs index 71ac4d3f4..98898dd30 100644 --- a/crypto/test/src/tls/test/MockTlsClient.cs +++ b/crypto/test/src/tls/test/MockTlsClient.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -22,9 +22,9 @@ namespace Org.BouncyCastle.Tls.Tests this.m_session = session; } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_1_1); protocolNames.Add(ProtocolName.Http_2_Tls); return protocolNames; @@ -58,12 +58,12 @@ namespace Org.BouncyCastle.Tls.Tests + ", " + AlertDescription.GetText(alertDescription)); } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); - IDictionary clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised( + var clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised( base.GetClientExtensions()); { @@ -130,7 +130,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); diff --git a/crypto/test/src/tls/test/MockTlsServer.cs b/crypto/test/src/tls/test/MockTlsServer.cs index 18494df12..d4e885117 100644 --- a/crypto/test/src/tls/test/MockTlsServer.cs +++ b/crypto/test/src/tls/test/MockTlsServer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -18,9 +18,9 @@ namespace Org.BouncyCastle.Tls.Tests { } - protected override IList GetProtocolNames() + protected override IList<ProtocolName> GetProtocolNames() { - IList protocolNames = new ArrayList(); + var protocolNames = new List<ProtocolName>(); protocolNames.Add(ProtocolName.Http_2_Tls); protocolNames.Add(ProtocolName.Http_1_1); return protocolNames; @@ -74,13 +74,13 @@ namespace Org.BouncyCastle.Tls.Tests public override CertificateRequest GetCertificateRequest() { - IList serverSigAlgs = null; + IList<SignatureAndHashAlgorithm> serverSigAlgs = null; if (TlsUtilities.IsSignatureAlgorithmsExtensionAllowed(m_context.ServerVersion)) { serverSigAlgs = TlsUtilities.GetDefaultSupportedSignatureAlgorithms(m_context); } - IList certificateAuthorities = new ArrayList(); + var certificateAuthorities = new List<X509Name>(); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-dsa.pem").Subject); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-ecdsa.pem").Subject); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-rsa.pem").Subject); @@ -94,7 +94,7 @@ namespace Org.BouncyCastle.Tls.Tests byte[] certificateRequestContext = TlsUtilities.EmptyBytes; // TODO[tls13] Add TlsTestConfig.serverCertReqSigAlgsCert - IList serverSigAlgsCert = null; + IList<SignatureAndHashAlgorithm> serverSigAlgsCert = null; return new CertificateRequest(certificateRequestContext, serverSigAlgs, serverSigAlgsCert, certificateAuthorities); @@ -157,7 +157,7 @@ namespace Org.BouncyCastle.Tls.Tests Console.WriteLine("Server 'tls-unique': " + ToHexString(tlsUnique)); } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -165,7 +165,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -173,7 +173,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -189,7 +189,7 @@ namespace Org.BouncyCastle.Tls.Tests protected override TlsCredentialedSigner GetRsaSignerCredentials() { - IList clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; + var clientSigAlgs = m_context.SecurityParameters.ClientSigAlgs; return TlsTestUtilities.LoadSignerCredentialsServer(m_context, clientSigAlgs, SignatureAlgorithm.rsa); } diff --git a/crypto/test/src/tls/test/TlsTestClientImpl.cs b/crypto/test/src/tls/test/TlsTestClientImpl.cs index 760dab038..5d612aaa8 100644 --- a/crypto/test/src/tls/test/TlsTestClientImpl.cs +++ b/crypto/test/src/tls/test/TlsTestClientImpl.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1; @@ -68,12 +68,12 @@ namespace Org.BouncyCastle.Tls.Tests get { return m_firstFatalAlertDescription; } } - public override IDictionary GetClientExtensions() + public override IDictionary<int, byte[]> GetClientExtensions() { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); - IDictionary clientExtensions = base.GetClientExtensions(); + var clientExtensions = base.GetClientExtensions(); if (clientExtensions != null) { if (!m_config.clientSendSignatureAlgorithms) @@ -90,7 +90,7 @@ namespace Org.BouncyCastle.Tls.Tests return clientExtensions; } - public override IList GetEarlyKeyShareGroups() + public override IList<int> GetEarlyKeyShareGroups() { if (m_config.clientEmptyKeyShare) return null; @@ -98,7 +98,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetEarlyKeyShareGroups(); } - protected override IList GetSupportedSignatureAlgorithms() + protected override IList<SignatureAndHashAlgorithm> GetSupportedSignatureAlgorithms() { if (m_config.clientCHSigAlgs != null) return TlsUtilities.GetSupportedSignatureAlgorithms(m_context, m_config.clientCHSigAlgs); @@ -190,7 +190,7 @@ namespace Org.BouncyCastle.Tls.Tests return new MyTlsAuthentication(this, m_context); } - public override void ProcessServerExtensions(IDictionary serverExtensions) + public override void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -326,7 +326,7 @@ namespace Org.BouncyCastle.Tls.Tests return null; } - IList supportedSigAlgs = certificateRequest.SupportedSignatureAlgorithms; + var supportedSigAlgs = certificateRequest.SupportedSignatureAlgorithms; if (supportedSigAlgs != null && config.clientAuthSigAlg != null) { supportedSigAlgs = TlsUtilities.VectorOfOne(config.clientAuthSigAlg); diff --git a/crypto/test/src/tls/test/TlsTestConfig.cs b/crypto/test/src/tls/test/TlsTestConfig.cs index 81784e3e3..acacd7136 100644 --- a/crypto/test/src/tls/test/TlsTestConfig.cs +++ b/crypto/test/src/tls/test/TlsTestConfig.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Org.BouncyCastle.Tls.Tests { @@ -47,7 +47,7 @@ namespace Org.BouncyCastle.Tls.Tests /// <summary>If TLS 1.2 or higher is negotiated, configures the set of supported signature algorithms in the /// ClientHello. If null, uses a default set.</summary> - public IList clientCHSigAlgs = null; + public IList<SignatureAndHashAlgorithm> clientCHSigAlgs = null; /// <summary>Control whether the client will call /// <see cref="TlsUtilities.CheckPeerSigAlgs(TlsContext, Crypto.TlsCertificate[])"/> to check the server @@ -84,7 +84,7 @@ namespace Org.BouncyCastle.Tls.Tests /// <summary>If TLS 1.2 or higher is negotiated, configures the set of supported signature algorithms in the /// CertificateRequest (if one is sent). If null, uses a default set.</summary> - public IList serverCertReqSigAlgs = null; + public IList<SignatureAndHashAlgorithm> serverCertReqSigAlgs = null; /// <summary>Control whether the server will call /// <see cref="TlsUtilities.CheckPeerSigAlgs(TlsContext, Crypto.TlsCertificate[])"/> to check the client diff --git a/crypto/test/src/tls/test/TlsTestServerImpl.cs b/crypto/test/src/tls/test/TlsTestServerImpl.cs index 22e05ffcc..499498f1e 100644 --- a/crypto/test/src/tls/test/TlsTestServerImpl.cs +++ b/crypto/test/src/tls/test/TlsTestServerImpl.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Org.BouncyCastle.Asn1.X509; @@ -166,7 +166,7 @@ namespace Org.BouncyCastle.Tls.Tests if (m_config.serverCertReq == TlsTestConfig.SERVER_CERT_REQ_NONE) return null; - IList serverSigAlgs = null; + IList<SignatureAndHashAlgorithm> serverSigAlgs = null; if (TlsUtilities.IsSignatureAlgorithmsExtensionAllowed(m_context.ServerVersion)) { serverSigAlgs = m_config.serverCertReqSigAlgs; @@ -176,7 +176,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - IList certificateAuthorities = new ArrayList(); + var certificateAuthorities = new List<X509Name>(); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-dsa.pem").Subject); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-ecdsa.pem").Subject); //certificateAuthorities.Add(TlsTestUtilities.LoadBcCertificateResource("x509-ca-rsa.pem").Subject); @@ -190,7 +190,7 @@ namespace Org.BouncyCastle.Tls.Tests byte[] certificateRequestContext = TlsUtilities.EmptyBytes; // TODO[tls13] Add TlsTestConfig.serverCertReqSigAlgsCert - IList serverSigAlgsCert = null; + IList<SignatureAndHashAlgorithm> serverSigAlgsCert = null; return new CertificateRequest(certificateRequestContext, serverSigAlgs, serverSigAlgsCert, certificateAuthorities); @@ -254,7 +254,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - public override void ProcessClientExtensions(IDictionary clientExtensions) + public override void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions) { if (m_context.SecurityParameters.ClientRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -262,7 +262,7 @@ namespace Org.BouncyCastle.Tls.Tests base.ProcessClientExtensions(clientExtensions); } - public override IDictionary GetServerExtensions() + public override IDictionary<int, byte[]> GetServerExtensions() { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -270,7 +270,7 @@ namespace Org.BouncyCastle.Tls.Tests return base.GetServerExtensions(); } - public override void GetServerExtensionsForConnection(IDictionary serverExtensions) + public override void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions) { if (m_context.SecurityParameters.ServerRandom == null) throw new TlsFatalAlert(AlertDescription.internal_error); @@ -278,7 +278,7 @@ namespace Org.BouncyCastle.Tls.Tests base.GetServerExtensionsForConnection(serverExtensions); } - protected virtual IList GetSupportedSignatureAlgorithms() + protected virtual IList<SignatureAndHashAlgorithm> GetSupportedSignatureAlgorithms() { if (TlsUtilities.IsTlsV12(m_context) && m_config.serverAuthSigAlg != null) { diff --git a/crypto/test/src/tls/test/TlsTestSuite.cs b/crypto/test/src/tls/test/TlsTestSuite.cs index 4f4e4e023..5139a3e6b 100644 --- a/crypto/test/src/tls/test/TlsTestSuite.cs +++ b/crypto/test/src/tls/test/TlsTestSuite.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using NUnit.Framework; @@ -30,14 +30,14 @@ namespace Org.BouncyCastle.Tls.Tests { } - public static IEnumerable Suite() + public static IEnumerable<TestCaseData> Suite() { - IList testSuite = new ArrayList(); + var testSuite = new List<TestCaseData>(); AddAllTests(testSuite, TlsTestConfig.CRYPTO_BC, TlsTestConfig.CRYPTO_BC); return testSuite; } - private static void AddAllTests(IList testSuite, int clientCrypto, int serverCrypto) + private static void AddAllTests(IList<TestCaseData> testSuite, int clientCrypto, int serverCrypto) { AddFallbackTests(testSuite, clientCrypto, serverCrypto); AddVersionTests(testSuite, ProtocolVersion.SSLv3, clientCrypto, serverCrypto); @@ -47,7 +47,7 @@ namespace Org.BouncyCastle.Tls.Tests AddVersionTests(testSuite, ProtocolVersion.TLSv13, clientCrypto, serverCrypto); } - private static void AddFallbackTests(IList testSuite, int clientCrypto, int serverCrypto) + private static void AddFallbackTests(IList<TestCaseData> testSuite, int clientCrypto, int serverCrypto) { string prefix = GetCryptoName(clientCrypto) + "_" + GetCryptoName(serverCrypto) + "_"; @@ -75,7 +75,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - private static void AddVersionTests(IList testSuite, ProtocolVersion version, int clientCrypto, + private static void AddVersionTests(IList<TestCaseData> testSuite, ProtocolVersion version, int clientCrypto, int serverCrypto) { string prefix = GetCryptoName(clientCrypto) + "_" + GetCryptoName(serverCrypto) + "_" @@ -148,7 +148,7 @@ namespace Org.BouncyCastle.Tls.Tests c.clientAuth = C.CLIENT_AUTH_VALID; c.clientAuthSigAlg = SignatureAndHashAlgorithm.rsa_pss_rsae_sha256; c.clientAuthSigAlgClaimed = SignatureScheme.GetSignatureAndHashAlgorithm(SignatureScheme.ecdsa_secp256r1_sha256); - c.serverCertReqSigAlgs = new ArrayList(2); + c.serverCertReqSigAlgs = new List<SignatureAndHashAlgorithm>(2); c.serverCertReqSigAlgs.Add(SignatureAndHashAlgorithm.rsa_pss_rsae_sha256); c.serverCertReqSigAlgs.Add( SignatureScheme.GetSignatureAndHashAlgorithm(SignatureScheme.ecdsa_secp256r1_sha256)); @@ -273,7 +273,7 @@ namespace Org.BouncyCastle.Tls.Tests } } - private static void AddTestCase(IList testSuite, TlsTestConfig config, string name) + private static void AddTestCase(IList<TestCaseData> testSuite, TlsTestConfig config, string name) { testSuite.Add(new TestCaseData(config).SetName(name)); } diff --git a/crypto/test/src/tls/test/TlsTestUtilities.cs b/crypto/test/src/tls/test/TlsTestUtilities.cs index 04e3a52d1..0625f42f4 100644 --- a/crypto/test/src/tls/test/TlsTestUtilities.cs +++ b/crypto/test/src/tls/test/TlsTestUtilities.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -239,7 +239,8 @@ namespace Org.BouncyCastle.Tls.Tests } internal static TlsCredentialedSigner LoadSignerCredentials(TlsContext context, - IList supportedSignatureAlgorithms, short signatureAlgorithm, string certResource, string keyResource) + IList<SignatureAndHashAlgorithm> supportedSignatureAlgorithms, short signatureAlgorithm, + string certResource, string keyResource) { if (supportedSignatureAlgorithms == null) { @@ -266,7 +267,7 @@ namespace Org.BouncyCastle.Tls.Tests } internal static TlsCredentialedSigner LoadSignerCredentialsServer(TlsContext context, - IList supportedSignatureAlgorithms, short signatureAlgorithm) + IList<SignatureAndHashAlgorithm> supportedSignatureAlgorithms, short signatureAlgorithm) { string sigName = GetResourceName(signatureAlgorithm); @@ -298,7 +299,7 @@ namespace Org.BouncyCastle.Tls.Tests TlsCertificate certificate = LoadCertificateResource(crypto, resources[i]); // TODO[tls13] Add possibility of specifying e.g. CertificateStatus - IDictionary extensions = null; + IDictionary<int, byte[]> extensions = null; certificateEntryList[i] = new CertificateEntry(certificate, extensions); } diff --git a/crypto/test/src/tls/test/TlsUtilitiesTest.cs b/crypto/test/src/tls/test/TlsUtilitiesTest.cs index 702c40082..858407fd4 100644 --- a/crypto/test/src/tls/test/TlsUtilitiesTest.cs +++ b/crypto/test/src/tls/test/TlsUtilitiesTest.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using NUnit.Framework; @@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Tls.Tests int keyExchangeAlgorithm = KeyExchangeAlgorithm.ECDHE_RSA; short signatureAlgorithm = TlsUtilities.GetLegacySignatureAlgorithmServer(keyExchangeAlgorithm); - IList supportedSignatureAlgorithms = GetSignatureAlgorithms(false); + var supportedSignatureAlgorithms = GetSignatureAlgorithms(false); SignatureAndHashAlgorithm sigAlg = TlsUtilities.ChooseSignatureAndHashAlgorithm(ProtocolVersion.TLSv12, supportedSignatureAlgorithms, signatureAlgorithm); Assert.AreEqual(HashAlgorithm.sha256, sigAlg.Hash); @@ -28,14 +28,14 @@ namespace Org.BouncyCastle.Tls.Tests } } - private static IList GetSignatureAlgorithms(bool randomise) + private static IList<SignatureAndHashAlgorithm> GetSignatureAlgorithms(bool randomise) { short[] hashAlgorithms = new short[]{ HashAlgorithm.sha1, HashAlgorithm.sha224, HashAlgorithm.sha256, HashAlgorithm.sha384, HashAlgorithm.sha512, HashAlgorithm.md5 }; short[] signatureAlgorithms = new short[]{ SignatureAlgorithm.rsa, SignatureAlgorithm.dsa, SignatureAlgorithm.ecdsa }; - IList result = new ArrayList(); + var result = new List<SignatureAndHashAlgorithm>(); for (int i = 0; i < signatureAlgorithms.Length; ++i) { for (int j = 0; j < hashAlgorithms.Length; ++j) @@ -53,7 +53,8 @@ namespace Org.BouncyCastle.Tls.Tests int dst = r.Next(count); if (src != dst) { - object a = result[src], b = result[dst]; + var a = result[src]; + var b = result[dst]; result[dst] = a; result[src] = b; } |