django_ca.subject - X509 Subject

Module for handling x509 subjects.

class django_ca.subject.Subject(subject=None)[source]

Convenience class to handle X509 Subjects.

This class accepts a variety of values and intelligently parses them:

>>> Subject('/CN=example.com')
Subject("/CN=example.com")
>>> Subject({'CN': 'example.com'})
Subject("/CN=example.com")
>>> Subject([('CN', 'example.com'), ])
Subject("/CN=example.com")

In most respects, this class handles like a dict:

>>> s = Subject('/CN=example.com')
>>> 'CN' in s
True
>>> s.get('OU', 'Default OU')
'Default OU'
>>> s.setdefault('C', 'AT')
['AT']
>>> s.setdefault('C', 'DE')
['AT']
>>> s['C'], s['CN']
('AT', 'example.com')
clear()[source]

Clear the subject.

copy()[source]

Create a copy of the subject.

property fields

This subject as a list of NameOID instances.

>>> list(Subject('/C=AT/CN=example.com').fields)  
[(<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, 'AT'),
 (<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, 'example.com')]
get(key, default=None)[source]

Return the value for key if key is in the subject, else default.

items()[source]

View of the subjects items.

keys()[source]

View on subject keys, in order.

property name

This subject as x509.Name.

>>> Subject('/C=AT/CN=example.com').name
<Name(C=AT,CN=example.com)>
setdefault(oid, value)[source]

Insert key with a value of default if key is not in the subject.

Return the value for key if key is in the subject, else default.

update(e=None, **f)[source]

Update S from subject/dict/iterable E and F.

values()[source]

View on subject values, in order.

django_ca.subject.get_default_subject()[source]

Get the default subject as configured by the CA_DEFAULT_SUBJECT setting.