# Rshare

A file sharing program written in Rust.

[ed25519](https://ed25519.cr.yp.to/) with SHA_2_512 is used to provide integrity and AES_256_GCM with
[X25519](https://tools.ietf.org/html/rfc7748#section-4.1) is used to provide privacy.

## Supported Platforms

Basic x86_64 instruction set or better.

### Linux

Linux 2.6 or later, 3.17 or later recommended.

### Windows

64 bit, seven or later.

## Installation

### Install With Your Package Manager

#### Arch Linux

Rshare is in the AUR. [Link](https://aur.archlinux.org/packages/rshare/).

### Download Precompiled Binary

Download the most applicable binary from [here](https://github.com/cedenday/rshare/releases/latest).

### Compile from source

1. Install [Git](https://git-scm.com/).
2. Follow the instruction [here](https://rustup.rs/).
3. Run `git clone https://github.com/cedenday/rshare.git`.
4. Run `cd rshare`.

#### Linux

1. Install [Clang](https://clang.llvm.org/) and [Musl](https://www.musl-libc.org/).
2. Run `./build_linux.sh`.

## Usage

Test server IPv6: `2601:184:300:500::3612`.

Test server IPv4: `73.143.75.225`.

Test Link:
Filename: `sintel.mkv`. 
Link: `p8e-_-NggAAFKC3-715NfNnfDdJLrhesiT9_vnOfefrsp7-aLix-KNTX_PEfTL2z02aDBsHuZwA=`.

### A Simple Example

#### Machine One

```
[test-one@test-one ~]$ rshare -q -s 2601:184:300:500::3612
> create /home/test-one/Documents/linux-4.11.2.tar.xz
4msKqmNmgAAFKJ3_3WPq5u-L9mxtsLezEtL7vzYudt931mZvR8YAg0u2M3OE2-xuttw91w0A
```

#### Machine Two

```
[test-two@test-two ~]$ rshare -q -s 2601:184:300:500::3612
> download /home/test-two/Downloads/linux-4.11.2.tar.xz 4msKqmNmgAAFKJ3_3WPq5u-L9mxtsLezEtL7vzYudt931mZvR8YAg0u2M3OE2-xuttw91w0A
> status 4msKqmNmgAAFKJ3_3WPq5u-L9mxtsLezEtL7vzYudt931mZvR8YAg0u2M3OE2-xuttw91w0A
3/3
```

## Inner Workings

### Creation

What happens when you use the `create` command:

1. An ed25519 key pair and a 64 bit nonce are generated.
2. The number of parts, the public key of the aforementioned key pair,
and the aforementioned nonce are encoded into the link. 
3. [Rayon](https://github.com/nikomatsakis/rayon) is used to iterate over the parts of the file. Each part is appended
by the aforementioned nonce and then the part's respective index. This is then hashed with SHA_2_512 and then signed
with the aforementioned key pair.
4. The result of the previous step is written to the persistent storage as metadata.

### Downloading

What happens when you use the `download` command:

1. The public signing key and the nonce from the link are added to the current
downloads list.
2. Every 15 seconds keys that don't have a high number of part advertisements are sent to the inputted servers to get
more adverts from peers connected to that server.
3. Every second a random wanted advert is selected to start key exchange.
[X25519](https://tools.ietf.org/html/rfc7748#section-4.1) is used for key agreement and 
[HKDF](https://tools.ietf.org/html/rfc5869) is used for extraction and expansion of agreed keys, with the link nonce
used as the shared info.
4. The part is encrypted with AES_256_GCM and the exchanged key by the sending peer and is decrypted by the
receiving peer.
5. The received SHA_2_512 hash is verified with the public key from the link.
6. The part's data's integrity is checked with the verified hash.
7. The part's data and it's metadata is written to disk.

## Contributing

1. Fork this repository.
2. Create a branch for your change(s).
3. Add some commits; don't overwrite your Git history.
5. Create a pull request.

## License

See [LICENSE](LICENSE).
