[Android][libraries] Throw PNSE for PersistKeySet flags (#57494)
authorMitchell Hwang <16830051+mdh1418@users.noreply.github.com>
Tue, 17 Aug 2021 18:06:02 +0000 (14:06 -0400)
committerGitHub <noreply@github.com>
Tue, 17 Aug 2021 18:06:02 +0000 (14:06 -0400)
* [Android][libraries] Throw PNSE for Exportable and PersistKeySet flags

* Ignore exportable flag

Co-authored-by: Mitchell Hwang <mitchell.hwang@microsoft.com>
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Android/AndroidCertificatePal.cs

index 2a98750..d765cd0 100644 (file)
@@ -63,6 +63,11 @@ namespace Internal.Cryptography.Pal
                     // We don't support determining this on Android right now, so we throw.
                     throw new CryptographicException(SR.Cryptography_X509_PKCS7_NoSigner);
                 case X509ContentType.Pkcs12:
+                    if ((keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
+                    {
+                        throw new PlatformNotSupportedException(SR.Cryptography_X509_PKCS12_PersistKeySetNotSupported);
+                    }
+
                     return ReadPkcs12(rawData, password, ephemeralSpecified);
                 case X509ContentType.Cert:
                 default: