One of the tasks of the Java application that I create is to connect to a remote SFTP server. For this, I have the certificate of the remote machine and the local identifier ( id_rsaand id_rsa.pubin the folder .ssh). This works fine.
I would like to put the certificate and identity in a password protected java keystore for simplification and more secure configuration. This works for me for a certificate, but I'm having problems storing SSH authentication in a JKS or PKCS12 key store (any of them will work).
To isolate the problem, I tried the following steps:
I use ssh-keygen -b 2048to create two identification files id_rsa_demoand id_rsa_demo.pubin a local directory. As far as I understand, these are private and public identifier keys, so I'm trying to combine them into a file identity.p12:
openssl pkcs12 -export \
-inkey "id_rsa_demo" \
-in "id_rsa_demo.pub" \
-out "identity.p12" \
-password "pass:topsecret" \
-name "demoalias"
This gives me an error unable to load certificates. I searched around and it seems that openssl is expecting a certificate with a full chain for the parameter -in. Since my generated identifier does not have this, I tried a parameter -nocerts, for example:
openssl pkcs12 -export \
-inkey "id_rsa_demo" \
-in "id_rsa_demo.pub" \
-out "identity.p12" \
-password "pass:topsecret" \
-name "demoalias" \
-nocerts
I get no errors, but the option is -nocertsas promised and does not add my public key to the pkcs12 file:
openssl pkcs12 -info -in identity.p12
Enter Import Password:
MAC Iteration 2048
MAC verified OK
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048
Bag Attributes
friendlyName: demoalias
Key Attributes: <No Attributes>
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIAOXpzckBb28CAggA
MBQGCCqGSIb3DQMHBAjPq9ibr445xQSCBMi5IlOk5F28kQPB5D97afiUb5d3It46
...
ejwYfHTj6bm+dEOUk68zNrWwKqwuJx5AZv3U8sm1cicVmh9W0HpL5tSmMMpDS1ey
Uos=
-----END ENCRYPTED PRIVATE KEY-----
Is there a way to store the SSH identifier in a PKCS12 or JKS key store?
source
share