コード例 #1
0
ファイル: Reference.cs プロジェクト: silegis-mg/XAdES-Signer
        public void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if ((value.LocalName != XmlSignature.ElementNames.Reference) || (value.NamespaceURI != XmlSignature.NamespaceURI))
            {
                throw new CryptographicException();
            }

            id   = GetAttribute(value, XmlSignature.AttributeNames.Id);
            uri  = GetAttribute(value, XmlSignature.AttributeNames.URI);
            type = GetAttribute(value, XmlSignature.AttributeNames.Type);
            // Note: order is important for validations
            XmlNodeList xnl = value.GetElementsByTagName(XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI);

            if ((xnl != null) && (xnl.Count > 0))
            {
                Transform t = null;
                foreach (XmlNode xn in xnl)
                {
                    string a = GetAttribute((XmlElement)xn, XmlSignature.AttributeNames.Algorithm);

                    t = TransformFactory.fromURI(a);

                    if (t == null)
                    {
                        throw new CryptographicException("Unknown transform {0}.", a);
                    }

                    if (xn.ChildNodes.Count > 0)
                    {
                        t.LoadInnerXml(xn.ChildNodes);
                    }
                    AddTransform(t);
                }
            }
            // get DigestMethod
            DigestMethod = XmlSignature.GetAttributeFromElement(value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.DigestMethod);
            // get DigestValue
            XmlElement dig = XmlSignature.GetChildElement(value, XmlSignature.ElementNames.DigestValue, XmlSignature.NamespaceURI);

            if (dig != null)
            {
                DigestValue = Convert.FromBase64String(dig.InnerText);
            }
            element = value;
        }
コード例 #2
0
ファイル: SignedInfo.cs プロジェクト: silegis-mg/XAdES-Signer
        public void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if ((value.LocalName != XmlSignature.ElementNames.SignedInfo) || (value.NamespaceURI != XmlSignature.NamespaceURI))
            {
                throw new CryptographicException();
            }

            id         = GetAttribute(value, XmlSignature.AttributeNames.Id);
            c14nMethod = XmlSignature.GetAttributeFromElement(value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.CanonicalizationMethod);

            XmlElement sm = XmlSignature.GetChildElement(value, XmlSignature.ElementNames.SignatureMethod, XmlSignature.NamespaceURI);

            if (sm != null)
            {
                signatureMethod = sm.GetAttribute(XmlSignature.AttributeNames.Algorithm);
                XmlElement length = XmlSignature.GetChildElement(sm, XmlSignature.ElementNames.HMACOutputLength, XmlSignature.NamespaceURI);
                if (length != null)
                {
                    signatureLength = length.InnerText;
                }
            }

            for (int i = 0; i < value.ChildNodes.Count; i++)
            {
                XmlNode n = value.ChildNodes [i];
                if (n.NodeType == XmlNodeType.Element &&
                    n.LocalName == XmlSignature.ElementNames.Reference &&
                    n.NamespaceURI == XmlSignature.NamespaceURI)
                {
                    Reference r = new Reference();
                    r.LoadXml((XmlElement)n);
                    AddReference(r);
                }
            }
            element = value;
        }
コード例 #3
0
        public override void LoadXml(XmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (IssuerSerialList != null)
            {
                IssuerSerialList.Clear();
            }
            if (SubjectKeyIdList != null)
            {
                SubjectKeyIdList.Clear();
            }
            if (SubjectNameList != null)
            {
                SubjectNameList.Clear();
            }
            if (X509CertificateList != null)
            {
                X509CertificateList.Clear();
            }
            x509crl = null;

            if ((element.LocalName != XmlSignature.ElementNames.X509Data) || (element.NamespaceURI != XmlSignature.NamespaceURI))
            {
                throw new CryptographicException("element");
            }

            XmlElement [] xnl = null;
            // <X509IssuerSerial>
            xnl = XmlSignature.GetChildElements(element, XmlSignature.ElementNames.X509IssuerSerial);
            if (xnl != null)
            {
                for (int i = 0; i < xnl.Length; i++)
                {
                    XmlElement xel    = (XmlElement)xnl[i];
                    XmlElement issuer = XmlSignature.GetChildElement(xel, XmlSignature.ElementNames.X509IssuerName, XmlSignature.NamespaceURI);
                    XmlElement serial = XmlSignature.GetChildElement(xel, XmlSignature.ElementNames.X509SerialNumber, XmlSignature.NamespaceURI);
                    AddIssuerSerial(issuer.InnerText, serial.InnerText);
                }
            }
            // <X509SKI>
            xnl = XmlSignature.GetChildElements(element, XmlSignature.ElementNames.X509SKI);
            if (xnl != null)
            {
                for (int i = 0; i < xnl.Length; i++)
                {
                    byte[] skid = Convert.FromBase64String(xnl[i].InnerXml);
                    AddSubjectKeyId(skid);
                }
            }
            // <X509SubjectName>
            xnl = XmlSignature.GetChildElements(element, XmlSignature.ElementNames.X509SubjectName);
            if (xnl != null)
            {
                for (int i = 0; i < xnl.Length; i++)
                {
                    AddSubjectName(xnl[i].InnerXml);
                }
            }
            // <X509Certificate>
            xnl = XmlSignature.GetChildElements(element, XmlSignature.ElementNames.X509Certificate);
            if (xnl != null)
            {
                for (int i = 0; i < xnl.Length; i++)
                {
                    byte[] cert = Convert.FromBase64String(xnl[i].InnerXml);
                    AddCertificate(new X509CertificateParser().ReadCertificate(cert));
                }
            }
            // only one <X509CRL>
            XmlElement x509el = XmlSignature.GetChildElement(element, XmlSignature.ElementNames.X509CRL, XmlSignature.NamespaceURI);

            if (x509el != null)
            {
                x509crl = Convert.FromBase64String(x509el.InnerXml);
            }
        }