-
Notifications
You must be signed in to change notification settings - Fork 60
fix: Fixed bug importing PIV private key in legacy classes #231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bf0cdbb
fix: fix conversion between PivPrivateKey and encoded formats
DennisDyallo 7fdc339
fix: fix setting of Algorithm in obsolete PivEccPrivateKey constructor
DennisDyallo 9c0008c
obsolete: set piv keys as obsolete
DennisDyallo 933ab6d
refactor: change zeroMemoryHandle to work with Memory<byte>
DennisDyallo 09dd9ae
docs: add remark for sensitive data
DennisDyallo 22868ea
test: add legacy test
DennisDyallo 7f365ff
Update GenerateKeyPairResponse.cs
DennisDyallo 5b1352d
fix: EcdsaVerify cannot be Ed25519
DennisDyallo a4b897f
refactor: use KeyDefinition lookup for PivEccPrivateKey
DennisDyallo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -33,31 +33,38 @@ public static class KeyExtensions | |
/// <param name="parameters">The public key parameters to encode.</param> | ||
/// <returns>A BER encoded byte array containing the encoded public key.</returns> | ||
/// <exception cref="ArgumentException">Thrown when the key type is not supported.</exception> | ||
public static Memory<byte> EncodeAsPiv(this IPublicKey parameters) | ||
{ | ||
return parameters switch | ||
public static Memory<byte> EncodeAsPiv(this IPublicKey parameters) => | ||
parameters switch | ||
{ | ||
ECPublicKey p => PivKeyEncoder.EncodeECPublicKey(p), | ||
RSAPublicKey p => PivKeyEncoder.EncodeRSAPublicKey(p), | ||
Curve25519PublicKey p => PivKeyEncoder.EncodeCurve25519PublicKey(p), | ||
_ => throw new ArgumentException("The type conversion for the specified key type is not supported", nameof(parameters)) | ||
|
||
#pragma warning disable CS0618 // Type or member is obsolete | ||
PivPublicKey p => p.PivEncodedPublicKey.ToArray(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the bugfix |
||
#pragma warning restore CS0618 // Type or member is obsolete | ||
_ => throw new ArgumentException( | ||
"The type conversion for the specified key type is not supported", nameof(parameters)) | ||
}; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Encodes a private key into the PIV format. | ||
/// </summary> | ||
/// <param name="parameters">The private key parameters to encode.</param> | ||
/// <returns>A BER encoded byte array containing the encoded private key.</returns> | ||
/// <exception cref="ArgumentException">Thrown when the key type is not supported or when RSA key components have invalid lengths.</exception> | ||
public static Memory<byte> EncodeAsPiv(this IPrivateKey parameters) | ||
{ | ||
return parameters switch | ||
/// <remarks>This method returns a newly allocated array containing sensitive information.</remarks> | ||
public static Memory<byte> EncodeAsPiv(this IPrivateKey parameters) => | ||
parameters switch | ||
{ | ||
ECPrivateKey p => PivKeyEncoder.EncodeECPrivateKey(p), | ||
RSAPrivateKey p => PivKeyEncoder.EncodeRSAPrivateKey(p), | ||
Curve25519PrivateKey p => PivKeyEncoder.EncodeCurve25519PrivateKey(p), | ||
_ => throw new ArgumentException("The type conversion for the specified key type is not supported", nameof(parameters)) | ||
|
||
#pragma warning disable CS0618 // Type or member is obsolete | ||
PivPrivateKey p => p.EncodedPrivateKey.ToArray(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the bugfix |
||
#pragma warning restore CS0618 // Type or member is obsolete | ||
_ => throw new ArgumentException( | ||
"The type conversion for the specified key type is not supported", nameof(parameters)) | ||
}; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning disable only wraps the class declaration, but the
GetData()
method still emits CS0618 warnings on the return type. Consider extending the pragma to coverGetData()
or annotate it with[Obsolete]
to fully suppress warnings.Copilot uses AI. Check for mistakes.