Example #1
0
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
Example #2
0
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
Example #3
0
 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) 
Example #4
0
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
Example #5
0
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
Example #6
0
  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))
Example #7
0
def EncryptHash(key, hashed):
    """Encrypt a hash with a public key."""
    encrypted = key.encrypt(compat.stringToBytes(hashed))
    return base64.b64encode(encrypted)
Example #8
0
def EncryptHash(key, hashed):
  """Encrypt a hash with a public key."""
  encrypted = key.encrypt(compat.stringToBytes(hashed))
  return base64.b64encode(encrypted)