aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-08-11 00:00:54 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-08-11 18:12:42 -0500
commitaa7a3221c3dae6b6af1f8321c840868318d0b051 (patch)
tree6592a5463a29525cc4f42ba99ebd36da5aa58d0d /src
parent4552fb87830f5c7e3af0532cfd4529b77bf7f988 (diff)
downloadcryptography-aa7a3221c3dae6b6af1f8321c840868318d0b051.tar.gz
cryptography-aa7a3221c3dae6b6af1f8321c840868318d0b051.tar.bz2
cryptography-aa7a3221c3dae6b6af1f8321c840868318d0b051.zip
move Extensions, Extension, ExtensionType, GeneralNames, SAN, & IAN
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/x509/__init__.py20
-rw-r--r--src/cryptography/x509/base.py146
-rw-r--r--src/cryptography/x509/extensions.py145
3 files changed, 154 insertions, 157 deletions
diff --git a/src/cryptography/x509/__init__.py b/src/cryptography/x509/__init__.py
index a6d376b5..1aa2598b 100644
--- a/src/cryptography/x509/__init__.py
+++ b/src/cryptography/x509/__init__.py
@@ -7,19 +7,19 @@ from __future__ import absolute_import, division, print_function
from cryptography.x509.base import (
Certificate, CertificateBuilder, CertificateRevocationList,
CertificateSigningRequest, CertificateSigningRequestBuilder,
- Extension, ExtensionType, GeneralNames,
- InvalidVersion, IssuerAlternativeName,
- ObjectIdentifier, RevokedCertificate, SubjectAlternativeName,
- Version, load_der_x509_certificate,
- load_der_x509_csr, load_pem_x509_certificate, load_pem_x509_csr,
+ InvalidVersion, RevokedCertificate,
+ Version, load_der_x509_certificate, load_der_x509_csr,
+ load_pem_x509_certificate, load_pem_x509_csr,
)
from cryptography.x509.extensions import (
AccessDescription, AuthorityInformationAccess,
AuthorityKeyIdentifier, BasicConstraints, CRLDistributionPoints,
CertificatePolicies, DistributionPoint, DuplicateExtension,
- ExtendedKeyUsage, ExtensionNotFound, Extensions, InhibitAnyPolicy,
- KeyUsage, NameConstraints, NoticeReference, OCSPNoCheck, PolicyInformation,
- ReasonFlags, SubjectKeyIdentifier, UnsupportedExtension, UserNotice
+ ExtendedKeyUsage, Extension, ExtensionNotFound, ExtensionType, Extensions,
+ GeneralNames, InhibitAnyPolicy, IssuerAlternativeName, KeyUsage,
+ NameConstraints, NoticeReference, OCSPNoCheck, PolicyInformation,
+ ReasonFlags, SubjectAlternativeName, SubjectKeyIdentifier,
+ UnsupportedExtension, UserNotice
)
from cryptography.x509.general_name import (
DNSName, DirectoryName, GeneralName, IPAddress, OtherName, RFC822Name,
@@ -29,8 +29,8 @@ from cryptography.x509.general_name import (
from cryptography.x509.name import Name, NameAttribute
from cryptography.x509.oid import (
AuthorityInformationAccessOID, CRLExtensionOID, CertificatePoliciesOID,
- ExtendedKeyUsageOID, ExtensionOID, NameOID, SignatureAlgorithmOID,
- _SIG_OIDS_TO_HASH
+ ExtendedKeyUsageOID, ExtensionOID, NameOID, ObjectIdentifier,
+ SignatureAlgorithmOID, _SIG_OIDS_TO_HASH
)
diff --git a/src/cryptography/x509/base.py b/src/cryptography/x509/base.py
index 312eea0c..27eafac6 100644
--- a/src/cryptography/x509/base.py
+++ b/src/cryptography/x509/base.py
@@ -12,11 +12,8 @@ import six
from cryptography import utils
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
-from cryptography.x509.general_name import GeneralName, OtherName
+from cryptography.x509.extensions import Extension, ExtensionType
from cryptography.x509.name import Name
-from cryptography.x509.oid import (
- ExtensionOID, ObjectIdentifier
-)
_UNIX_EPOCH = datetime.datetime(1970, 1, 1)
@@ -49,147 +46,6 @@ class InvalidVersion(Exception):
self.parsed_version = parsed_version
-class Extension(object):
- def __init__(self, oid, critical, value):
- if not isinstance(oid, ObjectIdentifier):
- raise TypeError(
- "oid argument must be an ObjectIdentifier instance."
- )
-
- if not isinstance(critical, bool):
- raise TypeError("critical must be a boolean value")
-
- self._oid = oid
- self._critical = critical
- self._value = value
-
- oid = utils.read_only_property("_oid")
- critical = utils.read_only_property("_critical")
- value = utils.read_only_property("_value")
-
- def __repr__(self):
- return ("<Extension(oid={0.oid}, critical={0.critical}, "
- "value={0.value})>").format(self)
-
- def __eq__(self, other):
- if not isinstance(other, Extension):
- return NotImplemented
-
- return (
- self.oid == other.oid and
- self.critical == other.critical and
- self.value == other.value
- )
-
- def __ne__(self, other):
- return not self == other
-
-
-@six.add_metaclass(abc.ABCMeta)
-class ExtensionType(object):
- @abc.abstractproperty
- def oid(self):
- """
- Returns the oid associated with the given extension type.
- """
-
-
-class GeneralNames(object):
- def __init__(self, general_names):
- if not all(isinstance(x, GeneralName) for x in general_names):
- raise TypeError(
- "Every item in the general_names list must be an "
- "object conforming to the GeneralName interface"
- )
-
- self._general_names = general_names
-
- def __iter__(self):
- return iter(self._general_names)
-
- def __len__(self):
- return len(self._general_names)
-
- def get_values_for_type(self, type):
- # Return the value of each GeneralName, except for OtherName instances
- # which we return directly because it has two important properties not
- # just one value.
- objs = (i for i in self if isinstance(i, type))
- if type != OtherName:
- objs = (i.value for i in objs)
- return list(objs)
-
- def __repr__(self):
- return "<GeneralNames({0})>".format(self._general_names)
-
- def __eq__(self, other):
- if not isinstance(other, GeneralNames):
- return NotImplemented
-
- return self._general_names == other._general_names
-
- def __ne__(self, other):
- return not self == other
-
-
-@utils.register_interface(ExtensionType)
-class SubjectAlternativeName(object):
- oid = ExtensionOID.SUBJECT_ALTERNATIVE_NAME
-
- def __init__(self, general_names):
- self._general_names = GeneralNames(general_names)
-
- def __iter__(self):
- return iter(self._general_names)
-
- def __len__(self):
- return len(self._general_names)
-
- def get_values_for_type(self, type):
- return self._general_names.get_values_for_type(type)
-
- def __repr__(self):
- return "<SubjectAlternativeName({0})>".format(self._general_names)
-
- def __eq__(self, other):
- if not isinstance(other, SubjectAlternativeName):
- return NotImplemented
-
- return self._general_names == other._general_names
-
- def __ne__(self, other):
- return not self == other
-
-
-@utils.register_interface(ExtensionType)
-class IssuerAlternativeName(object):
- oid = ExtensionOID.ISSUER_ALTERNATIVE_NAME
-
- def __init__(self, general_names):
- self._general_names = GeneralNames(general_names)
-
- def __iter__(self):
- return iter(self._general_names)
-
- def __len__(self):
- return len(self._general_names)
-
- def get_values_for_type(self, type):
- return self._general_names.get_values_for_type(type)
-
- def __repr__(self):
- return "<IssuerAlternativeName({0})>".format(self._general_names)
-
- def __eq__(self, other):
- if not isinstance(other, IssuerAlternativeName):
- return NotImplemented
-
- return self._general_names == other._general_names
-
- def __ne__(self, other):
- return not self == other
-
-
@six.add_metaclass(abc.ABCMeta)
class Certificate(object):
@abc.abstractmethod
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index 92a37357..798a0e3a 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -4,6 +4,7 @@
from __future__ import absolute_import, division, print_function
+import abc
import hashlib
import ipaddress
from enum import Enum
@@ -15,8 +16,7 @@ import six
from cryptography import utils
from cryptography.hazmat.primitives import serialization
-from cryptography.x509.base import ExtensionType
-from cryptography.x509.general_name import GeneralName, IPAddress
+from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
from cryptography.x509.name import Name
from cryptography.x509.oid import (
AuthorityInformationAccessOID, ExtensionOID, ObjectIdentifier
@@ -69,6 +69,15 @@ class ExtensionNotFound(Exception):
self.oid = oid
+@six.add_metaclass(abc.ABCMeta)
+class ExtensionType(object):
+ @abc.abstractproperty
+ def oid(self):
+ """
+ Returns the oid associated with the given extension type.
+ """
+
+
class Extensions(object):
def __init__(self, extensions):
self._extensions = extensions
@@ -769,3 +778,135 @@ class NameConstraints(object):
permitted_subtrees = utils.read_only_property("_permitted_subtrees")
excluded_subtrees = utils.read_only_property("_excluded_subtrees")
+
+
+class Extension(object):
+ def __init__(self, oid, critical, value):
+ if not isinstance(oid, ObjectIdentifier):
+ raise TypeError(
+ "oid argument must be an ObjectIdentifier instance."
+ )
+
+ if not isinstance(critical, bool):
+ raise TypeError("critical must be a boolean value")
+
+ self._oid = oid
+ self._critical = critical
+ self._value = value
+
+ oid = utils.read_only_property("_oid")
+ critical = utils.read_only_property("_critical")
+ value = utils.read_only_property("_value")
+
+ def __repr__(self):
+ return ("<Extension(oid={0.oid}, critical={0.critical}, "
+ "value={0.value})>").format(self)
+
+ def __eq__(self, other):
+ if not isinstance(other, Extension):
+ return NotImplemented
+
+ return (
+ self.oid == other.oid and
+ self.critical == other.critical and
+ self.value == other.value
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
+
+class GeneralNames(object):
+ def __init__(self, general_names):
+ if not all(isinstance(x, GeneralName) for x in general_names):
+ raise TypeError(
+ "Every item in the general_names list must be an "
+ "object conforming to the GeneralName interface"
+ )
+
+ self._general_names = general_names
+
+ def __iter__(self):
+ return iter(self._general_names)
+
+ def __len__(self):
+ return len(self._general_names)
+
+ def get_values_for_type(self, type):
+ # Return the value of each GeneralName, except for OtherName instances
+ # which we return directly because it has two important properties not
+ # just one value.
+ objs = (i for i in self if isinstance(i, type))
+ if type != OtherName:
+ objs = (i.value for i in objs)
+ return list(objs)
+
+ def __repr__(self):
+ return "<GeneralNames({0})>".format(self._general_names)
+
+ def __eq__(self, other):
+ if not isinstance(other, GeneralNames):
+ return NotImplemented
+
+ return self._general_names == other._general_names
+
+ def __ne__(self, other):
+ return not self == other
+
+
+@utils.register_interface(ExtensionType)
+class SubjectAlternativeName(object):
+ oid = ExtensionOID.SUBJECT_ALTERNATIVE_NAME
+
+ def __init__(self, general_names):
+ self._general_names = GeneralNames(general_names)
+
+ def __iter__(self):
+ return iter(self._general_names)
+
+ def __len__(self):
+ return len(self._general_names)
+
+ def get_values_for_type(self, type):
+ return self._general_names.get_values_for_type(type)
+
+ def __repr__(self):
+ return "<SubjectAlternativeName({0})>".format(self._general_names)
+
+ def __eq__(self, other):
+ if not isinstance(other, SubjectAlternativeName):
+ return NotImplemented
+
+ return self._general_names == other._general_names
+
+ def __ne__(self, other):
+ return not self == other
+
+
+@utils.register_interface(ExtensionType)
+class IssuerAlternativeName(object):
+ oid = ExtensionOID.ISSUER_ALTERNATIVE_NAME
+
+ def __init__(self, general_names):
+ self._general_names = GeneralNames(general_names)
+
+ def __iter__(self):
+ return iter(self._general_names)
+
+ def __len__(self):
+ return len(self._general_names)
+
+ def get_values_for_type(self, type):
+ return self._general_names.get_values_for_type(type)
+
+ def __repr__(self):
+ return "<IssuerAlternativeName({0})>".format(self._general_names)
+
+ def __eq__(self, other):
+ if not isinstance(other, IssuerAlternativeName):
+ return NotImplemented
+
+ return self._general_names == other._general_names
+
+ def __ne__(self, other):
+ return not self == other