Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit feed8e4

Browse files
committed
Make RsaOpenSsl::ExportParameters(true) on public keys.
The Windows version throws when private data export is requested of a public-only key. The Unix version returned the structure with the private key portions as null. This change makes the Unix version throw if the private parameters don't export (such as because it's a public-only key).
1 parent 98cfbe5 commit feed8e4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Common/src/Interop/Unix/libcrypto/Interop.Rsa.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ internal static unsafe RSAParameters ExportRsaParameters(SafeRsaHandle key, bool
8383
rsaParameters.Q = ExtractBignum(rsaStructure->q, halfModulus);
8484
rsaParameters.DQ = ExtractBignum(rsaStructure->dmq1, halfModulus);
8585
rsaParameters.InverseQ = ExtractBignum(rsaStructure->iqmp, halfModulus);
86+
87+
if (rsaParameters.D == null ||
88+
rsaParameters.P == null ||
89+
rsaParameters.DP == null ||
90+
rsaParameters.Q == null ||
91+
rsaParameters.DQ == null ||
92+
rsaParameters.InverseQ == null)
93+
{
94+
throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);
95+
}
8696
}
8797
}
8898
finally

src/System.Security.Cryptography.RSA/tests/ImportExport.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public static void MultiExport()
155155
}
156156

157157
[Fact]
158-
[ActiveIssue(1984, PlatformID.AnyUnix)]
159158
public static void PublicOnlyPrivateExport()
160159
{
161160
RSAParameters imported = new RSAParameters

0 commit comments

Comments
 (0)