Ejemplo n.º 1
0
        public void TestEvaluation()
        {
            IDkimRecordParser dkimRecordParser = Create();

            //string record = "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxBwakMBSvmNXD9UJvNVpP3X+QanFgeep6e89Yb5yVeHE7hs7UYglXEG2a2KEGnkOqxu7IfsHtbv3ibbZVSqk8OV9n58Gzl6uGs9MCQAa0JhIodRMzjF20PhxBhKBnSp9SX1E5RlgOplNF2Bat0+2ypb+TKmEgnMkjok9YXL8ddwIDAQAB; n=1024,1462785360,1";
            string record = "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIl6aF27aG0BCld/lgh2vC+1Mw55QdjrYKUsI/NksVASi9XQzh05yW87rlnSnmNg13k2E+gJaQL483/jUTGKwMWLlFUUQ8WwazUpw+xsuMdksHyp+RcHizR+reXNmNikJ3xbCKxaFW3er6MiZGRkf64zf87NwEvU8r47LGPcjK6wIDAQAB";

            DkimRecord dkimRecord = dkimRecordParser.Parse(new DnsRecord(record, new List <string>()));
        }
        public void ParseWithEd25519KeyDkimRecord()
        {
            IDkimRecordParser parser = Create();
            string            record = "v=DKIM1;"
                                       + "k=ed25519;"
                                       + "n=hello world;"
                                       + "s=*;"
                                       + "h=sha256;"
                                       + "t=y;"
                                       + "p=pEd4PDHp7GcYy1yc/0ZYw/aidpwIUPL2Z4433ZnuWoA=";

            DkimRecord dkimRecord = parser.Parse(new DnsRecord(record, new List <string>()));

            Assert.That(dkimRecord.Errors, Is.Empty);
        }
        public void ParseWithRsa2048KeyDkimRecord()
        {
            IDkimRecordParser parser = Create();
            string            record = "v=DKIM1;"
                                       + "k=rsa;"
                                       + "n=hello world;"
                                       + "s=*;"
                                       + "h=sha256;"
                                       + "t=y;"
                                       + "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvtzV5FCafF4GWCsuV0qhyDpV8pz7QrFxF8JABDl+kewpUIhTRujuKQbeAIuPzbiTe0djy1tPIyzEASChfPpSg7C9RrJlKlluyYN1H4ORJQsnAuwAy8+Eur+Zjo1o6xItxsac9RUvl4eCm8ZSkhtdu1HMRV0+rq2S1+E0cqwyO7xw2alhLRmu96Dgy2j4dz/8teguAUEaNGQECcd7h7DM" +
                                       "8vo8IZgyJHJdaMQHX7zhuRUP8fjsrD5YUfOsm/kzSJfSKEk9cXwKk8p5QoiHG+W4/tc/nyl+uqz9fUF/K0d9qCvHE31mu3to2GCakABPU9XpczhIwYkGB6ASdd53PKhXJwIDAQAB";

            DkimRecord dkimRecord = parser.Parse(new DnsRecord(record, new List <string>()));

            Assert.That(dkimRecord.Errors.Count, Is.EqualTo(0));
        }
        public void ParseWithPublicKeyDataTagMissing()
        {
            IDkimRecordParser parser = Create();
            string            record = "v=DKIM1;"
                                       + "k=rsa;"
                                       + "n=hello world;"
                                       + "s=*;"
                                       + "h=sha256;"
                                       + "t=y";

            DkimRecord dkimRecord = parser.Parse(new DnsRecord(record, new List <string>()));

            Assert.That(dkimRecord.Errors.Count, Is.EqualTo(1));
            Assert.That(dkimRecord.Errors.First().ErrorType, Is.EqualTo(EvaluationErrorType.Error));
            Assert.That(dkimRecord.Errors.First().Id, Is.EqualTo(Guid.Parse("f3895ef6-8709-499a-8c5c-40118a818087")));
        }
        public void ParseWithCorruptPublicKeyDkimRecordShouldError()
        {
            IDkimRecordParser parser = Create();
            string            record = "v=DKIM1;"
                                       + "k=rsa;"
                                       + "n=hello world;"
                                       + "s=*;"
                                       + "h=sha256;"
                                       + "t=y;"
                                       + "p=ABCfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDsRhw52Ldz6Cz4LYdSfDdCGi1x+SmR/xT+6PhGzvZfEgQN8SzRrQBnvmTW/Rizuivul+iq4bbS3Dc4S0ZoDkdG30jr4NRK35lGcDRWUV3XYsgX8Y5FzTFP73dbO9vHv3UVxmH0/giIOZ2j4xzIad7VHjn2AvDUafv2UkIwk/qlQIDAQAB";

            DkimRecord dkimRecord = parser.Parse(new DnsRecord(record, new List <string>()));

            Assert.That(dkimRecord.Errors.Count, Is.EqualTo(1));
            Assert.That(dkimRecord.Errors.First().ErrorType, Is.EqualTo(EvaluationErrorType.Error));
            Assert.That(dkimRecord.Errors.First().Id, Is.EqualTo(Guid.Parse("21B09D43-685C-4CAE-989E-7194CA093863")));
        }
        public void ParseWithRsa1024KeyDkimRecordShouldError()
        {
            IDkimRecordParser parser = Create();
            string            record = "v=DKIM1;"
                                       + "k=rsa;"
                                       + "n=hello world;"
                                       + "s=*;"
                                       + "h=sha256;"
                                       + "t=y;"
                                       + "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDsRhw52Ldz6Cz4LYdSfDdCGi1x+SmR/xT+6PhGzvZfEgQN8SzRrQBnvmTW/Rizuivul+iq4bbS3Dc4S0ZoDkdG30jr4NRK35lGcDRWUV3XYsgX8Y5FzTFP73dbO9vHv3UVxmH0/giIOZ2j4xzIad7VHjn2AvDUafv2UkIwk/qlQIDAQAB";

            DkimRecord dkimRecord = parser.Parse(new DnsRecord(record, new List <string>()));

            Assert.That(dkimRecord.Errors.Count, Is.EqualTo(1));
            Assert.That(dkimRecord.Errors.First().ErrorType, Is.EqualTo(EvaluationErrorType.Warning));
            Assert.That(dkimRecord.Errors.First().Id, Is.EqualTo(Guid.Parse("d16be8d5-8ed6-4dd0-a8aa-c8f1380a8d3c")));
        }
        public DkimRecord Parse(DnsRecord record)
        {
            string[] stringTags = record.Record.Split(Separator, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(_ => _.Trim())
                                  .ToArray();

            EvaluationResult <List <Tag> > evaluatedTags = _tagParser.Parse(stringTags.ToList());

            List <Tag> implicitTags = _implicitProvider.GetImplicitValues(evaluatedTags.Item);

            DkimRecord dkimRecord = new DkimRecord(record, evaluatedTags.Item.Concat(implicitTags).ToList(), evaluatedTags.Errors);

            if (evaluatedTags.Errors != null && evaluatedTags.Errors.All(x => x.ErrorType != EvaluationErrorType.Error))
            {
                EvaluationResult <DkimRecord> evaluationResult = _ruleEvaluator.Evaluate(dkimRecord).Result;

                dkimRecord.Errors.AddRange(evaluationResult.Errors);
            }

            return(dkimRecord);
        }
        public void ParseWithRsa1985KeyDkimRecord()
        {
            IRsaPublicKeyEvaluator rsaPublicKeyEvaluator = A.Fake <IRsaPublicKeyEvaluator>();
            int anOut;

            A.CallTo(() => rsaPublicKeyEvaluator.TryGetKeyLengthSize(A <string> ._, out anOut)).Returns(true).AssignsOutAndRefParameters(1985);

            IDkimRecordParser parser = Create(rsaPublicKeyEvaluator);
            string            record = "v=DKIM1;"
                                       + "k=rsa;"
                                       + "n=hello world;"
                                       + "s=*;"
                                       + "h=sha256;"
                                       + "t=y;"
                                       + "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvtzV5FCafF4GWCsuV0qhyDpV8pz7QrFxF8JABDl+kewpUIhTRujuKQbeAIuPzbiTe0djy1tPIyzEASChfPpSg7C9RrJlKlluyYN1H4ORJQsnAuwAy8+Eur+Zjo1o6xItxsac9RUvl4eCm8ZSkhtdu1HMRV0+rq2S1+E0cqwyO7xw2alhLRmu96Dgy2j4dz/8teguAUEaNGQECcd7h7DM" +
                                       "8vo8IZgyJHJdaMQHX7zhuRUP8fjsrD5YUfOsm/kzSJfSKEk9cXwKk8p5QoiHG+W4/tc/nyl+uqz9fUF/K0d9qCvHE31mu3to2GCakABPU9XpczhIwYkGB6ASdd53PKhXJwIDAQAB";

            DkimRecord dkimRecord = parser.Parse(new DnsRecord(record, new List <string>()));

            Assert.That(dkimRecord.Errors.Count, Is.EqualTo(1));
            Assert.That(dkimRecord.Errors.First().ErrorType, Is.EqualTo(EvaluationErrorType.Warning));
            Assert.That(dkimRecord.Errors.First().Id, Is.EqualTo(Guid.Parse("d16be8d5-8ed6-4dd0-a8aa-c8f1380a8d3c")));
        }
Ejemplo n.º 9
0
 private static DkimContractRecord MapToDkimContractRecord(DkimRecord dkimRecord)
 {
     return(new DkimContractRecord(dkimRecord.DnsRecord, dkimRecord.Errors.Select(MapToMessage).ToList()));
 }
Ejemplo n.º 10
0
 private static RecordResult MapToRecordResult(DkimRecord dkimRecord)
 {
     return(new RecordResult(dkimRecord.DnsRecord.Record, dkimRecord.Errors.Select(MapToEvaluatorMessage).ToList()));
 }