from dissononce.hash.sha256 import SHA256Hash
import dissononce, logging

if __name__ == "__main__":
    dissononce.logger.setLevel(logging.DEBUG)
    # setup initiator and responder variables
    alice_s = X25519DH().generate_keypair()
    bob_s = X25519DH().generate_keypair()

    # prepare handshakestate objects for initiator and responder
    alice_handshakestate = HandshakeState(
        SymmetricState(CipherState(AESGCMCipher()), SHA256Hash()), X25519DH())
    bob_handshakestate = HandshakeState(
        SymmetricState(CipherState(AESGCMCipher()), SHA256Hash()), X25519DH())
    # initialize handshakestate objects
    alice_handshakestate.initialize(XXHandshakePattern(), True, b'', s=alice_s)
    bob_handshakestate.initialize(XXHandshakePattern(), False, b'', s=bob_s)

    # -> e
    message_buffer = bytearray()
    alice_handshakestate.write_message(b'', message_buffer)
    bob_handshakestate.read_message(bytes(message_buffer), bytearray())

    # <- e, ee, s, es
    message_buffer = bytearray()
    bob_handshakestate.write_message(b'', message_buffer)
    alice_handshakestate.read_message(bytes(message_buffer), bytearray())

    # -> s, se
    message_buffer = bytearray()
    alice_cipherstates = alice_handshakestate.write_message(
Beispiel #2
0
    psks = (os.urandom(32), os.urandom(32))

    # prepare handshakestate objects for initiator and responder
    alice_handshakestate = HandshakeState(
        SymmetricState(CipherState(ChaChaPolyCipher()), Blake2sHash()),
        X25519DH())
    bob_handshakestate = HandshakeState(
        SymmetricState(CipherState(ChaChaPolyCipher()), Blake2sHash()),
        X25519DH())
    # modify NNHandshakePattern
    nn_psk0_pattern = PSKPatternModifier(0).modify(NNHandshakePattern())
    nn_psk0_psk2_pattern = PSKPatternModifier(2).modify(nn_psk0_pattern)
    # initialize handshakestate objects
    alice_handshakestate.initialize(nn_psk0_psk2_pattern,
                                    True,
                                    b'prologue',
                                    s=alice_s,
                                    psks=psks)
    bob_handshakestate.initialize(nn_psk0_psk2_pattern,
                                  False,
                                  b'prologue',
                                  s=bob_s,
                                  psks=psks)

    # -> psk, e
    message_buffer = bytearray()
    alice_handshakestate.write_message(b'', message_buffer)
    bob_handshakestate.read_message(bytes(message_buffer), bytearray())

    # <- e, ee, psk
    message_buffer = bytearray()
Beispiel #3
0
if __name__ == "__main__":
    dissononce.logger.setLevel(logging.DEBUG)
    # setup initiator and responder variables
    alice_s = X25519DH().generate_keypair()
    alice_rs = X25519DH().generate_keypair().public
    bob_s = X25519DH().generate_keypair()

    # prepare handshakestate objects for initiator and responder
    alice_handshakestate = HandshakeState(
        SymmetricState(CipherState(AESGCMCipher()), SHA256Hash()), X25519DH())
    bob_handshakestate = HandshakeState(
        SymmetricState(CipherState(AESGCMCipher()), SHA256Hash()), X25519DH())
    # initialize handshakestate objects
    alice_handshakestate.initialize(IKHandshakePattern(),
                                    True,
                                    b'',
                                    s=alice_s,
                                    rs=alice_rs)
    bob_handshakestate.initialize(IKHandshakePattern(), False, b'', s=bob_s)

    # -> e, es, s, ss
    message_buffer = bytearray()
    alice_handshakestate.write_message(b'', message_buffer)
    try:
        bob_handshakestate.read_message(bytes(message_buffer), bytearray())
    except DecryptFailedException:
        # bob failed to read alice's message, possibly because alice used wrong static keys for bob, will now fallback
        # to XX
        bob_handshakestate.initialize(FallbackPatternModifier().modify(
            XXHandshakePattern()),
                                      False,
Beispiel #4
0
if __name__ == "__main__":
    dissononce.logger.setLevel(logging.DEBUG)
    # setup initiator and responder variables
    alice_s = X25519DH().generate_keypair()
    bob_s = X25519DH().generate_keypair()

    # prepare handshakestate objects for initiator and responder
    alice_handshakestate = HandshakeState(
        SymmetricState(CipherState(AESGCMCipher()), SHA256Hash()), X25519DH())
    bob_handshakestate = HandshakeState(
        SymmetricState(CipherState(AESGCMCipher()), SHA256Hash()), X25519DH())
    # initialize handshakestate objects
    alice_handshakestate.initialize(IKHandshakePattern(),
                                    True,
                                    b'',
                                    s=alice_s,
                                    rs=bob_s.public)
    bob_handshakestate.initialize(IKHandshakePattern(), False, b'', s=bob_s)

    # -> e, es, s, ss
    message_buffer = bytearray()
    alice_handshakestate.write_message(b'', message_buffer)
    bob_handshakestate.read_message(bytes(message_buffer), bytearray())

    # <- e, ee, se
    message_buffer = bytearray()
    bob_cipherstates = bob_handshakestate.write_message(b'', message_buffer)
    alice_cipherstates = alice_handshakestate.read_message(
        bytes(message_buffer), bytearray())