private void InjectXadesXInformation(XadesSignedXml xadesSignedXml) { TimeStamp xadesXTimeStamp; ArrayList signatureValueElementXpaths; byte[] signatureValueHash; byte[] tsaTimeStamp; signatureValueElementXpaths = new ArrayList(); signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:CompleteCertificateRefs"); signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:CompleteRevocationRefs"); signatureValueHash = ComputeHashValueOfElementList(xadesSignedXml.GetXml(), signatureValueElementXpaths); //jbonilla tsaTimeStamp = this.tspSource.GetTimeStampToken(signatureValueHash); xadesXTimeStamp = new TimeStamp("RefsOnlyTimeStamp"); xadesXTimeStamp.EncapsulatedTimeStamp.PkiData = tsaTimeStamp; xadesXTimeStamp.CanonicalizationMethod.Algorithm = SignedXml.XmlDsigExcC14NTransformUrl; //xadesXTimeStamp.EncapsulatedTimeStamp.Id = ""; //jbonilla Deprecated //foreach (string elementIdValue in elementIdValues) //{ // hashDataInfo = new HashDataInfo(); // hashDataInfo.UriAttribute = "#" + elementIdValue; // xadesXTimeStamp.HashDataInfoCollection.Add(hashDataInfo); //} UnsignedProperties unsignedProperties = xadesSignedXml.UnsignedProperties; unsignedProperties.UnsignedSignatureProperties.RefsOnlyTimeStampFlag = true; unsignedProperties.UnsignedSignatureProperties.RefsOnlyTimeStampCollection.Add(xadesXTimeStamp); xadesSignedXml.UnsignedProperties = unsignedProperties; }
public override void Upgrade() { TimeStamp signatureTimeStamp; ArrayList signatureValueElementXpaths; byte[] signatureValueHash; UnsignedProperties unsignedProperties = _firma.XadesSignature.UnsignedProperties; try { if (unsignedProperties.UnsignedSignatureProperties.SignatureTimeStampCollection.Count > 0) { throw new Exception("La firma ya contiene un sello de tiempo"); } signatureValueElementXpaths = new ArrayList(); signatureValueElementXpaths.Add("ds:SignatureValue"); signatureValueHash = DigestUtil.ComputeHashValue(XMLUtil.ComputeValueOfElementList(_firma.XadesSignature, signatureValueElementXpaths), DigestMethod.SHA1); byte[] tsa = TimeStampClient.GetTimeStamp(_firma.TSAServer, signatureValueHash, DigestMethod.SHA1, true); signatureTimeStamp = new TimeStamp("SignatureTimeStamp"); signatureTimeStamp.Id = "SignatureTimeStamp-" + _firma.XadesSignature.Signature.Id; signatureTimeStamp.EncapsulatedTimeStamp.PkiData = tsa; signatureTimeStamp.EncapsulatedTimeStamp.Id = "SignatureTimeStamp-" + Guid.NewGuid().ToString(); unsignedProperties.UnsignedSignatureProperties.SignatureTimeStampCollection.Add(signatureTimeStamp); _firma.XadesSignature.UnsignedProperties = unsignedProperties; _firma.UpdateDocument(); } catch (Exception ex) { throw new Exception("Ha ocurrido un error al insertar el sellado de tiempo.", ex); } }
private void TimeStampCertRefs() { TimeStamp xadesXTimeStamp; ArrayList signatureValueElementXpaths; byte[] signatureValueHash; XmlElement nodoFirma = _firma.XadesSignature.GetSignatureElement(); XmlNamespaceManager nm = new XmlNamespaceManager(_firma.Document.NameTable); nm.AddNamespace("xades", XadesSignedXml.XadesNamespaceUri); nm.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl); XmlNode xmlCompleteCertRefs = nodoFirma.SelectSingleNode("ds:Object/xades:QualifyingProperties/xades:UnsignedProperties/xades:UnsignedSignatureProperties/xades:CompleteCertificateRefs", nm); if (xmlCompleteCertRefs == null) { _firma.UpdateDocument(); } signatureValueElementXpaths = new ArrayList(); signatureValueElementXpaths.Add("ds:SignatureValue"); signatureValueElementXpaths.Add("ds:Object/xades:QualifyingProperties/xades:UnsignedProperties/xades:UnsignedSignatureProperties/xades:SignatureTimeStamp"); signatureValueElementXpaths.Add("ds:Object/xades:QualifyingProperties/xades:UnsignedProperties/xades:UnsignedSignatureProperties/xades:CompleteCertificateRefs"); signatureValueElementXpaths.Add("ds:Object/xades:QualifyingProperties/xades:UnsignedProperties/xades:UnsignedSignatureProperties/xades:CompleteRevocationRefs"); signatureValueHash = DigestUtil.ComputeHashValue(XMLUtil.ComputeValueOfElementList(_firma.XadesSignature, signatureValueElementXpaths), DigestMethod.SHA1); byte[] tsa = TimeStampClient.GetTimeStamp(_firma.TSAServer, signatureValueHash, DigestMethod.SHA1, true); xadesXTimeStamp = new TimeStamp("SigAndRefsTimeStamp"); xadesXTimeStamp.Id = "SigAndRefsStamp-" + _firma.XadesSignature.Signature.Id; xadesXTimeStamp.EncapsulatedTimeStamp.PkiData = tsa; xadesXTimeStamp.EncapsulatedTimeStamp.Id = "SigAndRefsStamp-" + Guid.NewGuid().ToString(); UnsignedProperties unsignedProperties = _firma.XadesSignature.UnsignedProperties; unsignedProperties.UnsignedSignatureProperties.RefsOnlyTimeStampFlag = false; unsignedProperties.UnsignedSignatureProperties.SigAndRefsTimeStampCollection.Add(xadesXTimeStamp); _firma.XadesSignature.UnsignedProperties = unsignedProperties; }
/// <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 TimeStamp Add(TimeStamp objectToAdd) { base.Add(objectToAdd); return objectToAdd; }
/// <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(); } } }
private void RequestTimeStamp(XadesSignedXml xadesSignedXml) { TimeStamp signatureTimeStamp; ArrayList signatureValueElementXpaths; byte[] signatureValueHash; byte[] tsaTimeStamp; signatureValueElementXpaths = new ArrayList(); signatureValueElementXpaths.Add("ds:SignatureValue"); signatureValueHash = ComputeHashValueOfElementList(xadesSignedXml.GetXml(), signatureValueElementXpaths); //jbonilla tsaTimeStamp = this.tspSource.GetTimeStampToken(signatureValueHash); signatureTimeStamp = new TimeStamp("SignatureTimeStamp"); //signatureTimeStamp.EncapsulatedTimeStamp.Id = "SignatureTimeStamp" + this.uid; signatureTimeStamp.EncapsulatedTimeStamp.PkiData = tsaTimeStamp; signatureTimeStamp.CanonicalizationMethod.Algorithm = SignedXml.XmlDsigExcC14NTransformUrl; //jbonilla Deprecated //HashDataInfo hashDataInfo = new HashDataInfo(); //hashDataInfo.UriAttribute = "#" + elementIdValues[0]; //signatureTimeStamp.HashDataInfoCollection.Add(hashDataInfo); UnsignedProperties unsignedProperties = xadesSignedXml.UnsignedProperties; unsignedProperties.UnsignedSignatureProperties.SignatureTimeStampCollection.Add(signatureTimeStamp); xadesSignedXml.UnsignedProperties = unsignedProperties; //TODO jbonilla - Delete? XmlElement xml = xadesSignedXml.XadesObject.GetXml(); XmlElement xml1 = xadesSignedXml.GetXml(); }
private void requestTimeStampButton_Click(object sender, System.EventArgs e) { TimeStamp signatureTimeStamp; HttpTsaClient httpTSAClient; KnownTsaResponsePkiStatus tsaResponsePkiStatus; ArrayList signatureValueElementXpaths; byte[] signatureValueHash; if (this.xadesSignedXml.SignatureStandard == KnownSignatureStandard.Xades) { try { httpTSAClient = new HttpTsaClient(); httpTSAClient.RequestTsaCertificate = this.tsaCertificateInResponseCheckBox.Checked; signatureValueElementXpaths = new ArrayList(); signatureValueElementXpaths.Add("ds:SignatureValue"); ArrayList elementIdValues = new ArrayList(); signatureValueHash = httpTSAClient.ComputeHashValueOfElementList(this.xadesSignedXml.GetXml(), signatureValueElementXpaths, ref elementIdValues); httpTSAClient.SendTsaWebRequest(this.tsaUriTextBox.Text, signatureValueHash); tsaResponsePkiStatus = httpTSAClient.ParseTsaResponse(); if (tsaResponsePkiStatus == KnownTsaResponsePkiStatus.Granted) { signatureTimeStamp = new TimeStamp("SignatureTimeStamp"); signatureTimeStamp.EncapsulatedTimeStamp.Id = this.signatureTimeStampIdTextBox.Text; signatureTimeStamp.EncapsulatedTimeStamp.PkiData = httpTSAClient.TsaTimeStamp; HashDataInfo hashDataInfo = new HashDataInfo(); hashDataInfo.UriAttribute = "#" + elementIdValues[0]; signatureTimeStamp.HashDataInfoCollection.Add(hashDataInfo); UnsignedProperties unsignedProperties = this.xadesSignedXml.UnsignedProperties; unsignedProperties.UnsignedSignatureProperties.SignatureTimeStampCollection.Add(signatureTimeStamp); this.xadesSignedXml.UnsignedProperties = unsignedProperties; XmlElement xml = this.xadesSignedXml.XadesObject.GetXml(); XmlElement xml1 = this.xadesSignedXml.GetXml(); this.ShowSignature(); } else { MessageBox.Show("TSA timestamp request not granted: " + tsaResponsePkiStatus.ToString()); } } catch (Exception exception) { MessageBox.Show("Exception occurred during TSA timestamp request: " + exception.ToString()); } } else { MessageBox.Show("Signature standard should be XAdES. (You need to add XAdES info before computing the signature to be able to inject a timestamp)"); } }
private void injectXadesXInformationButton_Click(object sender, System.EventArgs e) { TimeStamp xadesXTimeStamp; HttpTsaClient httpTSAClient; KnownTsaResponsePkiStatus tsaResponsePkiStatus; ArrayList signatureValueElementXpaths; ArrayList elementIdValues; byte[] signatureValueHash; HashDataInfo hashDataInfo; httpTSAClient = new HttpTsaClient(); httpTSAClient.RequestTsaCertificate = this.tsaCertificateInResponseCheckBox.Checked; signatureValueElementXpaths = new ArrayList(); if (this.sigAndRefsTimeStampRadioButton.Checked) { signatureValueElementXpaths.Add("ds:SignatureValue"); signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:SignatureTimeStamp/xsd:EncapsulatedTimeStamp"); signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:CompleteCertificateRefs"); signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:CompleteRevocationRefs"); } else { signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:CompleteCertificateRefs"); signatureValueElementXpaths.Add("ds:Object/xsd:QualifyingProperties/xsd:UnsignedProperties/xsd:UnsignedSignatureProperties/xsd:CompleteRevocationRefs"); } elementIdValues = new ArrayList(); signatureValueHash = httpTSAClient.ComputeHashValueOfElementList(this.xadesSignedXml.GetXml(), signatureValueElementXpaths, ref elementIdValues); httpTSAClient.SendTsaWebRequest(this.tsaUriTextBox.Text, signatureValueHash); tsaResponsePkiStatus = httpTSAClient.ParseTsaResponse(); if (tsaResponsePkiStatus == KnownTsaResponsePkiStatus.Granted) { if (this.sigAndRefsTimeStampRadioButton.Checked) { xadesXTimeStamp = new TimeStamp("SigAndRefsTimeStamp"); } else { xadesXTimeStamp = new TimeStamp("RefsOnlyTimeStamp"); } xadesXTimeStamp.EncapsulatedTimeStamp.PkiData = httpTSAClient.TsaTimeStamp; xadesXTimeStamp.EncapsulatedTimeStamp.Id = this.xadesXTimeStampIdTextBox.Text; foreach (string elementIdValue in elementIdValues) { hashDataInfo = new HashDataInfo(); hashDataInfo.UriAttribute = "#" + elementIdValue; xadesXTimeStamp.HashDataInfoCollection.Add(hashDataInfo); } UnsignedProperties unsignedProperties = this.xadesSignedXml.UnsignedProperties; if (this.sigAndRefsTimeStampRadioButton.Checked) { unsignedProperties.UnsignedSignatureProperties.RefsOnlyTimeStampFlag = false; unsignedProperties.UnsignedSignatureProperties.SigAndRefsTimeStampCollection.Add(xadesXTimeStamp); } else { unsignedProperties.UnsignedSignatureProperties.RefsOnlyTimeStampFlag = true; unsignedProperties.UnsignedSignatureProperties.RefsOnlyTimeStampCollection.Add(xadesXTimeStamp); } this.xadesSignedXml.UnsignedProperties = unsignedProperties; this.ShowSignature(); } else { MessageBox.Show("TSA timestamp request not granted: " + tsaResponsePkiStatus.ToString()); } }
private bool CheckHashDataInfosOfSigAndRefsTimeStamp(TimeStamp timeStamp) { UnsignedSignatureProperties unsignedSignatureProperties; bool signatureValueHashDataInfoFound = false; bool allSignatureTimeStampHashDataInfosFound = false; bool completeCertificateRefsHashDataInfoFound = false; bool completeRevocationRefsHashDataInfoFound = false; ArrayList signatureTimeStampIds = new ArrayList(); bool retVal = true; unsignedSignatureProperties = this.XadesObject.QualifyingProperties.UnsignedProperties.UnsignedSignatureProperties; foreach (TimeStamp signatureTimeStamp in unsignedSignatureProperties.SignatureTimeStampCollection) { signatureTimeStampIds.Add("#" + signatureTimeStamp.EncapsulatedTimeStamp.Id); } signatureTimeStampIds.Sort(); foreach (HashDataInfo hashDataInfo in timeStamp.HashDataInfoCollection) { if (hashDataInfo.UriAttribute == "#" + this.signatureValueId) { signatureValueHashDataInfoFound = true; } int signatureTimeStampIdIndex = signatureTimeStampIds.BinarySearch(hashDataInfo.UriAttribute); if (signatureTimeStampIdIndex >= 0) { signatureTimeStampIds.RemoveAt(signatureTimeStampIdIndex); } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CompleteCertificateRefs.Id) { completeCertificateRefsHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CompleteRevocationRefs.Id) { completeRevocationRefsHashDataInfoFound = true; } } if (signatureTimeStampIds.Count == 0) { allSignatureTimeStampHashDataInfosFound = true; } retVal = signatureValueHashDataInfoFound && allSignatureTimeStampHashDataInfosFound && completeCertificateRefsHashDataInfoFound && completeRevocationRefsHashDataInfoFound; return retVal; }
private bool CheckHashDataInfosOfRefsOnlyTimeStamp(TimeStamp timeStamp) { UnsignedSignatureProperties unsignedSignatureProperties; bool completeCertificateRefsHashDataInfoFound; bool completeRevocationRefsHashDataInfoFound; bool retVal; completeCertificateRefsHashDataInfoFound = false; completeRevocationRefsHashDataInfoFound = false; retVal = true; unsignedSignatureProperties = this.XadesObject.QualifyingProperties.UnsignedProperties.UnsignedSignatureProperties; foreach (HashDataInfo hashDataInfo in timeStamp.HashDataInfoCollection) { if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CompleteCertificateRefs.Id) { completeCertificateRefsHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CompleteRevocationRefs.Id) { completeRevocationRefsHashDataInfoFound = true; } } retVal = completeCertificateRefsHashDataInfoFound && completeRevocationRefsHashDataInfoFound; return retVal; }
private bool CheckHashDataInfosOfArchiveTimeStamp(TimeStamp timeStamp) { UnsignedSignatureProperties unsignedSignatureProperties; SignedProperties signedProperties; bool allReferenceHashDataInfosFound = false; bool signedInfoHashDataInfoFound = false; bool signedPropertiesHashDataInfoFound = false; bool signatureValueHashDataInfoFound = false; bool allSignatureTimeStampHashDataInfosFound = false; bool completeCertificateRefsHashDataInfoFound = false; bool completeRevocationRefsHashDataInfoFound = false; bool certificatesValuesHashDataInfoFound = false; bool revocationValuesHashDataInfoFound = false; bool allSigAndRefsTimeStampHashDataInfosFound = false; bool allRefsOnlyTimeStampHashDataInfosFound = false; bool allArchiveTimeStampHashDataInfosFound = false; bool allOlderArchiveTimeStampsFound = false; ArrayList referenceIds = new ArrayList(); ArrayList signatureTimeStampIds = new ArrayList(); ArrayList sigAndRefsTimeStampIds = new ArrayList(); ArrayList refsOnlyTimeStampIds = new ArrayList(); ArrayList archiveTimeStampIds = new ArrayList(); bool retVal = true; unsignedSignatureProperties = this.XadesObject.QualifyingProperties.UnsignedProperties.UnsignedSignatureProperties; signedProperties = this.XadesObject.QualifyingProperties.SignedProperties; foreach (Reference reference in this.Signature.SignedInfo.References) { if (reference.Uri != "#" + signedProperties.Id) { referenceIds.Add(reference.Uri); } } referenceIds.Sort(); foreach (TimeStamp signatureTimeStamp in unsignedSignatureProperties.SignatureTimeStampCollection) { signatureTimeStampIds.Add("#" + signatureTimeStamp.EncapsulatedTimeStamp.Id); } signatureTimeStampIds.Sort(); foreach (TimeStamp sigAndRefsTimeStamp in unsignedSignatureProperties.SigAndRefsTimeStampCollection) { sigAndRefsTimeStampIds.Add("#" + sigAndRefsTimeStamp.EncapsulatedTimeStamp.Id); } sigAndRefsTimeStampIds.Sort(); foreach (TimeStamp refsOnlyTimeStamp in unsignedSignatureProperties.RefsOnlyTimeStampCollection) { refsOnlyTimeStampIds.Add("#" + refsOnlyTimeStamp.EncapsulatedTimeStamp.Id); } refsOnlyTimeStampIds.Sort(); allOlderArchiveTimeStampsFound = false; for (int archiveTimeStampCounter = 0; !allOlderArchiveTimeStampsFound && (archiveTimeStampCounter < unsignedSignatureProperties.ArchiveTimeStampCollection.Count); archiveTimeStampCounter++) { TimeStamp archiveTimeStamp = unsignedSignatureProperties.ArchiveTimeStampCollection[archiveTimeStampCounter]; if (archiveTimeStamp.EncapsulatedTimeStamp.Id == timeStamp.EncapsulatedTimeStamp.Id) { allOlderArchiveTimeStampsFound = true; } else { archiveTimeStampIds.Add("#" + archiveTimeStamp.EncapsulatedTimeStamp.Id); } } archiveTimeStampIds.Sort(); foreach (HashDataInfo hashDataInfo in timeStamp.HashDataInfoCollection) { int index = referenceIds.BinarySearch(hashDataInfo.UriAttribute); if (index >= 0) { referenceIds.RemoveAt(index); } if (hashDataInfo.UriAttribute == "#" + this.signedInfoIdBuffer) { signedInfoHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + signedProperties.Id) { signedPropertiesHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + this.signatureValueId) { signatureValueHashDataInfoFound = true; } index = signatureTimeStampIds.BinarySearch(hashDataInfo.UriAttribute); if (index >= 0) { signatureTimeStampIds.RemoveAt(index); } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CompleteCertificateRefs.Id) { completeCertificateRefsHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CompleteRevocationRefs.Id) { completeRevocationRefsHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.CertificateValues.Id) { certificatesValuesHashDataInfoFound = true; } if (hashDataInfo.UriAttribute == "#" + unsignedSignatureProperties.RevocationValues.Id) { revocationValuesHashDataInfoFound = true; } index = sigAndRefsTimeStampIds.BinarySearch(hashDataInfo.UriAttribute); if (index >= 0) { sigAndRefsTimeStampIds.RemoveAt(index); } index = refsOnlyTimeStampIds.BinarySearch(hashDataInfo.UriAttribute); if (index >= 0) { refsOnlyTimeStampIds.RemoveAt(index); } index = archiveTimeStampIds.BinarySearch(hashDataInfo.UriAttribute); if (index >= 0) { archiveTimeStampIds.RemoveAt(index); } } if (referenceIds.Count == 0) { allReferenceHashDataInfosFound = true; } if (signatureTimeStampIds.Count == 0) { allSignatureTimeStampHashDataInfosFound = true; } if (sigAndRefsTimeStampIds.Count == 0) { allSigAndRefsTimeStampHashDataInfosFound = true; } if (refsOnlyTimeStampIds.Count == 0) { allRefsOnlyTimeStampHashDataInfosFound = true; } if (archiveTimeStampIds.Count == 0) { allArchiveTimeStampHashDataInfosFound = true; } retVal = allReferenceHashDataInfosFound && signedInfoHashDataInfoFound && signedPropertiesHashDataInfoFound && signatureValueHashDataInfoFound && allSignatureTimeStampHashDataInfosFound && completeCertificateRefsHashDataInfoFound && completeRevocationRefsHashDataInfoFound && certificatesValuesHashDataInfoFound && revocationValuesHashDataInfoFound && allSigAndRefsTimeStampHashDataInfosFound && allRefsOnlyTimeStampHashDataInfosFound && allArchiveTimeStampHashDataInfosFound; return retVal; }
private bool CheckHashDataInfosForTimeStamp(TimeStamp timeStamp) { bool retVal = true; for (int referenceCounter = 0; retVal == true && (referenceCounter < this.SignedInfo.References.Count); referenceCounter++) { string referenceId = ((Reference)this.SignedInfo.References[referenceCounter]).Id; string referenceUri = ((Reference)this.SignedInfo.References[referenceCounter]).Uri; if (referenceUri != ("#" + this.XadesObject.QualifyingProperties.SignedProperties.Id)) { bool hashDataInfoFound = false; for (int hashDataInfoCounter = 0; hashDataInfoFound == false && (hashDataInfoCounter < timeStamp.HashDataInfoCollection.Count); hashDataInfoCounter++) { HashDataInfo hashDataInfo = timeStamp.HashDataInfoCollection[hashDataInfoCounter]; hashDataInfoFound = (("#" + referenceId) == hashDataInfo.UriAttribute); } retVal = hashDataInfoFound; } } return retVal; }
private bool CheckHashDataInfosExist(TimeStamp timeStamp) { bool retVal = true; for (int hashDataInfoCounter = 0; retVal == true && (hashDataInfoCounter < timeStamp.HashDataInfoCollection.Count); hashDataInfoCounter++) { HashDataInfo hashDataInfo = timeStamp.HashDataInfoCollection[hashDataInfoCounter]; bool referenceFound = false; string referenceId; for (int referenceCounter = 0; referenceFound == false && (referenceCounter < this.SignedInfo.References.Count); referenceCounter++) { referenceId = ((Reference)this.SignedInfo.References[referenceCounter]).Id; if (("#" + referenceId) == hashDataInfo.UriAttribute) { referenceFound = true; } } retVal = referenceFound; } return retVal; }
private bool CheckHashDataInfoPointsToSignatureValue(TimeStamp timeStamp) { bool retVal = true; foreach (HashDataInfo hashDataInfo in timeStamp.HashDataInfoCollection) { retVal &= (hashDataInfo.UriAttribute == ("#" + this.signatureValueId)); } return retVal; }
/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> /// <param name="counterSignedXmlElement">Element containing parent signature (needed if there are counter signatures)</param> public void LoadXml(System.Xml.XmlElement xmlElement, XmlElement counterSignedXmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; IEnumerator enumerator; XmlElement iterationXmlElement; XadesSignedXml newXadesSignedXml; TimeStamp newTimeStamp; XmlElement counterSignatureElement; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri); this.counterSignatureCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:CounterSignature", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { if (counterSignedXmlElement != null) { newXadesSignedXml = new XadesSignedXml(counterSignedXmlElement); } else { newXadesSignedXml = new XadesSignedXml(); } //Skip any whitespace at start counterSignatureElement = null; for (int childNodeCounter = 0; (childNodeCounter < iterationXmlElement.ChildNodes.Count) && (counterSignatureElement == null); childNodeCounter++) { if (iterationXmlElement.ChildNodes[childNodeCounter] is XmlElement) { counterSignatureElement = (XmlElement)iterationXmlElement.ChildNodes[childNodeCounter]; } } if (counterSignatureElement != null) { newXadesSignedXml.LoadXml(counterSignatureElement); this.counterSignatureCollection.Add(newXadesSignedXml); } else { throw new CryptographicException("CounterSignature element does not contain signature"); } } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.signatureTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:SignatureTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("SignatureTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.signatureTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } xmlNodeList = xmlElement.SelectNodes("xsd:CompleteCertificateRefs", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.completeCertificateRefs = new CompleteCertificateRefs(); this.completeCertificateRefs.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.completeCertificateRefs = null; } xmlNodeList = xmlElement.SelectNodes("xsd:CompleteRevocationRefs", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.CompleteRevocationRefs = new CompleteRevocationRefs(); this.CompleteRevocationRefs.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.completeRevocationRefs = null; } this.sigAndRefsTimeStampCollection.Clear(); this.refsOnlyTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:SigAndRefsTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count > 0) { this.refsOnlyTimeStampFlag = false; enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("SigAndRefsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.sigAndRefsTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { xmlNodeList = xmlElement.SelectNodes("xsd:RefsOnlyTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count > 0) { this.refsOnlyTimeStampFlag = true; enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("RefsOnlyTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.refsOnlyTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { this.refsOnlyTimeStampFlag = false; } } xmlNodeList = xmlElement.SelectNodes("xsd:CertificateValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.certificateValues = new CertificateValues(); this.certificateValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.certificateValues = null; } xmlNodeList = xmlElement.SelectNodes("xsd:RevocationValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.revocationValues = new RevocationValues(); this.revocationValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.revocationValues = null; } this.archiveTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:ArchiveTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("ArchiveTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.archiveTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }