Пример #1
0
        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)");
            }
        }
Пример #2
0
        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());
            }
        }