All Projects → plizonczyk → Noiseprotocol

plizonczyk / Noiseprotocol

Licence: mit
Noise Protocol Framework - Python 3 implementation

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Noiseprotocol

Demo Twilio Backend Nodejs
A sample backend that demonstrates how to generate a Virgil JWT and Twilio token used for authentication with the Virgil and Twilio services
Stars: ✭ 128 (-9.86%)
Mutual labels:  cryptography
Padding Oracle Attacker
🔓 CLI tool and library to execute padding oracle attacks easily, with support for concurrent network requests and an elegant UI.
Stars: ✭ 136 (-4.23%)
Mutual labels:  cryptography
Openabe
The OpenABE library - open source cryptographic library with attribute-based encryption implementations in C/C++
Stars: ✭ 140 (-1.41%)
Mutual labels:  cryptography
Merkle Tree
Merkle Trees and Merkle Inclusion Proofs
Stars: ✭ 130 (-8.45%)
Mutual labels:  cryptography
Sodium Plus
Developer-friendly libsodium interface
Stars: ✭ 132 (-7.04%)
Mutual labels:  cryptography
Curv
Rust language general purpose elliptic curve cryptography.
Stars: ✭ 138 (-2.82%)
Mutual labels:  cryptography
Torchbear
🔥🐻 The Speakeasy Scripting Engine Which Combines Speed, Safety, and Simplicity
Stars: ✭ 128 (-9.86%)
Mutual labels:  cryptography
Crypto1 bs
Bitsliced Crypto-1 brute-forcer
Stars: ✭ 140 (-1.41%)
Mutual labels:  cryptography
Tiny Keccak
An implementation of Keccak derived functions specified in FIPS-202, SP800-185 and KangarooTwelve
Stars: ✭ 134 (-5.63%)
Mutual labels:  cryptography
Crypto Rnn
Learning the Enigma with Recurrent Neural Networks
Stars: ✭ 139 (-2.11%)
Mutual labels:  cryptography
Lockbox Extension
Experimental Firefox extension for login management experiences, not being actively developed
Stars: ✭ 130 (-8.45%)
Mutual labels:  cryptography
Useful Crypto Resources
A place for useful crypto-related resources plus some of my fav stuff
Stars: ✭ 131 (-7.75%)
Mutual labels:  cryptography
Mstar Bin Tool
Scripts to manipulate Mstar firmware binaries (e.g. MstarUpgrade.bin, LetvUpgrade.bin etc)
Stars: ✭ 137 (-3.52%)
Mutual labels:  cryptography
Libsodium Doc
Gitbook documentation for libsodium
Stars: ✭ 129 (-9.15%)
Mutual labels:  cryptography
Trussed
Modern Cryptographic Firmware
Stars: ✭ 140 (-1.41%)
Mutual labels:  cryptography
Stream Ciphers
Collection of stream cipher algorithms
Stars: ✭ 127 (-10.56%)
Mutual labels:  cryptography
Cli
🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.
Stars: ✭ 2,151 (+1414.79%)
Mutual labels:  cryptography
Dizk
Java library for distributed zero knowledge proof systems
Stars: ✭ 140 (-1.41%)
Mutual labels:  cryptography
Yrssf
一个分布式(p2p)云教学/云课堂/直播平台系统CMS,睿易派的开源替代品
Stars: ✭ 141 (-0.7%)
Mutual labels:  cryptography
Sheep Wolf
Wolves Among the Sheep
Stars: ✭ 138 (-2.82%)
Mutual labels:  cryptography

noiseprotocol

CircleCI PyPI Documentation Status

This repository contains source code of noiseprotocol - a Python 3 implementation of Noise Protocol Framework. Compatible with revisions 32 and 33.

Master branch contains latest version released. Trunk branch is an active development branch.

Documentation

Available on Read the Docs. For now it provides basic documentation on HandshakeState, CipherState and SymmetricState. Refer to the rest of the README below for more information.

