Add TLS for encrypted comms, next HMAC

pull/2/head
Guillermo Rodriguez 2022-12-11 13:06:07 -03:00
parent ece290d805
commit d2e676627a
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
12 changed files with 265 additions and 11 deletions

33
certs/brain.cert 100644
View File

@ -0,0 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIFxDCCA6wCAQAwDQYJKoZIhvcNAQENBQAwgacxCzAJBgNVBAYTAlVZMRMwEQYD
VQQIDApNb250ZXZpZGVvMRMwEQYDVQQHDApNb250ZXZpZGVvMRowGAYDVQQKDBFz
a3luZXQtZm91bmRhdGlvbjENMAsGA1UECwwEbm9uZTEcMBoGA1UEAwwTR3VpbGxl
cm1vIFJvZHJpZ3VlejElMCMGCSqGSIb3DQEJARYWZ3VpbGxlcm1vckBmaW5nLmVk
dS51eTAeFw0yMjEyMTExNDM3NDVaFw0zMjEyMDgxNDM3NDVaMIGnMQswCQYDVQQG
EwJVWTETMBEGA1UECAwKTW9udGV2aWRlbzETMBEGA1UEBwwKTW9udGV2aWRlbzEa
MBgGA1UECgwRc2t5bmV0LWZvdW5kYXRpb24xDTALBgNVBAsMBG5vbmUxHDAaBgNV
BAMME0d1aWxsZXJtbyBSb2RyaWd1ZXoxJTAjBgkqhkiG9w0BCQEWFmd1aWxsZXJt
b3JAZmluZy5lZHUudXkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCu
HdqGPtsqtYqfIilVdq0MmqfEn9g4T+uglfWjRF2gWV3uQCuXDv1O61XfIIyaDQXl
VRqT36txtM8rvn213746SwK0jx9+ln5jD3EDbL4WZv1qvp4/jqA+UPKXFXnD3he+
pRpcDMu4IpYKuoPl667IW/auFSSy3TIWhIZb8ghqxzb2e2i6/OhzIWKHeFIKvbEA
EB6Z63wy3O0ACY7RVhHu0wzyzqUW1t1VNsbZvO9Xmmqm2EWZBJp0TFph3Z9kOR/g
0Ik7kxMLrGIfhV5/1gPQlNr3ADebGJnaMdGCBUi+pqeZcV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cA==
-----END CERTIFICATE-----

View File

@ -3,6 +3,7 @@ pynng
triopg
aiohttp
msgspec
pyOpenSSL
trio_asyncio
git+https://github.com/goodboy/tractor.git@piker_pin#egg=tractor

View File

@ -0,0 +1,44 @@
#!/usr/bin/python
'''Self signed x509 certificate generator
can look at generated file using openssl:
openssl x509 -inform pem -in selfsigned.crt -noout -text'''
import sys
from OpenSSL import crypto, SSL
from skynet_bot.constants import DEFAULT_CERTS_DIR
def input_or_skip(txt, default):
i = input(f'[default: {default}]: {txt}')
if len(i) == 0:
return default
else:
return i
if __name__ == '__main__':
# create a key pair
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 4096)
# create a self-signed cert
cert = crypto.X509()
cert.get_subject().C = input('country name two char ISO code (example: US): ')
cert.get_subject().ST = input('state or province name (example: Texas): ')
cert.get_subject().L = input('locality name (example: Dallas): ')
cert.get_subject().O = input('organization name: ')
cert.get_subject().OU = input_or_skip('organizational unit name: ', 'none')
cert.get_subject().CN = input('common name: ')
cert.get_subject().emailAddress = input('email address: ')
cert.set_serial_number(int(input_or_skip('numberic serial number: ', 0)))
cert.gmtime_adj_notBefore(int(input_or_skip('amount of seconds until cert is valid: ', 0)))
cert.gmtime_adj_notAfter(int(input_or_skip('amount of seconds until cert expires: ', 10*365*24*60*60)))
cert.set_issuer(cert.get_subject())
cert.set_pubkey(k)
cert.sign(k, 'sha512')
with open(f'{DEFAULT_CERTS_DIR}/{sys.argv[1]}.cert', "wt") as f:
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8"))
with open(f'{DEFAULT_CERTS_DIR}/{sys.argv[1]}.key', "wt") as f:
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8"))

View File

