aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/x509
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2018-12-01 12:15:20 +0800
committerAlex Gaynor <alex.gaynor@gmail.com>2018-11-30 23:15:20 -0500
commiteb3e2e0d73c86d876d48aa6bde9fcf01c761c98f (patch)
tree1b20470ee016a3d1a35e7b5680fe38f38c538574 /src/cryptography/x509
parente4e7b89fb627b372cde4158ceb7078d8769497cb (diff)
downloadcryptography-eb3e2e0d73c86d876d48aa6bde9fcf01c761c98f.tar.gz
cryptography-eb3e2e0d73c86d876d48aa6bde9fcf01c761c98f.tar.bz2
cryptography-eb3e2e0d73c86d876d48aa6bde9fcf01c761c98f.zip
IssuingDistributionPoint support (parse only) (#4552)
* IssuingDistributionPoint support h/t to Irina Renteria for the initial work here * python 2 unfortunately still exists * py2 repr * typo caught by flake8 * add docs * review feedback * reorder args, other fixes * use the alex name * add changelog
Diffstat (limited to 'src/cryptography/x509')
-rw-r--r--src/cryptography/x509/__init__.py7
-rw-r--r--src/cryptography/x509/extensions.py130
2 files changed, 134 insertions, 3 deletions
diff --git a/src/cryptography/x509/__init__.py b/src/cryptography/x509/__init__.py
index fd019455..b761e264 100644
--- a/src/cryptography/x509/__init__.py
+++ b/src/cryptography/x509/__init__.py
@@ -21,9 +21,9 @@ from cryptography.x509.extensions import (
DeltaCRLIndicator, DistributionPoint, DuplicateExtension, ExtendedKeyUsage,
Extension, ExtensionNotFound, ExtensionType, Extensions, FreshestCRL,
GeneralNames, InhibitAnyPolicy, InvalidityDate, IssuerAlternativeName,
- KeyUsage, NameConstraints, NoticeReference, OCSPNoCheck, OCSPNonce,
- PolicyConstraints, PolicyInformation, PrecertPoison,
- PrecertificateSignedCertificateTimestamps, ReasonFlags,
+ IssuingDistributionPoint, KeyUsage, NameConstraints, NoticeReference,
+ OCSPNoCheck, OCSPNonce, PolicyConstraints, PolicyInformation,
+ PrecertPoison, PrecertificateSignedCertificateTimestamps, ReasonFlags,
SubjectAlternativeName, SubjectKeyIdentifier, TLSFeature, TLSFeatureType,
UnrecognizedExtension, UserNotice
)
@@ -134,6 +134,7 @@ __all__ = [
"Extension",
"ExtendedKeyUsage",
"FreshestCRL",
+ "IssuingDistributionPoint",
"TLSFeature",
"TLSFeatureType",
"OCSPNoCheck",
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index fc5c17a9..12071b66 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -1447,6 +1447,136 @@ class OCSPNonce(object):
@utils.register_interface(ExtensionType)
+class IssuingDistributionPoint(object):
+ oid = ExtensionOID.ISSUING_DISTRIBUTION_POINT
+
+ def __init__(self, full_name, relative_name, only_contains_user_certs,
+ only_contains_ca_certs, only_some_reasons, indirect_crl,
+ only_contains_attribute_certs):
+ if (
+ only_some_reasons and (
+ not isinstance(only_some_reasons, frozenset) or not all(
+ isinstance(x, ReasonFlags) for x in only_some_reasons
+ )
+ )
+ ):
+ raise TypeError(
+ "only_some_reasons must be None or frozenset of ReasonFlags"
+ )
+
+ if only_some_reasons and (
+ ReasonFlags.unspecified in only_some_reasons or
+ ReasonFlags.remove_from_crl in only_some_reasons
+ ):
+ raise ValueError(
+ "unspecified and remove_from_crl are not valid reasons in an "
+ "IssuingDistributionPoint"
+ )
+
+ if not (
+ isinstance(only_contains_user_certs, bool) and
+ isinstance(only_contains_ca_certs, bool) and
+ isinstance(indirect_crl, bool) and
+ isinstance(only_contains_attribute_certs, bool)
+ ):
+ raise TypeError(
+ "only_contains_user_certs, only_contains_ca_certs, "
+ "indirect_crl and only_contains_attribute_certs "
+ "must all be boolean."
+ )
+
+ crl_constraints = [
+ only_contains_user_certs, only_contains_ca_certs,
+ indirect_crl, only_contains_attribute_certs
+ ]
+
+ if len([x for x in crl_constraints if x]) > 1:
+ raise ValueError(
+ "Only one of the following can be set to True: "
+ "only_contains_user_certs, only_contains_ca_certs, "
+ "indirect_crl, only_contains_attribute_certs"
+ )
+
+ if (
+ not any([
+ only_contains_user_certs, only_contains_ca_certs,
+ indirect_crl, only_contains_attribute_certs, full_name,
+ relative_name, only_some_reasons
+ ])
+ ):
+ raise ValueError(
+ "Cannot create empty extension: "
+ "if only_contains_user_certs, only_contains_ca_certs, "
+ "indirect_crl, and only_contains_attribute_certs are all False"
+ ", then either full_name, relative_name, or only_some_reasons "
+ "must have a value."
+ )
+
+ self._only_contains_user_certs = only_contains_user_certs
+ self._only_contains_ca_certs = only_contains_ca_certs
+ self._indirect_crl = indirect_crl
+ self._only_contains_attribute_certs = only_contains_attribute_certs
+ self._only_some_reasons = only_some_reasons
+ self._full_name = full_name
+ self._relative_name = relative_name
+
+ def __repr__(self):
+ return (
+ "<IssuingDistributionPoint(full_name={0.full_name}, "
+ "relative_name={0.relative_name}, "
+ "only_contains_user_certs={0.only_contains_user_certs}, "
+ "only_contains_ca_certs={0.only_contains_ca_certs}, "
+ "only_some_reasons={0.only_some_reasons}, "
+ "indirect_crl={0.indirect_crl}, "
+ "only_contains_attribute_certs="
+ "{0.only_contains_attribute_certs})>".format(self)
+ )
+
+ def __eq__(self, other):
+ if not isinstance(other, IssuingDistributionPoint):
+ return NotImplemented
+
+ return (
+ self.full_name == other.full_name and
+ self.relative_name == other.relative_name and
+ self.only_contains_user_certs == other.only_contains_user_certs and
+ self.only_contains_ca_certs == other.only_contains_ca_certs and
+ self.only_some_reasons == other.only_some_reasons and
+ self.indirect_crl == other.indirect_crl and
+ self.only_contains_attribute_certs ==
+ other.only_contains_attribute_certs
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
+ def __hash__(self):
+ return hash((
+ self.full_name,
+ self.relative_name,
+ self.only_contains_user_certs,
+ self.only_contains_ca_certs,
+ self.only_some_reasons,
+ self.indirect_crl,
+ self.only_contains_attribute_certs,
+ ))
+
+ full_name = utils.read_only_property("_full_name")
+ relative_name = utils.read_only_property("_relative_name")
+ only_contains_user_certs = utils.read_only_property(
+ "_only_contains_user_certs"
+ )
+ only_contains_ca_certs = utils.read_only_property(
+ "_only_contains_ca_certs"
+ )
+ only_some_reasons = utils.read_only_property("_only_some_reasons")
+ indirect_crl = utils.read_only_property("_indirect_crl")
+ only_contains_attribute_certs = utils.read_only_property(
+ "_only_contains_attribute_certs"
+ )
+
+
+@utils.register_interface(ExtensionType)
class UnrecognizedExtension(object):
def __init__(self, oid, value):
if not isinstance(oid, ObjectIdentifier):