This commit is contained in:
Ryan Tharp 2018-08-16 10:44:31 +00:00
commit a5f2f7080d
11 changed files with 163 additions and 12 deletions

View File

@ -403,7 +403,7 @@ set(STATIC_LIB ${LIB}-static)
include_directories(llarp)
include_directories(include)
include_directories(vendor/cppbackport-master/lib)
#include_directories(/usr/local/include)
include_directories(/usr/local/include)
include_directories(${sodium_INCLUDE_DIR})
if (WIN32 AND NOT MINGW)

View File

@ -247,7 +247,7 @@ main(int argc, char *argv[])
{
llarp_free_config(&config_reader);
llarp::LogError("failed to load config file ", conffname);
return false;
return 0;
}
llarp_config_iterator iter;
iter.user = &dnsr_config;

View File

@ -166,7 +166,7 @@ namespace llarp
uint64_t sequenceNo = 0;
llarp::SharedSecret sharedKey;
Endpoint* m_Parent;
uint64_t m_UpdateIntrosetTX = 0;
//uint64_t m_UpdateIntrosetTX = 0;
};
// passed a sendto context when we have a path established otherwise
@ -378,4 +378,4 @@ namespace llarp
} // namespace service
} // namespace llarp
#endif
#endif

View File

@ -1,4 +1,5 @@
#include <llarp/bencode.h>
#include "logger.hpp"
bool
bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz)
@ -124,7 +125,11 @@ bencode_read_list(llarp_buffer_t* buff, struct list_reader* r)
{
r->buffer = buff;
if(*r->buffer->cur != 'l') // ensure is a list
{
llarp::LogWarn("bencode::bencode_read_list - expecting list got ",
*r->buffer->cur);
return false;
}
r->buffer->cur++;
while(llarp_buffer_size_left(*r->buffer) && *r->buffer->cur != 'e')

View File

@ -44,29 +44,77 @@ namespace iwp
gen_intro(void *user)
{
iwp_async_intro *intro = static_cast< iwp_async_intro * >(user);
char ftmp[68] = {0};
const char *hexname = llarp::HexEncode< llarp::PubKey, decltype(ftmp) >(
intro->remote_pubkey, ftmp);
llarp::LogDebug("gen_intro remote_pubkey: ", hexname);
llarp::SharedSecret sharedkey;
llarp::ShortHash e_k;
llarp_crypto *crypto = intro->iwp->crypto;
byte_t tmp[64];
// S = TKE(a.k, b.k, n)
crypto->transport_dh_client(sharedkey, intro->remote_pubkey,
intro->secretkey, intro->nonce);
char ftmpShared[68] = {0};
const char *hexShared =
llarp::HexEncode< llarp::SharedSecret, decltype(ftmpShared) >(
sharedkey, ftmpShared);
llarp::LogDebug("gen_intro sharedkey ", hexShared);
byte_t tmp[64];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
llarp::SymmNonce n;
// copy nonce
memcpy(n, intro->nonce, 24);
char ftmpN[68] = {0};
const char *hexN =
llarp::HexEncode< llarp::SymmNonce, decltype(ftmpN) >(n, ftmpN);
llarp::LogDebug("gen_intro nonce ", hexN);
// e_k = HS(b.k + n)
llarp::ShortHash e_k;
memcpy(tmp, intro->remote_pubkey, 32);
memcpy(tmp + 32, intro->nonce, 32);
crypto->shorthash(e_k, buf);
char ftmpEk[68] = {0};
const char *hexEk =
llarp::HexEncode< llarp::ShortHash, decltype(ftmpEk) >(e_k, ftmpEk);
llarp::LogDebug("gen_intro e_k ", hexEk, " used ", strlen(hexEk));
// e = SE(a.k, e_k, n[0:24])
memcpy(intro->buf + 64, llarp::seckey_topublic(intro->secretkey), 32);
char ftmpSk[68] = {0};
const char *hexSk = llarp::HexEncode< llarp::PubKey, decltype(ftmpSk) >(
intro->secretkey, ftmpSk);
llarp::LogDebug("gen_intro SK ", hexSk);
char ftmpSkPub[68] = {0};
const char *hexSkPub =
llarp::HexEncode< llarp::PubKey, decltype(ftmpSkPub) >(
llarp::seckey_topublic(intro->secretkey), ftmpSkPub);
llarp::LogDebug("gen_intro SK pub ", hexSkPub);
buf.base = intro->buf + 64;
buf.cur = buf.base;
buf.sz = 32;
crypto->xchacha20(buf, e_k, intro->nonce);
// h = MDS( n + e + w0, S)
buf.base = intro->buf + 32;
buf.cur = buf.base;
buf.sz = intro->sz - 32;
crypto->hmac(intro->buf, buf, sharedkey);
char ftmpHmac[68] = {0}; // probably could be 65
const char *hexHmac = llarp::HexEncode< llarp::PubKey, decltype(ftmpHmac) >(
intro->buf, ftmpHmac);
llarp::LogDebug("gen_intro Hmac ", hexHmac);
// inform result
// intro->hook(intro);
llarp_logic_queue_job(intro->iwp->logic, {intro, &inform_intro});
@ -82,6 +130,12 @@ namespace iwp
llarp::SharedSecret h;
byte_t tmp[64];
const auto OurPK = llarp::seckey_topublic(intro->secretkey);
char ftmp[68] = {0};
const char *hexPk =
llarp::HexEncode< llarp::PubKey, decltype(ftmp) >(OurPK, ftmp);
llarp::LogDebug("intro OurPK ", hexPk);
// e_k = HS(b.k + n)
memcpy(tmp, OurPK, 32);
memcpy(tmp + 32, intro->nonce, 32);
@ -92,11 +146,25 @@ namespace iwp
buf.cur = buf.base;
buf.sz = 32;
memcpy(intro->remote_pubkey, intro->buf + 64, 32);
crypto->xchacha20(buf, e_K, intro->nonce);
llarp::LogInfo("handshake from ", llarp::RouterID(intro->remote_pubkey));
char ftmp2[68] = {0};
const char *hexRemotePK = llarp::HexEncode< llarp::PubKey, decltype(ftmp) >(
intro->remote_pubkey, ftmp2);
llarp::LogDebug("intro remote_pubkey ", hexRemotePK);
// S = TKE(a.k, b.k, n)
crypto->transport_dh_server(sharedkey, intro->remote_pubkey,
intro->secretkey, intro->nonce);
char ftmpShared[68] = {0};
const char *hexShared =
llarp::HexEncode< llarp::PubKey, decltype(ftmpShared) >(sharedkey,
ftmpShared);
llarp::LogDebug("intro sharedkey ", hexShared);
// h = MDS( n + e + w2, S)
buf.base = intro->buf + 32;
buf.cur = buf.base;
@ -104,6 +172,7 @@ namespace iwp
crypto->hmac(h, buf, sharedkey);
if(memcmp(h, intro->buf, 32))
{
llarp::LogWarn("intro HMAC failure");
// hmac fail
intro->buf = nullptr;
}
@ -375,11 +444,19 @@ iwp_decrypt_frame(struct iwp_async_frame *frame)
crypto->hmac(digest, buf, frame->sessionkey);
// check hmac
frame->success = memcmp(digest, hmac, 32) == 0;
if(!frame->success)
{
// [", digest, "] vs [", hmac, "]
llarp::LogWarn("crypto_async::iwp_decrypt_frame failed to decrypt");
//} else {
// llarp::Debug("crypto_async::iwp_decrypt_frame decrypted");
}
// x = SE(S, p, n[0:24])
buf.base = body;
buf.cur = buf.base;
buf.sz = frame->sz - 64;
crypto->xchacha20(buf, frame->sessionkey, nonce);
return frame->success;
}

View File

@ -39,10 +39,40 @@ namespace llarp
const uint8_t *n)
{
llarp::SharedSecret dh_result;
char ftmpPk[68] = {0};
const char *hexPk =
llarp::HexEncode< llarp::PubKey, decltype(ftmpPk) >(pk, ftmpPk);
llarp::LogDebug("PK :", hexPk);
char ftmpSk[68] = {0};
const char *hexSk =
llarp::HexEncode< llarp::PubKey, decltype(ftmpSk) >(sk, ftmpSk);
llarp::LogDebug("SK :", hexSk);
char ftmpSkPub[68] = {0};
const char *hexSkPub =
llarp::HexEncode< llarp::PubKey, decltype(ftmpSkPub) >(
llarp::seckey_topublic(sk), ftmpSkPub);
llarp::LogDebug("SK pub :", hexSkPub);
if(dh(dh_result, llarp::seckey_topublic(sk), pk, pk, sk))
{
return crypto_generichash(shared, 32, n, 32, dh_result, 32) != -1;
char ftmpResult[68] = {0};
const char *hexResult =
llarp::HexEncode< llarp::SharedSecret, decltype(ftmpResult) >(
dh_result, ftmpResult);
llarp::LogDebug("Result :", hexResult);
bool res = crypto_generichash(shared, 32, n, 32, dh_result, 32) != -1;
char ftmpShared[68] = {0};
const char *hexShared =
llarp::HexEncode< llarp::SharedSecret, decltype(ftmpShared) >(
shared, ftmpShared);
llarp::LogDebug("Shared :", hexShared);
return res;
}
llarp::LogWarn("crypto::dh_client - dh failed");
return false;
}
@ -55,6 +85,7 @@ namespace llarp
{
return crypto_generichash(shared, 32, n, 32, dh_result, 32) != -1;
}
llarp::LogWarn("crypto::dh_server - dh failed");
return false;
}

