mirror of
https://github.com/morgan9e/noiseprotocol
synced 2026-04-14 00:14:05 +09:00
@@ -3,14 +3,13 @@ Changelog
|
||||
|
||||
.. _v0-2-0:
|
||||
|
||||
0.2.0 - `trunk`
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
.. note:: This version is not yet released and is under active development.
|
||||
0.2.0 - 2017-11-01
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Compatible with revision 33 (doesn't break compatibility with revision 32).
|
||||
* Cryptography requirement updated to the newest version (2.1.1) - **Python 3.5** is supported again.
|
||||
* Adding sphinx documentation for Read the Docs publication.
|
||||
* Cryptography requirement updated to the newest version (2.1.2) - **Python 3.5** is supported again.
|
||||
* Adding sphinx documentation for Read the Docs publication and README update
|
||||
* Renamed NoiseBuilder to NoiseConnection
|
||||
* Minor fixes for better performance.
|
||||
|
||||
|
||||
|
||||
17
README.md
17
README.md
@@ -27,20 +27,20 @@ pip install noiseprotocol
|
||||
## Usage
|
||||
|
||||
#### Basic usage
|
||||
NoiseBuilder 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 NoiseBuilder could look like this:
|
||||
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:
|
||||
|
||||
```python
|
||||
import socket
|
||||
|
||||
from noise.builder import NoiseBuilder
|
||||
from noise.connection import NoiseConnection
|
||||
|
||||
sock = socket.socket()
|
||||
sock.connect(('localhost', 2000))
|
||||
|
||||
# Create instance of NoiseBuilder, set up to use NN handshake pattern, Curve25519 for
|
||||
# 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 = NoiseBuilder.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')
|
||||
proto = NoiseConnection.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')
|
||||
|
||||
# Set role in this connection as initiator
|
||||
proto.set_as_initiator()
|
||||
@@ -60,7 +60,7 @@ 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 NoiseBuilder now for encryption and decryption of messages.
|
||||
# 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)
|
||||
|
||||
@@ -75,7 +75,7 @@ The example above covers the connection from the initiator's ("client") point of
|
||||
import socket
|
||||
from itertools import cycle
|
||||
|
||||
from noise.builder import NoiseBuilder
|
||||
from noise.connection import NoiseConnection
|
||||
|
||||
if __name__ == '__main__':
|
||||
s = socket.socket()
|
||||
@@ -86,7 +86,7 @@ if __name__ == '__main__':
|
||||
conn, addr = s.accept()
|
||||
print('Accepted connection from', addr)
|
||||
|
||||
noise = NoiseBuilder.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')
|
||||
noise = NoiseConnection.from_name(b'Noise_NN_25519_ChaChaPoly_SHA256')
|
||||
noise.set_as_responder()
|
||||
noise.start_handshake()
|
||||
|
||||
@@ -134,6 +134,7 @@ pytest
|
||||
|
||||
### Todo-list for the project:
|
||||
|
||||
- [ ] custom crypto backends
|
||||
- [ ] fallback patterns support
|
||||
- [ ] scripts for keypair generation (+ console entry points)
|
||||
- [ ] "echo" (noise-c like) example
|
||||
|
||||
@@ -6,7 +6,7 @@ import struct
|
||||
|
||||
from scapy.layers.inet import IP, ICMP
|
||||
|
||||
from noise.builder import NoiseBuilder, Keypair
|
||||
from noise.connection import NoiseConnection, Keypair
|
||||
|
||||
|
||||
address = ('demo.wireguard.com', 12913)
|
||||
@@ -16,7 +16,7 @@ their_public = base64.b64decode('qRCwZSKInrMAq5sepfCdaCsRJaoLe5jhtzfiw7CjbwM=')
|
||||
preshared = base64.b64decode('FpCyhws9cxwWoV4xELtfJvjJN+zQVRPISllRWgeopVE=')
|
||||
prologue = b'WireGuard v1 zx2c4 Jason@zx2c4.com'
|
||||
|
||||
noise = NoiseBuilder.from_name(b'Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s')
|
||||
noise = NoiseConnection.from_name(b'Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s')
|
||||
noise.set_as_initiator()
|
||||
noise.set_keypair_from_private_bytes(Keypair.STATIC, our_private)
|
||||
noise.set_keypair_from_public_bytes(Keypair.REMOTE_STATIC, their_public)
|
||||
|
||||
@@ -1 +1 @@
|
||||
__all__ = ['builder']
|
||||
__all__ = ['connection']
|
||||
|
||||
@@ -19,7 +19,7 @@ _keypairs = {Keypair.STATIC: 's', Keypair.REMOTE_STATIC: 'rs',
|
||||
Keypair.EPHEMERAL: 'e', Keypair.REMOTE_EPHEMERAL: 're'}
|
||||
|
||||
|
||||
class NoiseBuilder(object):
|
||||
class NoiseConnection(object):
|
||||
def __init__(self):
|
||||
self.noise_protocol = None
|
||||
self.protocol_name = None
|
||||
@@ -97,11 +97,11 @@ class NoiseBuilder(object):
|
||||
|
||||
def write_message(self, payload: bytes=b'') -> bytearray:
|
||||
if not self._handshake_started:
|
||||
raise NoiseHandshakeError('Call NoiseBuilder.start_handshake first')
|
||||
raise NoiseHandshakeError('Call NoiseConnection.start_handshake first')
|
||||
if self._next_fn != self.write_message:
|
||||
raise NoiseHandshakeError('NoiseBuilder.read_message has to be called now')
|
||||
raise NoiseHandshakeError('NoiseConnection.read_message has to be called now')
|
||||
if self.handshake_finished:
|
||||
raise NoiseHandshakeError('Handshake finished. NoiseBuilder.encrypt should be used now')
|
||||
raise NoiseHandshakeError('Handshake finished. NoiseConnection.encrypt should be used now')
|
||||
self._next_fn = self.read_message
|
||||
|
||||
buffer = bytearray()
|
||||
@@ -112,11 +112,11 @@ class NoiseBuilder(object):
|
||||
|
||||
def read_message(self, data: bytes) -> bytearray:
|
||||
if not self._handshake_started:
|
||||
raise NoiseHandshakeError('Call NoiseBuilder.start_handshake first')
|
||||
raise NoiseHandshakeError('Call NoiseConnection.start_handshake first')
|
||||
if self._next_fn != self.read_message:
|
||||
raise NoiseHandshakeError('NoiseBuilder.write_message has to be called now')
|
||||
raise NoiseHandshakeError('NoiseConnection.write_message has to be called now')
|
||||
if self.handshake_finished:
|
||||
raise NoiseHandshakeError('Handshake finished. NoiseBuilder.decrypt should be used now')
|
||||
raise NoiseHandshakeError('Handshake finished. NoiseConnection.decrypt should be used now')
|
||||
self._next_fn = self.write_message
|
||||
|
||||
buffer = bytearray()
|
||||
@@ -121,8 +121,8 @@ class NoiseProtocol(object):
|
||||
'given {}'.format(self.pattern.psk_count, len(self.psks)))
|
||||
|
||||
if self.initiator is None:
|
||||
raise NoiseValidationError('You need to set role with NoiseBuilder.set_as_initiator '
|
||||
'or NoiseBuilder.set_as_responder')
|
||||
raise NoiseValidationError('You need to set role with NoiseConnection.set_as_initiator '
|
||||
'or NoiseConnection.set_as_responder')
|
||||
|
||||
for keypair in self.pattern.get_required_keypairs(self.initiator):
|
||||
if self.keypairs[keypair] is None:
|
||||
|
||||
@@ -1 +1 @@
|
||||
cryptography==2.1.1
|
||||
cryptography==2.1.2
|
||||
|
||||
2
setup.py
2
setup.py
@@ -32,6 +32,6 @@ setup(
|
||||
],
|
||||
keywords='cryptography noiseprotocol noise security',
|
||||
packages=find_packages(exclude=['contrib', 'docs', 'tests', 'examples']),
|
||||
install_requires=['cryptography==2.1.1'],
|
||||
install_requires=['cryptography==2.1.2'],
|
||||
python_requires='~=3.5,~=3.6',
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from noise.builder import NoiseBuilder, Keypair
|
||||
from noise.connection import NoiseConnection, Keypair
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -56,20 +56,20 @@ class TestVectors(object):
|
||||
def vector(self, request):
|
||||
yield request.param
|
||||
|
||||
def _set_keypairs(self, vector, builder):
|
||||
role = 'init' if builder.noise_protocol.initiator else 'resp'
|
||||
def _set_keypairs(self, vector, connection):
|
||||
role = 'init' if connection.noise_protocol.initiator else 'resp'
|
||||
setters = [
|
||||
(builder.set_keypair_from_private_bytes, Keypair.STATIC, role + '_static'),
|
||||
(builder.set_keypair_from_private_bytes, Keypair.EPHEMERAL, role + '_ephemeral'),
|
||||
(builder.set_keypair_from_public_bytes, Keypair.REMOTE_STATIC, role + '_remote_static')
|
||||
(connection.set_keypair_from_private_bytes, Keypair.STATIC, role + '_static'),
|
||||
(connection.set_keypair_from_private_bytes, Keypair.EPHEMERAL, role + '_ephemeral'),
|
||||
(connection.set_keypair_from_public_bytes, Keypair.REMOTE_STATIC, role + '_remote_static')
|
||||
]
|
||||
for fn, keypair, name in setters:
|
||||
if name in vector:
|
||||
fn(keypair, vector[name])
|
||||
|
||||
def test_vector(self, vector):
|
||||
initiator = NoiseBuilder.from_name(vector['protocol_name'])
|
||||
responder = NoiseBuilder.from_name(vector['protocol_name'])
|
||||
initiator = NoiseConnection.from_name(vector['protocol_name'])
|
||||
responder = NoiseConnection.from_name(vector['protocol_name'])
|
||||
if 'init_psks' in vector and 'resp_psks' in vector:
|
||||
initiator.set_psks(psks=vector['init_psks'])
|
||||
responder.set_psks(psks=vector['resp_psks'])
|
||||
|
||||
Reference in New Issue
Block a user