Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DN Attribute OIDs

synta.oids.attr provides OID constants for Distinguished Name (DN) attribute types.

import synta.oids.attr

Constants

All constants are ObjectIdentifier instances.

ConstantOIDRFC 4514 label
COMMON_NAME2.5.4.3CN
ORGANIZATION2.5.4.10O
ORG_UNIT2.5.4.11OU
COUNTRY2.5.4.6C
STATE2.5.4.8ST
LOCALITY2.5.4.7L
STREET2.5.4.9street
SERIAL_NUMBER2.5.4.5serialNumber
EMAIL_ADDRESS1.2.840.113549.1.9.1emailAddress
GIVEN_NAME2.5.4.42givenName
SURNAME2.5.4.4SN
TITLE2.5.4.12title
INITIALS2.5.4.43initials
ORG_IDENTIFIER2.5.4.97organizationIdentifier
USER_ID0.9.2342.19200300.100.1.1uid
DOMAIN_COMPONENT0.9.2342.19200300.100.1.25dc

Usage

import synta
import synta.oids.attr as attr

# Parse a certificate subject and look up specific attributes
cert = synta.Certificate.from_der(open("cert.der", "rb").read())
name_attrs = synta.parse_name_attrs(cert.subject_raw_der)

# name_attrs is a list of (dotted_oid_str, value_str) tuples
for oid_str, value in name_attrs:
    if oid_str == str(attr.COMMON_NAME):
        print(f"CN={value}")
    elif oid_str == str(attr.ORGANIZATION):
        print(f"O={value}")
    elif oid_str == str(attr.COUNTRY):
        print(f"C={value}")

# Use as hashable key
lookup = {attr.COMMON_NAME: "common name", attr.ORGANIZATION: "org"}

See also Well-known OIDs for the complete OID constant catalog.