public void GenericTest() { var cert = GetEmbeddedBytes(@"pidgin.pkcs7"); var asn1 = Asn1Node.ReadNode(cert); Assert.NotNull(asn1); }
public void GenericTest() { var cert = File.ReadAllBytes(@"./test_files/pidgin.pkcs7"); var asn1 = Asn1Node.ReadNode(cert); Assert.NotNull(asn1); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1Null; Assert.NotNull(typed); }
public RsaPublicKey(Asn1BitString valueNode) { var value = Asn1Node.ReadNode(valueNode.Data); Modulus = GetRsaData((Asn1Integer)value.Nodes[0]); Exponent = GetRsaData((Asn1Integer)value.Nodes[1]); }
public void Asn1ShouldSupportIa5String() { var cert = File.ReadAllBytes(@"./Authenticode/pidgin.pkcs7"); var asn1 = Asn1Node.ReadNode(cert); Assert.NotNull(asn1); }
public void PreventOverflow() { var cert = File.ReadAllBytes(@"./Authenticode/pkcs7.bin"); var asn1 = Asn1Node.ReadNode(cert); Assert.NotNull(asn1); }
private static IPrivateKey ParseToIKey(byte[] data) { /* * node 30 * node[0] | 30 * node[0][0] | | 06 - Algorithm * node[0][1] | | ... * node[1][0] | 04 DATA */ var node = Asn1Node.ReadNode(data); var alro = node.Nodes[0].Nodes[0] as Asn1ObjectIdentifier; if (alro == null) { return(null); } if (alro.Value == "1.2.410.200004.1.15") { return(new SeedCBCWithSHA1(node)); } if (alro.Value == "1.2.840.113549.1.5.13") { return(new PKCS5PBES2(node)); } return(null); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1Integer; Assert.NotNull(typed); Assert.Equal(new byte[] { 0 }, typed.Value); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1PrintableString; Assert.IsNotNull(typed); Assert.AreEqual("TestOrg", typed.Value); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1Ia5String; Assert.NotNull(typed); Assert.AreEqual("StartCom Class 2 Primary Intermediate Object Signing Certificates", typed.Value); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1ObjectIdentifier; Assert.IsNotNull(typed); Assert.AreEqual("2.5.4.10", typed.Value); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1BmpString; Assert.NotNull(typed); Assert.Equal("г. Ижевск, пер. Северный, д. 61", typed.Value); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1NumericString; Assert.NotNull(typed); Assert.Equal("304741704700129", typed.Value); }
public void ReadTest() { var node = Asn1Node.ReadNode(new MemoryStream(_etalon)); var typed = node as Asn1Set; Assert.IsNotNull(typed); Assert.AreEqual(2, typed.Nodes.Count); }
public void ReadNode_UnsupportedUniversalType_DoesNotCrashButReturnsCustomType() { var cert = File.ReadAllBytes(@"./test_files/old_firefox_x86.pkcs7"); var node = Asn1Node.ReadNode(cert); Assert.Equal(Asn1TagClass.Universal, node.Nodes[0].TagClass); // Just access some value from the parsed cert. }
public void Filter_On_Asn1StringNode() { var cert = File.ReadAllBytes(@"./test_files/pidgin.pkcs7"); var node = Asn1Node.ReadNode(cert); var organizationalUnitNames = FindObjectIdentifiers(node, Asn1ObjectIdentifier.OrganizationalUnitName); Assert.Equal(2, organizationalUnitNames.Count); Assert.Contains(organizationalUnitNames, s => s == "Secure Digital Certificate Signing"); Assert.Contains(organizationalUnitNames, s => s == "http://www.usertrust.com"); }
public byte[] GetSubjectKeyIdentifier() { var data = GetExtensionValue(Asn1ObjectIdentifier.SubjectKeyIdentifier); if (data == null) { return(null); } var seq = (Asn1OctetString)Asn1Node.ReadNode(data); return(seq.Data); }
public void WriteWithTrailingZeroTest() { var data = new byte[] { 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x24, 0x00 }; var node = Asn1Node.ReadNode(new MemoryStream(data)); var typed = node as Asn1ObjectIdentifier; Assert.Equal("1.2.643.2.2.36.0", typed.Value); var newData = typed.GetBytes(); AreEqual(data, newData); }
public RsaPrivateKey(Asn1BitString valueNode) { var value = Asn1Node.ReadNode(valueNode.Data); Modulus = GetRsaData((Asn1Integer)value.Nodes[1]); Exponent = GetRsaData((Asn1Integer)value.Nodes[2]); D = GetRsaData((Asn1Integer)value.Nodes[3]); P = GetRsaData((Asn1Integer)value.Nodes[4]); Q = GetRsaData((Asn1Integer)value.Nodes[5]); DP = GetRsaData((Asn1Integer)value.Nodes[6]); DQ = GetRsaData((Asn1Integer)value.Nodes[7]); InverseQ = GetRsaData((Asn1Integer)value.Nodes[8]); }
public byte[] GetAuthorityKeyIdentifier() { var data = GetExtensionValue(Asn1ObjectIdentifier.AuthorityKeyIdentifier); if (data == null) { return(null); } var seq = (Asn1Sequence)Asn1Node.ReadNode(data); var idNode = seq.Nodes.FirstOrDefault(item => item.Is(Asn1TagClass.ContextDefined, 0x00)); return(((Asn1CustomNode)idNode) == null ? null : ((Asn1CustomNode)idNode).Data); }
public static RSA ToRSA(byte[] data) { var node = Asn1Node.ReadNode(data); var rsaSequence = Asn1Node.ReadNode((node.Nodes[1] as Asn1BitString).Data); var modulus = (rsaSequence.Nodes[0] as Asn1Integer).Value; var exponent = (rsaSequence.Nodes[1] as Asn1Integer).Value; var prms = new RSAParameters { Modulus = modulus, Exponent = exponent }; var rsa = RSA.Create(); rsa.ImportParameters(prms); return(rsa); }
public static RSA ToRSA(byte[] data) { var node = Asn1Node.ReadNode(data); Debug.Assert(node.Is(Asn1UniversalNodeType.Sequence)); var header = node.Nodes[0]; Debug.Assert(header.Is(Asn1UniversalNodeType.Sequence)); Debug.Assert((header.Nodes[0] as Asn1ObjectIdentifier).Value == "1.2.840.113549.1.1.1"); var rsaSequence = Asn1Node.ReadNode((node.Nodes[1] as Asn1BitString).Data); var modulus = (rsaSequence.Nodes[0] as Asn1Integer).Value; var exponent = (rsaSequence.Nodes[1] as Asn1Integer).Value; var prms = new RSAParameters { Modulus = modulus, Exponent = exponent }; var rsa = RSA.Create(); rsa.ImportParameters(prms); return(rsa); }
public ContentInfo(Span <byte> data) : this(Asn1Node.ReadNode(data.ToArray())) { }
public void OverflowTest() { var bytes = GetEmbeddedBytes(@"overflow.pkcs7"); Assert.Throws <Asn1ParsingException>(() => Asn1Node.ReadNode(bytes)); }
public ContentInfo(byte[] data) : this(Asn1Node.ReadNode(data)) { }
public void TryWithRaw() { var pubHex = "046A347F0488ABC7D92E2208794E327ECA15B0C2B27018B2B5B89DD8CB736FD7CC38F37D2D10822530AD97359ACBD837A65C2CA62D44B0CE569BD222C2DABF268F"; var privBytes = "48 119 2 1 1 4 32 36 32 85 234 114 73 227 18 64 63 130 39 155 80 70 109 242 211 48 21 9 238 238 96 191 178 8 11 9 221 183 246 160 10 6 8 42 134 72 206 61 3 1 7 161 68 3 66 0 4 106 52 127 4 136 171 199 217 46 34 8 121 78 50 126 202 21 176 194 178 112 24 178 181 184 157 216 203 115 111 215 204 56 243 125 45 16 130 37 48 173 151 53 154 203 216 55 166 92 44 166 45 68 176 206 86 155 210 34 194 218 191 38 143".FromIntList(); var pubBytes = pubHex.FromHex(); var msgBytes = "time for beer".StringToBytes(); var d = Asn1Node.ReadNode(privBytes); //Console.WriteLine(privBytes.ToHex()); var pk = d.Nodes.First(n => n.NodeType == Asn1UniversalNodeType.OctetString).GetBytes().Skip(2).ToArray(); // var oid = d.Nodes.First(n => n.NodeType == Asn1UniversalNodeType.ObjectId); //Console.WriteLine(pk.Length); //var npb = new List<byte>(); //npb.AddRange("45435332".FromHex()); //npb.AddRange("20000000".FromHex()); //var keyType = new byte[] {0x45, 0x43, 0x53, 0x31}; //var keyLength = new byte[] {0x20, 0x00, 0x00, 0x00}; //var key = pubBytes.Skip(1); //var keyImport = keyType.Concat(keyLength).Concat(key).ToArray(); //var cngKey = CngKey.Import(keyImport, CngKeyBlobFormat.EccPublicBlob); var keyType = new byte[] { 0x45, 0x43, 0x53, 0x32 }; var keyLength = new byte[] { 0x20, 0x00, 0x00, 0x00 }; var key = pubBytes.Skip(1); var keyImport = keyType.Concat(keyLength).Concat(key).Concat(pk.Take(32)).ToArray(); var cngKey = CngKey.Import(keyImport, CngKeyBlobFormat.EccPrivateBlob); // Console.WriteLine(msgBytes.ToIntList()); // Console.WriteLine(cngKey.Algorithm); using (var ecdsa = new ECDsaCng(cngKey)) { ; var sig = ecdsa.SignHash(msgBytes); var r = sig.Take(32).ToArray().ToIntList(); var s = sig.Skip(32).ToArray().ToIntList(); // Console.WriteLine($"r={r}"); //Console.WriteLine($"s={s}"); } var sm = new List <byte>(); var rb = "4 125 215 32 233 142 70 85 201 154 76 249 192 224 47 110 137 143 196 200 134 41 40 215 145 53 16 48 70 137 141 220".FromIntList(); var sb = "13 204 63 209 196 150 249 28 161 192 197 238 187 28 49 93 64 81 111 132 87 13 150 77 41 62 144 197 244 173 110 176".FromIntList(); var ri = new BigInteger(rb.Reverse().ToArray()); Console.WriteLine(ri); var bi = BigInteger.Parse("2031592040209509309444738411503462520448943330036365867913793138397723332060"); var bib = bi.ToByteArray(); Console.WriteLine(bib.ToIntList()); sm.AddRange(rb); sm.AddRange(sb); //Console.WriteLine(sm.Count); using (var ecdsa = new ECDsaCng(cngKey)) { Assert.True(ecdsa.VerifyHash(msgBytes, sm.ToArray())); } //npb.AddRange(pubBytes.Skip(1)); //npb.AddRange(pk); //var cngKey = CngKey.Import(npb.ToArray(), CngKeyBlobFormat.EccPrivateBlob); }
public void OverflowTest() { var cert = File.ReadAllBytes(@"overflow.pkcs7"); Assert.Throws <Asn1ParsingException>(() => Asn1Node.ReadNode(cert)); }