Verify() public method

Verify the specified DKIM-Signature header.
Verifies the specified DKIM-Signature header.
/// is null. /// -or- /// is null. /// -or- /// is null. /// /// is not a DKIM-Signature header. /// /// The DKIM-Signature header value is malformed. /// /// The operation was canceled via the cancellation token. ///
public Verify ( MimeKit.FormatOptions options, Header dkimSignature, IDkimPublicKeyLocator publicKeyLocator, CancellationToken cancellationToken = default(CancellationToken) ) : bool
options MimeKit.FormatOptions The formatting options.
dkimSignature Header The DKIM-Signature header.
publicKeyLocator IDkimPublicKeyLocator The public key locator service.
cancellationToken System.Threading.CancellationToken The cancellation token.
return bool
Ejemplo n.º 1
0
		static void TestDkimSignVerify (MimeMessage message, DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm headerAlgorithm, DkimCanonicalizationAlgorithm bodyAlgorithm)
		{
			var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
			var signer = CreateSigner (signatureAlgorithm);

			message.Sign (signer, headers, headerAlgorithm, bodyAlgorithm);

			var dkim = message.Headers[0];

			Assert.IsTrue (message.Verify (dkim, new DummyPublicKeyLocator (DkimKeys.Public)), "Failed to verify DKIM-Signature.");

			message.Headers.RemoveAt (0);
		}
Ejemplo n.º 2
0
		public void TestArgumentExceptions ()
		{
			var locator = new DummyPublicKeyLocator (DkimKeys.Public);
			var dkimHeader = new Header (HeaderId.DkimSignature, "value");
			var message = new MimeMessage ();

			Assert.Throws<ArgumentNullException> (() => message.Sign (null, new HeaderId[] { HeaderId.From }));
			Assert.Throws<ArgumentNullException> (() => message.Sign (CreateSigner (DkimSignatureAlgorithm.RsaSha1), null));
			Assert.Throws<ArgumentNullException> (() => message.Verify (null, locator));
			Assert.Throws<ArgumentNullException> (() => message.Verify (dkimHeader, null));
			Assert.Throws<ArgumentNullException> (() => message.Verify (null, dkimHeader, locator));
			Assert.Throws<ArgumentNullException> (() => message.Verify (FormatOptions.Default, null, locator));
			Assert.Throws<ArgumentNullException> (() => message.Verify (FormatOptions.Default, dkimHeader, null));
		}
Ejemplo n.º 3
0
		static void TestUnicode (DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm bodyAlgorithm, string expectedHash)
		{
			var headers = new [] { HeaderId.From, HeaderId.To, HeaderId.Subject, HeaderId.Date };
			var signer = CreateSigner (signatureAlgorithm);
			var message = new MimeMessage ();

			message.From.Add (new MailboxAddress ("", "*****@*****.**"));
			message.To.Add (new MailboxAddress ("", "*****@*****.**"));
			message.Subject = "This is a unicode message";
			message.Date = DateTimeOffset.Now;

			var builder = new BodyBuilder ();
			builder.TextBody = " تست  ";
			builder.HtmlBody = "  <div> تست </div> ";
			message.Body = builder.ToMessageBody ();

			((Multipart) message.Body).Boundary = "=-MultipartAlternativeBoundary";
			((Multipart) message.Body)[1].ContentId = null;

			message.Body.Prepare (EncodingConstraint.EightBit);

			message.Sign (signer, headers, DkimCanonicalizationAlgorithm.Simple, bodyAlgorithm);

			var dkim = message.Headers[0];

			Console.WriteLine ("{0}", dkim.Value);

			VerifyDkimBodyHash (message, signatureAlgorithm, expectedHash);

			Assert.IsTrue (message.Verify (dkim, new DummyPublicKeyLocator (DkimKeys.Public)), "Failed to verify DKIM-Signature.");
		}
Ejemplo n.º 4
0
		static void TestEmptyBody (DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm bodyAlgorithm, string expectedHash)
		{
			var headers = new [] { HeaderId.From, HeaderId.To, HeaderId.Subject, HeaderId.Date };
			var signer = CreateSigner (signatureAlgorithm);
			var message = new MimeMessage ();

			message.From.Add (new MailboxAddress ("", "*****@*****.**"));
			message.To.Add (new MailboxAddress ("", "*****@*****.**"));
			message.Subject = "This is an empty message";
			message.Date = DateTimeOffset.Now;

			message.Body = new TextPart ("plain") { Text = "" };

			message.Body.Prepare (EncodingConstraint.SevenBit);

			message.Sign (signer, headers, DkimCanonicalizationAlgorithm.Simple, bodyAlgorithm);

			VerifyDkimBodyHash (message, signatureAlgorithm, expectedHash);

			var dkim = message.Headers[0];

			Assert.IsTrue (message.Verify (dkim, new DummyPublicKeyLocator (DkimKeys.Public)), "Failed to verify DKIM-Signature.");
		}