def _make_secret_payload(self, encoded_secret):
    servercert = M2Crypto.X509.load_cert_der_string(self.ssl.getpeercert(True))
    clientcert = M2Crypto.X509.load_cert(self.certfile)

    def get_key_pair(c):
      return [remove_null_bytes(v[4:]) for v in c.get_pubkey().get_rsa().pub()]

    def remove_null_bytes(v):
      return ''.join(itertools.dropwhile(lambda x: x=='\0', v))

    sexp, smod = get_key_pair(servercert)
    cexp, cmod = get_key_pair(clientcert)

    # From reference implementation, secret payload is the SHA256 hash of:
    #   client modulus
    #   client exponent
    #   server modulus
    #   server exponent
    #   nonce (second half of binary-encoded secret)
    digest = hashlib.sha256()
    digest.update(cmod)
    digest.update(cexp)
    digest.update(smod)
    digest.update(sexp)

    # Only the second half is used (the first half is redundant).
    digest.update(encoded_secret[len(encoded_secret) // 2:])
    return digest.digest()
Builds payload out of binary secret.
dataset/ETHPy150Open stevenle/googletv-anymote/googletv/__init__.py/PairingProtocol._make_secret_payload