The SignedDataObjectProperties element contains properties that qualify some of the signed data objects
Ejemplo n.º 1
0
        /// <summary>
        /// Load state from an XML element
        /// </summary>
        /// <param name="xmlElement">XML element containing new state</param>
        public void LoadXml(System.Xml.XmlElement xmlElement)
        {
            XmlNamespaceManager xmlNamespaceManager;
            XmlNodeList         xmlNodeList;

            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }
            if (xmlElement.HasAttribute("Id"))
            {
                this.id = xmlElement.GetAttribute("Id");
            }
            else
            {
                this.id = "";
            }

            xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable);
            xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri);

            xmlNodeList = xmlElement.SelectNodes("xsd:SignedSignatureProperties", xmlNamespaceManager);
            if (xmlNodeList.Count == 0)
            {
                throw new CryptographicException("SignedSignatureProperties element is missing");
            }
            this.signedSignatureProperties = new SignedSignatureProperties();
            this.signedSignatureProperties.LoadXml((XmlElement)xmlNodeList.Item(0));

            xmlNodeList = xmlElement.SelectNodes("xsd:SignedDataObjectProperties", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.signedDataObjectProperties = new SignedDataObjectProperties();
                this.signedDataObjectProperties.LoadXml((XmlElement)xmlNodeList.Item(0));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public SignedProperties()
 {
     this.id = DefaultSignedPropertiesId;             //This is where signature reference points to
     this.signedSignatureProperties  = new SignedSignatureProperties();
     this.signedDataObjectProperties = new SignedDataObjectProperties();
 }
Ejemplo n.º 3
0
        private void AddSignatureProperties(SignedSignatureProperties signedSignatureProperties, SignedDataObjectProperties signedDataObjectProperties,
                   UnsignedSignatureProperties unsignedSignatureProperties, string mimeType, X509Certificate2 certificado)
        {
            Cert cert;

            cert = new Cert();
            cert.IssuerSerial.X509IssuerName = certificado.IssuerName.Name;
            cert.IssuerSerial.X509SerialNumber = CertUtil.HexToDecimal(certificado.SerialNumber);
            DigestUtil.SetCertDigest(_signCertificate.GetRawCertData(), _refsMethodUri, cert.CertDigest);
            signedSignatureProperties.SigningCertificate.CertCollection.Add(cert);

            if (!string.IsNullOrEmpty(_policyId))
            {
                signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyImplied = false;
                signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyId.SigPolicyId.Identifier.IdentifierUri = _policyId;
            }

            if (!string.IsNullOrEmpty(_policyUri))
            {
                SigPolicyQualifier spq = new SigPolicyQualifier();
                spq.AnyXmlElement = _document.CreateElement("SPURI", XadesSignedXml.XadesNamespaceUri);
                spq.AnyXmlElement.InnerText = _policyUri;

                signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyId.SigPolicyQualifiers.SigPolicyQualifierCollection.Add(spq);
            }

            if (!string.IsNullOrEmpty(_policyHash))
            {
                signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyId.SigPolicyHash.DigestMethod.Algorithm = SignedXml.XmlDsigSHA1Url;
                signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyId.SigPolicyHash.DigestValue = Convert.FromBase64String(PolicyHash);
            }

            signedSignatureProperties.SigningTime = DateTime.Now;

            if (!string.IsNullOrEmpty(mimeType))
            {
                DataObjectFormat newDataObjectFormat = new DataObjectFormat();

                newDataObjectFormat.MimeType = mimeType;
                newDataObjectFormat.ObjectReferenceAttribute = "#" + _objectReference;

                signedDataObjectProperties.DataObjectFormatCollection.Add(newDataObjectFormat);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public SignedProperties()
 {
     this.id = DefaultSignedPropertiesId; //This is where signature reference points to
     this.signedSignatureProperties = new SignedSignatureProperties();
     this.signedDataObjectProperties = new SignedDataObjectProperties();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Load state from an XML element
        /// </summary>
        /// <param name="xmlElement">XML element containing new state</param>
        public void LoadXml(System.Xml.XmlElement xmlElement)
        {
            XmlNamespaceManager xmlNamespaceManager;
            XmlNodeList xmlNodeList;

            if (xmlElement == null)
            {
                throw new ArgumentNullException("xmlElement");
            }
            if (xmlElement.HasAttribute("Id"))
            {
                this.id = xmlElement.GetAttribute("Id");
            }
            else
            {
                this.id = "";
            }

            xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable);
            xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri);

            xmlNodeList = xmlElement.SelectNodes("xsd:SignedSignatureProperties", xmlNamespaceManager);
            if (xmlNodeList.Count == 0)
            {
                throw new CryptographicException("SignedSignatureProperties missing");
            }
            this.signedSignatureProperties = new SignedSignatureProperties();
            this.signedSignatureProperties.LoadXml((XmlElement)xmlNodeList.Item(0));

            xmlNodeList = xmlElement.SelectNodes("xsd:SignedDataObjectProperties", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.signedDataObjectProperties = new SignedDataObjectProperties();
                this.signedDataObjectProperties.LoadXml((XmlElement)xmlNodeList.Item(0));
            }
        }
Ejemplo n.º 6
0
        private void AddSignedSignatureProperties(SignedSignatureProperties signedSignatureProperties, SignedDataObjectProperties signedDataObjectProperties,
            UnsignedSignatureProperties unsignedSignatureProperties)
        {
            XmlDocument xmlDocument;
            Cert cert;

            xmlDocument = new XmlDocument();

            cert = new Cert();
            cert.IssuerSerial.X509IssuerName = this.Certificate.IssuerName.Name;
            cert.IssuerSerial.X509SerialNumber = this.Certificate.SerialNumber;
            cert.CertDigest.DigestMethod.Algorithm = SignedXml.XmlDsigSHA1Url;
            cert.CertDigest.DigestValue = this.Certificate.GetCertHash();
            signedSignatureProperties.SigningCertificate.CertCollection.Add(cert);

            signedSignatureProperties.SigningTime = DateTime.Parse(this.signingTimeTextBox.Text);

            signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyImplied = true;

            if (this.includeSignatureProductionPlaceCheckBox.Checked)
            {
                signedSignatureProperties.SignatureProductionPlace.City = this.signatureCityTextBox.Text;
                signedSignatureProperties.SignatureProductionPlace.StateOrProvince = this.signatureStateOrProvinceTextBox.Text;
                signedSignatureProperties.SignatureProductionPlace.PostalCode = this.signaturePostalCodeTextBox.Text;
                signedSignatureProperties.SignatureProductionPlace.CountryName = this.signatureCountryNameTextBox.Text;
            }

            if (this.includeSignerRoleCheckBox.Checked)
            {
                ClaimedRole newClaimedRole = new ClaimedRole();

                xmlDocument.LoadXml(this.claimedRoleTextBox.Text);
                newClaimedRole.AnyXmlElement = (XmlElement)xmlDocument.FirstChild;
                signedSignatureProperties.SignerRole.ClaimedRoles.ClaimedRoleCollection.Add(newClaimedRole);
            }

            if (this.includeCommitmentTypeIndicationCheckBox.Checked)
            {
                CommitmentTypeIndication newCommitmentTypeIndication = new CommitmentTypeIndication();

                newCommitmentTypeIndication.CommitmentTypeId.Identifier.IdentifierUri = this.commitmentTypeIdentifierURITextBox.Text;
                switch (this.commitmentTypeIndicatorQualifierComboBox.Text)
                {
                    case "":
                        newCommitmentTypeIndication.CommitmentTypeId.Identifier.Qualifier = KnownQualifier.Uninitalized;
                        break;
                    case "OIDAsURI":
                        newCommitmentTypeIndication.CommitmentTypeId.Identifier.Qualifier = KnownQualifier.OIDAsURI;
                        break;
                    case "OIDAsURN":
                        newCommitmentTypeIndication.CommitmentTypeId.Identifier.Qualifier = KnownQualifier.OIDAsURN;
                        break;
                }
                newCommitmentTypeIndication.CommitmentTypeId.Description = this.commitmentTypeIndicationIdTextBox.Text;
                newCommitmentTypeIndication.AllSignedDataObjects = true;

                signedDataObjectProperties.CommitmentTypeIndicationCollection.Add(newCommitmentTypeIndication);
            }

            if (this.includeDataObjectFormatCheckBox.Checked)
            {
                DataObjectFormat newDataObjectFormat = new DataObjectFormat();

                newDataObjectFormat.Description = this.dataObjectDescriptionTextBox.Text;
                newDataObjectFormat.MimeType = this.dataObjectFormatMimetypeTextBox.Text;
                newDataObjectFormat.ObjectReferenceAttribute = this.dataObjectReferenceTextBox.Text;
                signedDataObjectProperties.DataObjectFormatCollection.Add(newDataObjectFormat);
            }
        }
Ejemplo n.º 7
0
        private void AddSignedSignatureProperties(SignedSignatureProperties signedSignatureProperties,
            SignedDataObjectProperties signedDataObjectProperties,
            UnsignedSignatureProperties unsignedSignatureProperties,
            SignatureParameters parameters
            )
        {
            XmlDocument xmlDocument;
            Cert cert;
            SystemX509.X509Certificate2 x509Cert;

            x509Cert = DotNetUtilities.ToX509Certificate2(parameters.SigningCertificate);

            xmlDocument = new XmlDocument();

            cert = new Cert();
            cert.IssuerSerial.X509IssuerName = x509Cert.IssuerName.Name;
            cert.IssuerSerial.X509SerialNumber = x509Cert.SerialNumber;
            cert.CertDigest.DigestMethod.Algorithm = SignedXml.XmlDsigSHA1Url;
            cert.CertDigest.DigestValue = x509Cert.GetCertHash();
            signedSignatureProperties.SigningCertificate.CertCollection.Add(cert);

            signedSignatureProperties.SigningTime = parameters.SigningDate;

            signedSignatureProperties.SignaturePolicyIdentifier.SignaturePolicyImplied = true;

            DataObjectFormat newDataObjectFormat = new DataObjectFormat();

            //TODO jbonilla - Replace Description with text parameter
            newDataObjectFormat.Description = "Generado con 'intisign'";
            newDataObjectFormat.MimeType = "text/xml";
            newDataObjectFormat.ObjectReferenceAttribute = "#xml_ref_id";
            signedDataObjectProperties.DataObjectFormatCollection.Add(newDataObjectFormat);
        }