예제 #1
0
        static IssuerInformation issuerInformationFromPreCertificateSigningCert(Certificate certificate, byte[] keyHash)
        {
            try
            {
                Asn1InputStream aIssuerIn = new Asn1InputStream(certificate.GetEncoded());
                X509CertificateStructure.GetInstance(aIssuerIn.ReadObject());
                CertificateList parsedIssuerCert = CertificateList.GetInstance(aIssuerIn.ReadObject());

                X509Extensions issuerExtensions           = parsedIssuerCert.TbsCertList.Extensions;//.GetExtension(new DerObjectIdentifier(X509_AUTHORITY_KEY_IDENTIFIER));
                X509Extension  x509authorityKeyIdentifier = null;
                if (issuerExtensions != null)
                {
                    //Org.BouncyCastle.Asn1.DerObjectIdentifier
                    x509authorityKeyIdentifier =
                        issuerExtensions.GetExtension(new DerObjectIdentifier(X509_AUTHORITY_KEY_IDENTIFIER));
                }

                return(new IssuerInformation(parsedIssuerCert.Issuer, keyHash, x509authorityKeyIdentifier, true));
            }
            catch (CertificateEncodingException e)
            {
                throw new CertificateTransparencyException(
                          "Certificate could not be encoded: " + e.Message, e);
            }
            catch (Java.IO.IOException e)
            {
                throw new CertificateTransparencyException("Error during ASN.1 parsing of certificate: " + e.Message, e);
            }
        }
예제 #2
0
        /// <summary>
        /// Upgrade the deployment for the service.
        /// </summary>
        private void UpgradeDeployment()
        {
            Debug.Assert(
                !string.IsNullOrEmpty(_hostedServiceName),
                "_hostedServiceName cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.Label),
                "Label cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.DeploymentName),
                "DeploymentName cannot be null or empty.");

            UpgradeDeploymentInput deploymentInput = new UpgradeDeploymentInput
            {
                PackageUrl    = UploadPackage(),
                Configuration = GetConfiguration(),
                Label         = ServiceManagementHelper.EncodeToBase64String(_deploymentSettings.Label),
                Mode          = UpgradeType.Auto
            };

            CertificateList uploadedCertificates = RetryCall <CertificateList>(subscription => Channel.ListCertificates(subscription, _hostedServiceName));

            AddCertificates(uploadedCertificates);
            InvokeInOperationContext(() =>
            {
                SafeWriteObjectWithTimestamp(Resources.PublishUpgradingMessage);
                RetryCall(subscription =>
                          Channel.UpgradeDeployment(
                              subscription,
                              _hostedServiceName,
                              _deploymentSettings.DeploymentName,
                              deploymentInput));
                WaitForDeploymentToStart();
            });
        }
예제 #3
0
        private void AddCertificates(CertificateList uploadedCertificates)
        {
            if (_azureService.Components.CloudConfig.Role != null)
            {
                foreach (ServiceConfigurationSchema.Certificate certElement in _azureService.Components.CloudConfig.Role.
                         SelectMany(r => (null == r.Certificates) ? new ServiceConfigurationSchema.Certificate[0] : r.Certificates).Distinct())
                {
                    if (uploadedCertificates == null || (uploadedCertificates.Count <Certificate>(c => c.Thumbprint.Equals(
                                                                                                      certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1))
                    {
                        X509Certificate2 cert     = General.GetCertificateFromStore(certElement.thumbprint);
                        CertificateFile  certFile = null;
                        try
                        {
                            certFile = new CertificateFile
                            {
                                Data              = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)),
                                Password          = string.Empty,
                                CertificateFormat = "pfx"
                            };
                        }
                        catch (CryptographicException exception)
                        {
                            throw new ArgumentException(string.Format(Resources.CertificatePrivateKeyAccessError, certElement.name), exception);
                        }

                        RetryCall(subscription => Channel.AddCertificates(subscription, _hostedServiceName, certFile));
                        WaitForCertificateToBeAdded(certElement);
                    }
                }
            }
        }
