Ejemplo n.º 1
0
        public KnownTsaResponsePkiStatus ParseTsaResponse()
        {
            Asn1Parser asn1Parser;
            XmlNode    pkiStatusXmlNode;
            string     pkiStatusValue;
            XmlNode    timeStampXmlNode;
            KnownTsaResponsePkiStatus retVal;

            retVal = KnownTsaResponsePkiStatus.Waiting;
            if (this.rawTsaResponse == null)
            {
                throw new Exception("There is no response to parse, call SendTsaWebRequest first");
            }
            asn1Parser = new Asn1Parser();
            asn1Parser.ParseAsn1(this.rawTsaResponse);
            pkiStatusXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/Universal_Primitive_Integer");
            if (pkiStatusXmlNode != null)
            {
                pkiStatusValue = pkiStatusXmlNode.Attributes["Value"].Value;
                retVal         = (KnownTsaResponsePkiStatus)(int.Parse(pkiStatusValue));
            }
            else
            {
                throw new Exception("Parse error TSA response: can't find PkiStatus");
            }

            if (retVal == KnownTsaResponsePkiStatus.Granted)
            {
                //timeStampXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/ContextSpecific_Constructed_A0/RawData[../../Universal_Primitive_Oid/@Value=\"1.2.840.113549.1.7.2\"]");
                timeStampXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/RawData[../Universal_Primitive_Oid/@Value=\"1.2.840.113549.1.7.2\"]");
                if (timeStampXmlNode != null)
                {
                    this.tsaTimeStamp = Convert.FromBase64String(timeStampXmlNode.InnerText);
                }
                else
                {
                    throw new Exception("Parse error TSA response: can't find TSA TimeStamp (OID=1.2.840.113549.1.7.2)");
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        private void injectXadesCInformationButton_Click(object sender, System.EventArgs e)
        {
            UnsignedProperties unsignedProperties = null;
            Cert chainCert = null;
            SHA1 sha1Managed;
            byte[] crlDigest;
            CRLRef incCRLRef;

            if (this.includeCertificateChainCheckBox.Checked)
            {
                if (this.Chain != null)
                {
                    unsignedProperties = this.xadesSignedXml.UnsignedProperties;
                    unsignedProperties.UnsignedSignatureProperties.CompleteCertificateRefs = new CompleteCertificateRefs();

                    foreach (X509ChainElement element in this.Chain.ChainElements)
                    {
                        chainCert = new Cert();
                        chainCert.IssuerSerial.X509IssuerName = element.Certificate.IssuerName.Name;
                        chainCert.IssuerSerial.X509SerialNumber = element.Certificate.SerialNumber;
                        chainCert.CertDigest.DigestMethod.Algorithm = SignedXml.XmlDsigSHA1Url;
                        chainCert.CertDigest.DigestValue = this.Certificate.GetCertHash();
                        unsignedProperties.UnsignedSignatureProperties.CompleteCertificateRefs.Id = this.completeCertificateRefsTextBox.Text;
                        unsignedProperties.UnsignedSignatureProperties.CompleteCertificateRefs.CertRefs.CertCollection.Add(chainCert);
                    }

                    this.xadesSignedXml.UnsignedProperties = unsignedProperties;
                }
                else
                {
                    MessageBox.Show("The certificate chain was not accepted, can't add certificate chain information to CompleteCertificateRefs element");
                }
            }

            if (this.includeCrlCheckBox.Checked)
            { //In this sample we will load the CRL from file on a CRL archive.
                Stream crlStream = File.OpenRead(this.crlFileTextBox.Text);
                sha1Managed = new SHA1Managed();
                crlDigest = sha1Managed.ComputeHash(crlStream);
                crlStream.Close();

                incCRLRef = new CRLRef();
                incCRLRef.CertDigest.DigestMethod.Algorithm = SignedXml.XmlDsigSHA1Url;
                incCRLRef.CertDigest.DigestValue = crlDigest;
                incCRLRef.CRLIdentifier.UriAttribute = this.crlFileTextBox.Text;

                Asn1Parser asn1Parser;
                asn1Parser = new Asn1Parser();
                asn1Parser.ParseAsn1(this.GetFileBytes(this.crlFileTextBox.Text));
                XmlNode searchXmlNode;
                searchXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/Universal_Constructed_Sequence/Universal_Constructed_Set/Universal_Constructed_Sequence/Universal_Primitive_PrintableString");
                if (searchXmlNode != null)
                {
                    incCRLRef.CRLIdentifier.Issuer = searchXmlNode.Attributes["Value"].Value;
                }
                else
                {
                    throw new Exception("Parse error TSA response: can't find Issuer in CRL");
                }
                searchXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/Universal_Primitive_UtcTime");
                if (searchXmlNode != null)
                {
                    incCRLRef.CRLIdentifier.IssueTime = DateTime.Parse(searchXmlNode.Attributes["Value"].Value);
                }
                else
                {
                    throw new Exception("Parse error TSA response: can't find IssueTime in CRL");
                }

                unsignedProperties = this.xadesSignedXml.UnsignedProperties;
                unsignedProperties.UnsignedSignatureProperties.CompleteRevocationRefs = new CompleteRevocationRefs();
                unsignedProperties.UnsignedSignatureProperties.CompleteRevocationRefs.Id = this.completeRevocationRefsIdTextBox.Text;
                unsignedProperties.UnsignedSignatureProperties.CompleteRevocationRefs.CRLRefs.CRLRefCollection.Add(incCRLRef);
                this.xadesSignedXml.UnsignedProperties = unsignedProperties;
            }

            if (this.includeCrlCheckBox.Checked || this.includeCertificateChainCheckBox.Checked)
            {
                this.ShowSignature();
            }
        }
Ejemplo n.º 3
0
		public KnownTsaResponsePkiStatus ParseTsaResponse()
		{
			Asn1Parser asn1Parser;
			XmlNode pkiStatusXmlNode;
			string pkiStatusValue;
			XmlNode timeStampXmlNode;
			KnownTsaResponsePkiStatus retVal;

			retVal = KnownTsaResponsePkiStatus.Waiting;
			if (this.rawTsaResponse == null)
			{
				throw new Exception("There is no response to parse, call SendTsaWebRequest first");
			}
			asn1Parser = new Asn1Parser();
			asn1Parser.ParseAsn1(this.rawTsaResponse);
			pkiStatusXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/Universal_Primitive_Integer");
			if (pkiStatusXmlNode != null)
			{
				pkiStatusValue = pkiStatusXmlNode.Attributes["Value"].Value;
				retVal = (KnownTsaResponsePkiStatus)(int.Parse(pkiStatusValue));
			}
			else
			{
				throw new Exception("Parse error TSA response: can't find PkiStatus");
			}

			if (retVal == KnownTsaResponsePkiStatus.Granted)
			{
				//timeStampXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/ContextSpecific_Constructed_A0/RawData[../../Universal_Primitive_Oid/@Value=\"1.2.840.113549.1.7.2\"]");
                timeStampXmlNode = asn1Parser.ParseTree.SelectSingleNode("//Universal_Constructed_Sequence/Universal_Constructed_Sequence/RawData[../Universal_Primitive_Oid/@Value=\"1.2.840.113549.1.7.2\"]");
                if (timeStampXmlNode != null)
				{
					this.tsaTimeStamp = Convert.FromBase64String(timeStampXmlNode.InnerText);
				}
				else
				{
					throw new Exception("Parse error TSA response: can't find TSA TimeStamp (OID=1.2.840.113549.1.7.2)");
				}
			}

			return retVal;
		}