The SoftwareCertificate class.
Ejemplo n.º 1
0
        /// <summary cref="IEncodeable.IsEqual(IEncodeable)" />
        public virtual bool IsEqual(IEncodeable encodeable)
        {
            if (Object.ReferenceEquals(this, encodeable))
            {
                return(true);
            }

            SoftwareCertificate value = encodeable as SoftwareCertificate;

            if (value == null)
            {
                return(false);
            }

            if (!Utils.IsEqual(m_productName, value.m_productName))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_productUri, value.m_productUri))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_vendorName, value.m_vendorName))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_vendorProductCertificate, value.m_vendorProductCertificate))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_softwareVersion, value.m_softwareVersion))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_buildNumber, value.m_buildNumber))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_buildDate, value.m_buildDate))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_issuedBy, value.m_issuedBy))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_issueDate, value.m_issueDate))
            {
                return(false);
            }
            if (!Utils.IsEqual(m_supportedProfiles, value.m_supportedProfiles))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates a software certificate.
        /// </summary>
        public static ServiceResult Validate(
            CertificateValidator validator,
            byte[] signedCertificate, 
            out SoftwareCertificate softwareCertificate)
        {
            softwareCertificate = null;

            // validate the certificate.
            X509Certificate2 certificate = null;

            try
            {
                certificate = CertificateFactory.Create(signedCertificate, true);
                validator.Validate(certificate);
            }
            catch (Exception e)
            {
                return ServiceResult.Create(e, StatusCodes.BadDecodingError, "Could not decode software certificate body.");
            }

            // find the software certficate.
            byte[] encodedData = null;

            foreach (X509Extension extension in certificate.Extensions)
            {
                if (extension.Oid.Value == "0.0.0.0.0")
                {
                    encodedData = extension.RawData;
                    break;
                }
            }

            if (encodedData == null)
            {
                return ServiceResult.Create(StatusCodes.BadCertificateInvalid, "Could not find extension containing the software certficate.");
            }

            try
            {
                MemoryStream istrm = new MemoryStream(encodedData, false);
                DataContractSerializer serializer = new DataContractSerializer(typeof(SoftwareCertificate));
                softwareCertificate = (SoftwareCertificate)serializer.ReadObject(istrm);
                softwareCertificate.SignedCertificate = certificate;
            }
            catch (Exception e)
            {
                return ServiceResult.Create(e, StatusCodes.BadCertificateInvalid, "Certificate does not contain a valid SoftwareCertificate body.");
            }

            // certificate is valid.
            return ServiceResult.Good;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates a software certificate.
        /// </summary>
        public static ServiceResult Validate(
            CertificateValidator validator,
            byte[] signedCertificate,
            out SoftwareCertificate softwareCertificate)
        {
            softwareCertificate = null;

            // validate the certificate.
            X509Certificate2 certificate = null;

            try
            {
                certificate = CertificateFactory.Create(signedCertificate, true);
                validator.Validate(certificate);
            }
            catch (Exception e)
            {
                return(ServiceResult.Create(e, StatusCodes.BadDecodingError, "Could not decode software certificate body."));
            }

            // find the software certficate.
            byte[] encodedData = null;

            foreach (X509Extension extension in certificate.Extensions)
            {
                if (extension.Oid.Value == "0.0.0.0.0")
                {
                    encodedData = extension.RawData;
                    break;
                }
            }

            if (encodedData == null)
            {
                return(ServiceResult.Create(StatusCodes.BadCertificateInvalid, "Could not find extension containing the software certficate."));
            }

            try
            {
                MemoryStream           istrm      = new MemoryStream(encodedData, false);
                DataContractSerializer serializer = new DataContractSerializer(typeof(SoftwareCertificate));
                softwareCertificate = (SoftwareCertificate)serializer.ReadObject(istrm);
                softwareCertificate.SignedCertificate = certificate;
            }
            catch (Exception e)
            {
                return(ServiceResult.Create(e, StatusCodes.BadCertificateInvalid, "Certificate does not contain a valid SoftwareCertificate body."));
            }

            // certificate is valid.
            return(ServiceResult.Good);
        }
Ejemplo n.º 4
0
        /// <summary cref="ICloneable.Clone" />
        public virtual object Clone()
        {
            SoftwareCertificate clone = (SoftwareCertificate)this.MemberwiseClone();

            clone.m_productName = (string)Utils.Clone(this.m_productName);
            clone.m_productUri  = (string)Utils.Clone(this.m_productUri);
            clone.m_vendorName  = (string)Utils.Clone(this.m_vendorName);
            clone.m_vendorProductCertificate = (byte[])Utils.Clone(this.m_vendorProductCertificate);
            clone.m_softwareVersion          = (string)Utils.Clone(this.m_softwareVersion);
            clone.m_buildNumber       = (string)Utils.Clone(this.m_buildNumber);
            clone.m_buildDate         = (DateTime)Utils.Clone(this.m_buildDate);
            clone.m_issuedBy          = (string)Utils.Clone(this.m_issuedBy);
            clone.m_issueDate         = (DateTime)Utils.Clone(this.m_issueDate);
            clone.m_supportedProfiles = (SupportedProfileCollection)Utils.Clone(this.m_supportedProfiles);

            return(clone);
        }