Initial commit

This commit is contained in:
belong 2021-03-06 19:54:51 +00:00
commit cc27efba98
7 changed files with 211 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
.dub
docs.json
__dummy.html
docs/
/drop
drop.so
drop.dylib
drop.dll
drop.a
drop.lib
drop-test-*
*.exe
*.o
*.obj
*.lst

44
README.md Normal file
View File

@ -0,0 +1,44 @@
# Drop
The dropper is part the of the deaddrop project.
It is the server that handles the requests of clients.
By default it listens on localhost port 8080.
The repo includes a simple script to create an onion service
for this server.
## Required software:
- dmd
- dub
## Building
```bash
$ git clone http://repourl/dropper.git drop
$ cd dropper
$ dub build --build=release
```
## Simple usage:
```bash
./drop
```
## Running as an onion service
Append the following lines to your /etc/tor/torrc config:
```bash
HiddenServiceDir /var/lib/tor/deaddrop/
HiddenServicePort 80 127.0.0.1:8080
HiddenServiceVersion 3
```
To get the onion address simple run this command:
```bash
$ sudo cat /var/lib/tor/deaddrop/hostname
```

17
dub.json Normal file
View File

@ -0,0 +1,17 @@
{
"authors": [
"anon"
],
"copyright": "Copyright © 2021, anon",
"dependencies": {
"vibe-d": "~>0.9",
"vibe-d:tls": "*"
},
"description": "A simple vibe.d server application.",
"license": "proprietary",
"name": "drop",
"subConfigurations": {
"vibe-d:tls": "botan"
},
"versions": ["VibeDefaultMain"]
}

17
dub.selections.json Normal file
View File

@ -0,0 +1,17 @@
{
"fileVersion": 1,
"versions": {
"botan": "1.12.19",
"botan-math": "1.0.3",
"diet-ng": "1.7.4",
"eventcore": "0.9.13",
"libasync": "0.8.6",
"memutils": "1.0.4",
"mir-linux-kernel": "1.0.1",
"openssl": "1.1.6+1.0.1g",
"stdx-allocator": "2.77.5",
"taggedalgebraic": "0.11.19",
"vibe-core": "1.13.0",
"vibe-d": "0.9.3"
}
}

15
makeHiddenService.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
echo "HiddenServiceDir /var/lib/tor/deaddrop/
HiddenServicePort 80 127.0.0.1:8080
HiddenServiceVersion 3" >> /etc/tor/torrc
sv restart tor
hostname=$(cat /var/lib/tor/deaddrop/hostname)
echo "Add the following to your clients torrc: HidServAuth $hostname"

13
source/app.d Normal file
View File

@ -0,0 +1,13 @@
import vibe.vibe;
import datastore;
shared static this()
{
auto router = new URLRouter;
router.registerWebInterface(new Backend);
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["127.0.0.1"];
listenHTTP(settings, router);
}

90
source/datastore.d Normal file
View File

@ -0,0 +1,90 @@
module datastore;
import std.conv;
import vibe.d;
/// This class handles
/// the postage of new message
/// to the drop
/// FIXME: add sqlite backend for message
/// storage so messages survive restarts
class Backend
{
private struct Message
{
string recipient;
string payload;
}
private Message[] p_message;
private string serializeMessage(Message msg)
{
immutable string msg_template = `
{
"recipient": "%s",
"payload": "%s"
}
`;
import std.format : format;
return format(msg_template, msg.recipient, msg.payload);
}
/// This function gets all the posted
/// messages as a json array
@path("/messages")
@safe
Json getMessages(HTTPServerResponse res,)
{
return serializeToJson(p_message);
}
/// This function is
/// used to add a new
/// message to the drop-point
/// post data like so
/// {
/// "recipient": "base64 encoded publickey",
/// "sender": "base64 encoded publickey",
/// "payload": "base64 encoded payload data",
/// "nonce": "base64 encoded nonce"
/// }
@path("/add-message")
@method(HTTPMethod.POST)
@safe
void addMessage(
string recipient,
string payload,
HTTPServerResponse res,
)
{
logInfo(text("Backend: POST /add-message for : ", recipient));
auto m = Message(recipient, payload);
this.p_message ~= m;
res.writeBody("");
}
@path("/getmessages")
@method(HTTPMethod.POST)
@safe
Json getMessageForPubkeys(string pubkey)
{
logInfo(text("Backend: POST /getmessages for : ", pubkey));
Message[] user_messages;
foreach (Message key; p_message)
{
if (key.recipient == pubkey)
{
user_messages ~= key;
}
}
return serializeToJson(user_messages);
}
}