Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encrypted RSA key in OpenSSHKey format results- error in libcrypto #705

Closed
arpoch opened this issue Jul 24, 2021 · 7 comments
Closed

Encrypted RSA key in OpenSSHKey format results- error in libcrypto #705

arpoch opened this issue Jul 24, 2021 · 7 comments

Comments

@arpoch
Copy link

arpoch commented Jul 24, 2021

I am using sshj library to decrypt an encrypted RSA private key using the code below

        OpenSSHKeyV1KeyFile o = new OpenSSHKeyV1KeyFile();
        o.init(ENCRYPTED_RSA, "", new Pass(arr));
        PrivateKey p = o.getPrivate();
        byte[] c = p.getEncoded();

The above code works great and results in a decrypted private but to use it for git SSH authentication purpose through command line using GIT_SSH_COMMAND environment variable, I am converting the generated PKCS8(from getformat) byte encoded key to PEM and writing it in a temp file using the code below

      PemObject po = new PemObject("PRIVATE KEY", c);
      PemWriter pw = new PemWriter(new OutputStreamWriter(new FileOutputStream(tempFile)));
      pw.writeObject(po);
      pw.flush();
      pw.close();

But I am getting this error message every time I try to perform any git operation which requires authentication sign_and_send_pubkey: signing failed: error in libcrypto only for Encrypted RSA OpenSSH formatted key, I have test over ecdas19 and it works fine.

As I am currently working with
OS- Windows 10
OpenSSH- OpenSSH_for_Windows_8.1p1

@hierynomus
Copy link
Owner

@arpoch How is this an SSHJ issue?

@arpoch
Copy link
Author

arpoch commented Sep 24, 2021

The fingerprint generated for the decrypted private key(SSHJ library to decrypt the key) doesn't match with the actual private key(encrypted) fingerprint. So I believe there is an issue while decrypting an encrypted private key in OpenSSH format using SSHJ.

@arpoch
Copy link
Author

arpoch commented Sep 24, 2021

Forgot to add that the issue is encountered for RSA encrypted openssh formated keys, I have tested with ECDSA and it's working as expected.

@hierynomus
Copy link
Owner

Can you add a test case in a PR? Then we can have a look.

@arpoch
Copy link
Author

arpoch commented Sep 24, 2021

Sure, will try my best.

@exceptionfactory
Copy link
Contributor

@arpoch and @hierynomus I traced the issue down to RSA Private Key parsing in OpenSSHKeyV1KeyFile and submitted PR #726.

@hierynomus
Copy link
Owner

The mentioned PR #726 has been merged. I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants