private void ParseNode(Asn1Node root) { if ((root.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.SEQUENCE || root.ChildNodeCount != 3) { throw new InvalidX509Data(); } // TBS cert TbsCertificate = root.GetChildNode(0); if (TbsCertificate.ChildNodeCount < 7) { throw new InvalidX509Data(); } rawTBSCertificate = new byte[TbsCertificate.DataLength + 4]; Array.Copy(root.Data, 0, rawTBSCertificate, 0, rawTBSCertificate.Length); // get the serial number Asn1Node sn = TbsCertificate.GetChildNode(1); if ((sn.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.INTEGER) { throw new InvalidX509Data(); } SerialNumber = Asn1Util.ToHexString(sn.Data); // get the issuer Issuer = new DistinguishedName(TbsCertificate.GetChildNode(3)); // get the subject Subject = new DistinguishedName(TbsCertificate.GetChildNode(5)); // get the dates Asn1Node validTimes = TbsCertificate.GetChildNode(4); if ((validTimes.Tag & Asn1Tag.TAG_MASK) != Asn1Tag.SEQUENCE || validTimes.ChildNodeCount != 2) { throw new InvalidX509Data(); } ValidAfter = ParseTime(validTimes.GetChildNode(0)); ValidBefore = ParseTime(validTimes.GetChildNode(1)); // is this self signed? SelfSigned = Subject.Equals(Issuer); // get the pub key PubKey = new RSAKey(TbsCertificate.GetChildNode(6)); // set the tbs cert & signature data for signature verification Signature = root.GetChildNode(2); }
public GooglePlayValidator(byte[] rsaKey) { key = new RSAKey(rsaKey); }