예제 #4
0
        private IDictionary ExtendUnsignedAttributes(IDictionary unsignedAttrs, X509Certificate signingCertificate, DateTime signingDate, ICertificateSource optionalCertificateSource)
        {
            var validationContext = CertificateVerifier.ValidateCertificate(signingCertificate, signingDate, optionalCertificateSource, null, null);

            List <X509CertificateStructure> certificateValues = new List <X509CertificateStructure>();
            List <CertificateList>          crlValues         = new List <CertificateList>();
            List <BasicOcspResponse>        ocspValues        = new List <BasicOcspResponse>();

            foreach (CertificateAndContext c in validationContext.NeededCertificates)
            {
                if (!c.Equals(signingCertificate))
                {
                    certificateValues.Add(X509CertificateStructure.GetInstance(((Asn1Sequence)Asn1Object.FromByteArray(c.Certificate.GetEncoded()))));
                }
            }
            foreach (X509Crl relatedcrl in validationContext.NeededCRL)
            {
                crlValues.Add(CertificateList.GetInstance((Asn1Sequence)Asn1Object.FromByteArray(relatedcrl.GetEncoded())));
            }
            foreach (BasicOcspResp relatedocspresp in validationContext.NeededOCSPResp)
            {
                ocspValues.Add((BasicOcspResponse.GetInstance((Asn1Sequence)Asn1Object.FromByteArray(relatedocspresp.GetEncoded()))));
            }
            RevocationValues revocationValues = new RevocationValues(crlValues.ToArray(), ocspValues.ToArray(), null);

            unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new BcCms.Attribute(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new DerSet(revocationValues)));
            unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsCertValues, new BcCms.Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(certificateValues.ToArray()))));

            return(unsignedAttrs);
        }
예제 #5
0
        /// <summary>
        /// Create a new deployment for the service.
        /// </summary>
        private void CreateNewDeployment()
        {
            Debug.Assert(
                !string.IsNullOrEmpty(_hostedServiceName),
                "_hostedServiceName cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.ServiceSettings.Slot),
                "Slot cannot be null or empty.");

            CreateDeploymentInput deploymentInput = new CreateDeploymentInput
            {
                PackageUrl      = UploadPackage(),
                Configuration   = GetConfiguration(),
                Label           = ServiceManagementHelper.EncodeToBase64String(_deploymentSettings.Label),
                Name            = _deploymentSettings.DeploymentName,
                StartDeployment = true,
            };

            CertificateList uploadedCertificates = RetryCall <CertificateList>(subscription => Channel.ListCertificates(subscription, _hostedServiceName));

            AddCertificates(uploadedCertificates);
            InvokeInOperationContext(() =>
            {
                RetryCall(subscription =>
                          Channel.CreateOrUpdateDeployment(
                              subscription,
                              _hostedServiceName,
                              _deploymentSettings.ServiceSettings.Slot,
                              deploymentInput));
                WaitForDeploymentToStart();
            });
        }
        public virtual IX509Store GetCrls()
        {
            Asn1Set certificates = originatorInfo.Certificates;

            if (certificates != null)
            {
                global::System.Collections.IList list = Platform.CreateArrayList(certificates.Count);
                {
                    global::System.Collections.IEnumerator enumerator = certificates.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current();
                            Asn1Object    asn1Object    = asn1Encodable.ToAsn1Object();
                            if (asn1Object is Asn1Sequence)
                            {
                                list.Add((object)new X509Crl(CertificateList.GetInstance(asn1Object)));
                            }
                        }
                    }
                    finally
                    {
                        global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                return(X509StoreFactory.Create("CRL/Collection", new X509CollectionStoreParameters((global::System.Collections.ICollection)list)));
            }
            return(X509StoreFactory.Create("CRL/Collection", new X509CollectionStoreParameters((global::System.Collections.ICollection)Platform.CreateArrayList())));
        }
