Skip to content

Conversation

Tejaswikandula
Copy link
Contributor

@Tejaswikandula Tejaswikandula commented Jan 24, 2024

Replicating OpenSSH's behavior to handle RSA certificate authentication differently based on the remote server version.

  1. For OpenSSH versions >= 7.8, ascertain server's support for RSA Cert types by checking if the certificate's signature type is present in the 'server-sig-algs'.
  2. For OpenSSH versions < 7.8, Set the "SSH_BUG_SIGTYPE" flag when the RSA key in question is a certificate to ignore "server-sig-algs" and only offer ssh-rsa signature algorithm for RSA certs.
    This arises from the fact that OpenSSH versions up to 7.7 accept RSA-SHA2 keys but not RSA-SHA2 certificate types. Although OpenSSH <=7.7 includes RSA-SHA2 keys in the server-sig-algs, versions <=7.7 do not actually support RSA certs. Therefore, server sending RSA-SHA2 keys in server-sig-algs should not be interpreted as indicating support for RSA-SHA2 certs. So, server-sig-algs are ignored when the RSA key in question is a cert, and the remote server version is 7.7 or below.

Relevant sections of the OpenSSH source code:

https://github.com/openssh/openssh-portable/blob/V_8_9_P1/sshconnect2.c#L1191-L1197
https://github.com/openssh/openssh-portable/blob/master/compat.c#L43

sshconnect2.c
compat.c

…he supported RSA cert based algs in server-sig-algs extension, fallback to default othwerwise
@Tejaswikandula
Copy link
Contributor Author

@willco007 Did changes to allow algo upgrades for SSH RSA certs if the server also enumerates the supported RSA cert based algs in server-sig-algs extension, fallback to default otherwise. Thoughts/Suggestions?

@willco007
Copy link
Member

@Tejaswikandula No, the only types it supports are rsa-sha2-256 and rsa-sha2-512. At the time, these were the only upgrades OpenSSH supported, I'm not sure if OpenSSH now supports cert upgrades as well.

@Tejaswikandula
Copy link
Contributor Author

@Tejaswikandula No, the only types it supports are rsa-sha2-256 and rsa-sha2-512. At the time, these were the only upgrades OpenSSH supported, I'm not sure if OpenSSH now supports cert upgrades as well.

RFC 8332 mentions allowing for interoperable use of existing and new RSA keys with SHA-256 and SHA-512. Is this what you are referring to when you say "these were the only upgrades OpenSSH supported"?

While RFC 8332 doesn't explicitly discuss RSA certificates, RSA certs align with the hashing types used in RSA keys right? So, in case of certs, even though OpenSSH doesn't explicitly announce RSA certs in the server-sig-algs extension for flexible negotiation during key exchange process, can we infer that the support for RSA SHA-2 certificate-based authentications in newer OpenSSH versions indicates the potential for certificate upgrades?

@willco007
Copy link
Member

RFC 8332 mentions allowing for interoperable use of existing and new RSA keys with SHA-256 and SHA-512. Is this what > you are referring to when you say "these were the only upgrades OpenSSH supported"?

Correct.

...can we infer that the support for RSA SHA-2 certificate-based authentications in newer OpenSSH versions indicates the potential for certificate upgrades?

No, we can't infer this. When reviewing the OpenSSH server code while implementing this, it did not have RSA cert support. New versions may have support, but that would need to be confirmed.

@willco007
Copy link
Member

willco007 commented Feb 5, 2024

This is what comes back from 9.4:

Key Ex: Server to Client extension server-sig-algs: ssh-ed25519,sk-ssh-ed25519@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com,ssh-dss,ssh-rsa,rsa-sha2-256,rsa-sha2-512.
I see no mention of cert support.

@Tejaswikandula
Copy link
Contributor Author

RFC 8332 mentions allowing for interoperable use of existing and new RSA keys with SHA-256 and SHA-512. Is this what > you are referring to when you say "these were the only upgrades OpenSSH supported"?

Correct.

...can we infer that the support for RSA SHA-2 certificate-based authentications in newer OpenSSH versions indicates the potential for certificate upgrades?

