Exemplo n.º 1
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the RevokeRequestPayload object and decode it
        into its constituent parts.
        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.
        """
        super(RevokeRequestPayload, self).read(istream,
                                               kmip_version=kmip_version)
        tstream = BytearrayStream(istream.read(self.length))

        self.unique_identifier = attributes.UniqueIdentifier()
        self.unique_identifier.read(tstream, kmip_version=kmip_version)

        self.revocation_reason = objects.RevocationReason()
        self.revocation_reason.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.COMPROMISE_OCCURRENCE_DATE, tstream):
            self.compromise_occurrence_date = primitives.DateTime(
                tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE)
            self.compromise_occurrence_date.read(tstream,
                                                 kmip_version=kmip_version)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 2
0
    def test_write_with_known_uuid(self):
        """
        Test that a RevokeRequestPayload object with a known UUID can be
        written to a data stream.
        """
        reason = objects.RevocationReason(
            code=enums.RevocationReasonCode.KEY_COMPROMISE)
        date = primitives.DateTime(tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE,
                                   value=6)

        stream = utils.BytearrayStream()
        payload = payloads.RevokeRequestPayload(
            unique_identifier=self.uuid,
            revocation_reason=reason,
            compromise_occurrence_date=date)
        payload.write(stream)

        length_expected = len(self.encoding_a)
        length_received = len(stream)

        msg = "encoding lengths not equal"
        msg += "; expected {0}, received {1}".format(length_expected,
                                                     length_received)
        self.assertEqual(length_expected, length_received, msg)

        msg = "encoding mismatch"
        msg += ";\nexpected:\n{0}\nreceived:\n{1}".format(
            self.encoding_a, stream)

        self.assertEqual(self.encoding_a, stream, msg)
Exemplo n.º 3
0
 def test_validate_with_bad_date_type(self):
     """
     Test that a TypeError exception is raised when an invalid UUID type
     is used to construct a RevokeRequestPayload object.
     """
     reason = objects.RevocationReason()
     self.assertRaisesRegex(TypeError, "invalid compromise time",
                            payloads.RevokeRequestPayload, self.uuid,
                            reason, "not-a-date")
Exemplo n.º 4
0
 def __init__(self,
              unique_identifier=None,
              revocation_reason=None,
              compromise_occurrence_date=None):
     """
     Construct a RevokeRequestPayload object.
     Args:
         unique_identifier (UniqueIdentifier): The UUID of a managed
             cryptographic object.
         revocation_reason (RevocationReason): The reason why the object was
             revoked.
         compromise_occurrence_date (DateTime): the datetime when the object
             was first believed to be compromised.
     """
     super(RevokeRequestPayload, self).__init__()
     self.unique_identifier = unique_identifier
     self.compromise_occurrence_date = compromise_occurrence_date
     self.revocation_reason = revocation_reason
     if self.revocation_reason is None:
         self.revocation_reason = objects.RevocationReason()
     self.validate()
Exemplo n.º 5
0
    def _revoke(self,
                unique_identifier=None,
                revocation_code=None,
                revocation_message=None,
                credential=None):
        operation = Operation(OperationEnum.REVOKE)

        reason = objects.RevocationReason(code=revocation_code,
                                          message=revocation_message)
        uuid = None
        if unique_identifier is not None:
            uuid = attr.UniqueIdentifier(unique_identifier)

        payload = revoke.RevokeRequestPayload(
            unique_identifier=uuid,
            revocation_reason=reason,
            compromise_date=None)  # TODO(tim-kelsey): sort out date handling

        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=payload)
        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
        else:
            payload_unique_identifier = payload.unique_identifier

        result = RevokeResult(batch_item.result_status,
                              batch_item.result_reason,
                              batch_item.result_message,
                              payload_unique_identifier)
        return result
Exemplo n.º 6
0
 def __init__(self,
              unique_identifier=None,
              revocation_reason=None,
              compromise_date=None):
     """
     Construct a RevokeRequestPayload object.
     Args:
         unique_identifier (UniqueIdentifier): The UUID of a managed
             cryptographic object.
         revocation_reason (RevocationReason): The reason why the object was
             revoked.
         compromise_date (DateTime): the date of compromise if the object
             was compromised.
     """
     super(RevokeRequestPayload,
           self).__init__(tag=enums.Tags.REQUEST_PAYLOAD)
     self.unique_identifier = unique_identifier
     self.compromise_date = compromise_date
     self.revocation_reason = revocation_reason
     if self.revocation_reason is None:
         self.revocation_reason = objects.RevocationReason()
     self.validate()
Exemplo n.º 7
0
    def read(self, istream):
        """
        Read the data encoding the RevokeRequestPayload object and decode it
        into its constituent parts.
        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
        """
        super(RevokeRequestPayload, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.unique_identifier = attributes.UniqueIdentifier()
        self.unique_identifier.read(tstream)

        self.revocation_reason = objects.RevocationReason()
        self.revocation_reason.read(tstream)

        if self.is_tag_next(enums.Tags.COMPROMISE_OCCURRENCE_DATE, tstream):
            self.compromise_date = primitives.DateTime(
                tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE)
            self.compromise_date.read(tstream)

        self.is_oversized(tstream)
        self.validate()