예제 #7
0
 public static void Main(string[] args)
 {
     using (var factory = new PipelineFactory())
         using (var list = new CertificateList())
         {
             var thumb    = "48026c976caaf7f3a72d38c17d16ce69d04a6053".ToUpper();
             var provider = new Leto.Tls13.Certificates.Windows.CertificateProvider();
             list.AddCertificate(provider.LoadCertificateFromStore(thumb, true));
             using (var serverContext = new SecurePipelineListener(factory, list))
                 using (var socketClient = new System.IO.Pipelines.Networking.Sockets.SocketListener(factory))
                 {
                     var ip         = IPAddress.Any;
                     int port       = 443;
                     var ipEndPoint = new IPEndPoint(ip, port);
                     socketClient.OnConnection(async s =>
                     {
                         Console.WriteLine("Connected");
                         var sp = serverContext.CreateSecurePipeline(s);
                         Console.WriteLine("Secure Connection Created");
                         await ServerLoop.HandleConnection(sp);
                     });
                     socketClient.Start(ipEndPoint);
                     Console.ReadLine();
                 }
         }
 }
예제 #8
0
        public void FedictTs_ProvidedTime_ProvideOutdatedCrl()
        {
            CertificateList           crl1 = CertificateList.GetInstance(File.ReadAllBytes("files/fedictTs1.crl"));
            CertificateList           crl2 = CertificateList.GetInstance(File.ReadAllBytes("files/fedictTs2.crl"));
            CertificateList           crl3 = CertificateList.GetInstance(File.ReadAllBytes("files/fedictTs3.crl"));
            IList <CertificateList>   crls = new List <CertificateList>(new CertificateList[] { crl1, crl2 });
            IList <BasicOcspResponse> ocps = new List <BasicOcspResponse>(new BasicOcspResponse[] { });
            TimeStampToken            tst  = File.ReadAllBytes("files/fedictTs.ts").ToTimeStampToken();

            Timestamp ts = tst.Validate(crls, ocps, new DateTime(2019, 1, 5, 13, 34, 12, DateTimeKind.Utc));

            Assert.Equal(new DateTime(2014, 3, 15, 11, 50, 49, DateTimeKind.Utc), ts.Time);
            Assert.Equal(new DateTime(2019, 1, 23, 11, 0, 0, DateTimeKind.Utc), ts.RenewalTime);
            Assert.Equal(0, ts.TimestampStatus.Count(x => x.Status != X509ChainStatusFlags.NoError));
            if (ts.CertificateChain.ChainElements.Count == 2)
            {
                //belgian root CA
                Assert.Equal(3, crls.Count);
                Assert.Equal(0, ocps.Count);
            }
            else if (ts.CertificateChain.ChainElements.Count == 4)
            {
                //belgian resigned CA
                Assert.Equal(5, crls.Count); //the last one isn't oudated yet (put to 6 when it is expired)
                Assert.Equal(0, ocps.Count);
            }
            else
            {
                Assert.False(true, "The chain should be 4 or 2 long");
            }
        }
예제 #9
0
        /**
         * Return the CRLs stored in the underlying OriginatorInfo object.
         *
         * @return a Store of X509CRLHolder objects.
         */
        public virtual IX509Store GetCrls()
        {
            Asn1Set crlSet = originatorInfo.Certificates;

            if (crlSet != null)
            {
                IList crlList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(crlSet.Count);

                foreach (Asn1Encodable enc in crlSet)
                {
                    Asn1Object obj = enc.ToAsn1Object();
                    if (obj is Asn1Sequence)
                    {
                        crlList.Add(new X509Crl(CertificateList.GetInstance(obj)));
                    }
                }

                return(X509StoreFactory.Create(
                           "CRL/Collection",
                           new X509CollectionStoreParameters(crlList)));
            }

            return(X509StoreFactory.Create(
                       "CRL/Collection",
                       new X509CollectionStoreParameters(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList())));
        }
