mirror of https://github.com/oxen-io/lokinet
merge
This commit is contained in:
parent
ab3493ba3d
commit
ec237768d7
|
@ -352,7 +352,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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,40 @@ namespace llarp
|
|||
dh_client(uint8_t *shared, uint8_t *pk, uint8_t *sk, 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;
|
||||
}
|
||||
|
||||
|
@ -53,6 +83,7 @@ namespace llarp
|
|||
{
|
||||
return crypto_generichash(shared, 32, n, 32, dh_result, 32) != -1;
|
||||
}
|
||||
llarp::LogWarn("crypto::dh_server - dh failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -435,4 +435,4 @@ llarp_link::try_establish(struct llarp_link_establish_job* job)
|
|||
s->introduce(job->ai.enc_key);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
36
readme.md
36
readme.md
|
@ -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.
|
Loading…
Reference in New Issue