private void FormNodeContentEditor_Load(object sender, System.EventArgs e) { textBoxTag.Text = String.Format("{0:X2}", aNode.Tag); textBoxNodeContent.Text = aNode.GetDataStr(pureHexMode); string msg = ""; msg = String.Format("Tag:{0} (0x{0:X2}) : {1} \r\n" + "Offset:{2,4} (0x{2:X8})\r\n" + "Length:{3,4} (0x{3:X8})\r\n" + "Deepness: {4}\r\n" , aNode.Tag, Asn1Util.GetTagName(aNode.Tag), aNode.DataOffset, aNode.DataLength, aNode.Deepness ); if ((aNode.Tag & Asn1Tag.TAG_MASK) == Asn1Tag.BIT_STRING) { msg += "Unused Bits: " + aNode.UnusedBits.ToString() + "\r\n"; } msg += "Path: " + aNode.Path + "\r\n"; textBox1.Text = msg; if (aNode.ChildNodeCount > 0) { textBoxNodeContent.Enabled = false; buttonOK.Enabled = false; } else { textBoxNodeContent.Enabled = true; buttonOK.Enabled = true; } textBoxTag.ReadOnly = !enableTagEdit; if (textBoxNodeContent.Enabled) { textBoxNodeContent.Enabled = !enableTagEdit; } }
private static void BuildRoot(KerberosAuthorizeMessage msg, Asn1Node root) { if (root.ChildNodeCount == 2L) { Asn1Node childNode = root.GetChildNode(0); if (((int)childNode.Tag & 31) != 6) { throw new Exception("OBJECT_IDENTIFIER expected. (path: " + childNode.Path + ")"); } msg.MechType = new MechType(childNode.GetDataStr(false)); msg.NegotiationToken = (NegotiationToken) new NegTokenInit(); KerberosAuthorizeMessageBuilder.BuildNegotiateTokenInit((NegTokenInit)msg.NegotiationToken, root.GetChildNode(1).GetChildNode(0)); } else { if (root.ChildNodeCount != 1L) { return; } msg.NegotiationToken = (NegotiationToken) new NegTokenInit(); KerberosAuthorizeMessageBuilder.BuildNegotiateTokenInit((NegTokenInit)msg.NegotiationToken, root.GetChildNode(0)); } }
private void CheckStructure() { validStructure = false; if ((root.Tag & Asn1Tag.TAG_MASK) == Asn1Tag.SEQUENCE && root.ChildNodeCount == 2) { Asn1Node tt = root.GetChildNode(0); if ((tt.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.OBJECT_IDENTIFIER || tt.GetDataStr(false) != "1.2.840.113549.1.7.2") { throw new InvalidPKCS7Data(); } tt = root.GetChildNode(1); // [0] if (tt.ChildNodeCount != 1) { throw new InvalidPKCS7Data(); } int curChild = 0; tt = tt.GetChildNode(curChild++); // Seq if (tt.ChildNodeCount < 4 || (tt.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.SEQUENCE) { throw new InvalidPKCS7Data(); } Asn1Node tt2 = tt.GetChildNode(0); // version if ((tt2.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.INTEGER) { throw new InvalidPKCS7Data(); } tt2 = tt.GetChildNode(curChild++); // digest algo // TODO: check algo if ((tt2.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.SET) { throw new InvalidPKCS7Data(); } tt2 = tt.GetChildNode(curChild++); // pkcs7 data if ((tt2.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.SEQUENCE && tt2.ChildNodeCount != 2) { throw new InvalidPKCS7Data(); } data = tt2.GetChildNode(1).GetChildNode(0); if (tt.ChildNodeCount == 5) { // cert chain, this is optional certChain = new List <X509Cert>(); tt2 = tt.GetChildNode(curChild++); if (tt2.ChildNodeCount == 0) { throw new InvalidPKCS7Data(); } for (int i = 0; i < tt2.ChildNodeCount; i++) { certChain.Add(new X509Cert(tt2.GetChildNode(i))); } } tt2 = tt.GetChildNode(curChild++); // signer's info if ((tt2.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.SET || tt2.ChildNodeCount == 0) { throw new InvalidPKCS7Data(); } sinfos = new List <SignerInfo>(); for (int i = 0; i < tt2.ChildNodeCount; i++) { sinfos.Add(new SignerInfo(tt2.GetChildNode(i))); } validStructure = true; } }