Skip to content

Commit 653ca83

Browse files
committed
Fixed ECDH key to have keyAgreement in its KeyUsage extension
It seems that the latest X509Certificate2 impl validates that this key usage is set if the KeyUsage extension exists. Unfortunately, this still isn't enough to fix CmsSignerTests.TestConstructors() which is now failing with: System.Security.Cryptography.CryptographicException: Keyset does not exist at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider, CngKeyOpenOptions openOptions) at System.Security.Cryptography.X509Certificates.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng) at System.Security.Cryptography.X509Certificates.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints) at MimeKit.Cryptography.X509Certificate2Extensions.GetPrivateKeyAsAsymmetricKeyParameter(X509Certificate2 certificate) in C:\src\MimeKit\MimeKit\Cryptography\X509Certificate2Extensions.cs:line 249 at MimeKit.Cryptography.CmsSigner..ctor(X509Certificate2 certificate, SubjectIdentifierType signerIdentifierType) in C:\src\MimeKit\MimeKit\Cryptography\CmsSigner.cs:line 347 at UnitTests.Cryptography.CmsSignerTests.TestConstructors() in C:\src\MimeKit\UnitTests\Cryptography\CmsSignerTests.cs:line 155
1 parent c7b0f35 commit 653ca83

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

UnitTests/Cryptography/CmsSignerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public void TestConstructors ()
151151
}
152152

153153
try {
154-
signer = new CmsSigner (new X509Certificate2 (path, password, X509KeyStorageFlags.Exportable));
154+
var cert = new X509Certificate2 (path, password, X509KeyStorageFlags.Exportable);
155+
signer = new CmsSigner (cert);
155156
} catch (Exception ex) {
156157
Assert.Fail ($".ctor (X509Certificate2): {ex}");
157158
}

UnitTests/TestData/smime/ec/smime.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BasicConstraints = critical, CA:false
2525
DaysValid = 3650
2626
Issuer = ..\intermediate2.pfx
2727
IssuerPassword = no.secret
28-
KeyUsage = critical, digitalSignature, keyEncipherment, nonRepudiation
28+
KeyUsage = critical, digitalSignature, keyAgreement, keyEncipherment, nonRepudiation
2929
SignatureAlgorithm = SHA256WithRSA
3030
#Output = smime.pfx
3131
Password = no.secret
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-----BEGIN EC PRIVATE KEY-----
2+
MIGkAgEBBDBmMPHErht57LDf+Cqs9FnZNFGOKgoufuiA1oUfJfPDBQTHhPK1EQlJ
3+
YV8iz2+Pbv2gBwYFK4EEACKhZANiAAT3RoBDTLPIr7D2y6MPfm4T7MuJubEfEkXL
4+
IH+pqeYQQrbz2D0X4Gek9BTG51uZ7q2ra8toWPZCWwksb8BbWQsvPwr0w3/2zGXJ
5+
GYZO1WLD97i88PODLoFqO/weGtJpi/8=
6+
-----END EC PRIVATE KEY-----
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)