diff --git a/cellframe-sdk b/cellframe-sdk index 21886ef54e5b6d00c605221271530f83201b1574..94910007b490c61d506b5025304348a722a3c0ef 160000 --- a/cellframe-sdk +++ b/cellframe-sdk @@ -1 +1 @@ -Subproject commit 21886ef54e5b6d00c605221271530f83201b1574 +Subproject commit 94910007b490c61d506b5025304348a722a3c0ef diff --git a/dists/examples/1.Authority/MyAuth.py b/dists/examples/1.Authority/MyAuth.py index c95a64a2e7bd15b9ef8eb5a2ba225eef1b381720..8d2dbdc0dbbdf9523a2efcd0d57415c921153886 100755 --- a/dists/examples/1.Authority/MyAuth.py +++ b/dists/examples/1.Authority/MyAuth.py @@ -10,27 +10,27 @@ app_name = "MyAuth" jsonCfg=MyAuthConf.getJsonString(app_name) try: - init( jsonCfg ) + rsi = init( jsonCfg ) except json.decoder.JSONDecodeError as jex: sys.stderr.write("load_json_config JSONdecode :%s" % jex) exit(-1) setLogLevel(DEBUG) +ev = rsi[1] server_host_name = configGetItem("server", "listen_address") server_port = int(configGetItem("server", "listen_port_tcp")) -sr = ServerCore.listen(server_host_name, server_port, 0) +sr = ServerCore.listen(ev, server_host_name, server_port, 0) Http.new(sr, app_name) EncHttp.addProc(sr, "/enc_http") Stream.addProcHttp(sr, "/stream") StreamCtl.addProcHttp(sr, "/stream_ctl") -ev = Events() ev.start() MyAuthCmd.init() print(app_name+" v0.1 runned on port "+str(server_port)) -rc = ServerCore.loop(sr) +rc = ev.wait() deinit() diff --git a/dists/examples/1.Authority/MyAuthCA.py b/dists/examples/1.Authority/MyAuthCA.py index 05223b1a9e7b242c438406dd4bb9af09d1c43259..f762a94c19d8b5a334791b56f7b4aa791aee6c37 100755 --- a/dists/examples/1.Authority/MyAuthCA.py +++ b/dists/examples/1.Authority/MyAuthCA.py @@ -3,6 +3,7 @@ from CellFrame import init, Cert, CryptoKeyType # from string import Template # import os import sys +import os import json import MyAuthConf import random @@ -96,13 +97,15 @@ elif action == "init_root_ca": print("(!) Wrong algo name \""+rootCaAlgoName+"\", possible names: sig_bliss, sig_tesla, sig_picnic, sig_dil") help() exit(-1) - # Create certs print("Init root "+str(rootCaNumber)+" certificates with algo " + rootCaAlgoName) print("Record somewhere the restore string(without braces): \"" + restoreString+"\"") for cur in range(int(rootCaNumber)): - cname = MyAuthConf.getNetworkName(appName, "_") + "_root_" + str(cur) - cert = Cert.generate(cname, rootCaAlgo, restoreString) - cert.save() + cname = MyAuthConf.getNetworkName(appName, "-") + ".root." + str(cur) + Cert.folderAdd (os.getcwd()+"/var/lib/ca/") + certobject = Cert.generate(cname, rootCaAlgo, restoreString) + dir(certobject) + certobject.save() + print("Save certificate") diff --git a/dists/examples/1.Authority/MyAuthConf.py b/dists/examples/1.Authority/MyAuthConf.py index 0ef9a83a85bf97b87eb1738a5a3567211e7fb4c4..520f5f89f8817fdd6de4c03d0d439711e19a64fc 100644 --- a/dists/examples/1.Authority/MyAuthConf.py +++ b/dists/examples/1.Authority/MyAuthConf.py @@ -13,10 +13,10 @@ def getJsonString(app_name, log_level="DEBUG"): ret_tpl = Template(""" { "modules": [ - "Crypto", "ServerCore", "Http", - "HttpFolder","GlobalDB","Client","HttpClientSimple","Mempool", + "Crypto", "Events", "Server", "Http", + "HttpFolder","GlobalDB","Client","HttpClientSimple", "EncHttp", "Mempool", "Stream", "StreamCtl", "Chain", "Wallet", "ChainCSDag", "ChainCSDagPoa", "ChainCSDagPos", "GDB", "Net", "AppCliServer", - "ChainNetSrv", "EncHttp","Stream", "StreamCtl", "HttpSimple", "StreamChChain", "StreamChChainNet", + "ChainNetSrv","HttpSimple", "StreamChChain", "StreamChChainNet", "StreamChChainNetSrv" ], "Core": { "config_dir": "${tmp_dir}", @@ -32,6 +32,9 @@ def getJsonString(app_name, log_level="DEBUG"): "conn": 0 }, "Configuration" : { + "general": { + "seed_mode": true + }, "server": { "enabled": true, "listen_address": "0.0.0.0", @@ -58,20 +61,25 @@ def getJsonString(app_name, log_level="DEBUG"): "node-role": "root", "gdb_groups_prefix": "${net_name}" }, + "dag-poa":{ + "events-sign-cert": "${net_name}.root.0" + }, "name_cfg_files": ["main"], "conf_files":{ "main": { - "general": { - "id": "0xF00000000000000F", + "chain":{ + "id": "0x0A0000000000000F", "name": "main", - "consensus": "dag-poa", + "consensus": "dag_poa", "datum_types": ["ca", "transaction","token","token_update","emission","shard"] }, "dag":{ "is_single_line": false, "is_celled": true, "is_add_directly": true, - "datum_and_hash_count": 3 + "datum_and_hash_count": 1, + "#is_static_genesis_event": true, + "#static_genesis_event": "0x642DEBE847A73FA0505C6648C1086675B6B4ADDDC4A8D333DCCD4169228E1E97" }, "dag-poa":{ "auth_certs_prefix": "${net_name}.root", @@ -80,7 +88,7 @@ def getJsonString(app_name, log_level="DEBUG"): "auth_certs_dir": "${var_dir}/lib/ca" }, "files":{ - "storage_dir":"{$var_dir}/lib/network/${net_name}/main" + "storage_dir":"${var_dir}/lib/network/${net_name}/main/" } } } diff --git a/modules/dap-sdk/crypto/include/wrapping_cert.h b/modules/dap-sdk/crypto/include/wrapping_cert.h index 97e77964db37a3f8e4b24daae7af1d3d2d896285..d672e35b1892792ca532b3700ff6641b0b4e334f 100644 --- a/modules/dap-sdk/crypto/include/wrapping_cert.h +++ b/modules/dap-sdk/crypto/include/wrapping_cert.h @@ -28,6 +28,7 @@ #include <Python.h> #include "dap_common.h" #include "dap_cert.h" +#include "dap_cert_file.h" #ifdef __cplusplus extern "C" { @@ -56,11 +57,6 @@ PyObject* dap_cert_folder_add_py(PyObject *self, PyObject *args); PyObject* dap_cert_folder_get_py(PyObject *self, PyObject *args); static PyMethodDef g_crypto_cert_methods_py[] = { - {"generate",dap_cert_generate_py , METH_VARARGS | METH_STATIC, "Generate from seed or randomly the new certificate"}, - {"find", dap_cert_find_py, METH_VARARGS | METH_STATIC, ""}, - {"folderAdd", dap_cert_folder_add_py, METH_VARARGS | METH_STATIC, "Add folders with .dcert files in it"}, - {"folderGet", dap_cert_folder_get_py, METH_VARARGS | METH_STATIC, "Get folder by number or the default one"}, - {"load", dap_cert_load_py, METH_VARARGS | METH_STATIC ,""}, {"dump", dap_cert_dump_py, METH_VARARGS , ""}, {"pkey", dap_cert_pkey_py, METH_VARARGS , ""}, {"sign", dap_cert_sign_py, METH_VARARGS , ""}, @@ -68,6 +64,11 @@ static PyMethodDef g_crypto_cert_methods_py[] = { {"certSigns", dap_cert_cert_signs_py, METH_VARARGS , ""}, {"compare", dap_cert_compare_py, METH_VARARGS, ""}, {"save", dap_cert_save_py, METH_VARARGS , "Save to the first directory in cert folders list"}, + {"generate",dap_cert_generate_py , METH_VARARGS | METH_STATIC, "Generate from seed or randomly the new certificate"}, + {"find", dap_cert_find_py, METH_VARARGS | METH_STATIC, ""}, + {"folderAdd", dap_cert_folder_add_py, METH_VARARGS | METH_STATIC, "Add folders with .dcert files in it"}, + {"folderGet", dap_cert_folder_get_py, METH_VARARGS | METH_STATIC, "Get folder by number or the default one"}, + {"load", dap_cert_load_py, METH_VARARGS | METH_STATIC ,""}, {NULL, NULL, 0, NULL} }; diff --git a/modules/dap-sdk/crypto/src/wrapping_cert.c b/modules/dap-sdk/crypto/src/wrapping_cert.c index ff401fa87502206db4f3bbff67dac9b6f9cd6635..4a5f02b9a5dab8cfadc37f04968d6902e6ac3472 100644 --- a/modules/dap-sdk/crypto/src/wrapping_cert.c +++ b/modules/dap-sdk/crypto/src/wrapping_cert.c @@ -55,19 +55,21 @@ PyObject* dap_cert_generate_py(PyObject *self, PyObject *args) if (l_arg_seed_string != 0) l_seed = l_arg_seed_string; - PyCryptoCertObject *obj_cert = (PyCryptoCertObject*)_PyObject_New(&g_crypto_cert_type_py); + PyCryptoCertObject *obj_cert = PyObject_New(PyCryptoCertObject, &g_crypto_cert_type_py); +// PyCryptoCertObject *obj_cert = (PyCryptoCertObject*)_PyObject_New(&g_crypto_cert_type_py); obj_cert->cert = l_seed ? dap_cert_generate_mem_with_seed( l_cert_name, l_arg_cert_key_type, l_seed, strlen(l_seed) ) :dap_cert_generate_mem( l_cert_name,l_arg_cert_key_type ); - return Py_BuildValue("O", (PyObject*)obj_cert); + if (obj_cert->cert == NULL) + return Py_BuildValue("O", Py_None); + else + return Py_BuildValue("O", (PyObject*)obj_cert); } PyObject* dap_cert_dump_py(PyObject *self, PyObject *args) { - (void) self; (void) args; - /// TODO: Implement it! - PyErr_SetString(PyExc_TypeError, "Unimplemented function"); - return NULL; + dap_cert_dump(((PyCryptoCertObject*)self)->cert); + return Py_BuildValue("(O)", Py_None); } PyObject* dap_cert_pkey_py(PyObject *self, PyObject *args) @@ -161,20 +163,21 @@ void dap_cert_delete_py(PyObject *self) PyObject* dap_cert_folder_add_py(PyObject *self, PyObject *args) { (void) self; - (void) args; - /// TODO: Implement it! - PyErr_SetString(PyExc_TypeError, "Unimplemented function"); - return NULL; + const char *a_folder_path; + if(!PyArg_ParseTuple(args, "s", &a_folder_path)) + return NULL; + dap_cert_add_folder(a_folder_path); + return Py_BuildValue("(O)", Py_None); } PyObject* dap_cert_folder_get_py(PyObject *self, PyObject *args) { (void)self; - const char *a_folder_path; - if(!PyArg_ParseTuple(args, "s", &a_folder_path)) + int n_folder; + if(!PyArg_ParseTuple(args, "i", &n_folder)) return NULL; - dap_cert_add_folder(a_folder_path); - return PyLong_FromLong(0); + const char *l_ret = dap_cert_get_folder(n_folder); + return Py_BuildValue("(S)", l_ret); } int dap_cert_init_py(void)