def filter(packetNo, data, source, target): bytes = stringToBytes(data) if packetNo == 0 and 'Client2Server' in str(source): p = Parser(bytes[5:]) p.get(1) clientHello = ClientHello() clientHello.parse(p) print bcolors.OKGREEN + "Client supports TLS version: %s" % \ str(clientHello.client_version) print "Client supports ciphersuites: %s" % \ str([CIPHER_MAP.get(i,i) for i in clientHello.cipher_suites]) \ + bcolors.ENDC elif packetNo == 0 and 'Client2Server' not in str(source): p = Parser(bytes[5:]) p.get(1) serverHello = ServerHello() serverHello.parse(p) print bcolors.OKGREEN + "Server selected TLS version: %s" % \ str(serverHello.server_version) print "Server selected ciphersuite: %s" % \ str(CIPHER_MAP.get(serverHello.cipher_suite, serverHello.cipher_suite)) + bcolors.ENDC target.write(data) return data
def DecryptHash(key, ciphertext): """Decrypt a hash with a private key.""" encrypted = base64.b64decode(ciphertext) plaintext = key.decrypt(compat.stringToBytes(encrypted)) if plaintext: return compat.bytesToString(plaintext) else: # decryption failed return None
def signWithPEM(self, data, key_file): file = open(os.path.join(self.key_location,key_file)) pem = file.read() file.close() key = keyfactory.parsePEMKey(pem, private=True) signature = key.hashAndSign(compat.stringToBytes(data)) return cryptomath.bytesToBase64(signature)
def filter(packetNo, data, source, target): bytes = stringToBytes(data) if packetNo == 0 and 'Client2Server' in str(source): pass elif packetNo == 1 and 'Client2Server' not in str(source): print "server says hello" print bytes result = bytesToString(bytes) target.write(result) return result
def verifyWithPEM(self, data, signature, key_file): file = open(os.path.join(self.key_location,key_file)) pem = file.read() file.close() decoded_sig = cryptomath.base64ToBytes(signature) x5 = X509.X509() x5.parse(pem) publickey = x5.publicKey return publickey.hashAndVerify(decoded_sig, compat.stringToBytes(data))
def EncryptHash(key, hashed): """Encrypt a hash with a public key.""" encrypted = key.encrypt(compat.stringToBytes(hashed)) return base64.b64encode(encrypted)