Metadata-Version: 2.4
Name: shitty-secure-encryption
Version: 1.3.1
Summary: Amateur encrypted asymmetrical (RSA) and symmetrical (AES) communication via Pythons TCP-Sockets from socket.socket.
Project-URL: Homepage, https://github.com/N00NY/shitty_secure_connection
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pycryptodome==3.23.0
Dynamic: license-file

# shitty_secure_connection (ssc)
Amateur encrypted asymmetrical (RSA) and symmetrical (AES) communication via Pythons TCP-Sockets from socket.socket.

# The idea
Follows a client-server model.
Multiple clients are able to connect to the server.
I implemented this process after reading a bit about SSH and capturing
SSH packets with Wireshark to better understand how SSH works.

The connection between client and server is initiated in plaintext.
When instanciating the server and or client a new RSA public and private key
pair, as well a AES 256-bit key is generated.
Aftwards the client and server will exchange their generated public keys with
each other. The client then sends their AES key to the server. The Server sets
the AES key for this connection.
Lastly, the client and server have a session together.

Further protocols for e.g. a chat app or even streaming media can be built
on top of it.

## Step-by-step process
1) Instanciate server
2) Instanciate client
3) Connect client to server
4) Exchange public keys
5) Client sends AES key to server
6) Server saves the AES key
7) A new session is born

# Possbile weaknesses
I dunno. I'm not a professional cryptographer nor a security specialist.
**Use this code under extreme caution. I will not take responsibility for data
that might be exposed if you use this code to exchange sensitive information!!!!**

## List of possible weaknesses
* Only one AES key is ever exchanged
    * A two-way exchange where the client has to encrypt data with a server generated AES key might be less of a security concern
    * Generating a new AES key after a random interval might also help

# Code examples

## TCP `ServerConnection`

```
import ssc.tcp.serverconnection as serverconnection

# Instanciate new ServerConnection object that will
# bind to '127.0.0.1:1337'
sc = serverconnection.ServerConnection(ip="127.0.0.1", port=1337)
sc.listen(1)
sc.bind()

new_connection = sc.accept()
# Do stuff...

```

## TCP `ClientConnection`

```
import ssc.tcp.clientconnection as clientconnection

# Instanciate new ClientConnection object that will
# connect to '127.0.0.1:1337'
cc = clientconnection.ClientConnection(ip="127.0.0.1", port=1337)
cc.connect()

# Do stuff...

```

## `EncryptedConnection`
`EncryptedConnection` is used as the base class for `ServerConnection` and 
`ClientConnection`. `EncryptedConnection` acts as type of wrapper for a normal
`socket.socket` object. This means that an object of type `ClientConnection` can be handled the same as an object that is returned by the `accept` method of `ServerConnection`. The `send_packet` and `receive_packet` methods both use AES encryption. 
The methods `send_unencrypted_packet` and `receive_unencrypted_packet` don't use any encryption. However, you can still send or receive encrypted data with these methods. Simply encrypt the data before sending or decrypt the data after
receiving with the help of `encrypt_with_rsa` and `decrypt_with_rsa`.

You *can* send up to 4GB of data. Well, you can, butt this of course doesn't mean that you necessarily *should*.
