Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

koviubi56/p2sn

p2sn

DEPRECATED - Use anything else

CodeQL CodeFactor Codacy Badge pre-commit.ci status Build Status

P2SN is a Peer to Peer, encrypted Socket Network written in python. P2SN uses asymmetric/public key encription (RSA) for all* communication between the two peers. P2SN uses Base64 (with the '+' and '/' characters) to encode and decode everything**.

*: Everything, except PUBKEY, pubkey, ERRORKEY, and NULL.

**: Everything, except PUBKEY, ERRORKEY, and NULL

How does it work

You can read the official P2SN standard in the standard.md file.

Key exchange

Can't see it?

sequenceDiagram
    participant SERVER
    participant CLIENT
    CLIENT->>SERVER: What's your public key?
    SERVER->>CLIENT: It's 12642607...
    CLIENT->>SERVER: [KEYCHECK]
    SERVER->>CLIENT: What's your public key?
    CLIENT->>SERVER: It's 12642607...
    SERVER->>CLIENT: [KEYCHECK]

b"..." means a bytes string. \x04 marks the end of the message, ASCII code 4. [KEYCHECK] is simply used for checking if the peer received the right key correctly. The bytes b"P2SN:KEYCHECK" are encrypted. [ERRORKEY] is b"P2SN:ERRORKEY"

The client and the server must have a public, and a private RSA key. Minimum recommended keysize: 1024 bits.

  • Client connects to server.
  • Client sends b"P2SN:PUBKEY\x04"
  • Server sends its public key saved with pkcs1 PEM encoded with Base64 + b"\x04"
  • Client sends encrypted [KEYCHECK] encoded with Base64 + b"\x04"
    • If error happens, server replies with [ERRORKEY] + b"\x04"
  • Server sends b"P2SN:PUBKEY\x04"
  • Client sends its public key saved with pkcs1 PEM encoded with Base64 + b"\x04"
  • Server sends encrypted [KEYCHECK]
    • If error happens, client does nothing.

Communicating

The client must be initialized. The client is initialized if its connected to the server, and the key exchange successfully happened (see above).

  • Client sends message encrypted with the server's public key, encoded with Base64 + b"\x04"
  • Server replies with message encrypted with the client's public key, encoded with Base64 + b"\x04"