From fe90b976e9d10ab85a89da6c8cefbc82e6f835f9 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Mon, 30 Jan 2023 15:31:15 +0100 Subject: [PATCH] Backport d5d34241e21305379f1858556f225e7645cd294e --- .../security/tools/keytool/CertAndKeyGen.java | 8 ++++---- .../classes/sun/security/pkcs11/Config.java | 18 +++++++++++++----- .../sun/security/pkcs11/P11AEADCipher.java | 4 ++-- .../security/pkcs11/P11KeyPairGenerator.java | 2 +- .../sun/security/pkcs11/P11KeyStore.java | 2 +- .../sun/security/pkcs11/P11PSSSignature.java | 2 +- .../sun/security/pkcs11/P11Signature.java | 4 ++-- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/java.base/share/classes/sun/security/tools/keytool/CertAndKeyGen.java b/src/java.base/share/classes/sun/security/tools/keytool/CertAndKeyGen.java index 8ceab17e8e3..30647a0e1b1 100644 --- a/src/java.base/share/classes/sun/security/tools/keytool/CertAndKeyGen.java +++ b/src/java.base/share/classes/sun/security/tools/keytool/CertAndKeyGen.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2019, 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 @@ -144,7 +144,7 @@ public void generate(String name) { } } catch (Exception e) { - throw new IllegalArgumentException(e.getMessage()); + throw new IllegalArgumentException(e.getMessage(), e); } generateInternal(); } @@ -160,7 +160,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(); @@ -317,7 +317,7 @@ public X509Certificate getSelfCertificate (X500Name myname, Date firstDate, } catch (IOException e) { throw new CertificateEncodingException("getSelfCert: " + - e.getMessage()); + e.getMessage(), e); } catch (InvalidAlgorithmParameterException e2) { throw new SignatureException( "Unsupported PSSParameterSpec: " + e2.getMessage()); diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java index 3bcef1fac3e..83b633358ac 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java @@ -357,7 +357,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); } } @@ -395,6 +395,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(); @@ -799,7 +803,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); } } } @@ -959,7 +963,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); } } @@ -971,7 +975,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); } } } @@ -983,7 +987,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); } } } @@ -1039,4 +1043,8 @@ class ConfigurationException extends IOException { ConfigurationException(String msg) { super(msg); } + + ConfigurationException(String msg, Throwable e) { + super(msg, e); + } } diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java index bae116e2bdf..7f8d4a3a390 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java @@ -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 @@ -139,7 +139,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; diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyPairGenerator.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyPairGenerator.java index f13ae3cd67d..1301f8f2bcb 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyPairGenerator.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyPairGenerator.java @@ -145,7 +145,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")) { diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java index c9c2362bcc1..0ab49c46c27 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java @@ -1321,7 +1321,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, diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java index a1542f56ad6..26eaa4735f1 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java @@ -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 diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java index 94d38ffcd6f..e3af106d05a 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java @@ -440,7 +440,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; @@ -801,7 +801,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); } }