示例#1
0
    def from_key_verification_start(cls, own_user, own_device, own_fp_key,
                                    other_olm_device, event):
        # type: (str, str, str, OlmDevice, KeyVerificationStart) -> Sas
        """Create a SAS object from a KeyVerificationStart event.

        Args:
            own_user (str): The user id of our own user.
            own_device (str): The device id of our own user.
            own_fp_key (str): The fingerprint key of our own device that will
                be verified by the other client.
            other_olm_device (OlmDevice): The Olm device of the other user that
                should be verified.
            event (KeyVerificationStart): The event that we received from the
                other device to start the key verification process.

        """
        obj = cls(
            own_user,
            own_device,
            own_fp_key,
            other_olm_device,
            event.transaction_id,
            event.short_authentication_string,
            event.message_authentication_codes,
        )
        obj.we_started_it = False
        obj.state = SasState.started

        string_content = Api.to_canonical_json(event.source["content"])
        obj.commitment = olm.sha256(obj.pubkey + string_content)
        obj.key_agreement_protocols = event.key_agreement_protocols

        if (Sas._sas_method_v1 != event.method or
            (Sas._key_agreement_v1 not in event.key_agreement_protocols
             and Sas._key_agreement_v2 not in event.key_agreement_protocols)
                or Sas._hash_v1 not in event.hashes
                or (Sas._mac_normal not in event.message_authentication_codes
                    and Sas._mac_old not in event.message_authentication_codes)
                or ("emoji" not in event.short_authentication_string
                    and "decimal" not in event.short_authentication_string)):
            obj.state = SasState.canceled
            obj.cancel_code, obj.cancel_reason = obj._unknonw_method_error

        return obj
示例#2
0
 def _check_commitment(self, key):
     assert self.commitment
     calculated_commitment = olm.sha256(
         key + Api.to_canonical_json(self.start_verification()))
     return self.commitment == calculated_commitment