public override void PerformTest() { DerInteger val = new DerInteger(9); DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val); if (!AreEqual(impData, tagged.GetEncoded())) { Fail("implicit encoding failed"); } DerInteger recVal = (DerInteger)tagged.GetObject(Asn1Tags.Integer); if (!val.Equals(recVal)) { Fail("implicit read back failed"); } DerApplicationSpecific certObj = (DerApplicationSpecific) Asn1Object.FromByteArray(certData); if (!certObj.IsConstructed() || certObj.ApplicationTag != 33) { Fail("parsing of certificate data failed"); } byte[] encoded = certObj.GetDerEncoded(); if (!Arrays.AreEqual(certData, encoded)) { Console.WriteLine(Encoding.ASCII.GetString(certData, 0, certData.Length).Substring(0, 20)); Console.WriteLine(Encoding.ASCII.GetString(encoded, 0, encoded.Length).Substring(0, 20)); Fail("re-encoding of certificate data failed"); } }
public override byte[] ToArray() { DerApplicationSpecific bits = new DerApplicationSpecific(GetValue("TagNo").Value, this["Octets"].ToArray()); return(bits.GetDerEncoded()); }
public override void PerformTest() { DerInteger val = new DerInteger(9); DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val); if (!AreEqual(impData, tagged.GetEncoded())) { Fail("implicit encoding failed"); } DerInteger recVal = (DerInteger) tagged.GetObject(Asn1Tags.Integer); if (!val.Equals(recVal)) { Fail("implicit read back failed"); } DerApplicationSpecific certObj = (DerApplicationSpecific) Asn1Object.FromByteArray(certData); if (!certObj.IsConstructed() || certObj.ApplicationTag != 33) { Fail("parsing of certificate data failed"); } byte[] encoded = certObj.GetDerEncoded(); if (!Arrays.AreEqual(certData, encoded)) { Console.WriteLine(Encoding.ASCII.GetString(certData, 0, certData.Length).Substring(0, 20)); Console.WriteLine(Encoding.ASCII.GetString(encoded, 0, encoded.Length).Substring(0, 20)); Fail("re-encoding of certificate data failed"); } }
protected override void EncodeParameters(Asn1Generator generator) { // Id var id = new DerApplicationSpecific(TAG_PARAM_ID, BinaryParser.ConvertInt16(Id, ByteEndianess.BigEndian)); // Keyset - IA Modulus var iaModulus = new DerApplicationSpecific(TAG_KEYSET_IAMODULUS, new byte[PlaidApplication.LENGTH_KEY_RSA]); // Keyset - IA Exponent var iaExponent = new DerApplicationSpecific(TAG_KEYSET_IAEXPONENT, new byte[PlaidApplication.LENGTH_PUBLIC_EXPONENT]); // Keyset - FAKey var faKey = new DerApplicationSpecific(TAG_KEYSET_FAKEY, new byte[PlaidApplication.LENGTH_KEY_AES]); // Rules List <DerOctetString> rules = new List <DerOctetString>(); foreach (var rule in Rules) { rules.Add(new DerOctetString(rule)); } // Parameters (Choice) var parameters = new DerSequenceGenerator(generator.GetRawOutputStream(), OP_KEY_CREATE, false); parameters.AddObject(id); parameters.AddObject(new DerApplicationSpecific(TAG_PARAM_KEY, new Asn1EncodableVector(iaModulus, iaExponent, faKey))); parameters.AddObject(new DerApplicationSpecific(TAG_PARAM_RULES, new Asn1EncodableVector(rules.ToArray()))); parameters.Close(); // SamId var samId = new DerApplicationSpecific(TAG_SAMID, BinaryParser.ConvertInt16(SamId, ByteEndianess.BigEndian)); generator.AddObject(samId); }
private static string outputApplicationSpecific( string type, string indent, bool verbose, DerApplicationSpecific app) { StringBuilder buf = new StringBuilder(); if (app.IsConstructed()) { try { Asn1Sequence s = Asn1Sequence.GetInstance(app.GetObject(Asn1Tags.Sequence)); buf.Append(indent + type + " ApplicationSpecific[" + app.ApplicationTag + "]" + NewLine); foreach (Asn1Encodable ae in s) { AsString(indent + Tab, verbose, ae.ToAsn1Object(), buf); } } catch (IOException e) { buf.Append(e); } return(buf.ToString()); } return(indent + type + " ApplicationSpecific[" + app.ApplicationTag + "] (" + Hex.ToHexString(app.GetContents()) + ")" + NewLine); }
private void TestTaggedObject() { // boolean explicit, int tagNo, ASN1Encodable obj bool isExplicit = false; // Type1 ::= VisibleString DerVisibleString type1 = new DerVisibleString("Jones"); if (!Arrays.AreEqual(Hex.Decode("1A054A6F6E6573"), type1.GetEncoded())) { Fail("ERROR: expected value doesn't match!"); } // Type2 ::= [APPLICATION 3] IMPLICIT Type1 isExplicit = false; DerApplicationSpecific type2 = new DerApplicationSpecific(isExplicit, 3, type1); // type2.isConstructed() if (!Arrays.AreEqual(Hex.Decode("43054A6F6E6573"), type2.GetEncoded())) { Fail("ERROR: expected value doesn't match!"); } // Type3 ::= [2] Type2 isExplicit = true; DerTaggedObject type3 = new DerTaggedObject(isExplicit, 2, type2); if (!Arrays.AreEqual(Hex.Decode("A20743054A6F6E6573"), type3.GetEncoded())) { Fail("ERROR: expected value doesn't match!"); } // Type4 ::= [APPLICATION 7] IMPLICIT Type3 isExplicit = false; DerApplicationSpecific type4 = new DerApplicationSpecific(isExplicit, 7, type3); if (!Arrays.AreEqual(Hex.Decode("670743054A6F6E6573"), type4.GetEncoded())) { Fail("ERROR: expected value doesn't match!"); } // Type5 ::= [2] IMPLICIT Type2 isExplicit = false; DerTaggedObject type5 = new DerTaggedObject(isExplicit, 2, type2); // type5.isConstructed() if (!Arrays.AreEqual(Hex.Decode("82054A6F6E6573"), type5.GetEncoded())) { Fail("ERROR: expected value doesn't match!"); } }
protected override bool Asn1Equals(Asn1Object asn1Object) { DerApplicationSpecific derApplicationSpecific = asn1Object as DerApplicationSpecific; if (derApplicationSpecific == null) { return(false); } if (isConstructed == derApplicationSpecific.isConstructed && tag == derApplicationSpecific.tag) { return(Arrays.AreEqual(octets, derApplicationSpecific.octets)); } return(false); }
public override void PerformTest() { TestTaggedObject(); DerApplicationSpecific appSpec = (DerApplicationSpecific)Asn1Object.FromByteArray(sampleData); if (1 != appSpec.ApplicationTag) { Fail("wrong tag detected"); } DerInteger val = new DerInteger(9); DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val); if (!AreEqual(impData, tagged.GetEncoded())) { Fail("implicit encoding failed"); } DerInteger recVal = (DerInteger)tagged.GetObject(Asn1Tags.Integer); if (!val.Equals(recVal)) { Fail("implicit read back failed"); } DerApplicationSpecific certObj = (DerApplicationSpecific) Asn1Object.FromByteArray(certData); if (!certObj.IsConstructed() || certObj.ApplicationTag != 33) { Fail("parsing of certificate data failed"); } byte[] encoded = certObj.GetDerEncoded(); if (!Arrays.AreEqual(certData, encoded)) { Fail("re-encoding of certificate data failed"); } }
private static string outputApplicationSpecific( string type, string indent, bool verbose, DerApplicationSpecific app) { StringBuilder buf = new StringBuilder(); if (app.IsConstructed()) { try { Asn1Sequence s = Asn1Sequence.GetInstance(app.GetObject(Asn1Tags.Sequence)); buf.Append(indent + type + " ApplicationSpecific[" + app.ApplicationTag + "]" + NewLine); foreach (Asn1Encodable ae in s) { AsString(indent + Tab, verbose, ae.ToAsn1Object(), buf); } } catch (IOException e) { buf.Append(e); } return buf.ToString(); } return indent + type + " ApplicationSpecific[" + app.ApplicationTag + "] (" + Hex.ToHexString(app.GetContents()) + ")" + NewLine; }
private void AddAsn1Object(string name, DataKey root, Asn1Object obj, int level, Logger logger) { Asn1Sequence seq = obj as Asn1Sequence; Asn1Set set = obj as Asn1Set; Asn1TaggedObject tag = obj as Asn1TaggedObject; string currName = name ?? obj.GetType().Name; System.Diagnostics.Trace.WriteLine(String.Format("{0} {1}", currName, obj.GetType())); if (seq != null) { if (!Config.IgnoreSequences) { DataKey key = new Asn1SequenceKey(currName, Config.NoVerify); foreach (Asn1Object o in seq) { AddAsn1Object(null, key, o, level + 1, logger); } root.AddSubNode(key); } else { root.AddValue(currName, obj.GetDerEncoded()); } } else if (set != null) { if (!Config.IgnoreSets) { DataKey key = new Asn1SetKey(currName, Config.NoVerify); foreach (Asn1Object o in set) { AddAsn1Object(null, key, o, level + 1, logger); } root.AddSubNode(key); } else { root.AddValue(currName, obj.GetDerEncoded()); } } else if (tag != null) { if (!Config.IgnoreTaggedObjects) { DataKey key = new Asn1TaggedObjectKey(currName, tag.TagNo, Config.NoVerify); root.AddSubNode(key); Asn1Object o = tag.GetObject(); DerOctetString oct = o as DerOctetString; AddAsn1Object("Object", key, tag.GetObject(), level + 1, logger); //if (oct != null) //{ // Asn1InputStream input = new Asn1InputStream(oct.GetOctetStream()); // try // { // Asn1Object next = input.ReadObject(); // if (next == null) // { // AddAsn1Object("Object", key, o, logger); // } // else // { // Asn1OctetStringObject newRoot = new Asn1OctetStringObject("Object"); // while (next != null) // { // AddAsn1Object(next.GetType().Name, newRoot, next, logger); // next = input.ReadObject(); // } // key.AddSubNode(newRoot); // } // } // catch (IOException) // { // AddAsn1Object("Object", key, o, logger); // } //} //else //{ // AddAsn1Object("Object", key, tag.GetObject(), logger); //} } else { root.AddValue(currName, obj.GetDerEncoded()); } } else { if (!Config.NoDecode) { DerStringBase str = obj as DerStringBase; DerObjectIdentifier oid = obj as DerObjectIdentifier; DerInteger i = obj as DerInteger; DerOctetString oct = obj as DerOctetString; DerBitString bits = obj as DerBitString; DerBoolean boo = obj as DerBoolean; DerNull n = obj as DerNull; DerUtcTime time = obj as DerUtcTime; DerGeneralizedTime gt = obj as DerGeneralizedTime; DerApplicationSpecific app = obj as DerApplicationSpecific; if (oct != null) { root.AddValue(new Asn1OctetStringValue(currName, oct.GetOctets())); } else if (bits != null) { root.AddSubNode(new Asn1BitStringKey(currName, bits.PadBits, bits.GetBytes())); } else if (str != null) { Type stringType = typeof(Asn1StringValue <>).MakeGenericType(str.GetType()); root.AddValue((DataValue)Activator.CreateInstance(stringType, currName, str.GetString())); } else if (oid != null) { root.AddValue(new Asn1ObjectIdentifierValue(currName, oid.Id)); } else if (i != null) { root.AddValue(new Asn1IntegerValue(currName, i.Value.ToByteArray())); } else if (boo != null) { root.AddValue(new Asn1BooleanValue(currName, boo.IsTrue)); } else if (n != null) { root.AddValue(new Asn1NullValue(currName)); } else if (time != null) { root.AddValue(new Asn1DateTimeValue(currName, time.ToDateTime())); } else if (gt != null) { root.AddValue(new Asn1GeneralizedTimeValue(currName, gt.ToDateTime())); } else if (app != null) { root.AddSubNode(new Asn1ApplicationSpecificValue(currName, app.ApplicationTag, app.GetContents())); } else { logger.LogError("Cannot convert type {0} to a class", obj.GetType().Name); root.AddValue(currName, obj.GetDerEncoded()); } } else { root.AddValue(currName, obj.GetDerEncoded()); } } }
public override void PerformTest() { DerApplicationSpecific app = (DerApplicationSpecific) Asn1Object.FromByteArray(longTagged); app = (DerApplicationSpecific) Asn1Object.FromByteArray(app.GetContents()); Asn1InputStream aIn = new Asn1InputStream(app.GetContents()); Asn1TaggedObject tagged = (Asn1TaggedObject) aIn.ReadObject(); if (tagged.TagNo != 32) { Fail("unexpected tag value found - not 32"); } tagged = (Asn1TaggedObject) Asn1Object.FromByteArray(tagged.GetEncoded()); if (tagged.TagNo != 32) { Fail("unexpected tag value found on recode - not 32"); } tagged = (Asn1TaggedObject) aIn.ReadObject(); if (tagged.TagNo != 33) { Fail("unexpected tag value found - not 33"); } tagged = (Asn1TaggedObject) Asn1Object.FromByteArray(tagged.GetEncoded()); if (tagged.TagNo != 33) { Fail("unexpected tag value found on recode - not 33"); } aIn = new Asn1InputStream(longAppSpecificTag); app = (DerApplicationSpecific)aIn.ReadObject(); if (app.ApplicationTag != 97) { Fail("incorrect tag number read"); } app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded()); if (app.ApplicationTag != 97) { Fail("incorrect tag number read on recode"); } SecureRandom sr = new SecureRandom(); for (int i = 0; i < 100; ++i) { int testTag = (sr.NextInt() & int.MaxValue) >> sr.Next(26); app = new DerApplicationSpecific(testTag, new byte[]{ 1 }); app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded()); if (app.ApplicationTag != testTag) { Fail("incorrect tag number read on recode (random test value: " + testTag + ")"); } } }
private static string outputApplicationSpecific(string type, string indent, bool verbose, DerApplicationSpecific app) { StringBuilder stringBuilder = new StringBuilder(); if (app.IsConstructed()) { try { Asn1Sequence instance = Asn1Sequence.GetInstance(app.GetObject(16)); stringBuilder.Append(indent + type + " ApplicationSpecific[" + app.ApplicationTag + "]" + NewLine); foreach (Asn1Encodable item in instance) { AsString(indent + " ", verbose, item.ToAsn1Object(), stringBuilder); } } catch (IOException value) { stringBuilder.Append(value); } return(stringBuilder.ToString()); } return(indent + type + " ApplicationSpecific[" + app.ApplicationTag + "] (" + Hex.ToHexString(app.GetContents()) + ")" + NewLine); }
private static string outputApplicationSpecific(string type, string indent, bool verbose, DerApplicationSpecific app) { StringBuilder stringBuilder = new StringBuilder(); if (app.IsConstructed()) { try { Asn1Sequence instance = Asn1Sequence.GetInstance(app.GetObject(16)); stringBuilder.Append(string.Concat(new object[] { indent, type, " ApplicationSpecific[", app.ApplicationTag, "]", Asn1Dump.NewLine })); foreach (Asn1Encodable asn1Encodable in instance) { Asn1Dump.AsString(indent + " ", verbose, asn1Encodable.ToAsn1Object(), stringBuilder); } } catch (IOException value) { stringBuilder.Append(value); } return(stringBuilder.ToString()); } return(string.Concat(new object[] { indent, type, " ApplicationSpecific[", app.ApplicationTag, "] (", Hex.ToHexString(app.GetContents()), ")", Asn1Dump.NewLine })); }
private static string outputApplicationSpecific(string type, string indent, bool verbose, DerApplicationSpecific app) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_00bb: Expected O, but got Unknown StringBuilder val = new StringBuilder(); if (app.IsConstructed()) { try { Asn1Sequence instance = Asn1Sequence.GetInstance(app.GetObject(16)); val.Append(string.Concat(new object[6] { indent, type, " ApplicationSpecific[", app.ApplicationTag, "]", NewLine })); global::System.Collections.IEnumerator enumerator = instance.GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current(); AsString(indent + " ", verbose, asn1Encodable.ToAsn1Object(), val); } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } catch (IOException val2) { IOException val3 = val2; val.Append((object)val3); } return(val.ToString()); } return(string.Concat(new object[8] { indent, type, " ApplicationSpecific[", app.ApplicationTag, "] (", Hex.ToHexString(app.GetContents()), ")", NewLine })); }
public override void PerformTest() { TestTaggedObject(); DerApplicationSpecific appSpec = (DerApplicationSpecific)Asn1Object.FromByteArray(sampleData); if (1 != appSpec.ApplicationTag) { Fail("wrong tag detected"); } DerInteger val = new DerInteger(9); DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val); if (!AreEqual(impData, tagged.GetEncoded())) { Fail("implicit encoding failed"); } DerInteger recVal = (DerInteger) tagged.GetObject(Asn1Tags.Integer); if (!val.Equals(recVal)) { Fail("implicit read back failed"); } DerApplicationSpecific certObj = (DerApplicationSpecific) Asn1Object.FromByteArray(certData); if (!certObj.IsConstructed() || certObj.ApplicationTag != 33) { Fail("parsing of certificate data failed"); } byte[] encoded = certObj.GetDerEncoded(); if (!Arrays.AreEqual(certData, encoded)) { Fail("re-encoding of certificate data failed"); } }
public override void PerformTest() { DerApplicationSpecific app = (DerApplicationSpecific) Asn1Object.FromByteArray(longTagged); app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetContents()); Asn1InputStream aIn = new Asn1InputStream(app.GetContents()); Asn1TaggedObject tagged = (Asn1TaggedObject)aIn.ReadObject(); if (tagged.TagNo != 32) { Fail("unexpected tag value found - not 32"); } tagged = (Asn1TaggedObject)Asn1Object.FromByteArray(tagged.GetEncoded()); if (tagged.TagNo != 32) { Fail("unexpected tag value found on recode - not 32"); } tagged = (Asn1TaggedObject)aIn.ReadObject(); if (tagged.TagNo != 33) { Fail("unexpected tag value found - not 33"); } tagged = (Asn1TaggedObject)Asn1Object.FromByteArray(tagged.GetEncoded()); if (tagged.TagNo != 33) { Fail("unexpected tag value found on recode - not 33"); } aIn = new Asn1InputStream(longAppSpecificTag); app = (DerApplicationSpecific)aIn.ReadObject(); if (app.ApplicationTag != 97) { Fail("incorrect tag number read"); } app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded()); if (app.ApplicationTag != 97) { Fail("incorrect tag number read on recode"); } SecureRandom sr = new SecureRandom(); for (int i = 0; i < 100; ++i) { int testTag = (sr.NextInt() & int.MaxValue) >> sr.Next(26); app = new DerApplicationSpecific(testTag, new byte[] { 1 }); app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded()); if (app.ApplicationTag != testTag) { Fail("incorrect tag number read on recode (random test value: " + testTag + ")"); } } }
private static string outputApplicationSpecific(string type, string indent, bool verbose, DerApplicationSpecific app) { StringBuilder buf = new StringBuilder(); if (app.IsConstructed()) { try { Asn1Sequence instance = Asn1Sequence.GetInstance(app.GetObject(0x10)); buf.Append(string.Concat(new object[] { indent, type, " ApplicationSpecific[", app.ApplicationTag, "]", NewLine })); IEnumerator enumerator = instance.GetEnumerator(); try { while (enumerator.MoveNext()) { AsString(indent + " ", verbose, ((Asn1Encodable)enumerator.Current).ToAsn1Object(), buf); } } finally { if (enumerator is IDisposable disposable) { IDisposable disposable; disposable.Dispose(); } } } catch (IOException exception) { buf.Append(exception); } return(buf.ToString()); } object[] objArray2 = new object[] { indent, type, " ApplicationSpecific[", app.ApplicationTag, "] (", Hex.ToHexString(app.GetContents()), ")", NewLine }; return(string.Concat(objArray2)); }