From 7abd4af6873142092f5f38f93888a73c0a1bd17a Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 14 Jul 2021 23:45:24 +0700 Subject: Avoid redundant CheckUsageInRole calls --- crypto/BouncyCastle.Android.csproj | 1 - crypto/BouncyCastle.csproj | 1 - crypto/BouncyCastle.iOS.csproj | 1 - crypto/crypto.csproj | 5 ----- crypto/src/tls/TlsDHKeyExchange.cs | 6 ++---- crypto/src/tls/TlsECDHKeyExchange.cs | 4 ++-- crypto/src/tls/TlsPskKeyExchange.cs | 8 +++---- crypto/src/tls/TlsRsaKeyExchange.cs | 6 +++--- crypto/src/tls/TlsRsaUtilities.cs | 26 ----------------------- crypto/src/tls/TlsUtilities.cs | 12 +++++++++++ crypto/src/tls/crypto/TlsCertificate.cs | 3 +-- crypto/src/tls/crypto/impl/bc/BcTlsCertificate.cs | 21 +----------------- 12 files changed, 25 insertions(+), 69 deletions(-) delete mode 100644 crypto/src/tls/TlsRsaUtilities.cs diff --git a/crypto/BouncyCastle.Android.csproj b/crypto/BouncyCastle.Android.csproj index f8d4fa890..043cd2b27 100644 --- a/crypto/BouncyCastle.Android.csproj +++ b/crypto/BouncyCastle.Android.csproj @@ -1803,7 +1803,6 @@ - diff --git a/crypto/BouncyCastle.csproj b/crypto/BouncyCastle.csproj index 90c686996..8f93f8013 100644 --- a/crypto/BouncyCastle.csproj +++ b/crypto/BouncyCastle.csproj @@ -1797,7 +1797,6 @@ - diff --git a/crypto/BouncyCastle.iOS.csproj b/crypto/BouncyCastle.iOS.csproj index 70e241004..6417b95b0 100644 --- a/crypto/BouncyCastle.iOS.csproj +++ b/crypto/BouncyCastle.iOS.csproj @@ -1798,7 +1798,6 @@ - diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj index 62d523e33..0e9884ab2 100644 --- a/crypto/crypto.csproj +++ b/crypto/crypto.csproj @@ -8873,11 +8873,6 @@ SubType = "Code" BuildAction = "Compile" /> - RSA utility methods. - public abstract class TlsRsaUtilities - { - /// Generate a pre_master_secret and send it encrypted to the server. - /// - public static TlsSecret GenerateEncryptedPreMasterSecret(TlsContext context, TlsCertificate certificate, - Stream output) - { - TlsSecret preMasterSecret = context.Crypto.GenerateRsaPreMasterSecret(context.RsaPreMasterSecretVersion); - - TlsEncryptor encryptor = certificate.CreateEncryptor(TlsCertificateRole.RsaEncryption); - - byte[] encryptedPreMasterSecret = preMasterSecret.Encrypt(encryptor); - TlsUtilities.WriteEncryptedPms(context, encryptedPreMasterSecret, output); - - return preMasterSecret; - } - } -} diff --git a/crypto/src/tls/TlsUtilities.cs b/crypto/src/tls/TlsUtilities.cs index 98d834b6d..4cec13bae 100644 --- a/crypto/src/tls/TlsUtilities.cs +++ b/crypto/src/tls/TlsUtilities.cs @@ -5327,6 +5327,18 @@ namespace Org.BouncyCastle.Tls } } + /// Generate a pre_master_secret and send it encrypted to the server. + /// + public static TlsSecret GenerateEncryptedPreMasterSecret(TlsContext context, TlsEncryptor encryptor, + Stream output) + { + ProtocolVersion version = context.RsaPreMasterSecretVersion; + TlsSecret preMasterSecret = context.Crypto.GenerateRsaPreMasterSecret(version); + byte[] encryptedPreMasterSecret = preMasterSecret.Encrypt(encryptor); + WriteEncryptedPms(context, encryptedPreMasterSecret, output); + return preMasterSecret; + } + #if !PORTABLE || DOTNET public static bool IsTimeout(SocketException e) { diff --git a/crypto/src/tls/crypto/TlsCertificate.cs b/crypto/src/tls/crypto/TlsCertificate.cs index b9efe37b3..fe507a662 100644 --- a/crypto/src/tls/crypto/TlsCertificate.cs +++ b/crypto/src/tls/crypto/TlsCertificate.cs @@ -50,9 +50,8 @@ namespace Org.BouncyCastle.Tls.Crypto /// bool SupportsSignatureAlgorithmCA(short signatureAlgorithm); - /// /// /// - TlsCertificate CheckUsageInRole(int connectionEnd, int tlsCertificateRole); + TlsCertificate CheckUsageInRole(int tlsCertificateRole); } } diff --git a/crypto/src/tls/crypto/impl/bc/BcTlsCertificate.cs b/crypto/src/tls/crypto/impl/bc/BcTlsCertificate.cs index 2f331a166..9d4157050 100644 --- a/crypto/src/tls/crypto/impl/bc/BcTlsCertificate.cs +++ b/crypto/src/tls/crypto/impl/bc/BcTlsCertificate.cs @@ -342,7 +342,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC } /// - public virtual TlsCertificate CheckUsageInRole(int connectionEnd, int tlsCertificateRole) + public virtual TlsCertificate CheckUsageInRole(int tlsCertificateRole) { switch (tlsCertificateRole) { @@ -360,25 +360,6 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC } } - if (connectionEnd == ConnectionEnd.server) - { - switch (tlsCertificateRole) - { - case TlsCertificateRole.RsaEncryption: - { - ValidateKeyUsage(KeyUsage.KeyEncipherment); - this.m_pubKeyRsa = GetPubKeyRsa(); - return this; - } - case TlsCertificateRole.Sm2Encryption: - { - ValidateKeyUsage(KeyUsage.KeyEncipherment); - this.m_pubKeyEC = GetPubKeyEC(); - return this; - } - } - } - throw new TlsFatalAlert(AlertDescription.certificate_unknown); } -- cgit 1.4.1