Exemple #1
0
        internal static X509Certificate2[] X509ChainGetCertificates(SafeX509ChainContextHandle ctx)
        {
            int count = Interop.AndroidCrypto.X509ChainGetCertificateCount(ctx);

            var certPtrs = new IntPtr[count];

            int res = Interop.AndroidCrypto.X509ChainGetCertificates(ctx, certPtrs, certPtrs.Length);

            if (res == 0)
            {
                throw new CryptographicException();
            }

            Debug.Assert(res <= certPtrs.Length);

            var certs = new X509Certificate2[certPtrs.Length];

            for (int i = 0; i < res; i++)
            {
                certs[i] = new X509Certificate2(certPtrs[i]);
            }

            if (res == certPtrs.Length)
            {
                return(certs);
            }

            return(certs[0..res]);
Exemple #2
0
        internal static ValidationError[] X509ChainGetErrors(SafeX509ChainContextHandle ctx)
        {
            int count = Interop.AndroidCrypto.X509ChainGetErrorCount(ctx);

            if (count == 0)
            {
                return(Array.Empty <ValidationError>());
            }

            var errors = new ValidationError[count];
            int res    = Interop.AndroidCrypto.X509ChainGetErrors(ctx, errors, errors.Length);

            if (res != SUCCESS)
            {
                throw new CryptographicException();
            }

            return(errors);
        }
Exemple #3
0
 private static unsafe partial int X509ChainGetErrors(
     SafeX509ChainContextHandle ctx,
     ValidationError[] errors,
     int errorsLen);
Exemple #4
0
 private static partial int X509ChainGetErrorCount(SafeX509ChainContextHandle ctx);
Exemple #5
0
 private static partial int X509ChainGetCertificates(
     SafeX509ChainContextHandle ctx,
     IntPtr[] certs,
     int certsLen);
Exemple #6
0
 internal static partial bool X509ChainBuild(
     SafeX509ChainContextHandle ctx,
     long timeInMsFromUnixEpoch);
Exemple #7
0
 private static partial int X509ChainGetCertificateCount(SafeX509ChainContextHandle ctx);
Exemple #8
0
 internal static partial int X509ChainValidate(
     SafeX509ChainContextHandle ctx,
     X509RevocationMode revocationMode,
     X509RevocationFlag revocationFlag,
     out byte checkedRevocation);
Exemple #9
0
 internal static partial int X509ChainSetCustomTrustStore(
     SafeX509ChainContextHandle ctx,
     IntPtr[] customTrustStore,
     int customTrustStoreLen);
Exemple #10
0
            private static Dictionary <int, List <X509ChainStatus> > GetStatusByIndex(SafeX509ChainContextHandle ctx)
            {
                var statusByIndex = new Dictionary <int, List <X509ChainStatus> >();

                Interop.AndroidCrypto.ValidationError[] errors = Interop.AndroidCrypto.X509ChainGetErrors(ctx);
                for (int i = 0; i < errors.Length; i++)
                {
                    Interop.AndroidCrypto.ValidationError error = errors[i];
                    X509ChainStatus chainStatus = ValidationErrorToChainStatus(error);
                    Marshal.FreeHGlobal(error.Message);

                    if (!statusByIndex.ContainsKey(error.Index))
                    {
                        statusByIndex.Add(error.Index, new List <X509ChainStatus>());
                    }

                    statusByIndex[error.Index].Add(chainStatus);
                }

                return(statusByIndex);
            }
 private static unsafe extern int X509ChainGetErrors(
     SafeX509ChainContextHandle ctx,
     [Out] ValidationError[] errors,
     int errorsLen);
 private static extern int X509ChainGetErrorCount(SafeX509ChainContextHandle ctx);