示例#1
0
        public async Task TestVerifyRfc8463ExampleAsync()
        {
            var message  = MimeMessage.Load(Path.Combine(TestHelper.ProjectDir, "TestData", "dkim", "rfc8463-example.msg"));
            var locator  = new DkimPublicKeyLocator();
            var verifier = new DkimVerifier(locator);
            int index;

            locator.Add("brisbane._domainkey.football.example.com", "v=DKIM1; k=ed25519; p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=");
            locator.Add("test._domainkey.football.example.com", "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDkHlOQoBTzWRiGs5V6NpP3idY6Wk08a5qhdR6wy5bdOKb2jLQiY/J16JYi0Qvx/byYzCNb3W91y3FutACDfzwQ/BC/e/8uBsCR+yz1Lxj+PL6lHvqMKrM3rG4hstT5QjvHO9PzoxZyVYLzBfO2EeC3Ip3G+2kryOTIKT+l/K4w3QIDAQAB");

            // the last DKIM-Signature uses rsa-sha256
            index = message.Headers.LastIndexOf(HeaderId.DkimSignature);
            Assert.IsTrue(await verifier.VerifyAsync(message, message.Headers[index]), "Failed to verify rsa-sha256");

            // the first DKIM-Signature uses ed25519-sha256
            index = message.Headers.IndexOf(HeaderId.DkimSignature);
            Assert.IsTrue(await verifier.VerifyAsync(message, message.Headers[index]), "Failed to verify ed25519-sha256");
        }
        public void TestParseExceptions()
        {
            var locator = new DkimPublicKeyLocator();

            locator.Add("empty._domainkey.example.org", string.Empty);
            locator.Add("whitespace._domainkey.example.org", "     ");
            locator.Add("no-k-or-p-params._domainkey.example.org", "v=DKIM1; x=abc; y=def");
            //locator.Add ("no-k-param._domainkey.example.org", "v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDkHlOQoBTzWRiGs5V6NpP3id Y6Wk08a5qhdR6wy5bdOKb2jLQiY/J16JYi0Qvx/byYzCNb3W91y3FutACDfzwQ/BC/e/8uBsCR+yz1Lx j+PL6lHvqMKrM3rG4hstT5QjvHO9PzoxZyVYLzBfO2EeC3Ip3G+2kryOTIKT+l/K4w3QIDAQAB");
            locator.Add("no-p-param._domainkey.example.org", "v=DKIM1; k=rsa");
            locator.Add("unknown-algorithm._domainkey.example.org", "v=DKIM1; k=dummy; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDkHlOQoBTzWRiGs5V6NpP3id");

            Assert.Throws <ParseException> (() => locator.LocatePublicKey("dns/txt", "example.org", "empty"));
            Assert.Throws <ParseException> (() => locator.LocatePublicKey("dns/txt", "example.org", "whitespace"));
            Assert.Throws <ParseException> (() => locator.LocatePublicKey("dns/txt", "example.org", "no-k-or-p-params"));
            //Assert.Throws<ParseException> (() => locator.LocatePublicKey ("dns/txt", "example.org", "no-k-param"));
            Assert.Throws <ParseException> (() => locator.LocatePublicKey("dns/txt", "example.org", "no-p-param"));
            Assert.Throws <ParseException> (() => locator.LocatePublicKey("dns/txt", "example.org", "unknown-algorithm"));
        }
        public void TestArgumentExceptions()
        {
            var locator = new DkimPublicKeyLocator();

            locator.Add("dummy._domainkey.example.org", null);

            Assert.Throws <ArgumentNullException> (() => locator.LocatePublicKey("dns/txt", "example.org", "dummy"));
            Assert.ThrowsAsync <ArgumentNullException> (async() => await locator.LocatePublicKeyAsync("dns/txt", "example.org", "dummy"));
        }
        public void TestParseMissingKParamDefaultsToRsa()
        {
            var locator = new DkimPublicKeyLocator();

            locator.Add("no-k-param._domainkey.example.org", "v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDkHlOQoBTzWRiGs5V6NpP3id Y6Wk08a5qhdR6wy5bdOKb2jLQiY/J16JYi0Qvx/byYzCNb3W91y3FutACDfzwQ/BC/e/8uBsCR+yz1Lx j+PL6lHvqMKrM3rG4hstT5QjvHO9PzoxZyVYLzBfO2EeC3Ip3G+2kryOTIKT+l/K4w3QIDAQAB");

            var key = locator.LocatePublicKey("dns/txt", "example.org", "no-k-param");

            Assert.IsInstanceOf <RsaKeyParameters> (key);
        }
示例#5
0
        public void TestSignRfc8463Example()
        {
            var message = MimeMessage.Load(Path.Combine(TestHelper.ProjectDir, "TestData", "dkim", "rfc8463-example.msg"));
            var signer  = new DkimSigner(Ed25519PrivateKey, "football.example.com", "brisbane", DkimSignatureAlgorithm.Ed25519Sha256)
            {
                HeaderCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Relaxed,
                BodyCanonicalizationAlgorithm   = DkimCanonicalizationAlgorithm.Relaxed,
                AgentOrUserIdentifier           = "@football.example.com"
            };
            var headers = new string[] { "from", "to", "subject", "date", "message-id", "from", "subject", "date" };

            signer.Sign(message, headers);

            int index    = message.Headers.IndexOf(HeaderId.DkimSignature);
            var locator  = new DkimPublicKeyLocator();
            var verifier = new DkimVerifier(locator);
            var dkim     = message.Headers[index];

            locator.Add("brisbane._domainkey.football.example.com", "v=DKIM1; k=ed25519; p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=");
            locator.Add("test._domainkey.football.example.com", "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDkHlOQoBTzWRiGs5V6NpP3idY6Wk08a5qhdR6wy5bdOKb2jLQiY/J16JYi0Qvx/byYzCNb3W91y3FutACDfzwQ/BC/e/8uBsCR+yz1Lxj+PL6lHvqMKrM3rG4hstT5QjvHO9PzoxZyVYLzBfO2EeC3Ip3G+2kryOTIKT+l/K4w3QIDAQAB");

            Assert.IsTrue(verifier.Verify(message, message.Headers[index]), "Failed to verify ed25519-sha256");
        }