1 | /*
|
2 | * Copyright (c) 2020-2023, Stalwart Labs Ltd.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
5 | * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
6 | * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
7 | * option. This file may not be copied, modified, or distributed
|
8 | * except according to those terms.
|
9 | */
|
10 |
|
11 | use mail_auth::{AuthenticatedMessage, DkimResult, Resolver};
|
12 |
|
13 | const TEST_MESSAGE: &str = r#"DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed;
|
14 | d=football.example.com; i=@football.example.com;
|
15 | q=dns/txt; s=brisbane; t=1528637909; h=from : to :
|
16 | subject : date : message-id : from : subject : date;
|
17 | bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
|
18 | b=/gCrinpcQOoIfuHNQIbq4pgh9kyIK3AQUdt9OdqQehSwhEIug4D11Bus
|
19 | Fa3bT3FY5OsU7ZbnKELq+eXdp1Q1Dw==
|
20 | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
|
21 | d=football.example.com; i=@football.example.com;
|
22 | q=dns/txt; s=test; t=1528637909; h=from : to : subject :
|
23 | date : message-id : from : subject : date;
|
24 | bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
|
25 | b=F45dVWDfMbQDGHJFlXUNB2HKfbCeLRyhDXgFpEL8GwpsRe0IeIixNTe3
|
26 | DhCVlUrSjV4BwcVcOF6+FF3Zo9Rpo1tFOeS9mPYQTnGdaSGsgeefOsk2Jz
|
27 | dA+L10TeYt9BgDfQNZtKdN1WO//KgIqXP7OdEFE4LjFYNcUxZQ4FADY+8=
|
28 | From: Joe SixPack <joe@football.example.com>
|
29 | To: Suzie Q <suzie@shopping.example.net>
|
30 | Subject: Is dinner ready?
|
31 | Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
|
32 | Message-ID: <20030712040037.46341.5F8J@football.example.com>
|
33 |
|
34 | Hi.
|
35 |
|
36 | We lost the game. Are you hungry yet?
|
37 |
|
38 | Joe."#;
|
39 |
|
40 | #[tokio::main]
|
41 | async fn main() {
|
42 | // Create a resolver using Cloudflare DNS
|
43 | let resolver = Resolver::new_cloudflare_tls().unwrap();
|
44 |
|
45 | // Parse message
|
46 | let authenticated_message = AuthenticatedMessage::parse(TEST_MESSAGE.as_bytes()).unwrap();
|
47 |
|
48 | // Validate signature
|
49 | let result = resolver.verify_dkim(&authenticated_message).await;
|
50 |
|
51 | // Make sure all signatures passed verification
|
52 | assert!(result.iter().all(|s| s.result() == &DkimResult::Pass));
|
53 | }
|