private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.ClassCode = ndhp.GetAttributeString("claim:classCode"); this.ClassCodeTableId = ndhp.GetAttributeString("claim:classCodeId"); this.ClassName = ndhp.GetNodeText("claim:className"); this.AdministrationCode = ndhp.GetChildNodeAttributeString("claim:administration", "claim:adminCode"); this.AdministrationCodeTableId = ndhp.GetChildNodeAttributeString("claim:administration", "claim:adminCodeId"); this.AdministrationMemo = ndhp.GetNodeText("admMemo"); this.BundleNumber = ndhp.GetNodeTextToInteger("claim:bundleNumber", 1); this.DetailList = new List <BundleDetailItem>(); foreach (XmlNode dtnode in ndhp.SelectNodes("claim:item")) { BundleDetailItem dt = new BundleDetailItem(dtnode); this.DetailList.Add(dt); } this.Memo = ndhp.GetNodeText("claim:memo"); }
public void TestOuterXml ( ) { this.tracer.WriteLine ( "测试属性 OuterXml" ); try { XmlNodeHelper<XmlNode> nodeClass = new XmlNodeHelper<XmlNode> ( "class" ); nodeClass["name"] = "1.1"; nodeClass["color"] = Color.Red; XmlNodeHelper<XmlNode> nodeStudent1 = new XmlNodeHelper<XmlNode> ( "student" ); nodeStudent1["name"] = "小明"; nodeStudent1["age"] = 12; XmlNodeHelper<XmlNode> nodeStudent2 = new XmlNodeHelper<XmlNode> ( "student" ); nodeStudent2["name"] = "小红"; nodeStudent2["age"] = 11; nodeClass.ChildNodeHelpers.Add ( nodeStudent1 ); nodeClass.ChildNodeHelpers.Add ( nodeStudent2 ); this.tracer.WriteLine ( nodeClass.OuterXml ); } catch ( Exception err ) { this.tracer.WriteLine ( string.Format ( "异常: {0}", err.Message ) ); } this.tracer.WaitPressEnter ( ); }
public void TestOuterXml( ) { this.tracer.WriteLine("测试属性 OuterXml"); try { XmlNodeHelper <XmlNode> nodeClass = new XmlNodeHelper <XmlNode> ("class"); nodeClass["name"] = "1.1"; nodeClass["color"] = Color.Red; XmlNodeHelper <XmlNode> nodeStudent1 = new XmlNodeHelper <XmlNode> ("student"); nodeStudent1["name"] = "小明"; nodeStudent1["age"] = 12; XmlNodeHelper <XmlNode> nodeStudent2 = new XmlNodeHelper <XmlNode> ("student"); nodeStudent2["name"] = "小红"; nodeStudent2["age"] = 11; nodeClass.ChildNodeHelpers.Add(nodeStudent1); nodeClass.ChildNodeHelpers.Add(nodeStudent2); this.tracer.WriteLine(nodeClass.OuterXml); } catch (Exception err) { this.tracer.WriteLine(string.Format("异常: {0}", err.Message)); } this.tracer.WaitPressEnter( ); }
private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.Text = ndhp.Node.InnerText; }
private X509Certificate GetSignerCertificate(XmlDocument xmlDoc) { X509Certificate signerCertificate = null; try { TimeStampToken token = XmlNodeHelper.GetTimeStampToken(xmlDoc); var certificates = token.GetCertificates("Collection").GetMatches(null).Cast <X509Certificate>().ToList(); foreach (X509Certificate certificate in certificates) { string cerIssuerName = certificate.IssuerDN.ToString(true, new Dictionary <string, string>()); string signerIssuerName = token.SignerID.Issuer.ToString(true, new Dictionary <string, string>()); if (cerIssuerName == signerIssuerName && certificate.SerialNumber.Equals(token.SignerID.SerialNumber)) { signerCertificate = certificate; break; } } } catch (Exception) { } return(signerCertificate); }
/// <summary> /// Generates the list of "RulesModel" for each issue /// </summary> /// <param name="xmlDocument">The xml document that has the list of data</param> private void GenerateRuleTreeList(XmlDocument xmlDocument) { var rules = xmlDocument.GetElementsByTagName("Rule"); foreach (XmlNode rule in rules) { var ruleModel = new RuleModel(xmlDocument.BaseURI) { TypeName = XmlNodeHelper.GetNodeAttributeValue(rule, "TypeName"), Category = XmlNodeHelper.GetNodeAttributeValue(rule, "Category"), CheckId = XmlNodeHelper.GetNodeAttributeValue(rule, "CheckId"), Name = rule["Name"]?.InnerText, Description = rule["Description"]?.InnerText, Resolution = new ResolutionModel { Name = XmlNodeHelper.GetNodeAttributeValue(rule["Resolution"], "Name"), Text = rule["Resolution"]?.InnerText }, Owner = rule["Owner"]?.InnerText, Url = rule["Url"]?.InnerText, MessageLevel = new MessageLevelModel { Certainty = Convert.ToInt32(XmlNodeHelper.GetNodeAttributeValue(rule["MessageLevel"], "Certainty") ?? "0"), Text = rule["MessageLevel"]?.InnerText } }; ruleModelList.Add(ruleModel); } }
private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.SubClassCode = ndhp.GetAttributeString("claim:subclassCode"); this.SubClassCodeTableId = ndhp.GetAttributeString("claim:subclassCodeId"); this.Code = ndhp.GetAttributeString("claim:code"); this.CodeTableId = ndhp.GetAttributeString("claim:tableId"); this.AliasCode = ndhp.GetAttributeString("claim:aliasCode"); this.AliasCodeTableId = ndhp.GetAttributeString("claim:aliasTableId"); this.Name = ndhp.GetNodeText("claim:name"); this.NumberList = new List <NumberItem>(); foreach (XmlNode subnd in ndhp.SelectNodes("claim:number")) { NumberItem numitm = new NumberItem(subnd); this.NumberList.Add(numitm); } string tmpstr = ndhp.GetNodeText("claim:duration"); this.Duration = new TimeSpan(0, 0, 0); if (tmpstr != null) { //書式PTnHnM tmpstr = tmpstr.Replace("RT", ""); tmpstr = tmpstr.Replace("M", ""); tmpstr = tmpstr.Replace("H", ":"); string[] tm = tmpstr.Split(':'); if (tm.Length == 2) { this.Duration = new TimeSpan(int.Parse(tm[0]), int.Parse(tm[1]), 0); } } this.LocationList = new List <LocationItem>(); foreach (XmlNode subnd in ndhp.SelectNodes("claim:location")) { LocationItem numitm = new LocationItem(subnd); this.LocationList.Add(numitm); } this.FilmList = new List <FilmItem>(); foreach (XmlNode subnd in ndhp.SelectNodes("claim:film")) { FilmItem numitm = new FilmItem(subnd); this.FilmList.Add(numitm); } this.Event = new EventItem(ndhp.GetNode("claim:event")); this.Memo = ndhp.GetNodeText("claim:memo"); }
private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.StartDate = ndhp.GetAttributeDate("claim:eventStart", DateTime.MinValue); this.EndDate = ndhp.GetAttributeDate("claim:eventEnd", DateTime.MinValue); this.Text = ndhp.Node.InnerText; }
private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.SizeCode = ndhp.GetChildNodeAttributeString("claim:filmSize", "claim:sizeCode"); this.SizeCodeTableId = ndhp.GetChildNodeAttributeString("claim:filmSize", "claim:sizeCodeId"); this.FilmDivision = ndhp.GetChildNodeAttributeString("claim:filmSize", "claim:filmDivision"); this.FilmName = ndhp.GetNodeText("claim:filmSize"); this.FilmNumber = ndhp.GetNodeTextToInteger("claim:filmNumber", 0); }
private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.Code = ndhp.GetAttributeString("claim:numberCode"); this.CodeTableId = ndhp.GetAttributeString("claim:numberCodeId"); this.Unit = ndhp.GetAttributeString("claim:unit"); string tmpstr = ndhp.Node.InnerText; decimal val; if (!Decimal.TryParse(tmpstr, out val)) { this.Value = val; } else { this.Value = 0; } }
static void AddOrMergeNode(TreeNodeCollection treeNodeCollection, XmlNode inXmlNode, ref int index, GetString <XmlNode> getNodeName, GetString <XmlNode> getNodeText, Predicate <XmlNode> filter, Dictionary <string, List <TreeNode> > dict) { if (filter != null && !filter(inXmlNode)) { return; } string treeName = getNodeName(inXmlNode); string treeText = (getNodeText == null ? treeName : getNodeText(inXmlNode)); bool added = false; TreeNode treeNode; if (!DictionaryExtensions.TryRemoveFirst(dict, treeName, out treeNode)) { treeNode = new TreeNode(); treeNode.Name = treeName; treeNode.Text = treeText; added = true; treeNodeCollection.Insert(index, treeNode); } else { if (!IsNodeAtIndex(treeNodeCollection, treeNode, index)) { treeNodeCollection.Remove(treeNode); treeNodeCollection.Insert(index, treeNode); } } index++; if (treeNode.Text != treeText) { treeNode.Text = treeText; } if (inXmlNode.HasChildNodes) { AddOrMergeNodes(treeNode.Nodes, XmlNodeHelper.OfType <XmlNode>(inXmlNode.ChildNodes), getNodeName, getNodeText, filter); } else { treeNode.Nodes.Clear(); } if (added) { treeNode.ExpandAll(); } }
public ValidationError ValidationHandler1(XmlDocument xmlDoc, string xmlFileName) { ValidationError validationError = new ValidationError(xmlFileName, null); TimeStampToken token = XmlNodeHelper.GetTimeStampToken(xmlDoc); Org.BouncyCastle.X509.X509Certificate certificate = XmlNodeHelper.GetX509Certificate(xmlDoc); if (certificate == null) { return(validationError.AppendErrorMessage("Nepodarilo sa nájsť certifikát")); } if (token == null) { return(validationError.AppendErrorMessage("Nepodarilo sa nájsť token")); } // Check certificate validity against timestamp token time try { certificate.CheckValidity(token.TimeStampInfo.GenTime); } catch (Exception ex) { return(validationError.AppendErrorMessage("Platnosť podpisového certifikátu neodpovedá času z časovej pečiatky. ErrorMessage ->" + ex.Message)); } // Check certificate validity against crl X509CrlEntry entry = CrlHelper.GetRevokedCertificateEntry(certificate.SerialNumber); if (entry == null) { return(validationError); } if (entry.RevocationDate < token.TimeStampInfo.GenTime) { return(validationError.AppendErrorMessage("Platnosť certifikátu vypršala")); } return(validationError); }
public ValidationError ValidationHandler2(XmlDocument xmlDoc, string xmlFileName) { ValidationError validationError = new ValidationError(xmlFileName, null); TimeStampToken token = XmlNodeHelper.GetTimeStampToken(xmlDoc); byte[] timesStampDigestArray = token.TimeStampInfo.GetMessageImprintDigest(); string hashAlgorithmId = token.TimeStampInfo.HashAlgorithm.Algorithm.Id; var signatureEle = xmlDoc.SelectXmlNode("//ds:Signature/ds:SignatureValue"); if (signatureEle == null) { return(validationError.AppendErrorMessage("Missing SignatureValue element.")); } byte[] signatureValueByteArray = Convert.FromBase64String(signatureEle.InnerText); var signatureMethodAlgorithm = xmlDoc.SelectXmlNode("//ds:SignedInfo/ds:SignatureMethod").AtrValue("Algorithm"); if (signatureMethodAlgorithm != "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256") { return(validationError.AppendErrorMessage($"Unknown SignatureMethod Algorithm {signatureMethodAlgorithm}.")); } System.Security.Cryptography.HashAlgorithm hashAlgo = System.Security.Cryptography.SHA256Managed.Create(); var conputedSignatureByteArray = hashAlgo.ComputeHash(signatureValueByteArray); if (!StructuralComparisons.StructuralEqualityComparer.Equals(conputedSignatureByteArray, timesStampDigestArray)) { return(validationError.AppendErrorMessage("Missing SignatureValue element.")); } return(validationError); }
public ValidationError SignatureValueVerificationHandler(XmlDocument xmlDoc, string xmlFileName) { ValidationError validationError = new ValidationError(xmlFileName, null); var signedInfoElement = xmlDoc.SelectXmlNode("//ds:Signature/ds:SignedInfo"); var signatureMethodElement = xmlDoc.SelectXmlNode("//ds:Signature/ds:SignedInfo/ds:SignatureMethod"); var canonicalizationMethodElement = xmlDoc.SelectXmlNode("//ds:Signature/ds:SignedInfo/ds:CanonicalizationMethod"); var signatureValueElement = xmlDoc.SelectXmlNode("//ds:Signature/ds:SignatureValue"); if (signatureValueElement == null) { return(validationError.AppendErrorMessage(nameof(signatureValueElement) + " missing")); } if (signatureMethodElement == null) { return(validationError.AppendErrorMessage(nameof(signatureMethodElement) + " missing")); } if (canonicalizationMethodElement == null) { return(validationError.AppendErrorMessage(nameof(canonicalizationMethodElement) + " missing")); } if (signedInfoElement == null) { return(validationError.AppendErrorMessage(nameof(signedInfoElement) + " missing")); } var certificate = XmlNodeHelper.GetX509Certificate(xmlDoc); if (certificate == null) { return(validationError.AppendErrorMessage("X509Certificate element is missing")); } var canMethod = canonicalizationMethodElement.AtrValue("Algorithm"); if (canMethod != ValidationEnums.Canonicalization.CanonicalizationMethod) { return(validationError.AppendErrorMessage($"Not supported cannonicalization method. {canMethod}")); } var digestBytes = CanonicalizationHelper.CanonicalizeXml(signedInfoElement); string singnatureAlgorithm = signatureMethodElement.AtrValue("Algorithm"); if (!ValidationEnums.Cryptography.SupportedSignatureSchemasMappings.ContainsKey(singnatureAlgorithm)) { return(validationError.AppendErrorMessage($"Not supported signing algorithm {singnatureAlgorithm}")); } var signingAlgo = ValidationEnums.Cryptography.SupportedSignatureSchemasMappings[singnatureAlgorithm]; AsymmetricKeyParameter publicKey = certificate.GetPublicKey(); ISigner signer = SignerUtilities.GetSigner(signingAlgo); signer.Init(false, publicKey); signer.BlockUpdate(digestBytes, 0, digestBytes.Length); if (!signer.VerifySignature(Convert.FromBase64String(signatureValueElement.InnerText))) { return(validationError.AppendErrorMessage("Cannot verify signature with publick key.")); } return(validationError); }
public ValidationError ValidationHandler1(XmlDocument xmlDoc, string xmlFileName) { ValidationError validationError = new ValidationError(xmlFileName, null); var keyInfoEle = xmlDoc.SelectXmlNode("//ds:Signature/ds:KeyInfo"); if (keyInfoEle == null || !keyInfoEle.AtrExists("Id")) { return(validationError.AppendErrorMessage("KeyInfo does not exists or missing Id attribute.")); } // check x509 var x509Data = xmlDoc.SelectXmlNode("//ds:Signature/ds:KeyInfo/ds:X509Data"); if (x509Data == null) { return(validationError.AppendErrorMessage("KeyInfo musí obsahovať element x509Data")); } if (x509Data.SelectXmlNode("ds:X509Certificate") == null) { return(validationError.AppendErrorMessage("x509Data musí obsahovať element x509Certificate")); } X509Certificate certificate = XmlNodeHelper.GetX509Certificate(xmlDoc); //check SubjectName if (x509Data.SelectXmlNode("ds:X509SubjectName") == null) { return(validationError.AppendErrorMessage("x509Data musí obsahovať element SubjectName")); } else { var X509SubjectName = x509Data.SelectXmlNode("ds:X509SubjectName"); if (X509SubjectName.InnerText != certificate.CertificateStructure.Subject.ToString()) { return(validationError.AppendErrorMessage("X509SubjectName sa nezhoduje")); } } //check IssuerSerial if (x509Data.SelectXmlNode("ds:X509IssuerSerial") == null) { validationError.AppendErrorMessage("x509Data musí obsahovať element IssuerSerial"); } else { var X509IssuerSerial = x509Data.SelectXmlNode("ds:X509IssuerSerial/ds:X509IssuerName"); X509Name xmlName = new X509Name(X509IssuerSerial.InnerText.Replace("S=", "ST=")); if (!xmlName.Equivalent(certificate.CertificateStructure.Issuer)) { return(validationError.AppendErrorMessage("IssuerSerial sa nezhoduje")); } } //check SerialNumber var X509SerialNumber = x509Data.SelectXmlNode("ds:X509IssuerSerial/ds:X509SerialNumber"); if (X509SerialNumber == null) { return(validationError.AppendErrorMessage("x509Data musí obsahovať element SerialNumber")); } else if (X509SerialNumber.InnerText != certificate.SerialNumber.ToString()) { return(validationError.AppendErrorMessage("X509SerialNumber sa nezhoduje")); } return(validationError); }
private void LoadFromXml(XmlNode node) { XmlNodeHelper ndhp = new XmlNodeHelper(node); ndhp.NamespaceManager.AddNamespace("claim", NameSpaceURI); this.SubClassCode = ndhp.GetAttributeString("claim:subclassCode"); this.SubClassCodeTableId = ndhp.GetAttributeString("claim:subclassCodeId"); this.Code = ndhp.GetAttributeString("claim:code"); this.CodeTableId = ndhp.GetAttributeString("claim:tableId"); this.AliasCode = ndhp.GetAttributeString("claim:aliasCode"); this.AliasCodeTableId = ndhp.GetAttributeString("claim:aliasTableId"); this.Name = ndhp.GetNodeText("claim:name"); this.NumberList = new List<NumberItem>(); foreach (XmlNode subnd in ndhp.SelectNodes("claim:number")) { NumberItem numitm = new NumberItem(subnd); this.NumberList.Add(numitm); } string tmpstr = ndhp.GetNodeText("claim:duration"); this.Duration = new TimeSpan(0, 0, 0); if (tmpstr != null) { //書式PTnHnM tmpstr = tmpstr.Replace("RT", ""); tmpstr = tmpstr.Replace("M", ""); tmpstr = tmpstr.Replace("H", ":"); string[] tm = tmpstr.Split(':'); if (tm.Length == 2) { this.Duration = new TimeSpan(int.Parse(tm[0]), int.Parse(tm[1]),0); } } this.LocationList = new List<LocationItem>(); foreach (XmlNode subnd in ndhp.SelectNodes("claim:location")) { LocationItem numitm = new LocationItem(subnd); this.LocationList.Add(numitm); } this.FilmList = new List<FilmItem>(); foreach (XmlNode subnd in ndhp.SelectNodes("claim:film")) { FilmItem numitm = new FilmItem(subnd); this.FilmList.Add(numitm); } this.Event = new EventItem(ndhp.GetNode("claim:event")); this.Memo = ndhp.GetNodeText("claim:memo"); }