예제 #10
0
        private void CreateDeployment(PublishContext context)
        {
            CreateDeploymentInput deploymentInput = new CreateDeploymentInput
            {
                PackageUrl      = UploadPackage(context),
                Configuration   = General.GetConfiguration(context.ConfigPath),
                Label           = context.ServiceName,
                Name            = context.DeploymentName,
                StartDeployment = true,
            };

            WriteVerboseWithTimestamp(Resources.PublishStartingMessage);

            CertificateList uploadedCertificates = ServiceManagementChannel.ListCertificates(
                subscriptionId,
                context.ServiceName);

            AddCertificates(uploadedCertificates, context);

            ServiceManagementChannel.CreateOrUpdateDeployment(
                subscriptionId,
                context.ServiceName,
                context.ServiceSettings.Slot,
                deploymentInput);
        }
예제 #11
0
        /** [シングルトン]constructor
         */
        private File()
        {
            //work
            this.work_pool = new List.NodePool <WorkItem>(16);
            this.work_add  = new System.Collections.Generic.LinkedList <WorkItem>();
            this.work_list = new System.Collections.Generic.LinkedList <WorkItem>();

            //main_androidcontent
            this.main_androidcontent = new Main_AndroidContent();

            //main_io
            this.main_io = new Main_Io();

            //main_webrequest
            this.main_webrequest = new Main_WebRequest();

            //main_resources
            this.main_resources = new Main_Resources();

            //certificate_list
            this.certificate_list = new CertificateList();

            //PlayerLoopType
            this.playerloop_flag = true;
            Fee.PlayerLoopSystem.PlayerLoopSystem.GetInstance().Add(Config.PLAYERLOOP_ADDTYPE, Config.PLAYERLOOP_TARGETTYPE, typeof(PlayerLoopType.Fee_File_Main), this.Main);
        }
예제 #12
0
 protected void InitialCredential_SelectedIndexChanged(object sender, EventArgs e)
 {
     //display programs DDL based on credential choice
     if (InitialCredential.SelectedValue == "Certificate")
     {
         CertificateList.Visible = true;
         DiplomaList.DataBind();
         DiplomaList.Visible = false;
         DegreeList.DataBind();
         DegreeList.Visible = false;
     }
     else if (InitialCredential.SelectedValue == "Diploma")
     {
         CertificateList.Visible = false;
         CertificateList.DataBind();
         DiplomaList.Visible = true;
         DegreeList.DataBind();
         DegreeList.Visible = false;
     }
     else if (InitialCredential.SelectedValue == "Degree")
     {
         CertificateList.DataBind();
         CertificateList.Visible = false;
         DiplomaList.DataBind();
         DiplomaList.Visible = false;
         DegreeList.Visible  = true;
     }
     else
     {
         CertificateList.Visible = false;
         DiplomaList.Visible     = false;
         DegreeList.Visible      = false;
     }
 }
예제 #13
0
        public X509Crl(
            CertificateList c)
        {
            this.c = c;

            try
            {
                this.sigAlgName = X509SignatureUtilities.GetSignatureName(c.SignatureAlgorithm);

                if (c.SignatureAlgorithm.Parameters != null)
                {
                    this.sigAlgParams = ((Asn1Encodable)c.SignatureAlgorithm.Parameters).GetDerEncoded();
                }
                else
                {
                    this.sigAlgParams = null;
                }

                this.isIndirect = IsIndirectCrl;
            }
            catch (Exception e)
            {
                throw new CrlException("CRL contents invalid: " + e);
            }
        }
예제 #14
0
        public static IList GetCrlsFromStore(
            IX509Store crlStore)
        {
            try
            {
                IList crls = new ArrayList();

                if (crlStore != null)
                {
                    foreach (X509Crl c in crlStore.GetMatches(null))
                    {
                        crls.Add(
                            CertificateList.GetInstance(
                                Asn1Object.FromByteArray(c.GetEncoded())));
                    }
                }

                return(crls);
            }
            catch (CrlException e)
            {
                throw new CmsException("error encoding crls", e);
            }
            catch (Exception e)
            {
                throw new CmsException("error processing crls", e);
            }
        }
