Unencrypted private keys in JKS files cannot be decrypted with the JKS passphrase
See original GitHub issueOur application creates JKS files using PyJKS version 17.1.0 using the following method:
def jks_key(alias: str, chain: list, key_der: bytes, passphrase: str) -> bytes:
""" generate a java keystore with an alias for the given key """
pke = jks.PrivateKeyEntry.new(alias, chain, key_der, 'rsa_raw')
keystore = jks.KeyStore.new('jks', [pke])
return keystore.saves(passphrase)
Up until recently the JKS files have worked well, and our Java application could read and decrypt the private key using the provided passphrase.
Since the pyasn1
module was updated to version 0.3.2 and pyasn1-modules
to version 0.0.11, the JKS files created by the application no longer work. The passphrase can decrypt the JKS itself, but cannot decrypt the private key within it anymore.
http://pyjks.readthedocs.io/en/latest/jks.html#jks.jks.KeyStore.saves states: “If any of the private keys are unencrypted, they will be encrypted with the same password as the keystore.” This statement does not seem to hold true anymore.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Decryption using private key from jks file - CodeRanch
I am trying to decrypt a key using the private key in my keystore jks file. Everything is working correctly except for the...
Read more >What causes keytool error "Failed to decrypt safe contents ...
Sometimes this error is symptomatic of using an incorrect password for the p12 key.
Read more >Import an encrypted private key into a Java Key Store
Import an encrypted private key into a Java KeyStore ... OpenSSL prompts me for a passphrase that I must provide in order to...
Read more >Keystore error with mismatching key and ... - Salesforce Help
Keystore error with mismatching key and keystore passwords for certificates. ... if the Private Key and the Keystore are encrypted using different password:...
Read more >PyJKS Documentation - Read the Docs
if the key could not be decrypted using the store password,. # decrypt with ... creating a jks keystore with the private key,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This broke by: https://github.com/etingof/pyasn1/commit/6fa0e312ea80713983b1a3c1e4529e7452b0e0fe
The problem is that the optional attributes field in the PrivateKeyInfo is now being included without anything in it. Before:
After:
We can fix this in our code, but it seems strange to me that we have to. I will create a bug in pyasn1 and ask if this is how it’s supposed to be. If it is, then I will create a fix.
Yes, this should be fixed soon @jcdevil. Sorry that it has taken forever!