Installation and prerequisites

Only Python 3.5+ is supported. The author provides support for Linux systems only. Theoretically, package should work under Windows and OS X too, but those systems are not included in CI workflow.

Install via pip:

pip install noiseprotocol 

noiseprotocol depends on Cryptography package (and its' pre-packaged OpenSSL v1.1) as a source of crypto-primitives. Usage of non-default crypto backend is possible as of version 0.3.0.

Usage

Basic usage

NoiseConnection class provides highest level of abstraction for the package. You can access full functionality of the package through this class' interfaces. An example for setting up NoiseConnection could look like this:

import socket

from noise.connection import NoiseConnection

sock = socket.socket()
sock.connect(('localhost', 2000))

# Create instance of NoiseConnection, set up to use NN handshake pattern, Curve25519 for
# elliptic curve keypair, ChaCha20Poly1305 as cipher function and SHA256 for hashing.  
proto = NoiseConnection.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')

# Set role in this connection as initiator
proto.set_as_initiator()
# Enter handshake mode
proto.start_handshake()

# Perform handshake - as we are the initiator, we need to generate first message. 
# We don't provide any payload (although we could, but it would be cleartext for this pattern).
message = proto.write_message()
# Send the message to the responder - you may simply use sockets or any other way 
# to exchange bytes between communicating parties. 
sock.sendall(message)
# Receive the message from the responder 
received = sock.recv(2048)
# Feed the received message into noise
payload = proto.read_message(received)

# As of now, the handshake should be finished (as we are using NN pattern). 
# Any further calls to write_message or read_message would raise NoiseHandshakeError exception.
# We can use encrypt/decrypt methods of NoiseConnection now for encryption and decryption of messages.
encrypted_message = proto.encrypt(b'This is an example payload')
sock.sendall(encrypted_message)

ciphertext = sock.recv(2048)
plaintext = proto.decrypt(ciphertext)
print(plaintext)

The example above covers the connection from the initiator's ("client") point of view. The snippet below is an example of responder's code ("server") using a socket connection to send and receive ciphertext.

import socket
from itertools import cycle

from noise.connection import NoiseConnection

if __name__ == '__main__':
    s = socket.socket()
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('localhost', 2000))
    s.listen(1)

    conn, addr = s.accept()
    print('Accepted connection from', addr)

    noise = NoiseConnection.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')
    noise.set_as_responder()
    noise.start_handshake()

    # Perform handshake. Break when finished
    for action in cycle(['receive', 'send']):
        if noise.handshake_finished:
            break
        elif action == 'send':
            ciphertext = noise.write_message()
            conn.sendall(ciphertext)
        elif action == 'receive':
            data = conn.recv(2048)
            plaintext = noise.read_message(data)

    # Endless loop "echoing" received data
    while True:
        data = conn.recv(2048)
        if not data:
            break
        received = noise.decrypt(data)
        conn.sendall(noise.encrypt(received))

Wireguard integration example

In examples directory, there is an example of interoperation of this package with Wireguard VPN solution. Please refer to README.md of that example for details.


Bug reports

This software was tested only on Linux. It may or may not work on Windows, explicit support for this system may be added in future.

Please file any bug reports in project's issue tracker.

Development & contributing

Additional packages that may be useful during development are contained in dev_requirements.txt. Installation:

pip install -r dev_requirements.txt

Running tests (from root directory):

pytest

Todo-list for the project:

  • [x] add non-default crypto algorithms support, as requested
  • [ ] fallback patterns support
  • [ ] scripts for keypair generation (+ console entry points)
  • [ ] "echo" (noise-c like) example
  • [ ] extensive logging
  • [x] move away from custom ed448 implementation
  • [ ] implement countermeasures for side-channel attacks
  • [ ] get peer review of the code

You are more than welcome to propose new things to this list and/or implement them and file a merge request.

Contact the author: plizonczyk.public [at] gmail.com

License

This project is licensed under the MIT License - see the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].