No, we can't infer this. When reviewing the OpenSSH server code while implementing this, it did not have RSA cert support. New versions may have support, but that would need to be confirmed.

OpenSSH do support RSA certs from a long time and newer versions do also support RSA SHA2 certs. OpenSSH deprecated support for SHA1 certs along with the keys. Please refer to this PR - https://github.com/openssh/openssh-portable/commit/2344750250247111a6c3c6a4fe84ed583a61cc11. I'm able to successfully test using certs against different OpenSSH versions

@Tejaswikandula
Copy link
Contributor Author

This is what comes back from 9.4:

Key Ex: Server to Client extension server-sig-algs: ssh-ed25519,sk-ssh-ed25519@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com,ssh-dss,ssh-rsa,rsa-sha2-256,rsa-sha2-512. I see no mention of cert support.

That's true. Though OpenSSH supports cert based authentication, it's not listing the same in server-sig-algs

@willco007
Copy link
Member

Yes, that is true, but I believe you're conflating server-sig-algs list and normal key auth. The server-sig-algs list is used to upgrade insecure keys while certs are used for normal key auth which is what you have implemented in this MR.

@Tejaswikandula
Copy link
Contributor Author

@vszakats Requesting review again on this one. Also, the build is failing with docker error unrelated to my changes (probably flaky), can you help with restarting the build?

Tejaswikandula and others added 3 commits March 7, 2024 16:15
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
@Tejaswikandula
Copy link
Contributor Author

Tejaswikandula commented Mar 8, 2024

Thanks @Tejaswikandula, LGTM!

@vszakats Thanks for the review. Need your help with restarting the build again, thanks!!

@vszakats vszakats changed the title Support RSA SHA2 cert based authentication (rsa-sha2-512_cert and rsa-sha2-256_cert) Support RSA SHA2 cert-based authentication (rsa-sha2-512_cert & rsa-sha2-256_cert) Apr 3, 2024
@vszakats vszakats changed the title Support RSA SHA2 cert-based authentication (rsa-sha2-512_cert & rsa-sha2-256_cert) Support RSA SHA2 cert-based authentication (rsa-sha2-512_cert and rsa-sha2-256_cert) Apr 3, 2024
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 3, 2024
@vszakats
Copy link
Member

vszakats commented Apr 3, 2024

@vszakats vszakats merged commit 3a6ab70 into libssh2:master Apr 3, 2024
@vszakats
Copy link
Member

vszakats commented Apr 3, 2024

Thank you @Tejaswikandula for this, also for your patience. To @willco007 for all the help.
Merged now!

agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
…-sha2-256_cert) (libssh2#1314)

Replicating OpenSSH's behavior to handle RSA certificate authentication
differently based on the remote server version.

1. For OpenSSH versions >= 7.8, ascertain server's support for RSA Cert
   types by checking if the certificate's signature type is present in
   the `server-sig-algs`.

2. For OpenSSH versions < 7.8, Set the "SSH_BUG_SIGTYPE" flag when the
   RSA key in question is a certificate to ignore `server-sig-algs` and
   only offer ssh-rsa signature algorithm for RSA certs.

This arises from the fact that OpenSSH versions up to 7.7 accept
RSA-SHA2 keys but not RSA-SHA2 certificate types. Although OpenSSH <=7.7
includes RSA-SHA2 keys in the `server-sig-algs`, versions <=7.7 do not
actually support RSA certs. Therefore, server sending RSA-SHA2 keys in
`server-sig-algs` should not be interpreted as indicating support for
RSA-SHA2 certs. So, `server-sig-algs` are ignored when the RSA key in
question is a cert, and the remote server version is 7.7 or below.

Relevant sections of the OpenSSH source code:
                                                                                          
<https://github.com/openssh/openssh-portable/blob/V_8_9_P1/sshconnect2.c#L1191-L1197>     
<https://github.com/openssh/openssh-portable/blob/master/compat.c#L43>                    
                                                                                          
Assisted-by: Will Cosgrove                                                                
Reviewed-by: Viktor Szakats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants