Module dkim
[hide private]
[frames] | no frames]

Module dkim

source code

Classes [hide private]
  DKIMException
Base class for DKIM errors.
  InternalError
Internal error in dkim module.
  KeyFormatError
Key format error while parsing an RSA public or private key.
  MessageFormatError
RFC822 message format error.
  ParameterError
Input parameter error.
  Relaxed
Class that represents the "relaxed" canonicalization algorithm.
  Simple
Class that represents the "simple" canonicalization algorithm.
Functions [hide private]
 
_remove(s, t) source code
 
asn1_build(node)
Build an ASN.1 data structure based on pairs of (type, data).
source code
 
asn1_length(n)
Return a string representing a field length in ASN.1 format.
source code
 
asn1_parse(template, data)
Parse a data structure according to ASN.1 template.
source code
 
dnstxt(name)
Return a TXT record associated with a DNS name.
source code
 
fold(header)
Fold a header line into multiple crlf-separated lines at column 72.
source code
 
int2str(n, length=-1)
Convert an integer to an octet string.
source code
 
rfc822_parse(message)
Parse a message in RFC822 format.
source code
 
sign(message, selector, domain, privkey, identity=None, canonicalize=(<class dkim.Simple at 0x83fb8cc>, <class dkim.Simple at 0x83f..., include_headers=None, length=False, debuglog=None)
Sign an RFC822 message and return the DKIM-Signature header line.
source code
 
str2int(s)
Convert an octet string to an integer.
source code
 
verify(message, debuglog=None)
Verify a DKIM signature on an RFC822 formatted message.
source code
Variables [hide private]
  ASN1_Object = [(48, [(48, [(6), (5)]), (3)])]
  ASN1_RSAPrivateKey = [(48, [(2), (2), (2), (2), (2), (2), (2),...
  ASN1_RSAPublicKey = [(48, [(2), (2)])]
  BIT_STRING = 3
  HASHID_SHA1 = '+\x0e\x03\x02\x1a'
  HASHID_SHA256 = '`\x86H\x01e\x03\x04\x02\x01'
  INTEGER = 2
  NULL = 5
  OBJECT_IDENTIFIER = 6
  OCTET_STRING = 4
  SEQUENCE = 48
Function Details [hide private]

asn1_parse(template, data)

source code 

Parse a data structure according to ASN.1 template.

Parameters:
  • template - A list of tuples comprising the ASN.1 template.
  • data - A list of bytes to parse.

int2str(n, length=-1)

source code 

Convert an integer to an octet string. Number must be positive.

Parameters:
  • n - Number to convert.
  • length - Minimum length, or -1 to return the smallest number of bytes that represent the integer.

rfc822_parse(message)

source code 

Parse a message in RFC822 format.

Parameters:
  • message - The message in RFC822 format. Either CRLF or LF is an accepted line separator.

    @return Returns a tuple of (headers, body) where headers is a list of (name, value) pairs. The body is a CRLF-separated string.

sign(message, selector, domain, privkey, identity=None, canonicalize=(<class dkim.Simple at 0x83fb8cc>, <class dkim.Simple at 0x83f..., include_headers=None, length=False, debuglog=None)

source code 

Sign an RFC822 message and return the DKIM-Signature header line.

Parameters:
  • message - an RFC822 formatted message (with either \n or \r\n line endings)
  • selector - the DKIM selector value for the signature
  • domain - the DKIM domain value for the signature
  • privkey - a PKCS#1 private key in base64-encoded text form
  • identity - the DKIM identity value for the signature (default "@"+domain)
  • canonicalize - the canonicalization algorithms to use (default (Simple, Simple))
  • include_headers - a list of strings indicating which headers are to be signed (default all headers)
  • length - true if the l= tag should be included to indicate body length (default False)
  • debuglog - a file-like object to which debug info will be written (default None)

str2int(s)

source code 

Convert an octet string to an integer. Octet string assumed to represent a positive integer.

verify(message, debuglog=None)

source code 

Verify a DKIM signature on an RFC822 formatted message.

Parameters:
  • message - an RFC822 formatted message (with either \n or \r\n line endings)
  • debuglog - a file-like object to which debug info will be written (default None)

Variables Details [hide private]

ASN1_RSAPrivateKey

Value:
[(48, [(2), (2), (2), (2), (2), (2), (2), (2), (2)])]