예제 #15
0
 private X509Crl GetCrl()
 {
     if (sCrlData == null || sCrlDataObjectCount >= sCrlData.Count)
     {
         return(null);
     }
     return(CreateX509Crl(CertificateList.GetInstance(sCrlData[sCrlDataObjectCount++])));
 }
예제 #16
0
 private TimeStampAndCrl(Asn1Sequence seq)
 {
     this.timeStamp = ContentInfo.GetInstance(seq[0]);
     if (seq.Count == 2)
     {
         this.crl = CertificateList.GetInstance(seq[1]);
     }
 }
예제 #17
0
 public virtual RevRepContentBuilder AddCrl(CertificateList crl)
 {
     this.crls.Add(new Asn1Encodable[]
     {
         crl
     });
     return(this);
 }
예제 #18
0
 private X509Crl GenerateJcaObject(
     TbsCertificateList tbsCrl,
     byte[]                          signature)
 {
     return(new X509Crl(
                CertificateList.GetInstance(
                    new DerSequence(tbsCrl, sigAlgId, new DerBitString(signature)))));
 }
예제 #19
0
        public void GetCertificateListOfRootCa_NA()
        {
            var target = new X509Certificate2(@"files/belgiumrca4.crt");

            CertificateList result = target.GetCertificateList();

            Assert.Null(result);
        }
예제 #20
0
 private X509Crl GetCrl()
 {
     if ((this.sCrlData != null) && (this.sCrlDataObjectCount < this.sCrlData.Count))
     {
         return(this.CreateX509Crl(CertificateList.GetInstance(this.sCrlData[this.sCrlDataObjectCount++])));
     }
     return(null);
 }
예제 #21
0
        public async Task Init()
        {
            var certificatesList = await _certificateService.GetAll <List <Certificate> >(null);

            foreach (var certificate in certificatesList)
            {
                CertificateList.Add(certificate);
            }
        }
예제 #22
0
        public LetoConnectionAdapter(LetoConnectionAdapterOptions options, ILoggerFactory loggerFactory)
        {
            _certList = new CertificateList();
            var provider = new Tls13.Certificates.OpenSsl11.CertificateProvider();

            _certList.AddCertificate(provider.LoadPfx12(options.PfxPath, options.PfxPassword));
            _listener = new SecurePipeListener(_pipeFactory, _certList, loggerFactory);
            _logger   = loggerFactory?.CreateLogger <LetoConnectionAdapter>();
        }
예제 #23
0
 public virtual CertificateList[] ToCertificateListArray()
 {
     CertificateList[] array = new CertificateList[content.Count];
     for (int i = 0; i != array.Length; i++)
     {
         array[i] = CertificateList.GetInstance(content[i]);
     }
     return(array);
 }
예제 #24
0
 public virtual CertificateList[] ToCertificateListArray()
 {
     CertificateList[] result = new CertificateList[content.Count];
     for (int i = 0; i != result.Length; ++i)
     {
         result[i] = CertificateList.GetInstance(content[i]);
     }
     return(result);
 }
예제 #25
0
        private X509Crl ReadPemCrl(
            Stream inStream)
        {
            Asn1Sequence seq = PemCrlParser.ReadPemObject(inStream);

            return(seq == null
                                ?       null
                                :       CreateX509Crl(CertificateList.GetInstance(seq)));
        }
예제 #26
0
 public CertificateList[] GetCrlVals()
 {
     CertificateList[] array = new CertificateList[crlVals.Count];
     for (int i = 0; i < crlVals.Count; i++)
     {
         array[i] = CertificateList.GetInstance(crlVals[i].ToAsn1Object());
     }
     return(array);
 }
예제 #27
0
 public virtual CertificateList[] ToCertificateListArray()
 {
     CertificateList[] array = new CertificateList[this.content.Count];
     for (int num = 0; num != array.Length; num++)
     {
         array[num] = CertificateList.GetInstance(this.content[num]);
     }
     return(array);
 }
