Bug 1662196

Summary: keytool: Spurious KeyStoreException in using external JCE provider
Product: [Fedora] Fedora Reporter: space88man <shihping.chan>
Component: java-11-openjdkAssignee: jiri vanek <jvanek>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 29CC: jerboaa, jvanek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-11-27 20:33:12 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description space88man 2018-12-27 01:21:00 UTC
Description of problem:
When using keytool with bouncycastle-1.60-1.fc29.noarch and using a non-standard keystore type (i.e., not JKS, not PKCS12), keytool will leak KeyStoreException to the console


Version-Release number of selected component (if applicable):
java-11-openjdk-headless-11.0.1.13-4.fc29.x86_64
bouncycastle-1.60-1.fc29.noarch

How reproducible:
Always

Steps to Reproduce:
1. Create a keystore of type BCKFS
2. List a keystore of type BCFKS
3.

Actual results:
1. Creation: keystore is created with KeyStoreException shown on console (keystore seems to have been created correctly)

keytool -providerpath /usr/share/java/bcprov.jar -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider -keystore testing.fips -storepass changeit -storetype BCFKS -genkeypair -keyalg RSA -keysize 2048 -alias testing -dname CN=testing
Enter key password for <testing>
	(RETURN if same as keystore password):  
keytool error: java.security.KeyStoreException: Unrecognized keystore format: null

# despite the error message, the keystore is created!


2. Listing: keystore is listed correctly with KeyStoreException shown on console

$ keytool -providerpath /usr/share/java/bcprov.jar -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider -keystore testing.fips -storepass changeit -storetype BCFKS -list
Keystore type: BCFKS
Keystore provider: BC

Your keystore contains 1 entry

testing, Dec 27, 2018, PrivateKeyEntry, 
Certificate fingerprint (SHA-256): EA:73:0A:6A:D4:6A:0B:16:48:1A:81:D6:D0:93:63:15:57:66:35:CD:2C:B4:5C:5A:C7:3A:51:BB:C3:D7:D8:7C
keytool error: java.security.KeyStoreException: Unrecognized keystore format: null


Expected results:
With java-1.8.0-openjdk-1.8.0.191.b12-11.fc29.x86_64 we get "clean" results; i.e., same behaviour but no Exceptions printed

# 

Additional info:

Repeat with Java 8 java-1.8.0-openjdk-1.8.0.191.b12-11.fc29.x86_64

$ keytool -providerpath /usr/share/java/bcprov.jar -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider -keystore testing.fips -storepass changeit -storetype BCFKS -genkeypair -keyalg RSA -keysize 2048 -alias testing -dname CN=testing
Enter key password for <testing>
	(RETURN if same as keystore password):  

# no "noise" about KeyStoreException

$ keytool -providerpath /usr/share/java/bcprov.jar -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider -keystore testing.fips -storepass changeit -storetype BCFKS -list
Keystore type: BCFKS
Keystore provider: BC

Your keystore contains 1 entry

testing, Dec 27, 2018, PrivateKeyEntry, 
Certificate fingerprint (SHA1): E5:53:A5:42:76:67:FA:9A:21:D9:03:30:FB:2A:CC:12:0F:FF:02:B3

Tried with another JCE provider Amazon CloudHSM's JCE (LunaProvider) and got the same results

Comment 1 space88man 2018-12-27 01:29:42 UTC
This also happens with JDK distributed by AdoptOpenJDK

Comment 2 space88man 2018-12-27 01:32:36 UTC
This also happens with Azul's zulu11.2.3-jdk11.0.1-linux_x64.tar.gz

Comment 3 space88man 2019-01-02 23:38:03 UTC
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/sun/security/tools/keytool/Main.java:1326

The error is due to a keytool check for JKS in which it is trying to provide
a JKS warning; this happens at the end of the command so the actual operation is successful.


    keyStore = KeyStore.getInstance(f, pass);

The code does not catch a KeyStore exception if File f is pointing to a non-standard KeyStore like
BKS, BCFKS, SafeNet Luna, etc.

The code should probably be in a try-catch block.

Keystore type: LUNA
Keystore provider: LunaProvider

Your keystore contains 0 entries

keytool error: java.security.KeyStoreException: Unrecognized keystore format: null
java.security.KeyStoreException: Unrecognized keystore format: null
        at java.base/java.security.KeyStore.getInstance(KeyStore.java:1816)
        at java.base/java.security.KeyStore.getInstance(KeyStore.java:1687)
        at java.base/sun.security.tools.keytool.Main.doCommands(Main.java:1326)
        at java.base/sun.security.tools.keytool.Main.run(Main.java:397)
        at java.base/sun.security.tools.keytool.Main.main(Main.java:390)

Comment 4 Ben Cotton 2019-10-31 20:14:06 UTC
This message is a reminder that Fedora 29 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 29 on 2019-11-26.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '29'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 29 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 5 Ben Cotton 2019-11-27 20:33:12 UTC
Fedora 29 changed to end-of-life (EOL) status on 2019-11-26. Fedora 29 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.