@ -6,6 +6,7 @@ import base64
import logging
from uuid import UUID
from pathlib import Path
from functools import partial
from collections import OrderedDict
@ -13,6 +14,8 @@ import trio
import pynng
import trio_asyncio
from pynng import TLSConfig
from .db import *
from .types import *
from .constants import *
@ -241,11 +244,33 @@ async def run_skynet(
db_host: str = DB_HOST,
rpc_address: str = DEFAULT_RPC_ADDR,
dgpu_address: str = DEFAULT_DGPU_ADDR,
task_status = trio.TASK_STATUS_IGNORED
task_status = trio.TASK_STATUS_IGNORED,
security: bool = True
):
logging.basicConfig(level=logging.INFO)
logging.info('skynet is starting')
tls_config = None
if security:
# load tls certs
certs_dir = Path(DEFAULT_CERTS_DIR).resolve()
tls_key = (certs_dir / DEFAULT_CERT_SKYNET_PRIV).read_text()
tls_cert = (certs_dir / DEFAULT_CERT_SKYNET_PUB).read_text()
tls_whitelist = [
(cert_path).read_text()
for cert_path in (certs_dir / 'whitelist').glob('*.cert')]
logging.info(f'tls_key: {tls_key}')
logging.info(f'tls_cert: {tls_cert}')
logging.info(f'tls_whitelist len: {len(tls_whitelist)}')
rpc_address = 'tls+' + rpc_address
dgpu_address = 'tls+' + dgpu_address
tls_config = TLSConfig(
TLSConfig.MODE_SERVER,
own_key_string=tls_key,
own_cert_string=tls_cert)
async with (
trio.open_nursery() as n,
open_database_connection(
@ -253,9 +278,16 @@ async def run_skynet(
):
logging.info('connected to db.')
with (
pynng.Rep0(listen=rpc_address) as rpc_sock,
pynng.Bus0(listen=dgpu_address) as dgpu_bus
pynng.Rep0() as rpc_sock,
pynng.Bus0() as dgpu_bus
):
if security:
rpc_sock.tls_config = tls_config
dgpu_bus.tls_config = tls_config
rpc_sock.listen(rpc_address)
dgpu_bus.listen(dgpu_address)
n.start_soon(
rpc_service, rpc_sock, dgpu_bus, db_pool)
task_status.started()

View File

@ -113,6 +113,12 @@ DEFAULT_ALGO = 'midj'
DEFAULT_ROLE = 'pleb'
DEFAULT_UPSCALER = None
DEFAULT_CERTS_DIR = 'certs'
DEFAULT_CERT_WHITELIST_DIR = 'whitelist'
DEFAULT_CERT_SKYNET_PUB = 'brain.cert'
DEFAULT_CERT_SKYNET_PRIV = 'brain.key'
DEFAULT_CERT_DGPU = 'dgpu.key'
DEFAULT_RPC_ADDR = 'tcp://127.0.0.1:41000'
DEFAULT_DGPU_ADDR = 'tcp://127.0.0.1:41069'

View File

@ -16,10 +16,13 @@ from .frontend import rpc_call
async def open_dgpu_node(
cert_name: str,
key_name: Optional[str],
rpc_address: str = DEFAULT_RPC_ADDR,
dgpu_address: str = DEFAULT_DGPU_ADDR,
dgpu_max_tasks: int = DEFAULT_DGPU_MAX_TASKS,
initial_algos: str = DEFAULT_INITAL_ALGOS
initial_algos: str = DEFAULT_INITAL_ALGOS,
security: bool = True
):
logging.basicConfig(level=logging.INFO)
@ -65,7 +68,11 @@ async def open_dgpu_node(
return img
async with open_skynet_rpc() as rpc_call:
async with open_skynet_rpc(
security=security,
cert_name=cert_name,
key_name=key_name
) as rpc_call:
with pynng.Bus0(dial=dgpu_address) as dgpu_sock:
async def _process_dgpu_req(req: DGPUBusRequest):
img = await gpu_compute_one(

View File

@ -2,11 +2,14 @@
import json
from typing import Union
from typing import Union, Optional
from pathlib import Path
from contextlib import asynccontextmanager as acm
import pynng
from pynng import TLSConfig
from ..types import SkynetRPCRequest, SkynetRPCResponse
from ..constants import *
@ -48,8 +51,33 @@ async def rpc_call(
@acm
async def open_skynet_rpc(rpc_address: str = DEFAULT_RPC_ADDR):
with pynng.Req0(dial=rpc_address) as sock:
async def open_skynet_rpc(
rpc_address: str = DEFAULT_RPC_ADDR,
security: bool = False,
cert_name: Optional[str] = None,
key_name: Optional[str] = None
):
tls_config = None
if security:
# load tls certs
if not key_name:
key_name = certs_name
certs_dir = Path(DEFAULT_CERTS_DIR).resolve()
skynet_cert = (certs_dir / 'brain.cert').read_text()
tls_cert = (certs_dir / f'{cert_name}.cert').read_text()
tls_key = (certs_dir / f'{key_name}.key').read_text()
rpc_address = 'tls+' + rpc_address
tls_config = TLSConfig(
TLSConfig.MODE_CLIENT,
own_key_string=tls_key,
own_cert_string=tls_cert,
ca_string=skynet_cert)
with pynng.Req0() as sock:
if security:
sock.tls_config = tls_config
sock.dial(rpc_address)
async def _rpc_call(*args, **kwargs):
return await rpc_call(sock, *args, **kwargs)

View File

@ -24,7 +24,9 @@ async def run_skynet_telegram(
logging.basicConfig(level=logging.INFO)
bot = AsyncTeleBot(tg_token)
with open_skynet_rpc() as rpc_call:
with open_skynet_rpc(
security=True, cert_name='telegram-frontend'
) as rpc_call:
async def _rpc_call(
uid: int,
@ -69,7 +71,7 @@ async def run_skynet_telegram(
'config', {'attr': attr, 'val': val})
except BaseException as e:
reply_text = e.message
reply_text = str(e.value)
finally:
await bot.reply_to(message, reply_txt)

View File

@ -0,0 +1,2 @@
from OpenSSL.crypto import load_publickey, FILETYPE_PEM, verify, X509

View File

@ -3,6 +3,8 @@
import logging
import trio
import pynng
import pytest
import trio_asyncio
from skynet_bot.types import *
@ -10,8 +12,20 @@ from skynet_bot.brain import run_skynet
from skynet_bot.frontend import open_skynet_rpc
async def test_skynet_attempt_insecure(skynet_running):
with pytest.raises(pynng.exceptions.NNGException) as e:
async with open_skynet_rpc():
...
assert str(e.value) == 'Connection shutdown'
async def test_skynet_dgpu_connection_simple(skynet_running):
async with open_skynet_rpc() as rpc_call:
async with open_skynet_rpc(
security=True,
cert_name='whitelist/testing',
key_name='testing'
) as rpc_call:
# check 0 nodes are connected
res = await rpc_call('dgpu-0', 'dgpu_workers')
logging.info(res)