From d27ea5d2285423db131bd0e8f595b51acc4a44fc Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 9 Sep 2019 11:33:51 -0600 Subject: [PATCH] whip initial secio --- libp2p/protocols/secure/secio.nim | 32 +++++++++++++++++++ libp2p/protocols/secure/seciocrypto.nim | 40 ++++++++++++++++++++++++ libp2p/protocols/{ => secure}/secure.nim | 10 ++++-- 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 libp2p/protocols/secure/secio.nim create mode 100644 libp2p/protocols/secure/seciocrypto.nim rename libp2p/protocols/{ => secure}/secure.nim (75%) diff --git a/libp2p/protocols/secure/secio.nim b/libp2p/protocols/secure/secio.nim new file mode 100644 index 0000000..7d49280 --- /dev/null +++ b/libp2p/protocols/secure/secio.nim @@ -0,0 +1,32 @@ +## Nim-LibP2P +## Copyright (c) 2018 Status Research & Development GmbH +## Licensed under either of +## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +## * MIT license ([LICENSE-MIT](LICENSE-MIT)) +## at your option. +## This file may not be copied, modified, or distributed except according to +## those terms. + +import chronos +import secure, + ../../connection + +const SecioCodec* = "/plaintext/1.0.0" + +type + Secio = ref object of Secure + +proc encodeProposalMsg*() = discard +proc decodeProposalMsg*() = discard + +method init(p: Secio) {.gcsafe.} = + proc handle(conn: Connection, proto: string) {.async, gcsafe.} = + discard + + p.codec = SecioCodec + p.handler = handle + +proc newSecio*(): Secio = + new result + result.init() + diff --git a/libp2p/protocols/secure/seciocrypto.nim b/libp2p/protocols/secure/seciocrypto.nim new file mode 100644 index 0000000..b43953e --- /dev/null +++ b/libp2p/protocols/secure/seciocrypto.nim @@ -0,0 +1,40 @@ +## Nim-LibP2P +## Copyright (c) 2018 Status Research & Development GmbH +## Licensed under either of +## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +## * MIT license ([LICENSE-MIT](LICENSE-MIT)) +## at your option. +## This file may not be copied, modified, or distributed except according to +## those terms. + +type + Exchanges* {.pure.} = enum + P256 = "P-256", + P384 = "P-384", + P521 = "P-521" + + Ciphers* {.pure.} = enum + AES256 = "AES-256", + AES128 = "AES-128" + + Hashes* {.pure.} = enum + SHA256 = "SHA256" + SHA512 = "SHA512" + + Propose* = tuple + rand: seq[byte] + pubkey: seq[byte] + exchanges: string + ciphers: string + hashes: string + + Exchange = tuple + epubkey: seq[byte] + signature: seq[byte] + +proc proposal*() = discard +proc exchange*() = discard +proc selectBest*() = discard +proc verify*() = discard +proc generateKeys*() = discard +proc verifyNonce*() = discard \ No newline at end of file diff --git a/libp2p/protocols/secure.nim b/libp2p/protocols/secure/secure.nim similarity index 75% rename from libp2p/protocols/secure.nim rename to libp2p/protocols/secure/secure.nim index be9eac4..03207b7 100644 --- a/libp2p/protocols/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -8,8 +8,8 @@ ## those terms. import chronos -import protocol -import ../connection +import ../protocol +import ../../connection const PlainTextCodec* = "/plaintext/1.0.0" @@ -19,12 +19,16 @@ type PlainText* = ref object of Secure method init(p: PlainText) {.gcsafe.} = - proc handle(conn: Connection, proto: string) {.async, gcsafe.} = discard + proc handle(conn: Connection, proto: string) + {.async, gcsafe.} = discard ## plain text doesn't do anything p.codec = PlainTextCodec p.handler = handle +method secure(p: Secure, conn: Connection): Future[Connection] + {.base, async, gcsafe.} = discard + proc newPlainText*(): PlainText = new result result.init()