-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to load a PKCS10 into CertificateRequest
PKCS#10 CertificateRequest objects can now be loaded into the .NET CertificateRequest object form. By default, the proof-of-key signature is validated during load. Callers can disable the check if they think that is appropriate, such as when certifying a(n IFC) Diffie-Hellman key (as that algorithm cannot sign itself). Another default behavior is that the extensions request attribute is ignored, other than being checked for structural validity. Callers who wish to load the extensions request attribute are cautioned to inspect them before signing/completing the request, and in that case the requested extensions populate directly into the `CertificateExtensions` collection. Any attributes from the request, such as the PKCS#9 ChallengePassword attribute, will populate the `OtherRequestAttributes` collection. This collection does not filter out duplicates, or check that the attributes are valid per their OID. And, since the collection populates on load, it's also respected on save.
- Loading branch information
Showing
20 changed files
with
2,163 additions
and
104 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/libraries/Common/src/System/Security/Cryptography/Asn1/PssParamsAsn.manual.cs
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Formats.Asn1; | ||
using Internal.Cryptography; | ||
|
||
namespace System.Security.Cryptography.Asn1 | ||
{ | ||
internal partial struct PssParamsAsn | ||
{ | ||
internal RSASignaturePadding GetSignaturePadding( | ||
int? digestValueLength = null) | ||
{ | ||
if (TrailerField != 1) | ||
{ | ||
throw new CryptographicException(SR.Cryptography_Pkcs_InvalidSignatureParameters); | ||
} | ||
|
||
if (MaskGenAlgorithm.Algorithm != Oids.Mgf1) | ||
{ | ||
throw new CryptographicException( | ||
SR.Cryptography_Pkcs_PssParametersMgfNotSupported, | ||
MaskGenAlgorithm.Algorithm); | ||
} | ||
|
||
if (MaskGenAlgorithm.Parameters == null) | ||
{ | ||
throw new CryptographicException(SR.Cryptography_Pkcs_InvalidSignatureParameters); | ||
} | ||
|
||
AlgorithmIdentifierAsn mgfParams = AlgorithmIdentifierAsn.Decode( | ||
MaskGenAlgorithm.Parameters.Value, | ||
AsnEncodingRules.DER); | ||
|
||
if (mgfParams.Algorithm != HashAlgorithm.Algorithm) | ||
{ | ||
throw new CryptographicException( | ||
SR.Format( | ||
SR.Cryptography_Pkcs_PssParametersMgfHashMismatch, | ||
mgfParams.Algorithm, | ||
HashAlgorithm.Algorithm)); | ||
} | ||
|
||
int saltSize = digestValueLength.GetValueOrDefault(); | ||
|
||
if (!digestValueLength.HasValue) | ||
{ | ||
saltSize = Helpers.HashOidToByteLength(HashAlgorithm.Algorithm); | ||
} | ||
|
||
if (SaltLength != saltSize) | ||
{ | ||
throw new CryptographicException( | ||
SR.Format( | ||
SR.Cryptography_Pkcs_PssParametersSaltMismatch, | ||
SaltLength, | ||
HashAlgorithm.Algorithm)); | ||
} | ||
|
||
// When RSASignaturePadding supports custom salt sizes this return will look different. | ||
return RSASignaturePadding.Pss; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.