Skip to content

Instantly share code, notes, and snippets.

@stevecheckoway
Created October 30, 2020 05:06

Revisions

  1. stevecheckoway created this gist Oct 30, 2020.
    21 changes: 21 additions & 0 deletions verify.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/usr/bin/env python3

    from dkim import DKIM
    import sys

    def get_txt(*args, **kwargs):
    return b'k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Kd87/UeJjenpabgbFwh+eBCsSTrqmwIYYvywlbhbqoo2DymndFkbjOVIPIldNs/m40KF+yzMn1skyoxcTUGCQs8g3FgD2Ap3ZB5DekAo5wMmk4wimDO+U8QzI3SD0" "7y2+07wlNWwIt8svnxgdxGkVbbhzY8i+RQ9DpSVpPbF7ykQxtKXkv/ahW3KjViiAH+ghvvIhkx4xYSIc9oSwVmAl5OctMEeWUwg8Istjqz8BZeTWbf41fbNhte7Y+YqZOwq1Sd0DbvYAD9NOZK9vlfuac0598HY+vtSBczUiKERHv1yRbcaQtZFh5wtiRrN04BLUTD21MycBX5jYchHjPY/wIDAQAB'

    failed = False

    for path in sys.argv[1:]:
    with open(path, 'rb') as f:
    verifier = DKIM(message=f.read())

    if verifier.verify(0, dnsfunc=get_txt):
    print("{}: DKIM signature verified".format(path))
    else:
    print("{}: DKIM signature verification failed".format(path))
    failed = True
    if failed:
    sys.exit(1)