Skip to content

Commit 8674e7c

Browse files
committed
8295405: Add cause in a couple of IllegalArgumentException and InvalidParameterException shown by sun/security/pkcs11 tests
Backport-of: d5d34241e21305379f1858556f225e7645cd294e
1 parent a3bc924 commit 8674e7c

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

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/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: 1 addition & 1 deletion
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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ private void checkRSAKeyLength(int len) throws InvalidKeyException {
433433
padding = RSAPadding.getInstance
434434
(RSAPadding.PAD_BLOCKTYPE_1, (len + 7) >> 3);
435435
} catch (InvalidAlgorithmParameterException iape) {
436-
throw new InvalidKeyException(iape.getMessage());
436+
throw new InvalidKeyException(iape.getMessage(), iape);
437437
}
438438
int maxDataSize = padding.getMaxDataSize();
439439
int encodedLength = switch (algorithm) {
@@ -804,7 +804,7 @@ private static byte[] dsaToASN1(byte[] signature) {
804804
DerValue result = new DerValue(DerValue.tag_Sequence,
805805
outseq.toByteArray());
806806
return result.toByteArray();
807-
} catch (java.io.IOException e) {
807+
} catch (IOException e) {
808808
throw new RuntimeException("Internal error", e);
809809
}
810810
}

0 commit comments

Comments
 (0)