Skip to content

Commit ffa38f7

Browse files
committed
Merge f4106d3 into d0de32e
2 parents d0de32e + f4106d3 commit ffa38f7

File tree

26 files changed

+1425
-217
lines changed

26 files changed

+1425
-217
lines changed

closed/openjdk-tag.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
OPENJDK_TAG := jdk-17.0.6+4
1+
OPENJDK_TAG := jdk-17.0.6+5

src/java.base/share/classes/sun/security/ssl/Utilities.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,19 @@ static List<SNIServerName> addToSNIServerNameList(
101101
* not look like a FQDN
102102
*/
103103
private static SNIHostName rawToSNIHostName(String hostname) {
104-
SNIHostName sniHostName = null;
104+
// Is it a Fully-Qualified Domain Names (FQDN) ending with a dot?
105+
if (hostname != null && hostname.endsWith(".")) {
106+
// Remove the ending dot, which is not allowed in SNIHostName.
107+
hostname = hostname.substring(0, hostname.length() - 1);
108+
}
109+
105110
if (hostname != null && hostname.indexOf('.') > 0 &&
106111
!hostname.endsWith(".") &&
107112
!IPAddressUtil.isIPv4LiteralAddress(hostname) &&
108113
!IPAddressUtil.isIPv6LiteralAddress(hostname)) {
109114

110115
try {
111-
sniHostName = new SNIHostName(hostname);
116+
return new SNIHostName(hostname);
112117
} catch (IllegalArgumentException iae) {
113118
// don't bother to handle illegal host_name
114119
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
@@ -118,7 +123,7 @@ private static SNIHostName rawToSNIHostName(String hostname) {
118123
}
119124
}
120125

121-
return sniHostName;
126+
return null;
122127
}
123128

124129
/**

src/java.base/share/classes/sun/security/ssl/X509TrustManagerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ static void checkIdentity(SSLSession session,
404404

405405
boolean identifiable = false;
406406
String peerHost = session.getPeerHost();
407+
// Is it a Fully-Qualified Domain Names (FQDN) ending with a dot?
408+
if (peerHost != null && peerHost.endsWith(".")) {
409+
// Remove the ending dot, which is not allowed in SNIHostName.
410+
peerHost = peerHost.substring(0, peerHost.length() - 1);
411+
}
412+
407413
if (!checkClientTrusted) {
408414
List<SNIServerName> sniNames = getRequestedServerNames(session);
409415
String sniHostName = getHostNameInSNI(sniNames);

src/java.base/share/classes/sun/security/tools/keytool/CertAndKeyGen.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -160,7 +160,7 @@ public void generate(String name) {
160160
}
161161

162162
} catch (Exception e) {
163-
throw new IllegalArgumentException(e.getMessage());
163+
throw new IllegalArgumentException(e.getMessage(), e);
164164
}
165165
generateInternal();
166166
}
@@ -176,7 +176,7 @@ public void generate(int keyBits) {
176176
keyGen.initialize(keyBits, prng);
177177

178178
} catch (Exception e) {
179-
throw new IllegalArgumentException(e.getMessage());
179+
throw new IllegalArgumentException(e.getMessage(), e);
180180
}
181181
}
182182
generateInternal();
@@ -349,7 +349,7 @@ public X509Certificate getSelfCertificate (X500Name myname, Date firstDate,
349349

350350
} catch (IOException e) {
351351
throw new CertificateEncodingException("getSelfCert: " +
352-
e.getMessage());
352+
e.getMessage(), e);
353353
}
354354
}
355355

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private static String expand(final String s) throws IOException {
358358
try {
359359
return PropertyExpander.expand(s);
360360
} catch (Exception e) {
361-
throw new RuntimeException(e.getMessage());
361+
throw new RuntimeException(e.getMessage(), e);
362362
}
363363
}
364364

@@ -396,6 +396,10 @@ private ConfigurationException excLine(String msg) {
396396
return new ConfigurationException(msg + ", line " + st.lineno());
397397
}
398398

399+
private ConfigurationException excLine(String msg, Throwable e) {
400+
return new ConfigurationException(msg + ", line " + st.lineno(), e);
401+
}
402+
399403
private void parse() throws IOException {
400404
while (true) {
401405
int token = nextToken();
@@ -792,7 +796,7 @@ private long parseMechanism(String mech) throws IOException {
792796
try {
793797
return Functions.getMechanismId(mech);
794798
} catch (IllegalArgumentException e) {
795-
throw excLine("Unknown mechanism: " + mech);
799+
throw excLine("Unknown mechanism: " + mech, e);
796800
}
797801
}
798802
}
@@ -952,7 +956,7 @@ private long parseObjectClass() throws IOException {
952956
try {
953957
return Functions.getObjectClassId(name);
954958
} catch (IllegalArgumentException e) {
955-
throw excLine("Unknown object class " + name);
959+
throw excLine("Unknown object class " + name, e);
956960
}
957961
}
958962

@@ -964,7 +968,7 @@ private long parseKeyAlgorithm() throws IOException {
964968
try {
965969
return Functions.getKeyId(name);
966970
} catch (IllegalArgumentException e) {
967-
throw excLine("Unknown key algorithm " + name);
971+
throw excLine("Unknown key algorithm " + name, e);
968972
}
969973
}
970974
}
@@ -976,7 +980,7 @@ private long decodeAttributeName(String name) throws IOException {
976980
try {
977981
return Functions.getAttributeId(name);
978982
} catch (IllegalArgumentException e) {
979-
throw excLine("Unknown attribute name " + name);
983+
throw excLine("Unknown attribute name " + name, e);
980984
}
981985
}
982986
}
@@ -1032,4 +1036,8 @@ class ConfigurationException extends IOException {
10321036
ConfigurationException(String msg) {
10331037
super(msg);
10341038
}
1039+
1040+
ConfigurationException(String msg, Throwable e) {
1041+
super(msg, e);
1042+
}
10351043
}

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -140,7 +140,7 @@ private enum Transformation {
140140
try {
141141
engineSetPadding(algoParts[2]);
142142
} catch (NoSuchPaddingException e) {
143-
throw new NoSuchAlgorithmException();
143+
throw new NoSuchAlgorithmException(e);
144144
}
145145
} else if (algoParts[0].equals("ChaCha20-Poly1305")) {
146146
fixedKeySize = 32;

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -808,13 +808,21 @@ private int implDoFinal(byte[] out, int outOfs, int outLen)
808808
if (paddingObj != null) {
809809
int startOff = 0;
810810
if (reqBlockUpdates) {
811-
startOff = padBufferLen;
811+
// call C_EncryptUpdate first if the padBuffer is full
812+
// to make room for padding bytes
813+
if (padBufferLen == padBuffer.length) {
814+
k = token.p11.C_EncryptUpdate(session.id(),
815+
0, padBuffer, 0, padBufferLen,
816+
0, out, outOfs, outLen);
817+
} else {
818+
startOff = padBufferLen;
819+
}
812820
}
813821
int actualPadLen = paddingObj.setPaddingBytes(padBuffer,
814822
startOff, requiredOutLen - bytesBuffered);
815-
k = token.p11.C_EncryptUpdate(session.id(),
823+
k += token.p11.C_EncryptUpdate(session.id(),
816824
0, padBuffer, 0, startOff + actualPadLen,
817-
0, out, outOfs, outLen);
825+
0, out, outOfs + k, outLen - k);
818826
}
819827
// Some implementations such as the NSS Software Token do not
820828
// cancel the operation upon a C_EncryptUpdate failure (as
@@ -896,13 +904,21 @@ private int implDoFinal(ByteBuffer outBuffer)
896904
if (paddingObj != null) {
897905
int startOff = 0;
898906
if (reqBlockUpdates) {
899-
startOff = padBufferLen;
907+
// call C_EncryptUpdate first if the padBuffer is full
908+
// to make room for padding bytes
909+
if (padBufferLen == padBuffer.length) {
910+
k = token.p11.C_EncryptUpdate(session.id(),
911+
0, padBuffer, 0, padBufferLen,
912+
outAddr, outArray, outOfs, outLen);
913+
} else {
914+
startOff = padBufferLen;
915+
}
900916
}
901917
int actualPadLen = paddingObj.setPaddingBytes(padBuffer,
902918
startOff, requiredOutLen - bytesBuffered);
903-
k = token.p11.C_EncryptUpdate(session.id(),
919+
k += token.p11.C_EncryptUpdate(session.id(),
904920
0, padBuffer, 0, startOff + actualPadLen,
905-
outAddr, outArray, outOfs, outLen);
921+
outAddr, outArray, outOfs + k, outLen - k);
906922
}
907923
// Some implementations such as the NSS Software Token do not
908924
// cancel the operation upon a C_EncryptUpdate failure (as

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyPairGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void initialize(int keySize, SecureRandom random) {
145145
try {
146146
checkKeySize(keySize, null);
147147
} catch (InvalidAlgorithmParameterException e) {
148-
throw new InvalidParameterException(e.getMessage());
148+
throw (InvalidParameterException) new InvalidParameterException(e.getMessage()).initCause(e);
149149
}
150150
this.params = null;
151151
if (algorithm.equals("EC")) {

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ private PrivateKey loadPkey(Session session, long oHandle)
13231323
RSAKeyFactory.checkKeyLengths(keyLength, null,
13241324
-1, Integer.MAX_VALUE);
13251325
} catch (InvalidKeyException e) {
1326-
throw new KeyStoreException(e.getMessage());
1326+
throw new KeyStoreException(e.getMessage(), e);
13271327
}
13281328

13291329
return P11Key.privateKey(session,

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -569,10 +569,10 @@ protected void engineUpdate(byte[] b, int ofs, int len)
569569
case T_UPDATE:
570570
try {
571571
if (mode == M_SIGN) {
572-
System.out.println(this + ": Calling C_SignUpdate");
572+
if (DEBUG) System.out.println(this + ": Calling C_SignUpdate");
573573
token.p11.C_SignUpdate(session.id(), 0, b, ofs, len);
574574
} else {
575-
System.out.println(this + ": Calling C_VerfifyUpdate");
575+
if (DEBUG) System.out.println(this + ": Calling C_VerfifyUpdate");
576576
token.p11.C_VerifyUpdate(session.id(), 0, b, ofs, len);
577577
}
578578
bytesProcessed += len;
@@ -618,11 +618,11 @@ protected void engineUpdate(ByteBuffer byteBuffer) {
618618
int ofs = byteBuffer.position();
619619
try {
620620
if (mode == M_SIGN) {
621-
System.out.println(this + ": Calling C_SignUpdate");
621+
if (DEBUG) System.out.println(this + ": Calling C_SignUpdate");
622622
token.p11.C_SignUpdate
623623
(session.id(), addr + ofs, null, 0, len);
624624
} else {
625-
System.out.println(this + ": Calling C_VerifyUpdate");
625+
if (DEBUG) System.out.println(this + ": Calling C_VerifyUpdate");
626626
token.p11.C_VerifyUpdate
627627
(session.id(), addr + ofs, null, 0, len);
628628
}

0 commit comments

Comments
 (0)