예제 #28
0
 public CertificateList[] GetCrlVals()
 {
     CertificateList[] result = new CertificateList[crlVals.Count];
     for (int i = 0; i < crlVals.Count; ++i)
     {
         result[i] = CertificateList.GetInstance(crlVals[i].ToAsn1Object());
     }
     return(result);
 }
예제 #29
0
        /// <exception cref="System.IO.IOException"></exception>
        //private IDictionary<DerObjectIdentifier, Asn1Encodable> ExtendUnsignedAttributes(IDictionary
        //    <DerObjectIdentifier, Asn1Encodable> unsignedAttrs, X509Certificate signingCertificate
        //    , DateTime signingDate, CertificateSource optionalCertificateSource)
        private IDictionary ExtendUnsignedAttributes(IDictionary unsignedAttrs
                                                     , X509Certificate signingCertificate, DateTime signingDate
                                                     , CertificateSource optionalCertificateSource)
        {
            ValidationContext validationContext = certificateVerifier.ValidateCertificate(signingCertificate
                                                                                          , signingDate, optionalCertificateSource, null, null);

            try
            {
                IList <X509CertificateStructure> certificateValues = new AList <X509CertificateStructure
                                                                                >();
                AList <CertificateList>   crlValues  = new AList <CertificateList>();
                AList <BasicOcspResponse> ocspValues = new AList <BasicOcspResponse>();
                foreach (CertificateAndContext c in validationContext.GetNeededCertificates())
                {
                    if (!c.Equals(signingCertificate))
                    {
                        certificateValues.AddItem(X509CertificateStructure.GetInstance(((Asn1Sequence)Asn1Object.FromByteArray
                                                                                            (c.GetCertificate().GetEncoded()))));
                    }
                }
                foreach (X509Crl relatedcrl in validationContext.GetNeededCRL())
                {
                    crlValues.AddItem(CertificateList.GetInstance((Asn1Sequence)Asn1Object.FromByteArray(((X509Crl
                                                                                                           )relatedcrl).GetEncoded())));
                }
                foreach (BasicOcspResp relatedocspresp in validationContext.GetNeededOCSPResp())
                {
                    ocspValues.AddItem((BasicOcspResponse.GetInstance((Asn1Sequence)Asn1Object.FromByteArray(
                                                                          relatedocspresp.GetEncoded()))));
                }
                CertificateList[]   crlValuesArray   = new CertificateList[crlValues.Count];
                BasicOcspResponse[] ocspValuesArray  = new BasicOcspResponse[ocspValues.Count];
                RevocationValues    revocationValues = new RevocationValues(Sharpen.Collections.ToArray
                                                                                (crlValues, crlValuesArray), Sharpen.Collections.ToArray(ocspValues, ocspValuesArray
                                                                                                                                         ), null);
                //unsignedAttrs.Put(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new Attribute
                unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new BcCms.Attribute
                                      (PkcsObjectIdentifiers.IdAAEtsRevocationValues, new DerSet(revocationValues))
                                  );
                X509CertificateStructure[] certValuesArray = new X509CertificateStructure[certificateValues
                                                                                          .Count];
                //unsignedAttrs.Put(PkcsObjectIdentifiers.IdAAEtsCertValues, new Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(Sharpen.Collections.ToArray(certificateValues
                unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsCertValues, new BcCms.Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(Sharpen.Collections.ToArray(certificateValues
                                                                                                                                                                                               , certValuesArray)))));
            }
            catch (CertificateEncodingException e)
            {
                throw new RuntimeException(e);
            }
            catch (CrlException e)
            {
                throw new RuntimeException(e);
            }
            return(unsignedAttrs);
        }
예제 #30
0
        public void GetCertificateListWithMulti_DownloadedFirst()
        {
            var target = new X509Certificate2(@"files/linuxize.crt");

            CertificateList result = target.GetCertificateList();

            Assert.NotNull(result);
            Assert.True(result.ThisUpdate.ToDateTime() <= DateTime.UtcNow);
            Assert.True(result.NextUpdate.ToDateTime() >= DateTime.UtcNow);
        }
