Metadata-Version: 2.3
Name: spproto
Version: 0.1.3
Summary: Secure Peer Protocol
Project-URL: Homepage, https://github.com/lifr0m/spproto
Author: Lifr0m
License: MIT License
        
        Copyright (c) 2024-Present Lifr0m
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: chacha20,chacha20-poly1305,chat,cryptography,dh,ec,ecdh,ecdhe,ecdsa,ed25519,eddsa,hkdf,kdf,message,peer,poly1305,protocol,secure
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: cryptography~=43.0.0
Provides-Extra: dev
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Description-Content-Type: text/markdown

# Secure Peer Protocol (SPP)

## Description

Chat with friends in a truly cryptographically secure way.

Intended to work as 5th OSI layer usually on top of TCP/IP.

### Mechanism

1. shared key is obtained using ECDHE. Transferred DH public keys are
signed and verified with pre-obtained Ed25519 public keys.
2. auth key is derived from shared key using HKDF.
3. Message using ChaCha20-Poly1305 with auth key.

## Preparation before using

1. Generate private key, give your public key to friend.
2. Get friend's public key through reliable channel.

```python
from pathlib import Path
from spproto.key import generate_private_key, get_public_key

def main() -> None:
    privkey_path = Path('~/Desktop/privkey').expanduser()
    pubkey_path = Path('~/Desktop/pubkey').expanduser()
    
    privkey = generate_private_key()
    pubkey = get_public_key(privkey)
    
    privkey_path.write_bytes(privkey)
    pubkey_path.write_bytes(pubkey)

main()
```

## How to use

### Client

Connect to your friend

```python
import asyncio
from pathlib import Path
from spproto.client import connect

async def main() -> None:
    privkey = Path('~/Desktop/privkey').expanduser().read_bytes()
    peer_pubkey = Path('~/Desktop/friend_pubkey').expanduser().read_bytes()

    host = '1.2.3.4'
    port = 4321
    async with connect(host, port, privkey, peer_pubkey) as conn:
        await conn.send(b'Hello, server!')
        print(await conn.receive())

asyncio.run(main())
```

### Server

Make your friend available to connect to you.

```python
import asyncio
from pathlib import Path
from spproto.connection import Connection
from spproto.server import serve

async def callback(
    conn: Connection
) -> None:
    print(await conn.receive())
    await conn.send(b'Hello, client')

async def main() -> None:
    privkey = Path('~/Desktop/privkey').expanduser().read_bytes()
    peer_pubkey = Path('~/Desktop/friend_pubkey').expanduser().read_bytes()

    host = '1.2.3.4'
    port = 4321
    await serve(host, port, privkey, peer_pubkey, callback)

asyncio.run(main())
```
