Package nss :: Module nss
[hide private]
[frames] | no frames]

Module nss

This module implements the NSS functions
Classes [hide private]
  CertDB
An object representing a Certificate Database
  Certificate
An object representing a Certificate
  DSAPublicKey
A object representing a DSA Public Key
  KEYPQGParams
An object representing key parameters - prime (also known as p) - subprime (also known as q) - base (also known as g)
  PK11Slot
An object representing a PKCS #11 Slot
  PrivateKey
An object representing a Private Key
  PublicKey
An object representing a Public Key
  RSAPublicKey
An object representing an RSA Public Key
  SecItem
DER encoded data.
  SignatureAlgorithm
An object representing a signature algorithm
  SignedData
A object representing a signature
  SubjectPublicKeyInfo
An object representing a Subject Public Key
Functions [hide private]
 
data_to_hex(data, octets_per_line=16, separator=":")
Format the binary data as a hex string.
 
find_cert_from_nickname(...)
find_cert_from_nickname(nickname, [user_data1, ...]) -> Certificate
 
find_key_by_any_cert(...)
find_key_by_any_cert(cert, [user_data1, ...]) -> Certificate
 
get_cert_nicknames(...)
get_cert_nicknames(certdb, what, [user_data1, ...]) -> name0, ...
 
get_default_certdb()
Returns the default certificate database as a CertDB object
string
indented_format(line_pairs, indent=' ')
This function is equivalent to:
 
md5_digest(...)
md5_digest(data) --> digest
 
set_password_callback(callback)
The callback has the signature:
 
sha1_digest(...)
sha1_digest(data) --> digest
 
sha256_digest(...)
sha256_digest(data) --> digest
 
sha512_digest(...)
sha512_digest(data) --> digest
Variables [hide private]
  SEC_CERT_NICKNAMES_ALL = 1
  SEC_CERT_NICKNAMES_CA = 4
  SEC_CERT_NICKNAMES_SERVER = 3
  SEC_CERT_NICKNAMES_USER = 2
  _C_API = <PyCObject object at 0x8d69320>
  certificateUsageAnyCA = 2048
  certificateUsageCheckAllUsages = 0
  certificateUsageEmailRecipient = 32
  certificateUsageEmailSigner = 16
  certificateUsageObjectSigner = 64
  certificateUsageProtectedObjectSigner = 512
  certificateUsageSSLCA = 8
  certificateUsageSSLClient = 1
  certificateUsageSSLServer = 2
  certificateUsageSSLServerWithStepUp = 4
  certificateUsageStatusResponder = 1024
  certificateUsageUserCertImport = 128
  certificateUsageVerifyCA = 256
  dhKey = 4
  dsaKey = 2
  ecKey = 6
  fortezzaKey = 3
  keaKey = 5
  nullKey = 0
  rsaKey = 1
  secCertTimeExpired = 1
  secCertTimeNotValidYet = 2
  secCertTimeValid = 0
  ssl_kea_dh = 2
  ssl_kea_ecdh = 4
  ssl_kea_fortezza = 3
  ssl_kea_null = 0
  ssl_kea_rsa = 1
Function Details [hide private]

data_to_hex(data, octets_per_line=16, separator=":")

 
Format the binary data as a hex string. If octets_per_line is an integer then return a list of lines otherwise return a single string
Parameters:
  • data (buffer) - binary data
  • octets_per_line (integer) - number of octets formatted on one line, if 0 then return a single string instead of an array of lines
  • separator (string) - string used to seperate each octet

find_cert_from_nickname(...)

 

find_cert_from_nickname(nickname, [user_data1, ...]) -> Certificate

A nickname is an alias for a certificate subject. There may be multiple certificates with the same subject, and hence the same nickname. This function will return the newest certificate that matches the subject, based on the NotBefore / NotAfter fields of the certificate.

Parameters:
  • nickname (string) - certificate nickname to search for
  • user_dataN (object ...) - zero or more caller supplied parameters which will be passed to the password callback function

find_key_by_any_cert(...)

 

find_key_by_any_cert(cert, [user_data1, ...]) -> Certificate

Finds the private key associated with a specified certificate in any available slot.

Parameters:
  • cert (Certificate object) - certificate whose private key is being searched for
  • user_dataN (object ...) - zero or more caller supplied parameters which will be passed to the password callback function

get_cert_nicknames(...)

 

get_cert_nicknames(certdb, what, [user_data1, ...]) -> name0, ...

Returns a tuple of the nicknames of the certificates in a specified certificate database.

Parameters:
  • certdb (CertDB object) - CertDB certificate database object
  • what (integer) -
    one of:
    • SEC_CERT_NICKNAMES_ALL
    • SEC_CERT_NICKNAMES_USER
    • SEC_CERT_NICKNAMES_SERVER
    • SEC_CERT_NICKNAMES_CA
  • user_dataN (object) - zero or more caller supplied parameters which will be passed to the password callback function

indented_format(line_pairs, indent=' ')

 

This function is equivalent to:

'\n'.join([indent*x[0]+x[1] for x in obj.format()])

But is more efficient and does more error checking.

Example:

format = [(0, 'line 1'), (1, 'line 2'), (0, 'line 3')]
nss.indented(format)

would print
line 1
    line 2
line 3
Parameters:
  • line_pairs ([(level, string),...]) - A list of pairs. Each pair is a 2 valued tuple with the first pair value being the indentation level and the second pair value being a string value for the line.
  • indent (string) - A string repeated level times and then prepended to the line string.
Returns: string

md5_digest(...)

 

md5_digest(data) --> digest

Returns 16 octet MD5 digest data as buffer object.

Note, if a hexidecimal string representation is desired then pass result to data_to_hex()

Parameters:
  • data (buffer or string) - buffer the digest will be computed for

set_password_callback(callback)

 

The callback has the signature:

password_callback(slot, retry, [user_data1, ...])
slot
PK11Slot object
retry
boolean indicating if this is a retry
user_dataN
zero or more caller supplied optional parameters
Parameters:
  • callback (function pointer) - The callback function

sha1_digest(...)

 

sha1_digest(data) --> digest

Returns 20 octet SHA1 digest data as buffer object.

Note, if a hexidecimal string representation is desired then pass result to data_to_hex()

Parameters:
  • data (buffer or string) - buffer the digest will be computed for

sha256_digest(...)

 

sha256_digest(data) --> digest

Returns 32 octet SHA256 digest data as buffer object.

Note, if a hexidecimal string representation is desired then pass result to data_to_hex()

Parameters:
  • data (buffer or string) - buffer the digest will be computed for

sha512_digest(...)

 

sha512_digest(data) --> digest

Returns 64 octet SHA512 digest data as buffer object.

Note, if a hexidecimal string representation is desired then pass result to data_to_hex()

Parameters:
  • data (buffer or string) - buffer the digest will be computed for