コード例 #1
0
privkey = open('key.pem', 'r').read()
rsakey = RSA.importKey(privkey)
rsa = PKCS1_v1_5.new(rsakey)
sentinel = 'Error'
premaster_secret = rsa.decrypt(hex_to_data(encrypted_premaster_secret),
                               sentinel)

# Your answer should be printed here
print('Decrypted Premaster Secret: %s' % data_to_hex(premaster_secret))
"""
2. Caclulate Master Secret (20 pts)
"""

# Your code goes here
prf = PRF(hash_name=PRF_ALGORITHM, tls_version=TLS_12)
master_secret = prf.compute_master_secret(premaster_secret, client_random,
                                          server_random)
# Your answer should be printed here
print('Master Secret: %s' % data_to_hex(master_secret))
"""
3. Calculate the Following (30 pts): 


    1) Client Write Key,
    2) Client Write IV,
    3) Client Write Mac Key,
    4) Server Write Key,
    5) Server Write IV,
    6) Server Write Mac Key

Hint: KeyBlock Layout is as the following
- Byte00-Byte015: Server Write IV
コード例 #2
0
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))

# Your answer should be printed here
print('Master Secret: %s\n' % data_to_hex(master_secret))
"""
3. Calculate the Following (30 pts): 


    1) Client Write Key,
    2) Client Write IV,
    3) Client Write Mac Key,
    4) Server Write Key,
    5) Server Write IV,
    6) Server Write Mac Key