Lars Rohwedder 7 months ago
parent
commit
70f8cd34b7
14 changed files with 382 additions and 186 deletions
  1. +34
    -0
      .gitignore
  2. +0
    -71
      .hgignore
  3. +14
    -1
      html/index.html
  4. +0
    -3
      html/logview.html
  5. +4
    -0
      html/logview.js
  6. +32
    -0
      html/test-encode-decode.js
  7. +41
    -0
      html/unittests.js
  8. +51
    -84
      server/Makefile
  9. +8
    -6
      server/Makefile.conf-old
  10. +39
    -3
      server/ev_server.cc
  11. +3
    -3
      server/function_map.hh
  12. +13
    -13
      server/json-adapter.cc
  13. +5
    -2
      server/server_version.cc
  14. +138
    -0
      server/unittest_encrypt_decrypt.cc

+ 34
- 0
.gitignore View File

@ -0,0 +1,34 @@
.DS_Store
*.o
*.Po
*.Plo
*.pc
*~
*.d
server/pep-json-server
server/servertest
server/unittests
server/*.a
server/prefix-config.cc
server/local.conf
server/*.d
server/json_spirit/*.d
build/
*.vcxproj.user
*.obj
*.exe
*.lib
build-windows/libevent/Release/*
build-windows/libevent/Debug/*
build-windows/pEpJSONServerAdapter/Release/*
build-windows/pEpJSONServerAdapter/Debug/*
server/pEp-mini-json-adapter
*.d.*
.??*.swp
tags

+ 0
- 71
.hgignore View File

@ -1,71 +0,0 @@
syntax: glob
.DS_Store
*.o
*.Po
*.Plo
*.pc
*~
libevent-*-stable/Makefile
libevent-*-stable/config.h
libevent-*-stable/config.log
libevent-*-stable/config.status
libevent-*-stable/include/Makefile
libevent-*-stable/libtool
libevent-*-stable/sample/Makefile
libevent-*-stable/stamp-h1
libevent-*-stable/test/Makefile
libevent-*-stable/**/.libs/
libevent-*-stable/*.lo
libevent-*-stable/*.la
libevent-*-stable/autom4te.cache/
libevent-*-stable/include/event2/event-config.h
libevent-*-stable/sample/dns-example
libevent-*-stable/sample/event-test
libevent-*-stable/sample/hello-world
libevent-*-stable/sample/http-server
libevent-*-stable/sample/le-proxy
libevent-*-stable/sample/signal-test
libevent-*-stable/sample/time-test
libevent-*-stable/test/bench
libevent-*-stable/test/bench_cascade
libevent-*-stable/test/bench_http
libevent-*-stable/test/bench_httpclient
libevent-*-stable/test/regress
libevent-*-stable/test/rpcgen-attempted
libevent-*-stable/test/test-changelist
libevent-*-stable/test/test-eof
libevent-*-stable/test/test-init
libevent-*-stable/test/test-ratelim
libevent-*-stable/test/test-time
libevent-*-stable/test/test-weof
libevent-*-stable/build/
server/pep-json-server
server/servertest
server/unittests
server/*.a
server/prefix-config.cc
server/local.conf
server/*.d
server/json_spirit/*.d
build/
*.vcxproj.user
*.obj
*.exe
*.lib
build-windows/libevent/Release/*
build-windows/libevent/Debug/*
build-windows/pEpJSONServerAdapter/Release/*
build-windows/pEpJSONServerAdapter/Debug/*
server/pEp-mini-json-adapter
*.d.*
.??*.swp
tags

+ 14
- 1
html/index.html View File

@ -6,10 +6,13 @@
<title>Send example calls via jQuery</title>
<style type="text/css">
body { font-family:Helvetica,Arial,Sans-serif;background-color:#cde; }
table { border-collapse:collapse; }
.bigtable { border-collapse:collapse; border:2px black solid; box-shadow:4px 4px 8px #666; background-color:#ffd; margin:1em;}
td, th { border:1px black solid; vertical-align:top; padding:0.5em;}
td.right { border:0px black solid; float:right; }
td.left { border:0px black solid; align:left; }
tr.t { border-bottom:1px black solid; }
.t td,th { border:0px black solid; }
input { white-space:pre }
.smalltable { border-collapse:collapse; border:2px black inset; margin-left:1em; padding:5px;}
.smalltable td { border:none; vertical-align:top; padding:5px;}
@ -19,6 +22,8 @@
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="pEp_functions.js"></script>
<script type="text/javascript" src="interactive.js"></script>
<script type="text/javascript" src="unittests.js"></script>
<script type="text/javascript" src="test-encode-decode.js"></script>
</head>
<body>
@ -53,7 +58,14 @@
</textarea>
</form>
<hr>
<h2>2. Generate documentation</h2>
<h2>2. Open WebSocket connection</h2>
<input type="button" onClick="openWebSocket()" id="openWsBtn" value="Open WebSocket!">
<hr>
<h2>3. Execute JavaScript tests</h2>
<p id='unittest_div'>(you have to activate JavaScript in your browser to see something useful here)</p>
<p>Unittest output: <textarea id='unittest_out'></textarea></p>
<hr>
<h2>4. Generate documentation</h2>
<form id="frm_doc" name="frm_doc">
Select output format:
<select id="doc_format" size="1">
@ -69,6 +81,7 @@
<script type="text/javascript">
init_pEp_functions();
on_select_change();
add_test_buttons();
</script>
</body>


+ 0
- 3
html/logview.html View File

@ -23,9 +23,6 @@
<table id="tbl" style="border:1px solid gray; border-collapse:collapse;"></table>
<script src="logview.js"></script>
<script>
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</body>
</html>

+ 4
- 0
html/logview.js View File

@ -1,3 +1,5 @@
var lineRegEx = /(\d\d\d\d-\d\d-\d\d\.\d\d:\d\d:\d\d) (¶\S+) (\S+) :(.*)/;
var colors = ['fcf7de', 'defde0', 'def3fd', 'f0defd', 'fddfdf', 'dfdfdf', 'B7C68B', 'F4F0CB', 'DED29E'];
@ -86,3 +88,5 @@ function handleFileSelect(evt)
reader.readAsText(file, "UTF-8");
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);

+ 32
- 0
html/test-encode-decode.js View File

@ -0,0 +1,32 @@
"use strict";
async function test_encode_decode()
{
var out = document.getElementById('unittest_out');
var rndName = gen_random_name();
var testAddress = 'enc-dec-test.' + rndName + '@peptest.ch';
var testUsername = 'Test User ' + rndName;
var identity = { "address": testAddress, "user_id": "pEp_own_userId", "username": testUsername };
var ret = await call_json_rpc_function("myself", [identity] );
var newIdent = ret.result.outParams[0];
var fpr = newIdent.fpr;
out.innerHTML = JSON.stringify(newIdent, null, 2);
var msg1 = {
"id":"<pEp." + gen_random_name() + "." + gen_random_name() + "@peptest.ch>",
"shortmsg": "Subject",
"longmsg": "Body",
"attachments": [],
"from": identity,
"to": [ identity ]
};
ret = await call_json_rpc_function("encrypt_message", [msg1, null, "out", 3, 0] );
out.innerHTML += "\n=========\n" + JSON.stringify(ret, null, 2);
await call_json_rpc_function("delete_keypair", [fpr] );
}
unittests.push( {"description": "Encode/Decode", "onclick":"test_encode_decode()" } );

+ 41
- 0
html/unittests.js View File

@ -0,0 +1,41 @@
'use strict';
// all unittests will add themselves here:
var unittests =
[
{"description":"call gen_random_name()", "onclick":"random_name_test()" }
];
var base32_alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
// creates a string of 12 random letters
function gen_random_name()
{
var rndArray = new Uint32Array(12);
window.crypto.getRandomValues(rndArray);
var s = '';
for(var i=0; i<rndArray.length; ++i)
{
s += base32_alphabet[ rndArray[i] % (base32_alphabet.length-1) ];
}
return s;
}
function add_test_buttons()
{
var content = '<table><tr class="t"><th></th><th>Test name</th><th></th></tr>\n';
for(var i=0; i<unittests.length; ++i)
{
var u = unittests[i];
content += '<tr class="t"><td>#' + (i+1) + '</td><td>' + u.description + '</td>'
+ '<td><button type="button" onclick="' + u.onclick + '"> Run! </button></td></tr>\n';
}
content += '</table>';
document.getElementById('unittest_div').innerHTML = content;
}
function random_name_test()
{
document.getElementById('unittest_out').innerHTML = 'pEp_' + gen_random_name() + '@pep.lol';
}

+ 51
- 84
server/Makefile View File

@ -6,32 +6,23 @@ endif
# default config
# set to 'etpan' or 'pEpMIME'
MIME_LIB?=etpan
# these are source builds
PREFIX?=$(HOME)/local
# where pEp stuff is installed into:
PEP_LIB_PATH?=$(PREFIX)/lib
PEP_INCLUDE?=$(PREFIX)/include
# where libs from the packages systems are installed into:
LIBRARY_PATH?=/usr/local/lib
PEP_WEBSERVER?=../../webserver
PEP_ADAPTER_LIBRARY=../../libpEpAdapter
PEP_ENGINE?=../../pEpEngine/src
LIBETPAN_FDIK?=../../libetpan/src/.libs
SEQUOIA_PGP?=../../sequoia/target/release
NETTLE?=../../nettle
BOOST_INCLUDE_PATH?=../../boost_1_72_0
BOOST_LIBRARY_PATH?=../../boost_1_72_0/stage/lib
ASN1_PATH?=$(PEP_ENGINE)/asn.1
# path to installed libraries
# paths to the .a libraries. Can be overridden in local.conf
PEP_WEBSERVER?=$(PEP_LIB_PATH)
PEP_ADAPTER_LIBRARY=$(PEP_LIB_PATH)
PEP_ENGINE?=$(PEP_LIB_PATH)
LIBETPAN_FDIK?=$(PEP_LIB_PATH)
PEP_MIME_PATH?=$(PEP_LIB_PATH)
SEQUOIA_PGP?=$(PEP_LIB_PATH)
ASN1_PATH?=$(PEP_LIB_PATH)
NETTLE?=$(LIBRARY_PATH)
BOOST_INCLUDE_PATH?=/usr/local/include
BOOST_LIBRARY_PATH?=$(LIBRARY_PATH)
PREFIX?=$(HOME)
PEP_INCLUDE?=$(PREFIX)/include
LIBRARY_PATH?=$(PREFIX)/lib
@ -41,78 +32,39 @@ LIBZ_LIBRARY_PATH?=$(LIBRARY_PATH)
ICONV_LIBRARY_PATH?=$(LIBRARY_PATH)
LIBEVENT_LIBRARY_PATH=$(LIBRARY_PATH)
AR?=/usr/bin/ar
AR?=ar
CC?=cc
CXX?=c++
CFLAGS+=-std=c14 -fvisibility=hidden
CXXFLAGS+=-I$(BOOST_INCLUDE_PATH) -I$(PEP_INCLUDE) -std=c++14 -fvisibility=hidden -fsanitize=address
LDFLAGS+=-std=c++14 -fsanitize=address
CFLAGS+=-std=c14
CXXFLAGS+=-I$(BOOST_INCLUDE_PATH) -I$(PEP_INCLUDE) -std=c++14
LDFLAGS+=-std=c++14
ifdef NDEBUG
CFLAGS+=-O3 -DNDEBUG
CXXFLAGS+=-O3 -DNDEBUG
CFLAGS+=-O3 -DNDEBUG -fvisibility=hidden -fno-stack-check
CXXFLAGS+=-O3 -DNDEBUG -fvisibility=hidden -fno-stack-check
else
CFLAGS+=-O0 -g -DDEBUG_ENABLED
CXXFLAGS+=-O0 -g -DDEBUG_ENABLED
CFLAGS+=-O0 -g -DDEBUG_ENABLED -fvisibility=hidden -fno-stack-check
CXXFLAGS+=-O0 -g -DDEBUG_ENABLED -fvisibility=hidden -fno-stack-check
endif
TARGET=pEp-mini-json-adapter
LIB_TARGET=libjson-adapter.a
ifeq ($(MIME_LIB),etpan)
LDLIBS+=-letpan
MIME_LIB_A=$(LIBETPAN_FDIK)/libetpan.a
OMIT_NFC_SOURCE=
else ifeq ($(MIME_LIB),pEpMIME)
LDLUBS+=-lpEpMIME
MIME_LIB_A=$(PEP_MIME_PATH)/libpEpMIME.a
# is already in libpEpMIME:
OMIT_NFC_SOURCE=nfc.cc nfc_sets.cc
else
$(error "You must set MIME_LIB to 'etpan' or 'pEpMIME'!" )
endif
ALL_SOURCE=$(filter-out parse_mail.cc unittest_%.cc, $(wildcard *.cc))
MA_SOURCE=$(wildcard mini-adapter-*.cc)
LIB_SOURCE=$(filter-out $(MA_SOURCE) $(OMIT_NFC_SOURCE), $(ALL_SOURCE))
ALL_SOURCE=$(filter-out unittest_%.cc,$(wildcard *.cc))
LIB_SOURCE=$(filter-out miniadapter-%.cc,$(ALL_SOURCE))
MA_SOURCE=$(wildcard miniadapter-*.cc)
DEPENDS=$(subst .cc,.d,$(ALL_SOURCE))
ALL_OBJECTS=$(subst .d,.o,$(DEPENDS))
LIB_OBJECTS=$(subst .cc,.o,$(LIB_SOURCE))
MA_OBJECTS=$(subst .cc,.o,$(MA_SOURCE))
SPIRIT_SOURCE=$(wildcard json_spirit/*.cpp)
SPIRIT_OBJECTS=$(subst .cpp,.o,$(SPIRIT_SOURCE))
TEST_SOURCE=$(wildcard unittest_*.cc)
TEST_SOURCE=$(wildcard test_*.cc)
TEST_OBJECTS=$(subst .cc,.o,$(TEST_SOURCE))
TESTS=$(subst .cc,,$(TEST_SOURCE))
ALL_STATIC_LIBS=$(PEP_ENGINE)/libpEpEngine.a \
$(PEP_ADAPTER_LIBRARY)/libpEpAdapter.a \
$(PEP_WEBSERVER)/libpEpwebserver.a \
$(BOOST_LIBRARY_PATH)/libboost_filesystem$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_program_options$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_system$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_thread$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_regex$(BOOST_MT).a \
$(SEQUOIA_PGP)/libsequoia_openpgp_ffi.a \
$(MIME_LIB_A) \
$(ASN1_PATH)/libasn1.a \
$(LIBZ_LIBRARY_PATH)/libz.a \
$(SQLITE3_LIBRARY_PATH)/libsqlite3.a \
$(NETTLE)/libhogweed.a \
$(NETTLE)/libnettle.a \
$(GMP_LIBRARY_PATH)/libgmp.a \
$(ICONV_LIBRARY_PATH)/libiconv.a
all: $(TARGET) unittests parse_mail
all: $(TARGET)
%.d: %.cc
@set -e; rm -f $@; \
@ -129,20 +81,35 @@ $(LIB_TARGET): $(LIB_OBJECTS)
$(AR) -cr $@ $^
$(TARGET): $(LIB_TARGET) $(MA_OBJECTS) $(SPIRIT_OBJECTS)
$(CXX) $(LDFLAGS) \
$(MA_OBJECTS) $(SPIRIT_OBJECTS) $(LIB_TARGET) \
$(CXX) $(LDFLAGS) -liconv \
-lobjc -framework Foundation -framework Security \
$(ALL_STATIC_LIBS)
-o "$@"
$(PEP_WEBSERVER)/libpEpwebserver.a \
$(BOOST_LIBRARY_PATH)/libboost_filesystem$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_program_options$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_system$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_thread$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_regex$(BOOST_MT).a \
$(ICONV_LIBRARY_PATH)/libiconv.a \
$(LIBZ_LIBRARY_PATH)/libz.a \
$(SQLITE3_LIBRARY_PATH)/libsqlite3.a \
$(GMP_LIBRARY_PATH)/libgmp.a \
$(NETTLE)/libnettle.a $(NETTLE)/libhogweed.a \
$(SEQUOIA_PGP)/libsequoia_ffi.a \
$(SEQUOIA_PGP)/libsequoia_openpgp_ffi.a \
$(LIBETPAN_FDIK)/libetpan.a \
$(PEP_ENGINE)/libpEpEngine.a \
$(ASN1_PATH)/libasn1.a \
$(PEP_ADAPTER_LIBRARY)/libpEpAdapter.a \
$(MA_OBJECTS) $(SPIRIT_OBJECTS) $(LIB_TARGET) -o "$@"
%.o: %.cc
$(CXX) $(CXXFLAGS) -c -o $@ $^
unittests: $(TEST_OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(ALL_STATIC_LIBS)
test_%: test_%.o $(TARGET)
$(CXX) $(LDFLAGS) $(TARGET) -o $@ $<
parse_mail: parse_mail.o $(LIB_TARGET) $(SPIRIT_OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(ALL_STATIC_LIBS) $(LIB_TARGET) -liconv
test: $(TESTS)
for i in $(TESTS) ; do ./$$i ; done
.PHONY: clean uninstall install
@ -155,7 +122,7 @@ uninstall:
for i in *.hh; do rm -f $(PREFIX)/include/pEp/\$i ; done
clean:
rm -vf *.o *.d *.d.* $(TARGET) $(TESTS) encode_decode
rm -vf *.o *.d *.d.* $(TARGET) $(TESTS)
local.conf:
@echo "# the following are directories with the source build" >> local.conf


+ 8
- 6
server/Makefile.conf-old View File

@ -103,12 +103,6 @@ endif
CXXFLAGS+= -Ijson_spirit $(BOOST_INC) $(ENGINE_INC) $(ETPAN_INC) $(GPGME_INC) $(UUID_INC)
LDFLAGS+= $(BOOST_LIB) $(ENGINE_LIB) $(ETPAN_LIB) $(GPGME_LIB) $(UUID_LIB)
ifeq ($(BUILD_FOR),Linux)
LDLIBS+= -lpEpEngine -lpEpAdapter -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_regex
GTEST_DIR=/usr/src/googletest/googletest/
else ifeq ($(BUILD_FOR),Darwin)
LDLIBS+= -lpEpEngine -lpEpAdapter -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_thread-mt -lboost_regex-mt
endif
LDLIBS+=$(WEBSERVER_LIB)
@ -120,6 +114,14 @@ else
$(error "You must set MIME_LIB to 'etpan' or 'pEpMIME'!" )
endif
ifeq ($(BUILD_FOR),Linux)
LDLIBS+= -lpEpEngine -lpEpAdapter -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_regex
GTEST_DIR=/usr/src/googletest/googletest/
else ifeq ($(BUILD_FOR),Darwin)
LDLIBS+= -lpEpEngine -lpEpAdapter -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_thread-mt -lboost_regex-mt
endif
######### Google Test #########
#GTEST_DIR=


+ 39
- 3
server/ev_server.cc View File

@ -64,6 +64,40 @@ std::string getBinaryPath()
}
bool has_non_pEp_user(PEP_SESSION session, const identity_list* il)
{
for(; il!=nullptr; il = il->next)
{
if((il->ident->comm_type | PEP_ct_confirmed) < PEP_ct_pEp)
return true;
}
return false;
}
PEP_STATUS outgoing_message_rating_with_partner_info(PEP_SESSION session, message* msg, PEP_rating* rating, bool* only_pEp_partners)
{
// Nota bene: outgoing_message_rating calls update_identity() on every recipient,
// but these changes in their identities are not given back to the JSON-RPC clients.
PEP_STATUS status = outgoing_message_rating(session, msg, rating);
if(*rating < PEP_rating_reliable)
{
// if mail would be sent unencrypted, we also cannot encrypt/protect the subject,
// so handle it the same way as if there were non-pEp recipients.
*only_pEp_partners = false;
}else{
if( has_non_pEp_user(session, msg->to)
|| has_non_pEp_user(session, msg->cc))
{
*only_pEp_partners = false;
}else{
*only_pEp_partners = true;
}
}
return status;
}
// these are the pEp functions that are callable by the client
const FunctionMap functions = {
@ -116,6 +150,7 @@ const FunctionMap functions = {
FP( "mark_as_comprimized", new FuncPC<PEP_STATUS, In_Pep_Session, In<c_string>> ( &mark_as_compromized) ),
FP( "identity_rating" , new FuncPC<PEP_STATUS, In_Pep_Session, In<pEp_identity*>, Out<PEP_rating>>( &identity_rating) ),
FP( "outgoing_message_rating", new FuncPC<PEP_STATUS, In_Pep_Session, In<message*>, Out<PEP_rating>>( &outgoing_message_rating) ),
FP( "outgoing_message_rating_with_partner_info", new FuncPC<PEP_STATUS, In_Pep_Session, In<message*>, Out<PEP_rating>, Out<bool>>( &outgoing_message_rating_with_partner_info) ),
FP( "outgoing_message_rating_preview", new FuncPC<PEP_STATUS, In_Pep_Session, In<message*>, Out<PEP_rating>>( &outgoing_message_rating_preview) ),
FP( "set_identity_flags" , new FuncPC<PEP_STATUS, In_Pep_Session, InOut<pEp_identity*>, In<identity_flags_t>>( &set_identity_flags) ),
FP( "unset_identity_flags" , new FuncPC<PEP_STATUS, In_Pep_Session, InOut<pEp_identity*>, In<identity_flags_t>>( &unset_identity_flags) ),
@ -168,6 +203,7 @@ const FunctionMap functions = {
FP( "leave_device_group" , new FuncPC<PEP_STATUS, In_Pep_Session> (&leave_device_group) ),
FP( "enable_identity_for_sync" , new FuncPC<PEP_STATUS, In_Pep_Session, InOut<pEp_identity*>> (&enable_identity_for_sync)),
FP( "disable_identity_for_sync", new FuncPC<PEP_STATUS, In_Pep_Session, InOut<pEp_identity*>> (&disable_identity_for_sync)),
FP( "disable_all_sync_channels", new Func<PEP_STATUS, In_Pep_Session> (&disable_all_sync_channels)),
#ifndef JSON_ADAPTER_LIBRARY
FP( "startSync", new Func<void> (&pEp::mini::startSync) ),
@ -205,7 +241,7 @@ ev_server::ev_server(const std::string& address, unsigned short port, bool deliv
pEp::Webserver::response ev_server::sendReplyString(const pEp::Webserver::request& req, const char* contentType, std::string&& outputText)
{
Log() << Logger::Debug << "sendReplyString(): "
DEBUG_LOG(Log()) << "sendReplyString(): "
<< ", contentType=" << (contentType ? "«" + std::string(contentType)+ "»" : "NULL")
<< ", output.size()=«" << outputText.size() << "»"
<< ", keep_alive=" << req.keep_alive() << ".";
@ -249,13 +285,13 @@ pEp::Webserver::response ev_server::OnOtherRequest(boost::cmatch match, const pE
const std::string path = req.target().to_string(); // NB: is percent-encoded! does not relevant for the supported paths above.
Log() << Logger::Debug << "** Request: [" << req.method_string().to_string() << "] " << "Path: [" + path + "]";
DEBUG_LOG( Log() ) << "** Request: [" << req.method_string().to_string() << "] " << "Path: [" + path + "]";
try{
const auto q = files.find(path);
if(q != files.end()) // found in "files" map
{
Log() << Logger::Debug << "\t found file \"" << q->second.fileName.string() << "\", type=" << q->second.mimeType << ".\n";
DEBUG_LOG(Log()) << "\t found file \"" << q->second.fileName.string() << "\", type=" << q->second.mimeType << ".\n";
return sendFile( req, q->second.mimeType, q->second.fileName);
}


+ 3
- 3
server/function_map.hh View File

@ -247,7 +247,7 @@ public:
// FIXME: Does only work with functions with type: void(PEP_SESSION, T):
const auto p1 = from_json< typename std::tuple_element<1, param_tuple_t>::type >(parameters[0]);
Log << Logger::Debug << "func_name=\"" << func_name << "\", value=" << p1 << ".";
DEBUG_LOG(Log) << "func_name=\"" << func_name << "\", value=" << p1 << ".";
std::function<void(PEP_SESSION)> func = std::bind(Base::fn, std::placeholders::_1, p1);
context->cache(func_name, func);
@ -277,7 +277,7 @@ public:
Logger Log("FuncCachePasswd::call");
const std::string& passphrase = parameters.at(0).get_str();
Log << Logger::Debug << "func_name=\"" << func_name << "\", value is confidential. ";
DEBUG_LOG(Log) << "func_name=\"" << func_name << "\", value is confidential. ";
pEp::passphrase_cache.add(passphrase); // for the current PEP_SESSION
std::function<void(PEP_SESSION)> func = [passphrase](PEP_SESSION session)
@ -312,7 +312,7 @@ public:
bool enable = parameters.at(0).get_bool();
const std::string& passphrase = parameters.at(1).get_str();
Log << Logger::Debug << "func_name=\"" << func_name << "\", value is confidential. ";
DEBUG_LOG(Log) << "func_name=\"" << func_name << "\", value is confidential.";
pEp::passphrase_cache.add_stored(passphrase); // for the current PEP_SESSION
std::function<void(PEP_SESSION)> func = [enable, passphrase](PEP_SESSION session)


+ 13
- 13
server/json-adapter.cc View File

@ -111,7 +111,7 @@ struct JsonAdapter::Internal
~Internal()
{
Log << Logger::Debug << "~JAI";
DEBUG_LOG(Log) << "~JAI";
}
@ -138,13 +138,13 @@ struct JsonAdapter::Internal
const std::string request_r = js::write(request);
Lock L(_mtx);
Log << Logger::Debug << "makeAndDeliverRequest: \n"
DEBUG_LOG(Log) << "makeAndDeliverRequest: \n"
"Request: " << request_r << "\n"
"Goes to " << eventListener.size() << " listener(s).";
for(auto& e : eventListener)
{
Log << Logger::Debug << " ~~~ " << to_log(e.first) << " has " << e.second.Q->size() << " old events waiting.";
DEBUG_LOG(Log) << " ~~~ " << to_log(e.first) << " has " << e.second.Q->size() << " old events waiting.";
e.second.Q->push_back(request);
}
}
@ -290,7 +290,7 @@ try
Logger L("JA:run");
L << Logger::Info << "This is " << (void*)this << ", thread id " << std::this_thread::get_id() << ".";
L << Logger::Debug << "Registry:\n" << i->session_registry->to_string();
DEBUG_LOG(L) << "Registry:\n" << i->session_registry->to_string();
i->running = true;
i->webserver->run();
@ -307,7 +307,7 @@ void JsonAdapter::connection_close_cb()
Lock L{_mtx};
const auto tid = std::this_thread::get_id();
auto q = i->eventListener.find( tid );
i->Log << Logger::Debug << "Connection Close Callback: " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for Thread " << tid << ".";
DEBUG_LOG(i->Log) << "Connection Close Callback: " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for Thread " << tid << ".";
if(q != i->eventListener.end())
{
i->Log.debug("%d listener(s) waiting on event queue", q->second.Q->waiting());
@ -325,10 +325,10 @@ void JsonAdapter::close_session(const std::string& session_id)
{
Lock L{_mtx};
auto q = i->eventListener.find( session_id );
i->Log << Logger::Debug << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for session_id \"" << session_id << "\".";
DEBUG_LOG(i->Log) << "Close session \"" << session_id << "\": " << (q==i->eventListener.end() ? "NO" : "1") << " entry in eventListener map for session_id \"" << session_id << "\".";
if(q != i->eventListener.end())
{
i->Log.debug("%d listener(s) waiting on event queue", q->second.Q->waiting());
DEBUG_OUT(i->Log, "%d listener(s) waiting on event queue", q->second.Q->waiting());
while(q->second.Q->waiting() > 0)
{
q->second.Q->push_back(queue_close_event);
@ -398,32 +398,32 @@ js::Array JsonAdapter::Internal::pollForEvents(const EventListenerKey& key, unsi
const size_t size = elQ->size();
if(size)
{
L << Logger::Debug << size << " events in queue for key " << to_log(key) << ":";
DEBUG_LOG(L) << size << " events in queue for key " << to_log(key) << ":";
// fetch all elements from queue
for(size_t i=0; i<size; ++i)
{
js::Object obj{ elQ->pop_front() };
const std::string obj_s = js::write( obj );
L << Logger::Debug << "\t#" << i << ": " << obj_s;
DEBUG_LOG(L) << "\t#" << i << ": " << obj_s;
arr.emplace_back( std::move(obj) );
}
}else{
// block until there is at least one element or timeout
L << Logger::Debug << "Queue for key " << to_log(key) << " is empty. I'll block for " << timeout_seconds << " seconds.";
DEBUG_LOG(L) << "Queue for key " << to_log(key) << " is empty. I'll block for " << timeout_seconds << " seconds.";
js::Object event;
const bool success = elQ->try_pop_front( event, std::chrono::seconds(timeout_seconds) );
if(success)
{
const std::string event_s = js::write(event);
L << Logger::Debug << "Success! Got this event: " << event_s ;
DEBUG_LOG(L) << "Success! Got this event: " << event_s ;
arr.emplace_back( std::move(event) );
}else{
L << Logger::Debug << "Timeout. No event after " << timeout_seconds << " seconds arrived. So sad.";
DEBUG_LOG(L) << "Timeout. No event after " << timeout_seconds << " seconds arrived. So sad.";
}
}
L << Logger::Debug << "Return array with " << arr.size() << " elements.";
DEBUG_LOG(L) << "Return array with " << arr.size() << " elements.";
return arr;
}


+ 5
- 2
server/server_version.cc View File

@ -78,7 +78,8 @@ static const std::string VersionName =
// "(44) Neudietendorf"; // replace my own sync thread code by libpEpAdapter's implementation.
// "(45) Kreuz Erfurt"; // fix of context-saved function parameters that would cause trouble when >1 request is processed in parallel.
// "(46) Erfurt-West"; // JSON-156: delete client cached values after timeout.
"(47a) Erfurt-Ost"; // JSON-160, JSON-172, JSON-179.
// "(47a) Erfurt-Ost"; // JSON-160, JSON-172, JSON-179.
"(47b) Erfurt-Vieselbach"; // JSON-183: "Provide an API for pEp4Tb to communicate whether the message subject should be hidden (replaced with pEp)"
} // end of anonymous namespace
////////////////////////////////////////////////////////////////////////////
@ -115,7 +116,9 @@ const ServerVersion& server_version()
//static const ServerVersion sv(0,20,1); // JSON-153: passphrase support
//static const ServerVersion sv(0,21,0); // import_key() expects binary data, so they are always base64-encoded!
//static const ServerVersion sv(0,21,1); // wrap _all_ Engine functions with passphrase_cache.api(), except config_*() functions.
static const ServerVersion sv(0,21,2); // JSON-165 the msg param of re_evaluate_message_rating() is now "inout" and not "in" any more
//static const ServerVersion sv(0,21,2); // JSON-165 the msg param of re_evaluate_message_rating() is now "inout" and not "in" any more
//static const ServerVersion sv(0,22,0); // JSON-183 "Provide an API for pEp4Tb to communicate whether the message subject should be hidden (replaced with pEp)"
static const ServerVersion sv(0,22,1); // ENGINE-890: add disable_all_sync_channels()
return sv;
}


+ 138
- 0
server/unittest_encrypt_decrypt.cc View File

@ -0,0 +1,138 @@
#include <gtest/gtest.h>
#include <random>
#include "inout.hh" // for to_json() and from_json()
#include "pEp-types.hh"
#include "pEp-utils.hh"
#include "json_spirit/json_spirit_reader.h"
#include <pEp/message.h>
#include <pEp/pEp_string.h>
#include <vector>
namespace js = json_spirit;
namespace {
std::string ptr0(const char* s)
{
return s ? ("\"" + std::string(s) + "\"") : "(NULL)";
}
const char alphabet_base36[]="qaywsxedcrfvtgbzhnujmikolp-_0987654321";
const unsigned alphabet_size = sizeof(alphabet_base36)-1;
static_assert( sizeof(alphabet_base36) >= 37 , "alphabet must have at least 36 chars + NUL");
std::string base36(uint64_t u)
{
if(u==0) return "qq";
std::string ret;
while(u)
{
ret += alphabet_base36[u % alphabet_size];
u = u / alphabet_size;
}
return ret;
}
std::string gen_random_name()
{
static std::random_device rd;
static std::mt19937_64 gen(rd());
return base36( gen() );;
}
} // end of anonymous namespace
class EncodeDecodeTest : public ::testing::Test
{
protected:
void SetUp() override
{
init(&session, &dummy_send, &dummy_inject);
random_name = gen_random_name();
const std::string address = "encode-decode-test." + random_name + "@peptest.ch";
const std::string username = "Test User " + random_name;
const std::string my_idens =
"{ \"address\":\"" + address + "\""
", \"user_id\": \"pEp_own_userId\""
", \"username\": \"" + username + "\""
"}";
js::Value my_idenv;
js::read_or_throw( my_idens, my_idenv );
my_identity = from_json<pEp_identity*>(my_idenv);
}
void TearDown() override
{
std::cout << "Delete key with fpr <" << my_identity->fpr << ">\n";
delete_keypair(session, my_identity->fpr);
free_identity(my_identity);
my_identity = nullptr;
release(session);
session = nullptr;
}
static
int dummy_inject(SYNC_EVENT, void*) {return PEP_STATUS_OK; }
static
PEP_STATUS dummy_send(struct _message*) { return PEP_STATUS_OK; }
PEP_SESSION session = nullptr;
std::string random_name;
pEp_identity* my_identity = nullptr;
};
TEST_F( EncodeDecodeTest, Msg )
{
ASSERT_EQ( myself(session, my_identity) , PEP_STATUS_OK );
const std::string msg1s =
"{ \"id\":\"<pEp." + gen_random_name() + "." + gen_random_name() + "@peptest.ch>\""
", \"shortmsg\": \"Subject\""
", \"longmsg\": \"Body\""
", \"attachments\": []"
", \"from\": " + js::write(to_json<pEp_identity*>(my_identity)) + "\n"
", \"to\": [ " + js::write(to_json<pEp_identity*>(my_identity)) + "] \n"
"}\n";
js::Value msg1v;
js::read_or_throw( msg1s, msg1v );
message* msg2_raw = nullptr;
auto msg1 = pEp::utility::make_c_ptr( from_json<message*>(msg1v), &free_message);
std::cout << "=== MESSAGE ORIGINAL ===\n"
<< js::write(to_json<message*>(msg1.get())) << std::endl;
PEP_STATUS status_enc = encrypt_message(session, msg1.get(), nullptr, &msg2_raw, PEP_enc_format(3), 0);
EXPECT_EQ( status_enc, PEP_STATUS_OK);
ASSERT_NE( msg2_raw , nullptr);
auto msg2 = pEp::utility::make_c_ptr( msg2_raw, &free_message);
std::cout << "=== MESSAGE ENCRYPTED ===\n"
<< js::write(to_json<message*>(msg2.get())) << std::endl;
message* msg3_raw = nullptr;
// FIXME: do you provide a non-empty keylist?
stringlist_t* keylist = new_stringlist(nullptr);
PEP_rating rating{};
PEP_decrypt_flags_t flags{}; // FIXME: which flags do you use on input?
PEP_STATUS status_dec = decrypt_message(session, msg2.get(), &msg3_raw, &keylist, &rating, &flags);
EXPECT_EQ( status_dec, PEP_STATUS_OK);
ASSERT_NE( msg3_raw , nullptr);
auto msg3 = pEp::utility::make_c_ptr( msg3_raw, &free_message);
std::cout << "=== MESSAGE DECRYPTED ===\n"
<< js::write(to_json<message*>(msg3.get())) << std::endl;
}

Loading…
Cancel
Save