View File

@ -38,7 +38,7 @@ namespace llarp
read(void* buf, size_t sz)
{
sockaddr_in6 src;
socklen_t slen = sizeof(src);
socklen_t slen = sizeof(sockaddr_in6);
sockaddr* addr = (sockaddr*)&src;
ssize_t ret = ::recvfrom(fd, buf, sz, 0, addr, &slen);
if(ret == -1)

View File

@ -475,4 +475,4 @@ llarp_link::try_establish(struct llarp_link_establish_job* job)
s->introduce(job->ai.enc_key);
return true;
}
}

View File

@ -110,6 +110,7 @@ namespace llarp
condition.NotifyOne();
}
/*
static int
runIsolated(void *arg)
{
@ -124,9 +125,10 @@ namespace llarp
func();
return 0;
}
*/
void
IsolatedPool::Spawn(int workers, const char *name)
IsolatedPool::Spawn(size_t workers, const char *name)
{
if(m_isolated)
return;

View File

@ -60,8 +60,8 @@ namespace llarp
{
}
void
Spawn(int workers, const char* name);
virtual void
Spawn(size_t workers, const char* name);
void
Join();

View File

@ -3,7 +3,43 @@
Lokinet is a private, decentralized and Sybil resistant overlay network for the internet, it uses a new routing protocol called LLARP (Low latency anonymous routing protocol)
You can learn more about the high level design of LLARP [here](doc/high-level.txt)
<<<<<<< Updated upstream
And you can read the LLARP protocol specification [here](doc/proto_v0.txt)
=======
And you can read the LLARP protocol specification [here](doc/proto_v0.txt)
## Building
$ sudo apt install build-essential libtool autoconf cmake git
$ git clone --recursive https://github.com/loki-project/lokinet-builder
$ cd lokinet-builder
$ make
## Running
<<<<<<< Updated upstream
$ ./lokinet
=======
$ sudo apt install build-essential libtool autoconf cmake git python3-venv
$ git clone --recursive https://github.com/majestrate/llarpd-builder
$ cd llarpd-builder
$ make
>>>>>>> Stashed changes
### Development
Please note development builds are likely to be unstable
Build requirements:
* CMake
* ninja
* libsodium >= 1.0.14
* c++ 11 capable C++ compiler (gcc 7.x+, llvm 3.8+)
Building a debug build:
>>>>>>> Stashed changes
To build lokinet see the [lokinet-builder](https://github.com/loki-project/lokinet-builder) repository.