public override void CopyFrom (AsnEncodedData asnEncodedData) { if (asnEncodedData == null) throw new ArgumentNullException ("asnEncodedData"); throw new ArgumentException ("Cannot convert the PKCS#9 attribute."); }
public PublicKey(Oid oid, AsnEncodedData parameters, AsnEncodedData keyValue) { _oid = new Oid(oid); EncodedParameters = new AsnEncodedData(parameters); EncodedKeyValue = new AsnEncodedData(keyValue); return; }
internal X509ExtensionCollection (MX.X509Certificate cert) { _list = new ArrayList (cert.Extensions.Count); if (cert.Extensions.Count == 0) return; object[] parameters = new object [2]; foreach (MX.X509Extension ext in cert.Extensions) { bool critical = ext.Critical; string oid = ext.Oid; byte[] raw_data = null; // extension data is embedded in an octet stream (4) ASN1 value = ext.Value; if ((value.Tag == 0x04) && (value.Count > 0)) raw_data = value [0].GetBytes (); parameters [0] = new AsnEncodedData (oid, raw_data); parameters [1] = critical; X509Extension newt = (X509Extension) CryptoConfig.CreateFromName (oid, parameters); if (newt == null) { // not registred in CryptoConfig, using default newt = new X509Extension (oid, raw_data, critical); } _list.Add (newt); } }
public static void TestSubjectAlternativeName() { byte[] sanExtension = { 0x30, 0x31, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x6F, 0x72, 0x67, 0x82, 0x0F, 0x73, 0x75, 0x62, 0x2E, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x6F, 0x72, 0x67, 0x82, 0x11, 0x2A, 0x2E, 0x73, 0x75, 0x62, 0x2E, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x6F, 0x72, 0x67, }; AsnEncodedData asnData = new AsnEncodedData( new Oid("2.5.29.17"), sanExtension); string s = asnData.Format(false); // Windows says: "DNS Name=example.org, DNS Name=sub.example.org, DNS Name=*.sub.example.org" // X-Plat (OpenSSL) says: "DNS:example.org, DNS:sub.example.org, DNS:*.sub.example.org". // This keeps the parsing generalized until we can get them to converge string[] parts = s.Split(new[] { ':', '=', ',' }, StringSplitOptions.RemoveEmptyEntries); // Parts is now { header, data, header, data, header, data }. string[] output = new string[parts.Length / 2]; for (int i = 0; i < output.Length; i++) { output[i] = parts[2 * i + 1]; } Assert.Equal(new[] { "example.org", "sub.example.org", "*.sub.example.org" }, output); }
public X509SubjectKeyIdentifierExtension (AsnEncodedData encodedSubjectKeyIdentifier, bool critical) { // ignore the Oid provided by encodedKeyUsage (our rules!) _oid = new Oid (oid, friendlyName); _raw = encodedSubjectKeyIdentifier.RawData; base.Critical = critical; _status = Decode (this.RawData); }
public X509EnhancedKeyUsageExtension (AsnEncodedData encodedEnhancedKeyUsages, bool critical) { // ignore the Oid provided by encodedKeyUsage (our rules!) _oid = new Oid (oid, friendlyName); _raw = encodedEnhancedKeyUsages.RawData; base.Critical = critical; _status = Decode (this.RawData); }
public static void FormatUnknownData() { byte[] rawData = { 0x41, 0x42, 0x43 }; AsnEncodedData a = new AsnEncodedData(rawData); a.Oid = null; String s = a.Format(true); Assert.Equal("41 42 43", s); return; }
public override void CopyFrom (AsnEncodedData asnEncodedData) { if (asnEncodedData == null) throw new ArgumentNullException ("asnEncodedData"); Decode (asnEncodedData.RawData); Oid = asnEncodedData.Oid; RawData = asnEncodedData.RawData; }
public override void CopyFrom(AsnEncodedData asnEncodedData) { if (asnEncodedData == null) throw new ArgumentNullException(nameof(asnEncodedData)); if (!(asnEncodedData is Pkcs9AttributeObject)) throw new ArgumentException(SR.Cryptography_Pkcs9_AttributeMismatch); base.CopyFrom(asnEncodedData); }
public static void FormatInvalidTypedData() { // This passes in data in an illegal format. AsnEncodedData.Format() swallows the error and falls back to a simple hex-encoding scheme. byte[] rawData = { 0x41, 0x42, 0x43 }; AsnEncodedData a = new AsnEncodedData(rawData); a.Oid = new Oid("1.3.6.1.4.1.311.2.1.27"); //SPC_FINANCIAL_CRITERIA_OBJID String s = a.Format(true); Assert.Equal("414243", s); return; }
public X509Extension (AsnEncodedData encodedExtension, bool critical) { // Match MS if (encodedExtension == null) // throw new ArgumentNullException ("encodedExtension"); if (encodedExtension.Oid == null) throw new ArgumentNullException ("encodedExtension.Oid"); Oid = encodedExtension.Oid; RawData = encodedExtension.RawData; _critical = critical; }
public override void CopyFrom(AsnEncodedData asnEncodedData) { if (asnEncodedData == null) throw new ArgumentNullException("asnEncodedData"); X509Extension extension = asnEncodedData as X509Extension; if (extension == null) throw new ArgumentException(SR.Cryptography_X509_ExtensionMismatch); base.CopyFrom(asnEncodedData); Critical = extension.Critical; }
public X500DistinguishedName (AsnEncodedData encodedDistinguishedName) { if (encodedDistinguishedName == null) throw new ArgumentNullException ("encodedDistinguishedName"); RawData = encodedDistinguishedName.RawData; if (RawData.Length > 0) DecodeRawData (); else name = String.Empty; }
public Pkcs9AttributeObject(AsnEncodedData asnEncodedData) : base(asnEncodedData) { if (asnEncodedData.Oid == null) throw new ArgumentNullException(nameof(asnEncodedData.Oid)); string szOid = base.Oid.Value; if (szOid == null) throw new ArgumentNullException("oid.Value"); if (szOid.Length == 0) throw new ArgumentException(SR.Arg_EmptyOrNullString, "oid.Value"); }
internal PublicKey (Mono.Security.X509.X509Certificate certificate) { if (certificate.KeyAlgorithm == "1.2.840.113549.1.1.1") { _key = certificate.RSA; } else { _key = certificate.DSA; } _oid = new Oid (certificate.KeyAlgorithm); _keyValue = new AsnEncodedData (_oid, certificate.PublicKey); _params = new AsnEncodedData (_oid, certificate.KeyAlgorithmParameters); }
// methods public override void CopyFrom (AsnEncodedData asnEncodedData) { if (asnEncodedData == null) throw new ArgumentNullException ("encodedData"); X509Extension ex = (asnEncodedData as X509Extension); if (ex == null) throw new ArgumentException (Locale.GetText ("Expected a X509Extension instance.")); base.CopyFrom (asnEncodedData); // and we deal with critical _critical = ex.Critical; }
public PublicKey (Oid oid, AsnEncodedData parameters, AsnEncodedData keyValue) { if (oid == null) throw new ArgumentNullException ("oid"); if (parameters == null) throw new ArgumentNullException ("parameters"); if (keyValue == null) throw new ArgumentNullException ("keyValue"); _oid = new Oid (oid); _params = new AsnEncodedData (parameters); _keyValue = new AsnEncodedData (keyValue); }
public static void Add() { AsnEncodedData a0 = new AsnEncodedData("1.0", Array.Empty<byte>()); AsnEncodedData a1 = new AsnEncodedData("1.1", Array.Empty<byte>()); AsnEncodedData a2 = new AsnEncodedData("1.2", Array.Empty<byte>()); AsnEncodedDataCollection c = new AsnEncodedDataCollection(); int index; index = c.Add(a0); Assert.Equal(0, index); index = c.Add(a1); Assert.Equal(1, index); index = c.Add(a2); Assert.Equal(2, index); AssertEquals(c, new AsnEncodedData[] { a0, a1, a2 }); }
internal X509ExtensionCollection (MX.X509Certificate cert) { _list = new ArrayList (cert.Extensions.Count); if (cert.Extensions.Count == 0) return; object[] parameters = new object [2]; foreach (MX.X509Extension ext in cert.Extensions) { bool critical = ext.Critical; string oid = ext.Oid; byte[] raw_data = null; // extension data is embedded in an octet stream (4) ASN1 value = ext.Value; if ((value.Tag == 0x04) && (value.Count > 0)) raw_data = value [0].GetBytes (); X509Extension newt = null; #if FULL_AOT_RUNTIME // non-extensible switch (oid) { case "2.5.29.14": newt = new X509SubjectKeyIdentifierExtension (new AsnEncodedData (oid, raw_data), critical); break; case "2.5.29.15": newt = new X509KeyUsageExtension (new AsnEncodedData (oid, raw_data), critical); break; case "2.5.29.19": newt = new X509BasicConstraintsExtension (new AsnEncodedData (oid, raw_data), critical); break; case "2.5.29.37": newt = new X509EnhancedKeyUsageExtension (new AsnEncodedData (oid, raw_data), critical); break; } #else parameters [0] = new AsnEncodedData (oid, raw_data ?? Empty); parameters [1] = critical; newt = (X509Extension) CryptoConfig.CreateFromName (oid, parameters); #endif if (newt == null) { // not registred in CryptoConfig, using default newt = new X509Extension (oid, raw_data ?? Empty, critical); } _list.Add (newt); } }
public AsnEncodedDataCollection(AsnEncodedData asnEncodedData) {}
public void CopyTo(AsnEncodedData[] array, int index) {}
/// <inheritdoc /> public override void CopyFrom(AsnEncodedData asnEncodedData) { base.CopyFrom(asnEncodedData); _decoded = null; }
public override void CopyFrom(AsnEncodedData asnEncodedData) { base.CopyFrom(asnEncodedData); _decoded = false; }
public X509SubjectKeyIdentifierExtension(AsnEncodedData encodedSubjectKeyIdentifier, bool critical) : base(Oids.SubjectKeyIdentifier, encodedSubjectKeyIdentifier.RawData, critical) { }
static void TestAdd() { asn = new AsnEncodedDataCollection() ; try { asn.Add( null ) ; Result = false ; } catch( ArgumentNullException ) { Result = true ; } catch( Exception ) { Result = false ; } //add normal case AsnEncodedData data1 = new AsnEncodedData( oid , new byte[]{1,2,3} ) ; AsnEncodedData data2 = new AsnEncodedData( oid , new byte[]{5,6,7} ) ; asn = new AsnEncodedDataCollection(data1) ; asn.Add( data2 ) ; Result = asn.Count == 2 ; //Add where OIDs don't match data2 = new AsnEncodedData(badOid , new byte[]{1,2,3,4} ) ; asn = GetCollection(data1) ; try { asn.Add(data2) ; Result = false ; } catch(CryptographicException) { Result = true ; } catch(Exception e) { Result = false ; Console.WriteLine(e) ; } //add w/ a empty Oid data2.Oid = new Oid() ; asn = GetCollection(data1) ; try { asn.Add(data2) ; Result = false ; } catch(CryptographicException) { Result = true ; } catch(Exception e) { Result = false ; Console.WriteLine(e) ; } }
static AsnEncodedDataCollection GetCollection(AsnEncodedData data) { AsnEncodedDataCollection asn = new AsnEncodedDataCollection(data) ; FieldInfo fi = asn.GetType().GetField( "m_oid" , BindingFlags.NonPublic | BindingFlags.Instance ) ; fi.SetValue( asn , oid ) ; return asn ; }
static Oid badOid = new Oid( "1.3.14.3.2.27" ) ; //bogus OID static void TestCopyTo() { asn = GetCollection( new AsnEncodedData( oid , new byte[]{1,2,3} ) ); AsnEncodedData[] array = new AsnEncodedData[asn.Count] ; //straight up copy asn.CopyTo( array , 0 ) ; Result = array[0] != null ; //ary is null try { asn.CopyTo( null , 0 ) ; Result = false ; } catch(ArgumentNullException) { Result = true ; } catch(Exception e) { Result = false ; Console.WriteLine(e) ; } //index is too big/small try { asn.CopyTo( array , -1 ) ; Result = false ; } catch(ArgumentOutOfRangeException) { Result = true ; } catch(Exception e) { Result = false ; Console.WriteLine(e) ; } try { asn.CopyTo( array , 10 ) ; Result = false ; } catch(ArgumentOutOfRangeException) { Result = true ; } catch(Exception e) { Result = false ; Console.WriteLine(e) ; } //count + length mistmatch try { asn.CopyTo( array , 1 ) ; Result = false ; } catch(ArgumentException) { Result = true ; } catch(Exception e) { Result = false ; Console.WriteLine(e) ; } }
public override void CopyFrom(AsnEncodedData asnEncodedData) { base.CopyFrom(asnEncodedData); _lazyDocumentName = null; }
public override void CopyFrom(AsnEncodedData asnEncodedData) { base.CopyFrom(asnEncodedData); _lazyContentType = null; }
/// <summary> /// Creates an extension from ASN.1 encoded data. /// </summary> public X509SubjectAltNameExtension(AsnEncodedData encodedExtension, bool critical) : this(encodedExtension.Oid, encodedExtension.RawData, critical) { }
// Methods public int Add(AsnEncodedData asnEncodedData) {}
public override void CopyFrom (AsnEncodedData asnEncodedData) { base.CopyFrom (asnEncodedData); Decode (this.RawData); }
public void Remove(AsnEncodedData asnEncodedData) {}
public override void CopyFrom(AsnEncodedData asnEncodedData) { base.CopyFrom(asnEncodedData); _lazyMessageDigest = null; }