Skip to content

Commit 4f71aac

Browse files
committed
Merge branch 'main' of gitlab.cryptoworkshop.com:root/bc-java
2 parents 42b7051 + 7a2cc6f commit 4f71aac

5 files changed

Lines changed: 13 additions & 48 deletions

File tree

ci/common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
3+

tls/src/main/java/org/bouncycastle/tls/DTLSProtocol.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ protected static void sendCertificateMessage(TlsContext context, DTLSReliableHan
9494
protected static int validateSelectedCipherSuite(int selectedCipherSuite, short alertDescription)
9595
throws IOException
9696
{
97-
switch (TlsUtils.getEncryptionAlgorithm(selectedCipherSuite))
97+
int encryptionAlgorithm = TlsUtils.getEncryptionAlgorithm(selectedCipherSuite);
98+
if (EncryptionAlgorithm.NULL != encryptionAlgorithm)
9899
{
99-
case EncryptionAlgorithm.RC4_40:
100-
case EncryptionAlgorithm.RC4_128:
101-
case -1:
102-
throw new TlsFatalAlert(alertDescription);
103-
default:
104-
return selectedCipherSuite;
100+
int cipherType = TlsUtils.getEncryptionAlgorithmType(encryptionAlgorithm);
101+
if (cipherType < 0 || CipherType.stream == cipherType)
102+
{
103+
throw new TlsFatalAlert(alertDescription);
104+
}
105105
}
106+
return selectedCipherSuite;
106107
}
107108
}

tls/src/main/java/org/bouncycastle/tls/SecurityParameters.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class SecurityParameters
1818
short maxFragmentLength = -1;
1919
int prfAlgorithm = -1;
2020
int prfCryptoHashAlgorithm = -1;
21-
short prfHashAlgorithm = -1;
2221
int prfHashLength = -1;
2322
int verifyDataLength = -1;
2423
TlsSecret baseKeyClient = null;
@@ -215,16 +214,6 @@ public int getPRFCryptoHashAlgorithm()
215214
return prfCryptoHashAlgorithm;
216215
}
217216

218-
/**
219-
* @return {@link HashAlgorithm} for the current {@link PRFAlgorithm}
220-
*
221-
* @deprecated Use {@link #getPRFCryptoHashAlgorithm()} instead.
222-
*/
223-
public short getPRFHashAlgorithm()
224-
{
225-
return prfHashAlgorithm;
226-
}
227-
228217
public int getPRFHashLength()
229218
{
230219
return prfHashLength;

tls/src/main/java/org/bouncycastle/tls/TlsServerProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ protected ServerHello generate13ServerHello(ClientHello clientHello, HandshakeMe
398398
int namedGroup = clientShare.getNamedGroup();
399399

400400
TlsAgreement agreement;
401-
if (NamedGroup.refersToASpecificCurve(namedGroup))
401+
if (NamedGroup.refersToAnECDHCurve(namedGroup))
402402
{
403403
agreement = crypto.createECDomain(new TlsECConfig(namedGroup)).createECDH();
404404
}

tls/src/main/java/org/bouncycastle/tls/TlsUtils.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,30 +1960,6 @@ private static TlsSecret update13TrafficSecret(SecurityParameters securityParame
19601960
EMPTY_BYTES, securityParameters.getPRFHashLength());
19611961
}
19621962

1963-
/**
1964-
* @deprecated Will be removed. {@link TlsCryptoUtils#getHashForPRF(int)} should be a useful alternative.
1965-
*/
1966-
public static short getHashAlgorithmForPRFAlgorithm(int prfAlgorithm)
1967-
{
1968-
switch (prfAlgorithm)
1969-
{
1970-
case PRFAlgorithm.ssl_prf_legacy:
1971-
case PRFAlgorithm.tls_prf_legacy:
1972-
throw new IllegalArgumentException("legacy PRF not a valid algorithm");
1973-
case PRFAlgorithm.tls_prf_sha256:
1974-
case PRFAlgorithm.tls13_hkdf_sha256:
1975-
return HashAlgorithm.sha256;
1976-
case PRFAlgorithm.tls_prf_sha384:
1977-
case PRFAlgorithm.tls13_hkdf_sha384:
1978-
return HashAlgorithm.sha384;
1979-
// TODO[RFC 8998]
1980-
// case PRFAlgorithm.tls13_hkdf_sm3:
1981-
// return HashAlgorithm.sm3;
1982-
default:
1983-
throw new IllegalArgumentException("unknown PRFAlgorithm: " + PRFAlgorithm.getText(prfAlgorithm));
1984-
}
1985-
}
1986-
19871963
public static ASN1ObjectIdentifier getOIDForHashAlgorithm(short hashAlgorithm)
19881964
{
19891965
switch (hashAlgorithm)
@@ -5360,7 +5336,7 @@ private static void collectKeyShares(TlsClientContext clientContext, int[] suppo
53605336
}
53615337

53625338
TlsAgreement agreement = null;
5363-
if (NamedGroup.refersToASpecificCurve(supportedGroup))
5339+
if (NamedGroup.refersToAnECDHCurve(supportedGroup))
53645340
{
53655341
if (crypto.hasECDHAgreement())
53665342
{
@@ -5433,7 +5409,7 @@ static KeyShareEntry selectKeyShare(TlsCrypto crypto, ProtocolVersion negotiated
54335409
continue;
54345410
}
54355411

5436-
if ((NamedGroup.refersToASpecificCurve(group) && !crypto.hasECDHAgreement()) ||
5412+
if ((NamedGroup.refersToAnECDHCurve(group) && !crypto.hasECDHAgreement()) ||
54375413
(NamedGroup.refersToASpecificFiniteField(group) && !crypto.hasDHAgreement()) ||
54385414
(NamedGroup.refersToASpecificKem(group) && !crypto.hasKemAgreement()))
54395415
{
@@ -5470,7 +5446,7 @@ static int selectKeyShareGroup(TlsCrypto crypto, ProtocolVersion negotiatedVersi
54705446
continue;
54715447
}
54725448

5473-
if ((NamedGroup.refersToASpecificCurve(group) && !crypto.hasECDHAgreement()) ||
5449+
if ((NamedGroup.refersToAnECDHCurve(group) && !crypto.hasECDHAgreement()) ||
54745450
(NamedGroup.refersToASpecificFiniteField(group) && !crypto.hasDHAgreement()) ||
54755451
(NamedGroup.refersToASpecificKem(group) && !crypto.hasKemAgreement()))
54765452
{
@@ -5622,7 +5598,6 @@ static void negotiatedCipherSuite(SecurityParameters securityParameters, int cip
56225598
case PRFAlgorithm.tls_prf_legacy:
56235599
{
56245600
securityParameters.prfCryptoHashAlgorithm = -1;
5625-
securityParameters.prfHashAlgorithm = -1;
56265601
securityParameters.prfHashLength = -1;
56275602
break;
56285603
}
@@ -5631,7 +5606,6 @@ static void negotiatedCipherSuite(SecurityParameters securityParameters, int cip
56315606
int prfCryptoHashAlgorithm = TlsCryptoUtils.getHashForPRF(prfAlgorithm);
56325607

56335608
securityParameters.prfCryptoHashAlgorithm = prfCryptoHashAlgorithm;
5634-
securityParameters.prfHashAlgorithm = getHashAlgorithmForPRFAlgorithm(prfAlgorithm);
56355609
securityParameters.prfHashLength = TlsCryptoUtils.getHashOutputSize(prfCryptoHashAlgorithm);
56365610
break;
56375611
}

0 commit comments

Comments
 (0)