Пример #1
0
        internal X509ExtensionCollection(MonoSecurity::Mono.Security.X509.X509Certificate cert)
        {
            _list = new ArrayList(cert.Extensions.Count);
            if (cert.Extensions.Count == 0)
            {
                return;
            }

            foreach (MonoSecurity::Mono.Security.X509.X509Extension ext in cert.Extensions)
            {
                bool   critical = ext.Critical;
                string oid      = ext.Oid;
                byte[] raw_data = null;
                // extension data is embedded in an octet stream (4)
                var value = ext.Value;
                if ((value.Tag == 0x04) && (value.Count > 0))
                {
                    raw_data = value [0].GetBytes();
                }

                X509Extension newt = null;
#if FULL_AOT_RUNTIME
                // non-extensible
                switch (oid)
                {
                case "2.5.29.14":
                    newt = new X509SubjectKeyIdentifierExtension(new AsnEncodedData(oid, raw_data), critical);
                    break;

                case "2.5.29.15":
                    newt = new X509KeyUsageExtension(new AsnEncodedData(oid, raw_data), critical);
                    break;

                case "2.5.29.19":
                    newt = new X509BasicConstraintsExtension(new AsnEncodedData(oid, raw_data), critical);
                    break;

                case "2.5.29.37":
                    newt = new X509EnhancedKeyUsageExtension(new AsnEncodedData(oid, raw_data), critical);
                    break;
                }
#else
                object[] parameters = new object [2];
                parameters [0] = new AsnEncodedData(oid, raw_data ?? Empty);
                parameters [1] = critical;
                newt           = (X509Extension)CryptoConfig.CreateFromName(oid, parameters);
#endif
                if (newt == null)
                {
                    // not registred in CryptoConfig, using default
                    newt = new X509Extension(oid, raw_data ?? Empty, critical);
                }
                _list.Add(newt);
            }
        }
        public void UpdateCertificateRSA()
        {
            if (clientCertificate == null)
            {
                CertificateRSA = null;
            }
            else
            {
                var cert = new MonoSecurity::Mono.Security.X509.X509Certificate(clientCertificate.GetRawCertData());

                CertificateRSA = new RSAManaged(
                    cert.RSA.KeySize);

                CertificateRSA.ImportParameters(
                    cert.RSA.ExportParameters(false));
            }
        }