-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds partial support for "sk" keys that are associated with a hardware key. We can only read keys but can't use them for signing. Reference: https://api.libssh.org/rfc/PROTOCOL.u2f Issue: dlech/KeeAgent#300
- Loading branch information
Showing
10 changed files
with
324 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,9 @@ public string AuthorizedKeysString | |
{ | ||
var builder = new StringBuilder(); | ||
|
||
builder.Append(GetAlgorithmIdentifier(Parameter, Certificate != null)); | ||
builder.Append( | ||
GetAlgorithmIdentifier(Parameter, Certificate != null, Application != null) | ||
); | ||
builder.Append(' '); | ||
builder.Append(Convert.ToBase64String(KeyBlob)); | ||
|
||
|
@@ -81,6 +83,12 @@ public string AuthorizedKeysString | |
|
||
public OpensshCertificateInfo Certificate { get; } | ||
|
||
/// <summary> | ||
/// Gets the application for hardware security keys or <c>null</c> if | ||
/// this key is not associated with a hardware key. | ||
/// </summary> | ||
public string Application { get; } | ||
|
||
/// <summary> | ||
/// Creates a new public key. | ||
/// </summary> | ||
|
@@ -101,9 +109,14 @@ public SshPublicKey(SshVersion version, byte[] keyBlob, string comment = "") | |
Parameter = parser.ReadSsh1PublicKeyData(); | ||
break; | ||
case SshVersion.SSH2: | ||
Parameter = parser.ReadSsh2PublicKeyData(out var nonce, out var certificate); | ||
Parameter = parser.ReadSsh2PublicKeyData( | ||
out var nonce, | ||
out var certificate, | ||
out var application | ||
); | ||
Nonce = nonce; | ||
Certificate = certificate; | ||
Application = application; | ||
break; | ||
default: | ||
throw new ArgumentException("unsupported SSH version", nameof(version)); | ||
|
@@ -136,8 +149,12 @@ public SshPublicKey WithoutCertificate() | |
|
||
// separate the key from the certificate | ||
var parser = new BlobParser(KeyBlob); | ||
var parameters = parser.ReadSsh2PublicKeyData(out var nonce, out var certificate); | ||
var key = new SshKey(Version, parameters); | ||
var parameters = parser.ReadSsh2PublicKeyData( | ||
out var nonce, | ||
out var certificate, | ||
out var application | ||
); | ||
var key = new SshKey(Version, parameters, null, "", null, null, application); | ||
|
||
return new SshPublicKey(Version, key.GetPublicKeyBlob(), Comment); | ||
} | ||
|
@@ -176,7 +193,8 @@ public static SshPublicKey Read(Stream stream) | |
|
||
private static string GetAlgorithmIdentifier( | ||
AsymmetricKeyParameter parameters, | ||
bool hasCertificate | ||
bool hasCertificate, | ||
bool hasApplication | ||
) | ||
{ | ||
var algorithm = GetBaseAlgorithmIdentifier(parameters); | ||
|
@@ -186,6 +204,16 @@ bool hasCertificate | |
algorithm += "[email protected]"; | ||
} | ||
|
||
if (hasApplication) | ||
{ | ||
algorithm = "sk-" + algorithm; | ||
|
||
if (!hasCertificate) | ||
{ | ||
algorithm += "@openssh.com"; | ||
} | ||
} | ||
|
||
return algorithm; | ||
} | ||
|
||
|
Oops, something went wrong.