Skip to content

Commit

Permalink
8295405: Add cause in a couple of IllegalArgumentException and Invali…
Browse files Browse the repository at this point in the history
…dParameterException shown by sun/security/pkcs11 tests

Reviewed-by: mdoerr, mullan
  • Loading branch information
MBaesken committed Oct 28, 2022
1 parent fd668dc commit d5d3424
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -160,7 +160,7 @@ public void generate(String name) {
}

} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
throw new IllegalArgumentException(e.getMessage(), e);
}
generateInternal();
}
Expand All @@ -176,7 +176,7 @@ public void generate(int keyBits) {
keyGen.initialize(keyBits, prng);

} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
throw new IllegalArgumentException(e.getMessage(), e);
}
}
generateInternal();
Expand Down Expand Up @@ -349,7 +349,7 @@ public X509Certificate getSelfCertificate (X500Name myname, Date firstDate,

} catch (IOException e) {
throw new CertificateEncodingException("getSelfCert: " +
e.getMessage());
e.getMessage(), e);
}
}

Expand Down
Expand Up @@ -358,7 +358,7 @@ private static String expand(final String s) throws IOException {
try {
return PropertyExpander.expand(s);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}

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

private ConfigurationException excLine(String msg, Throwable e) {
return new ConfigurationException(msg + ", line " + st.lineno(), e);
}

private void parse() throws IOException {
while (true) {
int token = nextToken();
Expand Down Expand Up @@ -817,7 +821,7 @@ private long parseMechanism(String mech) throws IOException {
try {
return Functions.getMechanismId(mech);
} catch (IllegalArgumentException e) {
throw excLine("Unknown mechanism: " + mech);
throw excLine("Unknown mechanism: " + mech, e);
}
}
}
Expand Down Expand Up @@ -977,7 +981,7 @@ private long parseObjectClass() throws IOException {
try {
return Functions.getObjectClassId(name);
} catch (IllegalArgumentException e) {
throw excLine("Unknown object class " + name);
throw excLine("Unknown object class " + name, e);
}
}

Expand All @@ -989,7 +993,7 @@ private long parseKeyAlgorithm() throws IOException {
try {
return Functions.getKeyId(name);
} catch (IllegalArgumentException e) {
throw excLine("Unknown key algorithm " + name);
throw excLine("Unknown key algorithm " + name, e);
}
}
}
Expand All @@ -1001,7 +1005,7 @@ private long decodeAttributeName(String name) throws IOException {
try {
return Functions.getAttributeId(name);
} catch (IllegalArgumentException e) {
throw excLine("Unknown attribute name " + name);
throw excLine("Unknown attribute name " + name, e);
}
}
}
Expand Down Expand Up @@ -1061,4 +1065,8 @@ class ConfigurationException extends IOException {
ConfigurationException(String msg) {
super(msg);
}

ConfigurationException(String msg, Throwable e) {
super(msg, e);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -140,7 +140,7 @@ private enum Transformation {
try {
engineSetPadding(algoParts[2]);
} catch (NoSuchPaddingException e) {
throw new NoSuchAlgorithmException();
throw new NoSuchAlgorithmException(e);
}
} else if (algoParts[0].equals("ChaCha20-Poly1305")) {
fixedKeySize = 32;
Expand Down
Expand Up @@ -151,7 +151,7 @@ public void initialize(int keySize, SecureRandom random) {
try {
checkKeySize(keySize, null);
} catch (InvalidAlgorithmParameterException e) {
throw new InvalidParameterException(e.getMessage());
throw (InvalidParameterException) new InvalidParameterException(e.getMessage()).initCause(e);
}
this.params = null;
if (algorithm.equals("EC")) {
Expand Down
Expand Up @@ -1332,7 +1332,7 @@ private PrivateKey loadPkey(Session session, long oHandle)
RSAKeyFactory.checkKeyLengths(keyLength, null,
-1, Integer.MAX_VALUE);
} catch (InvalidKeyException e) {
throw new KeyStoreException(e.getMessage());
throw new KeyStoreException(e.getMessage(), e);
}

return P11Key.privateKey(session,
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down
Expand Up @@ -445,7 +445,7 @@ private void checkRSAKeyLength(int len) throws InvalidKeyException {
padding = RSAPadding.getInstance
(RSAPadding.PAD_BLOCKTYPE_1, (len + 7) >> 3);
} catch (InvalidAlgorithmParameterException iape) {
throw new InvalidKeyException(iape.getMessage());
throw new InvalidKeyException(iape.getMessage(), iape);
}
int maxDataSize = padding.getMaxDataSize();
int encodedLength = switch (algorithm) {
Expand Down Expand Up @@ -809,7 +809,7 @@ private static byte[] dsaToASN1(byte[] signature) {
DerValue result = new DerValue(DerValue.tag_Sequence,
outseq.toByteArray());
return result.toByteArray();
} catch (java.io.IOException e) {
} catch (IOException e) {
throw new RuntimeException("Internal error", e);
}
}
Expand Down

5 comments on commit d5d3424

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d5d3424 Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch MBaesken-backport-d5d34241 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d5d34241 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 28 Oct 2022 and was reviewed by Martin Doerr and Sean Mullan.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-d5d34241:MBaesken-backport-d5d34241
$ git checkout MBaesken-backport-d5d34241
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-d5d34241

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d5d3424 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken Could not automatically backport d5d34241 to openjdk/jdk11u-dev due to conflicts in the following files:

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

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b MBaesken-backport-d5d34241

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk d5d34241e21305379f1858556f225e7645cd294e

# Backport the commit
$ git cherry-pick --no-commit d5d34241e21305379f1858556f225e7645cd294e
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport d5d34241e21305379f1858556f225e7645cd294e'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport d5d34241e21305379f1858556f225e7645cd294e.

Please sign in to comment.