Skip to content

Commit 727ae39

Browse files
committed
8295405: Add cause in a couple of IllegalArgumentException and InvalidParameterException shown by sun/security/pkcs11 tests
Reviewed-by: phh Backport-of: d5d34241e21305379f1858556f225e7645cd294e
1 parent 64d7622 commit 727ae39

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, 2019, 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
@@ -144,7 +144,7 @@ public void generate(String name) {
144144
}
145145

146146
} catch (Exception e) {
147-
throw new IllegalArgumentException(e.getMessage());
147+
throw new IllegalArgumentException(e.getMessage(), e);
148148
}
149149
generateInternal();
150150
}
@@ -160,7 +160,7 @@ public void generate(int keyBits) {
160160
keyGen.initialize(keyBits, prng);
161161

162162
} catch (Exception e) {
163-
throw new IllegalArgumentException(e.getMessage());
163+
throw new IllegalArgumentException(e.getMessage(), e);
164164
}
165165
}
166166
generateInternal();
@@ -317,7 +317,7 @@ public X509Certificate getSelfCertificate (X500Name myname, Date firstDate,
317317

318318
} catch (IOException e) {
319319
throw new CertificateEncodingException("getSelfCert: " +
320-
e.getMessage());
320+
e.getMessage(), e);
321321
} catch (InvalidAlgorithmParameterException e2) {
322322
throw new SignatureException(
323323
"Unsupported PSSParameterSpec: " + e2.getMessage());

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
@@ -357,7 +357,7 @@ private static String expand(final String s) throws IOException {
357357
try {
358358
return PropertyExpander.expand(s);
359359
} catch (Exception e) {
360-
throw new RuntimeException(e.getMessage());
360+
throw new RuntimeException(e.getMessage(), e);
361361
}
362362
}
363363

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

398+
private ConfigurationException excLine(String msg, Throwable e) {
399+
return new ConfigurationException(msg + ", line " + st.lineno(), e);
400+
}
401+
398402
private void parse() throws IOException {
399403
while (true) {
400404
int token = nextToken();
@@ -799,7 +803,7 @@ private long parseMechanism(String mech) throws IOException {
799803
try {
800804
return Functions.getMechanismId(mech);
801805
} catch (IllegalArgumentException e) {
802-
throw excLine("Unknown mechanism: " + mech);
806+
throw excLine("Unknown mechanism: " + mech, e);
803807
}
804808
}
805809
}
@@ -959,7 +963,7 @@ private long parseObjectClass() throws IOException {
959963
try {
960964
return Functions.getObjectClassId(name);
961965
} catch (IllegalArgumentException e) {
962-
throw excLine("Unknown object class " + name);
966+
throw excLine("Unknown object class " + name, e);
963967
}
964968
}
965969

@@ -971,7 +975,7 @@ private long parseKeyAlgorithm() throws IOException {
971975
try {
972976
return Functions.getKeyId(name);
973977
} catch (IllegalArgumentException e) {
974-
throw excLine("Unknown key algorithm " + name);
978+
throw excLine("Unknown key algorithm " + name, e);
975979
}
976980
}
977981
}
@@ -983,7 +987,7 @@ private long decodeAttributeName(String name) throws IOException {
983987
try {
984988
return Functions.getAttributeId(name);
985989
} catch (IllegalArgumentException e) {
986-
throw excLine("Unknown attribute name " + name);
990+
throw excLine("Unknown attribute name " + name, e);
987991
}
988992
}
989993
}
@@ -1039,4 +1043,8 @@ class ConfigurationException extends IOException {
10391043
ConfigurationException(String msg) {
10401044
super(msg);
10411045
}
1046+
1047+
ConfigurationException(String msg, Throwable e) {
1048+
super(msg, e);
1049+
}
10421050
}

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
@@ -139,7 +139,7 @@ private enum Transformation {
139139
try {
140140
engineSetPadding(algoParts[2]);
141141
} catch (NoSuchPaddingException e) {
142-
throw new NoSuchAlgorithmException();
142+
throw new NoSuchAlgorithmException(e);
143143
}
144144
} else if (algoParts[0].equals("ChaCha20-Poly1305")) {
145145
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
@@ -1321,7 +1321,7 @@ private PrivateKey loadPkey(Session session, long oHandle)
13211321
RSAKeyFactory.checkKeyLengths(keyLength, null,
13221322
-1, Integer.MAX_VALUE);
13231323
} catch (InvalidKeyException e) {
1324-
throw new KeyStoreException(e.getMessage());
1324+
throw new KeyStoreException(e.getMessage(), e);
13251325
}
13261326

13271327
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
@@ -440,7 +440,7 @@ private void checkRSAKeyLength(int len) throws InvalidKeyException {
440440
padding = RSAPadding.getInstance
441441
(RSAPadding.PAD_BLOCKTYPE_1, (len + 7) >> 3);
442442
} catch (InvalidAlgorithmParameterException iape) {
443-
throw new InvalidKeyException(iape.getMessage());
443+
throw new InvalidKeyException(iape.getMessage(), iape);
444444
}
445445
int maxDataSize = padding.getMaxDataSize();
446446
int encodedLength;
@@ -801,7 +801,7 @@ private static byte[] dsaToASN1(byte[] signature) {
801801
DerValue result = new DerValue(DerValue.tag_Sequence,
802802
outseq.toByteArray());
803803
return result.toByteArray();
804-
} catch (java.io.IOException e) {
804+
} catch (IOException e) {
805805
throw new RuntimeException("Internal error", e);
806806
}
807807
}

0 commit comments

Comments
 (0)