예제 #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);
            }
        }
예제 #2
0
        public static bool IsPkcs12(ReadOnlySpan <byte> data)
        {
            try
            {
                using (var reader = new AndroidPkcs12Reader(data))
                {
                    return(true);
                }
            }
            catch (CryptographicException)
            {
            }

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

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

                return(pal);
            }
        }
예제 #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();
            }