The DataObjectFormat element provides information that describes the format of the signed data object. This element must be present when it is mandatory to present the signed data object to human users on verification. This is a signed property that qualifies one specific signed data object. In consequence, a XAdES signature may contain more than one DataObjectFormat elements, each one qualifying one signed data object.
예제 #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;
			IEnumerator enumerator;
			XmlElement iterationXmlElement;
			DataObjectFormat newDataObjectFormat;
			CommitmentTypeIndication newCommitmentTypeIndication;
			TimeStamp newTimeStamp;
			
			if (xmlElement == null)
			{
				throw new ArgumentNullException("xmlElement");
			}

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

			this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:DataObjectFormat", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newDataObjectFormat = new DataObjectFormat();
						newDataObjectFormat.LoadXml(iterationXmlElement);
						this.dataObjectFormatCollection.Add(newDataObjectFormat);
					}
				}
			}
			finally 
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}

			this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeIndication", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newCommitmentTypeIndication = new CommitmentTypeIndication();
						newCommitmentTypeIndication.LoadXml(iterationXmlElement);
						this.commitmentTypeIndicationCollection.Add(newCommitmentTypeIndication);
					}
				}
			}
			finally 
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}

			this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:AllDataObjectsTimeStamp", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newTimeStamp = new TimeStamp("AllDataObjectsTimeStamp");
						newTimeStamp.LoadXml(iterationXmlElement);
						this.allDataObjectsTimeStampCollection.Add(newTimeStamp);
					}
				}
			}
			finally 
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}

			this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:IndividualDataObjectsTimeStamp", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newTimeStamp = new TimeStamp("IndividualDataObjectsTimeStamp");
						newTimeStamp.LoadXml(iterationXmlElement);
						this.individualDataObjectsTimeStampCollection.Add(newTimeStamp);
					}
				}
			}
			finally 
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
		}
예제 #2
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;
			IEnumerator enumerator;
			XmlElement iterationXmlElement;
			DataObjectFormat newDataObjectFormat;
			CommitmentTypeIndication newCommitmentTypeIndication;
			TimeStamp newTimeStamp;
			
			if (xmlElement == null)
			{
				throw new ArgumentNullException(nameof(xmlElement));
			}

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

			this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:DataObjectFormat", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newDataObjectFormat = new DataObjectFormat();
						newDataObjectFormat.LoadXml(iterationXmlElement);
						this.dataObjectFormatCollection.Add(newDataObjectFormat);
					}
				}
			}
			finally 
			{
                if (enumerator is IDisposable disposable)
                    disposable.Dispose();
            }

			//this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeIndication", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newCommitmentTypeIndication = new CommitmentTypeIndication();
						newCommitmentTypeIndication.LoadXml(iterationXmlElement);
						this.commitmentTypeIndicationCollection.Add(newCommitmentTypeIndication);
					}
				}
			}
			finally 
			{
                if (enumerator is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }

			//this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:AllDataObjectsTimeStamp", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newTimeStamp = new TimeStamp("AllDataObjectsTimeStamp");
						newTimeStamp.LoadXml(iterationXmlElement);
						this.allDataObjectsTimeStampCollection.Add(newTimeStamp);
					}
				}
			}
			finally 
			{
                if (enumerator is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }

			//this.dataObjectFormatCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:IndividualDataObjectsTimeStamp", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newTimeStamp = new TimeStamp("IndividualDataObjectsTimeStamp");
						newTimeStamp.LoadXml(iterationXmlElement);
						this.individualDataObjectsTimeStampCollection.Add(newTimeStamp);
					}
				}
			}
			finally 
			{
                if (enumerator is IDisposable disposable)
                    disposable.Dispose();
            }
		}
예제 #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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        /// <summary>
        /// Add typed object to the collection
        /// </summary>
        /// <param name="objectToAdd">Typed object to be added to collection</param>
        /// <returns>The object that has been added to collection</returns>
        public DataObjectFormat Add(DataObjectFormat objectToAdd)
        {
            base.Add(objectToAdd);

            return(objectToAdd);
        }
예제 #6
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);
        }
        /// <summary>
        /// Add typed object to the collection
        /// </summary>
        /// <param name="objectToAdd">Typed object to be added to collection</param>
        /// <returns>The object that has been added to collection</returns>
        public DataObjectFormat Add(DataObjectFormat objectToAdd)
        {
            base.Add(objectToAdd);

            return objectToAdd;
        }