Exemplo n.º 1
0
        public void Remove(X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }
            if (!IsOpen)
            {
                throw new CryptographicException(Locale.GetText("Store isn't opened."));
            }

            if (!Exists(certificate))
            {
                return;
            }

            if (IsReadOnly)
            {
                throw new CryptographicException(Locale.GetText("Store is read-only."));
            }

            try {
                store.Remove(new MX.X509Certificate(certificate.RawData));
            }
            finally {
                CertList.Remove(certificate);
            }
        }
Exemplo n.º 2
0
        public void AddRange(X509Certificate2Collection certificates)
        {
            if (certificates == null)
            {
                throw new ArgumentNullException("certificates");
            }

            if (certificates.Count == 0)
            {
                return;
            }

            if (!IsOpen)
            {
                throw new CryptographicException(Locale.GetText("Store isn't opened."));
            }
            if (IsReadOnly)
            {
                throw new CryptographicException(Locale.GetText("Store is read-only."));
            }

            foreach (X509Certificate2 certificate in certificates)
            {
                if (!Exists(certificate))
                {
                    try {
                        store.Import(new MX.X509Certificate(certificate.RawData));
                    }
                    finally {
                        CertList.Add(certificate);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void RemoveRange(X509Certificate2Collection certificates)
        {
            if (certificates == null)
            {
                throw new ArgumentNullException("certificates");
            }

            if (certificates.Count == 0)
            {
                return;
            }

            if (!IsOpen)
            {
                throw new CryptographicException(Locale.GetText("Store isn't opened."));
            }

            bool delete = false;

            foreach (X509Certificate2 certificate in certificates)
            {
                if (Exists(certificate))
                {
                    delete = true;
                }
            }
            if (!delete)
            {
                return;
            }

            if (IsReadOnly)
            {
                throw new CryptographicException(Locale.GetText("Store is read-only."));
            }

            try {
                foreach (X509Certificate2 certificate in certificates)
                {
                    store.Remove(new MX.X509Certificate(certificate.RawData));
                }
            }
            finally {
                CertList.RemoveRange(certificates);
            }
        }
Exemplo n.º 4
0
        public void Open(OpenFlags flags)
        {
            if (String.IsNullOrEmpty(_name))
            {
                throw new CryptographicException(Locale.GetText("Invalid store name (null or empty)."));
            }

            /* keep existing Mono installations (pre 2.0) compatible with new stuff */
            string name;

            switch (_name)
            {
            case "Root":
                name = "Trust";
                break;

            default:
                name = _name;
                break;
            }

            bool create = ((flags & OpenFlags.OpenExistingOnly) != OpenFlags.OpenExistingOnly);

            store = Factory.Open(name, create);
            if (store == null)
            {
                throw new CryptographicException(Locale.GetText("Store {0} doesn't exists.", _name));
            }
            _flags = flags;

            foreach (MX.X509Certificate x in store.Certificates)
            {
                var cert2 = new X509Certificate2(x.RawData);
                cert2.PrivateKey = x.RSA;
                CertList.Add(cert2);
            }
        }