public void Constructor_Empty ()
		{
			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension ();
			ski.Identifier = new byte[] {
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00
			};
			Empty (ski);
		}
		public void Constructor_ASN1 ()
		{
			SubjectKeyIdentifierExtension ext = new SubjectKeyIdentifierExtension ();
			ext.Identifier = new byte[] {
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00
			};
			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext.ASN1);
			Empty (ski);
		}
		private void Empty (SubjectKeyIdentifierExtension ski)
		{
			Assert.IsFalse (ski.Critical, "Critical");
			Assert.AreEqual ("2.5.29.14", ski.Oid, "Oid");
			Assert.IsNotNull (ski.Name, "Name");
			Assert.IsFalse (ski.Name == ski.Oid, "Name!=Oid");
			Assert.AreEqual (new byte[] {
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00
			}, ski.Identifier, "Identifier");
		}
Example #4
0
		private byte[] GetUniqueName (X509ExtensionCollection extensions) 
		{
			// We prefer Subject Key Identifier as the unique name
			// as it will provide faster lookups
			X509Extension ext = extensions ["2.5.29.14"];
			if (ext == null)
				return null;

			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
			return ski.Identifier;
		}
Example #5
0
		private byte[] GetUniqueName (X509ExtensionCollection extensions, byte[] serial = null) 
		{
			// We prefer Subject Key Identifier as the unique name
			// as it will provide faster lookups
			X509Extension ext = extensions ["2.5.29.14"];
			if (ext == null)
				return null;

			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
			if (serial == null) {
				return ski.Identifier;
			} else {
				byte[] uniqueWithSerial = new byte[ski.Identifier.Length + serial.Length];
				System.Buffer.BlockCopy (ski.Identifier, 0, uniqueWithSerial, 0, ski.Identifier.Length );
				System.Buffer.BlockCopy (serial, 0, uniqueWithSerial, ski.Identifier.Length, serial.Length );
				return uniqueWithSerial;
			}
		}
		// private stuff

		private string GetUniqueName (X509Certificate certificate) 
		{
			string method = null;
			byte[] name = null;

			// We prefer Subject Key Identifier as the unique name
			// as it will provide faster lookups
			X509Extension ext = certificate.Extensions ["2.5.29.14"];
			if (ext != null) {
				SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
				name = ski.Identifier;
				method = "ski";
			}
			else {
				method = "tbp"; // thumbprint
				name = certificate.Hash;
			}

			StringBuilder sb = new StringBuilder (method);
			sb.Append ("-");
			foreach (byte b in name) {
				sb.Append (b.ToString ("X2", CultureInfo.InvariantCulture));
			}
			sb.Append (".cer");

			return sb.ToString ();
		}
Example #7
0
		static byte [] GetSubjectKeyIdentifier (X509Extension ext)
		{
			if (ext == null)
				return null;

			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
			return ski.Identifier;
		}
		public void AuthorityKeyIdentifier_Critical ()
		{
			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension ();
			ski.Critical = true;
			ski.Identifier = new byte[] {
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00
			};
			Assert.AreEqual ("30-20-06-03-55-1D-0E-01-01-FF-04-16-04-14-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString (ski.GetBytes ()), "GetBytes");

			SubjectKeyIdentifierExtension ski2 = new SubjectKeyIdentifierExtension (ski.ASN1);
			Assert.IsTrue (ski2.Critical, "Critical");
			Assert.AreEqual (new byte[] {
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00
			}, ski2.Identifier, "Identifier");
		}
		public void EmptyIdentifier ()
		{
			SubjectKeyIdentifierExtension ext = new SubjectKeyIdentifierExtension ();
			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
			Empty (ski);
		}