Пример #1
0
    def validate_cert_private_key_chain(self, data):
        cert = None
        key = None
        if data.get("body"):
            try:
                cert = utils.parse_certificate(data["body"])
            except ValueError:
                raise ValidationError(
                    "Public certificate presented is not valid.",
                    field_names=["body"])

        if data.get("private_key"):
            try:
                key = utils.parse_private_key(data["private_key"])
            except ValueError:
                raise ValidationError("Private key presented is not valid.",
                                      field_names=["private_key"])

        if cert and key:
            # Throws ValidationError
            validators.verify_private_key_match(key, cert)

        if data.get("chain"):
            try:
                chain = utils.parse_cert_chain(data["chain"])
            except ValueError:
                raise ValidationError(
                    "Invalid certificate in certificate chain.",
                    field_names=["chain"])

            # Throws ValidationError
            validators.verify_cert_chain([cert] + chain)
Пример #2
0
    def validate_cert_private_key_chain(self, data):
        cert = None
        key = None
        if data.get('body'):
            try:
                cert = utils.parse_certificate(data['body'])
            except ValueError:
                raise ValidationError("Public certificate presented is not valid.", field_names=['body'])

        if data.get('private_key'):
            try:
                key = utils.parse_private_key(data['private_key'])
            except ValueError:
                raise ValidationError("Private key presented is not valid.", field_names=['private_key'])

        if cert and key:
            # Throws ValidationError
            validators.verify_private_key_match(key, cert)

        if data.get('chain'):
            try:
                chain = utils.parse_cert_chain(data['chain'])
            except ValueError:
                raise ValidationError("Invalid certificate in certificate chain.", field_names=['chain'])

            # Throws ValidationError
            validators.verify_cert_chain([cert] + chain)
Пример #3
0
def test_validate_private_key(session):
    key = parse_private_key(SAN_CERT_KEY)

    verify_private_key_match(key, SAN_CERT)

    with pytest.raises(ValidationError):
        # Wrong key for certificate
        verify_private_key_match(key, INTERMEDIATE_CERT)
Пример #4
0
def test_validate_private_key(session):
    key = parse_private_key(SAN_CERT_KEY)

    verify_private_key_match(key, SAN_CERT)

    with pytest.raises(ValidationError):
        # Wrong key for certificate
        verify_private_key_match(key, INTERMEDIATE_CERT)
Пример #5
0
 def check_integrity(self):
     """
     Integrity checks: Does the cert have a matching private key?
     """
     if self.private_key:
         validators.verify_private_key_match(utils.parse_private_key(
             self.private_key),
                                             self.parsed_cert,
                                             error_class=AssertionError)
Пример #6
0
    def check_integrity(self):
        """
        Integrity checks: Does the cert have a valid chain and matching private key?
        """
        if self.private_key:
            validators.verify_private_key_match(utils.parse_private_key(self.private_key), self.parsed_cert,
                                                error_class=AssertionError)

        if self.chain:
            chain = [self.parsed_cert] + utils.parse_cert_chain(self.chain)
            validators.verify_cert_chain(chain, error_class=AssertionError)
Пример #7
0
    def check_integrity(self):
        """
        Integrity checks: Does the cert have a valid chain and matching private key?
        """
        if self.private_key:
            validators.verify_private_key_match(utils.parse_private_key(
                self.private_key),
                                                self.parsed_cert,
                                                error_class=AssertionError)

        if self.chain:
            chain = [self.parsed_cert] + utils.parse_cert_chain(self.chain)
            validators.verify_cert_chain(chain, error_class=AssertionError)
Пример #8
0
    def validate_cert_private_key(self, data):
        cert = None
        key = None
        if data.get('body'):
            try:
                cert = utils.parse_certificate(data['body'])
            except ValueError:
                raise ValidationError(
                    "Public certificate presented is not valid.",
                    field_names=['body'])

        if data.get('private_key'):
            try:
                key = utils.parse_private_key(data['private_key'])
            except ValueError:
                raise ValidationError("Private key presented is not valid.",
                                      field_names=['private_key'])

        if cert and key:
            # Throws ValidationError
            validators.verify_private_key_match(key, cert)