예제 #31
0
        private void AddCertificates(CertificateList uploadedCertificates, PublishContext context)
        {
            string name = context.ServiceName;
            CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null);
            if (cloudServiceProject.Components.CloudConfig.Role != null)
            {
                foreach (ConfigCertificate certElement in cloudServiceProject.Components.CloudConfig.Role.
                    SelectMany(r => r.Certificates ?? new ConfigCertificate[0]).Distinct())
                {
                    if (uploadedCertificates == null || (uploadedCertificates.Count(c => c.Thumbprint.Equals(
                        certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1))
                    {
                        X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint);
                        CertificateFile certFile = null;
                        try
                        {
                            certFile = new CertificateFile
                            {
                                Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)),
                                Password = string.Empty,
                                CertificateFormat = "pfx"
                            };
                        }
                        catch (CryptographicException exception)
                        {
                            throw new ArgumentException(string.Format(
                                Resources.CertificatePrivateKeyAccessError,
                                certElement.name), exception);
                        }

                        CallSync(() => ServiceManagementChannel.AddCertificates(subscriptionId, name, certFile));
                    }
                }
            }
        }
        /// <summary>
        /// Creates a CertificateList object. 
        /// </summary>
        public static CertificateList ToCertificateList(Opc.Ua.CertificateIdentifierCollection input)
        {
            CertificateList output = new CertificateList();

            if (input != null)
            {
                output.ValidationOptions = (int)0;
                output.Certificates = new ListOfCertificateIdentifier();

                for (int ii = 0; ii < input.Count; ii++)
                {
                    output.Certificates.Add(ToCertificateIdentifier(input[ii]));
                }
            }

            return output;
        }
        /// <summary>
        /// Creates a CertificateIdentifierCollection object. 
        /// </summary>
        public static Opc.Ua.CertificateIdentifierCollection FromCertificateList(CertificateList input)
        {
            Opc.Ua.CertificateIdentifierCollection output = new Opc.Ua.CertificateIdentifierCollection();

            if (input != null && input.Certificates != null)
            {
                for (int ii = 0; ii < input.Certificates.Count; ii++)
                {
                    output.Add(FromCertificateIdentifier(input.Certificates[ii]));
                }
            }

            return output;
        }
예제 #34
0
            if (certificate.ThumbprintAlgorithm != null)
            {
                Console.WriteLine("Certificate ThumbprintAlgorithm:{0}", certificate.ThumbprintAlgorithm);
            }

            if (certificate.Thumbprint != null)
            {
                Console.WriteLine("Certificate Thumbprint:{0}", certificate.Thumbprint);
            }

            if (certificate.Data != null)
예제 #35
0
        private void AddCertificates(CertificateList uploadedCertificates)
        {
            if (_azureService.Components.CloudConfig.Role != null)
            {
                foreach (ServiceConfigurationSchema.Certificate certElement in _azureService.Components.CloudConfig.Role.SelectMany(r => r.Certificates).Distinct())
                {
                    if (uploadedCertificates == null || (uploadedCertificates.Count<Certificate>(c => c.Thumbprint.Equals(
                        certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1))
                    {
                        X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint);
                        CertificateFile certFile = null;
                        try
                        {
                            certFile = new CertificateFile
                            {
                                Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)),
                                Password = string.Empty,
                                CertificateFormat = "pfx"
                            };
                        }
                        catch (CryptographicException exception)
                        {
                            throw new ArgumentException(string.Format(Resources.CertificatePrivateKeyAccessError, certElement.name), exception);
                        }

                        RetryCall(subscription => Channel.AddCertificates(subscription, _hostedServiceName, certFile));
                        WaitForCertificateToBeAdded(certElement);
                    }
                }
            }
        }
예제 #36
0
		/// <summary>Member CacheCertList </summary>
		/// <param name='list'> </param>
		public void CacheCertList(CertificateList list)
		{
			_certCache.Instance.CacheCertList(list._list.Instance);
		}