160
160
>>> dar_fail.match_signature('mail-router.example.net')
163
RFC 5451 B.6(1) modified to use d= instead of i= with header.a and header.s added
165
>>> dsr_pass = authres.DKIMAuthenticationResult(result = 'pass', result_comment = 'good signature',
166
... header_d = 'mail-router.example.net', header_a = 'rsa-sha256', header_s = 'default')
167
>>> dsr_fail = authres.DKIMAuthenticationResult(result = 'fail',
168
... header_d = 'newyork.example.com', result_comment = 'bad signature')
169
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'example.com',
170
... results = [dsr_pass, dsr_fail]))
171
'Authentication-Results: example.com; dkim=pass (good signature) header.d=mail-router.example.net header.a=rsa-sha256 header.s=default; dkim=fail (bad signature) header.d=newyork.example.com'
172
>>> dsr_pass.match_signature_algorithm('mail-router.example.net', 'rsa-sha256')
174
>>> dsr_fail.match_signature_algorithm('mail-router.example.net', 'rsa-sha256')
177
Header from dcrup testing
179
>>> dss_pass = authres.DKIMAuthenticationResult(result = 'pass', result_comment = 'Good 256 bit ed25519-sha256 signature.',
180
... header_d = 'example.com', header_i = '@example.com', header_a = 'ed25519-sha256')
181
>>> dss_fail = authres.DKIMAuthenticationResult(result = 'fail', result_comment = 'Bad 1024 bit rsa-sha256 signature.',
182
... header_d = 'example.com', header_i = '@example.com', header_a = 'rsa-sha256')
183
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'relay02.example.org',
184
... results = [dss_pass, dss_fail]))
185
'Authentication-Results: relay02.example.org; dkim=pass (Good 256 bit ed25519-sha256 signature.) header.d=example.com header.i=@example.com header.a=ed25519-sha256; dkim=fail (Bad 1024 bit rsa-sha256 signature.) header.d=example.com header.i=@example.com header.a=rsa-sha256'
163
187
# Missing parsing header comment.
165
189
>>> import authres
525
549
... results = [mfrom_pass, helo_none]))
526
550
'Authentication-Results: example.com; spf=pass smtp.mailfrom=authenticated@example.net; spf=none reason="No SPF record for HELO" smtp.helo=mailserver.example.net'
528
# Create header field with ARC results (draft-ietf-dmarc-arc-protocol-05)
552
# Create header field with ARC results (draft-ietf-dmarc-arc-protocol-18)
529
553
>>> import authres
530
554
>>> import authres.arc
531
555
>>> arc_pass = authres.arc.ARCAuthenticationResult(result = 'pass',
532
... header_ams_d = 'example.net', header_ams_s='valimail2016', header_as_d="example.com", header_as_s="valimail2017")
556
... header_ams_d = 'example.net', header_ams_s='valimail2016', header_as_d="example.com", header_as_s="valimail2017", header_oldest_pass='1', smtp_remote_ip='203.0.113.1')
533
557
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'example.com',
534
558
... results = [arc_pass]))
535
'Authentication-Results: example.com; arc=pass header.ams-d=example.net header.ams-s=valimail2016 header.as-d=example.com header.as-s=valimail2017'
559
'Authentication-Results: example.com; arc=pass header.ams-d=example.net header.ams-s=valimail2016 header.as-d=example.com header.as-s=valimail2017 header.oldest-pass=1 smtp.remote-ip=203.0.113.1'
537
561
# Parsing IP6 address.
538
562
>>> arobj = authres_context.parse('Authentication-Results: mail.bmsi.com; iprev=pass policy.iprev="2001:748:100:40::2:2" (mout0.freenet.de); spf=none smtp.mailfrom=markuslaudi@freenet.de')
641
665
... results = [mfrom_auth]))
642
666
'Authentication-Results: example.com; auth=pass smtp.mailfrom=mailauth@example.net'
668
# Ignore unknown method (RFC 7601 2.7.6 SHOULD)
670
>>> arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; tls=pass smtp.TLSversion=TLSv1.2 smtp.TLScyper=ECDHE-RSA-CHACHA20-POLY1305 smtp.TLSbits=256')
671
>>> str(arobj.authserv_id)
673
>>> str(arobj.results[0])
674
'tls=pass smtp.tlsversion=TLSv1.2 smtp.tlscyper=ECDHE-RSA-CHACHA20-POLY1305 smtp.tlsbits=256'
675
>>> str(arobj.results[0].method)
677
>>> str(arobj.results[0].result)
679
>>> try: str(arobj.results[0].smtp_mailfrom)
680
... except AttributeError as e: print(e)
681
'AuthenticationResult' object has no attribute 'smtp_mailfrom'
682
>>> str(arobj.results[0].properties[0].type)
684
>>> str(arobj.results[0].properties[0].name)
686
>>> str(arobj.results[0].properties[0].value)
690
# Invalid ptype (error) and unknown method (OK)
692
>>> try: arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; x-tls=pass version=TLSv1.2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256')
693
... except authres.SyntaxError as e: print(e)
695
>>> str(arobj.authserv_id)
697
>>> str(arobj.results[0])
700
# Valid ptype (OK), unknown method (OK), unknown property (OKish)
702
>>> try: arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; x-tls=pass smtp.tlsversion=TLSv1.2')
703
... except authres.SyntaxError as e: print(e)
704
>>> str(arobj.authserv_id)
706
>>> str(arobj.results[0])
707
'x-tls=pass smtp.tlsversion=TLSv1.2'
708
>>> str(arobj.results[0].method)
710
>>> str(arobj.results[0].result)
712
>>> try: str(arobj.results[0].smtp_mailfrom)
713
... except AttributeError as e: print(e)
714
'AuthenticationResult' object has no attribute 'smtp_mailfrom'
715
>>> try: str(arobj.results[0].smtp_tlsversion)
716
... except AttributeError as e: print(e)
717
'AuthenticationResult' object has no attribute 'smtp_tlsversion'
718
>>> str(arobj.results[0].properties[0].type)
720
>>> str(arobj.results[0].properties[0].name)
722
>>> str(arobj.results[0].properties[0].value)
725
# Parse multiple result header field and toss out unknown ptype
727
>>> arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=example.net header.i=@example.net header.b=Qgi/FoC0; dmarc=none (p=none) header.from=example.net; spf=none smtp.mailfrom=test@example.net smtp.helo=mail-wm0-x232.example.com; x-tls=pass version=TLSv1.2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256')
728
>>> for result in arobj.results:
742
# Repeat authserv_id for each result (invalid)
744
>>> try: arobj = authres.AuthenticationResultsHeader.parse('authentication-results: thehesiod.com; dkim=none (message not signed) header.d=none;thehesiod.com; dmarc=none action=none header.from=hotmail.com;')
745
... except authres.SyntaxError as e: print(e)
746
Syntax error: Expected "=" at: ; dmarc=none action=none header.from=hot...