An identifier for a certificate.
        /// <summary>
        /// Creates a CertificateIdentifier object.
        /// </summary>
        public static Opc.Ua.CertificateIdentifier FromCertificateIdentifier(CertificateIdentifier input)
        {
            Opc.Ua.CertificateIdentifier output = new Opc.Ua.CertificateIdentifier();

            if (input != null)
            {
                output.StoreType         = input.StoreType;
                output.StorePath         = input.StorePath;
                output.SubjectName       = input.SubjectName;
                output.Thumbprint        = input.Thumbprint;
                output.ValidationOptions = (Opc.Ua.CertificateValidationOptions)input.ValidationOptions;
            }

            return(output);
        }
        /// <summary>
        /// Creates a CertificateIdentifier object.
        /// </summary>
        public static CertificateIdentifier ToCertificateIdentifier(Opc.Ua.CertificateIdentifier input)
        {
            if (input != null && !String.IsNullOrEmpty(input.StoreType) && !String.IsNullOrEmpty(input.StorePath))
            {
                CertificateIdentifier output = new CertificateIdentifier();

                output.StoreType             = input.StoreType;
                output.StorePath             = input.StorePath;
                output.SubjectName           = input.SubjectName;
                output.Thumbprint            = input.Thumbprint;
                output.ValidationOptions     = (int)input.ValidationOptions;
                output.OfflineRevocationList = null;
                output.OnlineRevocationList  = null;

                return(output);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private void OkBTN_Click(object sender, EventArgs e)
        {
            try
            {
                string storeType = null;
                string storePath = null;
                string applicationName = ApplicationNameTB.Text.Trim();
                string applicationUri = ApplicationUriTB.Text.Trim();
                string subjectName = SubjectNameTB.Text.Trim();
                string[] domainNames = null;

                string issuerKeyFilePath = IssuerKeyFilePathTB.Text.Trim();
                string issuerKeyFilePassword = IssuerPasswordTB.Text.Trim();

                if (!String.IsNullOrEmpty(issuerKeyFilePath))
                {
                    // verify certificate.
                    X509Certificate2 issuer = new X509Certificate2(
                        issuerKeyFilePath,
                        issuerKeyFilePassword,
                        X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet);

                    if (!issuer.HasPrivateKey)
                    {
                        throw new ApplicationException("Issuer certificate does not have a private key.");
                    }

                    // determine certificate type.
                    foreach (X509Extension extension in issuer.Extensions)
                    {
                        X509BasicConstraintsExtension basicContraints = extension as X509BasicConstraintsExtension;

                        if (basicContraints != null)
                        {
                            if (!basicContraints.CertificateAuthority)
                            {
                                throw new ApplicationException("Certificate cannot be used to issue new certificates.");
                            }
                        }
                    }
                }

                if (!String.IsNullOrEmpty(CertificateStoreCTRL.StorePath))
                {
                    storeType = CertificateStoreCTRL.StoreType;
                    storePath = CertificateStoreCTRL.StorePath;
                }

                domainNames = DomainsTB.Text.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

                if (String.IsNullOrEmpty(storePath))
                {
                    throw new ApplicationException("Please specify a store path.");
                }

                if (String.IsNullOrEmpty(applicationName))
                {
                    throw new ApplicationException("Please specify an application name.");
                }

                X509Certificate2 certificate = Opc.Ua.CertificateFactory.CreateCertificate(
                    storeType,
                    storePath,
                    null,
                    applicationUri,
                    applicationName,
                    subjectName,
                    domainNames,
                    Convert.ToUInt16(KeySizeCB.SelectedItem.ToString()),
                    DateTime.MinValue,
                    (ushort)LifeTimeInMonthsUD.Value,
                    0,
                    false,
                    (string)KeyFormatCB.SelectedItem == "PEM",
                    issuerKeyFilePath,
                    issuerKeyFilePassword);

                m_certificate = new CertificateIdentifier();
                m_certificate.StoreType = storeType;
                m_certificate.StorePath = storePath;
                m_certificate.Certificate = certificate;
                
                // close the dialog.
                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        /// <summary>
        /// Creates a CertificateIdentifier object. 
        /// </summary>
        public static Opc.Ua.CertificateIdentifier FromCertificateIdentifier(CertificateIdentifier input)
        {
            Opc.Ua.CertificateIdentifier output = new Opc.Ua.CertificateIdentifier();

            if (input != null)
            {
                output.StoreType = input.StoreType;
                output.StorePath = input.StorePath;
                output.SubjectName = input.SubjectName;
                output.Thumbprint = input.Thumbprint;
                output.ValidationOptions = (Opc.Ua.CertificateValidationOptions)input.ValidationOptions;
            }

            return output;
        }
        /// <summary>
        /// Creates a CertificateIdentifier object. 
        /// </summary>
        public static CertificateIdentifier ToCertificateIdentifier(Opc.Ua.CertificateIdentifier input)
        {
            if (input != null && !String.IsNullOrEmpty(input.StoreType) && !String.IsNullOrEmpty(input.StorePath))
            {
                CertificateIdentifier output = new CertificateIdentifier();

                output.StoreType = input.StoreType;
                output.StorePath = input.StorePath;
                output.SubjectName = input.SubjectName;
                output.Thumbprint = input.Thumbprint;
                output.ValidationOptions = (int)input.ValidationOptions;
                output.OfflineRevocationList = null;
                output.OnlineRevocationList = null;

                return output;
            }

            return null;
        }