def fill_missing(self): k = PrivKeyRSA() k.fill_and_store(modulusLen=512) self.tls_session.server_tmp_rsa_key = k pubNum = k.pubkey.public_numbers() if not self.rsamod: self.rsamod = pkcs_i2osp(pubNum.n, k.pubkey.key_size // 8) if self.rsamodlen is None: self.rsamodlen = len(self.rsamod) rsaexplen = math.ceil(math.log(pubNum.e) / math.log(2) / 8.) if not self.rsaexp: self.rsaexp = pkcs_i2osp(pubNum.e, rsaexplen) if self.rsaexplen is None: self.rsaexplen = len(self.rsaexp)
def fill_missing(self): ext_k = rsa.generate_private_key(public_exponent=0x10001, key_size=512, backend=default_backend()) pem_k = ext_k.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption()) k = PrivKeyRSA(pem_k) self.tls_session.server_tmp_rsa_key = k pubNum = k.pubkey.public_numbers() if self.rsamod is "": self.rsamod = pkcs_i2osp(pubNum.n, k.pubkey.key_size / 8) if self.rsamodlen is None: self.rsamodlen = len(self.rsamod) rsaexplen = math.ceil(math.log(pubNum.e) / math.log(2) / 8.) if self.rsaexp is "": self.rsaexp = pkcs_i2osp(pubNum.e, rsaexplen) if self.rsaexplen is None: self.rsaexplen = len(self.rsaexp)
return bytearray(data).hex() client_random = '50ba2c6dd9a809d3560429e5d4f36584b0120909ba76e642f012ed847d1711fe' server_random = '19a75738be10c27b2206d0acd7678336ee0c1a36f13e47109df94e9a7823ecc2' """ Note: Your answers should be in hexadecimal strings (e.g., 'c0d295a50d66...') """ """ 1. Decrypt the premaster secret and print it (10 pts) """ # Your code goes here encrypted_premaster_secret = '92c4684b5c1bb97aa3cd3bf8caf33cc659b1e3294d8f98618eb4f961792985ec75d18088f760db4096be2b894f5778a73e0f40b118120bd306340a158be3a770fc173977fceb7b1f1fad35f6cfbbe2efa4dcc7b4b9f798879b6ff22e190e3f75e194333e00472a7c6370425c4ef1702ed3a9166a2c27a1fe2587dc13794192cd0677b49e600e77ea153dce079ea34756bd813de352f3aeae9a09b9369cc16a79c8cd51d48bf484b08a6fc3f245812236ea10285ce347e41a93f0a398ec6f8b8b2edcd55d10fe35bb88ebbabb556d6d42544886f462bce76c1515b6ad0ed1f547cf4a1a9ba423853ffa99d174dfba8071d6808155ab4d9ac6866a472df7a77106' k = PrivKeyRSA('key.pem') premaster_secret = k.decrypt(bytes(hex_to_data(encrypted_premaster_secret))) # Your answer should be printed here print('Decrypted Premaster Secret: %s\n' % data_to_hex(premaster_secret)) """ 2. Caclulate Master Secret (20 pts) """ # Your code goes here f = PRF(PRF_ALGORITHM, TLS_12) master_secret = f.compute_master_secret(premaster_secret, hex_to_data(client_random), hex_to_data(server_random))