Skip to content

Commit e380617

Browse files
committed
Merge branch 'main' of gitlab.cryptoworkshop.com:root/bc-java
2 parents 0f06e15 + cb8239e commit e380617

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPSessionKey.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import java.util.regex.Matcher;
44
import java.util.regex.Pattern;
55

6+
import org.bouncycastle.util.Arrays;
67
import org.bouncycastle.util.encoders.Hex;
78

89
public class PGPSessionKey
910
{
11+
private static final Pattern ASCII_ENCODING_PATTERN = Pattern.compile("(\\d{1,3}):([0-9A-Fa-f]+)");
12+
1013
private final int algorithm;
1114
private final byte[] sessionKey;
1215

@@ -23,22 +26,20 @@ public int getAlgorithm()
2326

2427
public byte[] getKey()
2528
{
26-
byte[] copy = new byte[sessionKey.length];
27-
System.arraycopy(sessionKey, 0, copy, 0, sessionKey.length);
28-
return copy;
29+
return Arrays.clone(sessionKey);
2930
}
3031

31-
@SuppressWarnings("ArrayToString")
3232
public String toString()
3333
{
34-
// mote: we only print the reference to sessionKey to prevent accidental disclosure of the actual key value.
35-
return algorithm + ":" + sessionKey;
34+
// NOTE: Avoid disclosing the sessionKey value.
35+
String sessionKeyHashCode = Integer.toHexString(System.identityHashCode(sessionKey));
36+
37+
return algorithm + ":" + sessionKey.getClass().getName() + "@" + sessionKeyHashCode;
3638
}
3739

3840
public static PGPSessionKey fromAsciiRepresentation(String ascii)
3941
{
40-
Pattern pattern = Pattern.compile("(\\d{1,3}):([0-9A-Fa-f]+)");
41-
Matcher matcher = pattern.matcher(ascii);
42+
Matcher matcher = ASCII_ENCODING_PATTERN.matcher(ascii);
4243
if (!matcher.matches())
4344
{
4445
throw new IllegalArgumentException("Provided ascii encoding does not match expected format <algo-num>:<hex-key>");

pg/src/test/java/org/bouncycastle/openpgp/test/PGPSessionKeyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public class PGPSessionKeyTest
8888
public static void main(String[] args)
8989
throws Exception
9090
{
91-
PGPSessionKeyTest test = new PGPSessionKeyTest();
9291
Security.addProvider(new BouncyCastleProvider());
93-
test.performTest();
92+
93+
runTest(new PGPSessionKeyTest());
9494
}
9595

9696
public String getName()

tls/src/main/java/org/bouncycastle/jsse/provider/ProvSSLContextSpi.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,11 @@ private static Map<String, ProtocolVersion> createSupportedProtocolMapFips(
342342
}
343343

344344
private static String[] getDefaultEnabledCipherSuites(Map<String, CipherSuiteInfo> supportedCipherSuiteMap,
345-
List<String> defaultCipherSuiteList, boolean disableDHDefaultSuites, String cipherSuitesPropertyName)
345+
List<String> defaultCipherSuiteList, boolean disableDHDefaultSuites, String cipherSuitesPropertyName,
346+
String title)
346347
{
347348
List<String> candidates = getJdkTlsCipherSuites(cipherSuitesPropertyName, defaultCipherSuiteList);
349+
boolean disableDHSuites = disableDHDefaultSuites && candidates == defaultCipherSuiteList;
348350

349351
String[] result = new String[candidates.size()];
350352
int count = 0;
@@ -355,15 +357,15 @@ private static String[] getDefaultEnabledCipherSuites(Map<String, CipherSuiteInf
355357
{
356358
continue;
357359
}
358-
if (disableDHDefaultSuites &&
359-
candidates == defaultCipherSuiteList &&
360-
TlsDHUtils.isDHCipherSuite(cipherSuiteInfo.getCipherSuite()))
360+
if (disableDHSuites && TlsDHUtils.isDHCipherSuite(cipherSuiteInfo.getCipherSuite()))
361361
{
362+
LOG.finer(title + " default cipher suite disabled per DH disabling: " + candidate);
362363
continue;
363364
}
364365
if (!ProvAlgorithmConstraints.DEFAULT.permits(JsseUtils.KEY_AGREEMENT_CRYPTO_PRIMITIVES_BC, candidate,
365366
null))
366367
{
368+
LOG.fine(title + " default cipher suite disabled by AlgorithmConstraints: " + candidate);
367369
continue;
368370
}
369371

@@ -379,7 +381,7 @@ private static String[] getDefaultEnabledCipherSuitesClient(Map<String, CipherSu
379381
.getBooleanSystemProperty("org.bouncycastle.jsse.client.dh.disableDefaultSuites", false);
380382

381383
return getDefaultEnabledCipherSuites(supportedCipherSuiteMap, defaultCipherSuiteList, disableDHDefaultSuites,
382-
PROPERTY_CLIENT_CIPHERSUITES);
384+
PROPERTY_CLIENT_CIPHERSUITES, "Client");
383385
}
384386

385387
private static String[] getDefaultEnabledCipherSuitesServer(Map<String, CipherSuiteInfo> supportedCipherSuiteMap,
@@ -389,7 +391,7 @@ private static String[] getDefaultEnabledCipherSuitesServer(Map<String, CipherSu
389391
.getBooleanSystemProperty("org.bouncycastle.jsse.server.dh.disableDefaultSuites", false);
390392

391393
return getDefaultEnabledCipherSuites(supportedCipherSuiteMap, defaultCipherSuiteList, disableDHDefaultSuites,
392-
PROPERTY_SERVER_CIPHERSUITES);
394+
PROPERTY_SERVER_CIPHERSUITES, "Server");
393395
}
394396

395397
private static String[] getDefaultEnabledProtocols(Map<String, ProtocolVersion> supportedProtocolMap,

0 commit comments

Comments
 (0)