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

Add support for authentication with DSA & RSA user certificates (#153) #319

Merged
merged 3 commits into from
Apr 14, 2017
Merged

Conversation

chqr
Copy link
Contributor

@chqr chqr commented Apr 12, 2017

First pass at support for RSA & DSA certificate authentication. Thanks for maintaining this awesome library!

Updates:

  • KeyType.java - add support for two certificate key types
    ssh-rsa-cert-v01@openssh.com
    ssh-dsa-cert-v01@openssh.com

  • Buffer.java - allow uint64s that overflow Long.MAX_VALUE, otherwise
    we break on certificates with serial numbers greater Long.MAX_VALUE

  • OpenSSHKeyFile, KeyProviderUtil - prefer public key files that end
    "-cert.pub" if they exist

Added new class Certificate, which represents certificate key

Reference:

https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD

Updates:

- KeyType.java - add support for two certificate key types
    ssh-rsa-cert-v01@openssh.com
    ssh-dsa-cert-v01@openssh.com

- Buffer.java - allow uint64s that overflow Long.MAX_VALUE, otherwise
  we break on certificates with serial numbers greater Long.MAX_VALUE

- OpenSSHKeyFile, KeyProviderUtil - prefer public key files that end
  "-cert.pub" if they exist

Added new class Certificate, which represents certificate key

Reference:

https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
@hierynomus
Copy link
Owner

Hi @chqr,

Thanks for the PR. Looks pretty good already.
One of my main concerns is the change in Buffer currently. I think rather than doing that, we should be using readMPInt here, which allows 'arbitrary big values', and thus doesn't suffer from the overflow that UInt64 is prone to. Judging from the code that wouldn't be causing any problems at first sight. Do you agree?

@chqr
Copy link
Contributor Author

chqr commented Apr 12, 2017

Hi @hierynomus,

Thanks for the fast response! Looks like MPInts are encoded differently on the wire from UInt64s, so they can't be used interchangeably. But I could add new methods readUInt64AsBigInteger() and putUInt64(BigInteger uint64), and revert the changes to the existing put/readUInt64 methods.

Will look at the Codacy issues.

byte[] signature;

try {
nonce = buf.readStringAsBytes();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we immediately build the builder instead of first defining all the fields, then assigning them, and then passing them all into the builder?

critOptions = unpackMap(buf.readStringAsBytes());
extensions = unpackMap(buf.readStringAsBytes());
buf.readString(); // reserved
signatureKey = buf.readStringAsBytes();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not readBytes()?

extensions = unpackMap(buf.readStringAsBytes());
buf.readString(); // reserved
signatureKey = buf.readStringAsBytes();
signature = buf.readStringAsBytes();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not readBytes()

if (f.exists())
// try cert key location first
File pubKey = new File(location + "-cert.pub");
if (! pubKey.exists()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting, there should be no space between ! and statement.

.putString(packMap(certificate.getCritOptions()))
.putString(packMap(certificate.getExtensions()))
.putString("") // reserved
.putString(certificate.getSignatureKey())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putBytes (also for other places). Esp. signatures and keys are not strings but rather byte[].
Though the implementation in the buffer doesn't differ, the semantics are different.

@hierynomus
Copy link
Owner

Had a bit more in-depth look this morning, few questions/issues left.

@hierynomus
Copy link
Owner

Thanks for the great contribution!

@hierynomus hierynomus merged commit e36fd0f into hierynomus:master Apr 14, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants