Beispiel #1
0
        private static ICertificatePal[] ReadPkcs12Collection(
            ReadOnlySpan <byte> rawData,
            SafePasswordHandle password,
            bool ephemeralSpecified)
        {
            using (var reader = new AndroidPkcs12Reader(rawData))
            {
                reader.Decrypt(password, ephemeralSpecified);

                ICertificatePal[] certs = new ICertificatePal[reader.GetCertCount()];
                int idx = 0;
                foreach (UnixPkcs12Reader.CertAndKey certAndKey in reader.EnumerateAll())
                {
                    AndroidCertificatePal pal = (AndroidCertificatePal)certAndKey.Cert !;
                    if (certAndKey.Key != null)
                    {
                        pal.SetPrivateKey(AndroidPkcs12Reader.GetPrivateKey(certAndKey.Key));
                    }

                    certs[idx] = pal;
                    idx++;
                }

                return(certs);
            }
        }
Beispiel #2
0
        public static bool IsPkcs12(ReadOnlySpan <byte> data)
        {
            try
            {
                using (var reader = new AndroidPkcs12Reader(data))
                {
                    return(true);
                }
            }
            catch (CryptographicException)
            {
            }

            return(false);
        }
Beispiel #3
0
        private static ICertificatePal ReadPkcs12(ReadOnlySpan <byte> rawData, SafePasswordHandle password, bool ephemeralSpecified)
        {
            using (var reader = new AndroidPkcs12Reader(rawData))
            {
                reader.Decrypt(password, ephemeralSpecified);

                UnixPkcs12Reader.CertAndKey certAndKey = reader.GetSingleCert();
                AndroidCertificatePal       pal        = (AndroidCertificatePal)certAndKey.Cert !;
                if (certAndKey.Key != null)
                {
                    pal.SetPrivateKey(AndroidPkcs12Reader.GetPrivateKey(certAndKey.Key));
                }

                return(pal);
            }
        }
Beispiel #4
0
            public X509ContentType GetCertContentType(ReadOnlySpan <byte> rawData)
            {
                if (rawData == null || rawData.Length == 0)
                {
                    throw new CryptographicException();
                }

                X509ContentType contentType = Interop.AndroidCrypto.X509GetContentType(rawData);

                if (contentType != X509ContentType.Unknown)
                {
                    return(contentType);
                }

                if (AndroidPkcs12Reader.IsPkcs12(rawData))
                {
                    return(X509ContentType.Pkcs12);
                }

                // Throw on unknown type to match Unix and Windows
                throw new CryptographicException(SR.Cryptography_UnknownCertContentType);
            }