aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-02-10 17:22:16 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2015-02-10 17:22:16 -0500
commitcd18ac09b20670a6e448d778a684ecffdf01c3c6 (patch)
treedebc8542d9004686567acc2103274d518f24bb17 /src
parent7d93ad6f654313f86320153b797e34a5959c42eb (diff)
parent4bb464995cae1b1f86d383fb668f9c5276b3d059 (diff)
downloadcryptography-cd18ac09b20670a6e448d778a684ecffdf01c3c6.tar.gz
cryptography-cd18ac09b20670a6e448d778a684ecffdf01c3c6.tar.bz2
cryptography-cd18ac09b20670a6e448d778a684ecffdf01c3c6.zip
Merge pull request #1645 from reaperhulk/x509-attrs
add attribute and objectidentifier classes for x509 name
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/x509.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index be1298b6..e280980b 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -9,6 +9,27 @@ from enum import Enum
import six
+from cryptography import utils
+
+
+_OID_NAMES = {
+ "2.5.4.3": "commonName",
+ "2.5.4.6": "countryName",
+ "2.5.4.7": "localityName",
+ "2.5.4.8": "stateOrProvinceName",
+ "2.5.4.10": "organizationName",
+ "2.5.4.11": "organizationalUnitName",
+ "2.5.4.5": "serialNumber",
+ "2.5.4.4": "surname",
+ "2.5.4.42": "givenName",
+ "2.5.4.12": "title",
+ "2.5.4.44": "generationQualifier",
+ "2.5.4.46": "dnQualifier",
+ "2.5.4.65": "pseudonym",
+ "0.9.2342.19200300.100.1.25": "domainComponent",
+ "1.2.840.113549.1.9.1": "emailAddress",
+}
+
class Version(Enum):
v1 = 0
@@ -29,6 +50,71 @@ class InvalidVersion(Exception):
self.parsed_version = parsed_version
+class NameAttribute(object):
+ def __init__(self, oid, value):
+ if not isinstance(oid, ObjectIdentifier):
+ raise TypeError(
+ "oid argument must be an ObjectIdentifier instance."
+ )
+
+ self._oid = oid
+ self._value = value
+
+ oid = utils.read_only_property("_oid")
+ value = utils.read_only_property("_value")
+
+ def __eq__(self, other):
+ if not isinstance(other, NameAttribute):
+ return NotImplemented
+
+ return (
+ self.oid == other.oid and
+ self.value == other.value
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
+
+class ObjectIdentifier(object):
+ def __init__(self, dotted_string):
+ self._dotted_string = dotted_string
+
+ def __eq__(self, other):
+ if not isinstance(other, ObjectIdentifier):
+ return NotImplemented
+
+ return self._dotted_string == other._dotted_string
+
+ def __ne__(self, other):
+ return not self == other
+
+ def __repr__(self):
+ return "<ObjectIdentifier(oid={0}, name={1})>".format(
+ self._dotted_string,
+ _OID_NAMES.get(self._dotted_string, "Unknown OID")
+ )
+
+ dotted_string = utils.read_only_property("_dotted_string")
+
+
+OID_COMMON_NAME = ObjectIdentifier("2.5.4.3")
+OID_COUNTRY_NAME = ObjectIdentifier("2.5.4.6")
+OID_LOCALITY_NAME = ObjectIdentifier("2.5.4.7")
+OID_STATE_OR_PROVINCE_NAME = ObjectIdentifier("2.5.4.8")
+OID_ORGANIZATION_NAME = ObjectIdentifier("2.5.4.10")
+OID_ORGANIZATIONAL_UNIT_NAME = ObjectIdentifier("2.5.4.11")
+OID_SERIAL_NUMBER = ObjectIdentifier("2.5.4.5")
+OID_SURNAME = ObjectIdentifier("2.5.4.4")
+OID_GIVEN_NAME = ObjectIdentifier("2.5.4.42")
+OID_TITLE = ObjectIdentifier("2.5.4.12")
+OID_GENERATION_QUALIFIER = ObjectIdentifier("2.5.4.44")
+OID_DN_QUALIFIER = ObjectIdentifier("2.5.4.46")
+OID_PSEUDONYM = ObjectIdentifier("2.5.4.65")
+OID_DOMAIN_COMPONENT = ObjectIdentifier("0.9.2342.19200300.100.1.25")
+OID_EMAIL_ADDRESS = ObjectIdentifier("1.2.840.113549.1.9.1")
+
+
@six.add_metaclass(abc.ABCMeta)
class Certificate(object):
@abc.abstractmethod