Merged in default AND fixed SQL problem (oops)

doc_update_sequoia
Krista Bennett 5 years ago
commit 1190598db4

@ -57,3 +57,7 @@ random_seed
secring.gpg
trustdb.gpg
.pEp_management.db
.cache
__pycache__
*.pyc
test/python_tests/test?

@ -29,13 +29,13 @@ LOCAL_CFLAGS += -std=c99
#
LOCAL_CFLAGS += -DSQLITE_TEMP_STORE=3
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../src \
$(LOCAL_PATH)/../../asn.1 \
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../asn.1 \
$(GPGME_INCLUDE_PATH) \
$(LIBETPAN_PATH)/include
LOCAL_C_INCLUDES += $(GPGBUILD)/include
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/../../src
$(shell sh $(LOCAL_PATH)/../takeOutHeaderFiles.sh $(LOCAL_PATH)../../)
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)../include
ENGINE_SRC_FILES := $(shell find $(LOCAL_PATH)/../../src/ ! -name "*netpgp*" -name "*.c")
#ENGINE_SRC_FILES := $(wildcard $(LOCAL_PATH)/../../src/*.c)

@ -0,0 +1,9 @@
#!/bin/sh
set -e
engine_dir="$1"
mkdir -p "$engine_dir/build-android/include/pEp"
cd "$engine_dir/src"
cp *.h "$engine_dir/build-android/include/pEp"

@ -80,6 +80,7 @@ libpEpEngine.a: $(ALL_OBJECTS)
.PHONY: clean
clean:
rm -f *.d *.o *.a $(TARGET) *.dll *.so *.zip *.d.* *.def *~
rm -Rf $(TARGET).dSYM
.PHONY: install
install: $(TARGET)

@ -29,7 +29,8 @@ static bool is_a_pEpmessage(const message *msg)
return false;
}
static bool is_wrapper(message* src) {
static bool is_wrapper(message* src)
{
bool retval = false;
if (src) {
@ -62,20 +63,23 @@ static bool is_wrapper(message* src) {
}
static stringpair_t* search_optfields(const message* msg, const char* key) {
stringpair_list_t* opt_fields = msg->opt_fields;
const stringpair_list_t* curr;
for (curr = opt_fields; curr && curr->value; curr = curr->next) {
if (curr->value->key) {
if (strcasecmp(curr->value->key, key) == 0)
return curr->value;
}
}
return NULL;
}
/*
* static stringpair_t* search_optfields(const message* msg, const char* key) {
* if (msg && key) {
* stringpair_list_t* opt_fields = msg->opt_fields;
*
* const stringpair_list_t* curr;
*
* for (curr = opt_fields; curr && curr->value; curr = curr->next) {
* if (curr->value->key) {
* if (strcasecmp(curr->value->key, key) == 0)
* return curr->value;
* }
* }
* }
* return NULL;
* }
*/
static char * keylist_to_string(const stringlist_t *keylist)
{
@ -1415,15 +1419,15 @@ DYNAMIC_API PEP_STATUS encrypt_message(
assert(session);
assert(src);
assert(dst);
assert(enc_format != PEP_enc_none);
if (!(session && src && dst && enc_format != PEP_enc_none))
if (!(session && src && dst))
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
if (src->dir == PEP_dir_incoming)
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
determine_encryption_format(src);
// TODO: change this for multi-encryption in message format 2.0
if (src->enc_format != PEP_enc_none)
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
@ -1450,7 +1454,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
identity_list * _il;
if ((_il = src->bcc) && _il->ident)
if (enc_format != PEP_enc_none && (_il = src->bcc) && _il->ident)
{
// BCC limited support:
// - App splits mails with BCC in multiple mails.
@ -1524,7 +1528,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
}
if (!dest_keys_found ||
if (enc_format == PEP_enc_none || !dest_keys_found ||
stringlist_length(keys) == 0 ||
_rating(max_comm_type,
PEP_rating_undefined) < PEP_rating_reliable)
@ -2194,7 +2198,7 @@ static PEP_STATUS _decrypt_in_pieces(PEP_SESSION session,
char* ptext,
size_t psize) {
PEP_STATUS status = PEP_UNKNOWN_ERROR;
PEP_STATUS status = PEP_STATUS_OK;
*msg_ptr = clone_to_empty_message(src);
@ -2552,9 +2556,7 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
now we need to update the message rating with the
sender and recipients in mind */
status = amend_rating_according_to_sender_and_recipients(session,
rating,
src->from,
_keylist);
rating, src->from, _keylist);
if (status != PEP_STATUS_OK)
GOTO(pep_error);
@ -3190,9 +3192,6 @@ DYNAMIC_API PEP_STATUS MIME_encrypt_message(
GOTO(pep_error);
}
// Clear the encryption status, or mime_encode will ignore
// the plaintext and do all sorts of other stupid things
enc_msg->enc_format = PEP_enc_none;
status = _mime_encode_message_internal(enc_msg, false, mime_ciphertext, false);
pep_error:
@ -3379,10 +3378,8 @@ got_keylist:
if (status != PEP_STATUS_OK)
GOTO(pep_error);
status = amend_rating_according_to_sender_and_recipients(session,
&_rating,
msg->from,
_keylist);
status = amend_rating_according_to_sender_and_recipients(session, &_rating,
msg->from, _keylist);
if (status == PEP_STATUS_OK)
*rating = _rating;

@ -49,7 +49,8 @@ typedef unsigned int PEP_encrypt_flags_t;
// session (in) session handle
// src (in) message to encrypt
// extra (in) extra keys for encryption
// dst (out) pointer to new encrypted message or NULL on failure
// dst (out) pointer to new encrypted message or NULL if no
// encryption could take place
// enc_format (in) encrypted format
// flags (in) flags to set special encryption features
//
@ -60,9 +61,9 @@ typedef unsigned int PEP_encrypt_flags_t;
// PEP_KEY_HAS_AMBIG_NAME at least one of the receipient keys has
// an ambiguous name
// PEP_GET_KEY_FAILED cannot retrieve key
// PEP_UNENCRYPTED no recipients with usable key,
// message is left unencrypted,
// and key is attached to it
// PEP_UNENCRYPTED on demand or no recipients with usable
// key, is left unencrypted, and key is
// attached to it
//
// caveat:
// the ownershop of src remains with the caller

@ -110,7 +110,7 @@ static const char *sql_set_device_group =
// This will cascade to identity and trust
static const char* sql_replace_userid =
"update person set id = ?1"
"update person set id = ?1 "
"where id = ?2;";
static const char *sql_get_device_group =
@ -791,6 +791,10 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
(int)strlen(sql_get_own_userid), &_session->get_own_userid, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_replace_userid,
(int)strlen(sql_replace_userid), &_session->replace_userid, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_replace_identities_fpr,
(int)strlen(sql_replace_identities_fpr),
&_session->replace_identities_fpr, NULL);
@ -865,10 +869,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
(int)strlen(sql_i18n_token), &_session->i18n_token, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->system_db, sql_replace_userid,
(int)strlen(sql_replace_userid), &_session->replace_userid, NULL);
assert(int_result == SQLITE_OK);
// blacklist
int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_add,

@ -12,8 +12,160 @@
using namespace std;
void test_MIME_decrypt_message()
{
static const std::string private_key =
"-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
"\n"
"lQOmBFpCxkEBCCC8ugYsWOsv966JOl5Ahdw6YiobbU9peFLV8aMBOG+oNIPs3BQj\n"
"u3FUugkVqA5In93oqVgNZ2LU6Y/RWldN+Pc4IMf6qSZnTBj/1ffBjuqAow1hPEYV\n"
"354LNYoQtJXioY0X8FjRgt+NoBPphRbo+XJ0uIQckJey6uvvtukEZkMLM1ur1aID\n"
"9biJZ7yXtJM7KxN5792Vo2gGp/1hlFW6SfM7E0g60L5DT8C/BsYeKtMmxKNZngo6\n"
"ZBxLDAcxMcT5UpRW79B34pTINZAEsvLeT7TLajzqP/OggUrFkkwLr3KJk09aFF+6\n"
"TN6CI2fDdSqdoPVEgNrZE9zFqAgVWOdhLOHRpXgt7wARAQABAAgZATpqsN4xRaIk\n"
"giMdmujkGoMqB/ypoCOW0mqcp3ThESSqWR/Dh8n//k+poHj0Atf7fzie6JNsKruM\n"
"Yo3mdIzyuuxHsONp6xEtNnkDgEB4WTb2btQQFrNaWXNTPzGVqiBoBShcw5xI7SiG\n"
"CKaDlCePbaAHyBHO0uzBdVFo6czqkceXSJ+hNDY7xbURbkgIA5SGJ+8cssmcKKoc\n"
"LDY34S3Pu0gG3+K6gSedYaHAqVVQn8dmEitvDF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UAIzePBBDg8QXr\n"
"J/R6iZYnMNv/mzyNunbM3B7siwbILS1kLeS6lTYeaKORa7JFRc776rkWV//P1Soc\n"
"nW2byeBxNxOmdNXlNsA6Gg8O4rn3rxEgBZlsOYUG1ZcPZZu8kNFkLTYP+mgFIP3I\n"
"izn858IbnNFm0HjRMGiS+zip2r/rgbniIhLQ2l7/BBCL+2x0+Ww5I/el6A7k+y2X\n"
"3xazBVOQfpPl9BgMdsuO0BBlN5RpbTfE8TVpWneeamAuRJh7ArApbAS508Thw7Sj\n"
"8iLKXj5yScAEC2WO9ZsHqJ/RN3VyhCCI0u3Y75wB3qfcroZUlwvQb/WfH8/vHr2O\n"
"E72YoprbNOmRFZ7LZkRX56URRn2JASMEGAEIAAkFAlpCxkECGwwACgkQr2Mun8eZ\n"
"t9RozQggkb/Lb08g4w99CcXq6hV28D5bOHjiEx4XNdkeLVExhfk1zgQ9lf4rjyb2\n"
"ox+e3Dc5S590NoYg/35vd/QWPsg1JiCvAu296lzOLtIiTAI1KGUJdbsLxRIduOU7\n"
"6n/KVxRG4w4kJqpbu+UzBY7KtDbWzapJx8v0sdsTOVxg7kFxvYtra5TRaPfce4EX\n"
"ox2V2HPhtFNSILH8Jqh/R0PV5RRbNFHZA4cKXkBJMw3BcpbpXeLCXiD6P3FNVSKh\n"
"Rkd3JY0XJhwbvGPCRWkobtxkieZe0bCmKu8+gw0Zqm2QNA7J6iMT4rMZWH9k7lpp\n"
"okyt7GheXlwKEtVQSAcH/NalK9Q+ckaQttA=\n"
"=KACn\n"
"-----END PGP PRIVATE KEY BLOCK-----\n"
"\n";
static const std::string mimetext =
"To: denden@peptest.ch\r\n"
"From: Lars Rohwedder <roker@pep-project.org>\r\n"
"Subject: Test for ENGINE-322\r\n"
"Message-ID: <4b2d328c-b284-e359-1c2c-fe136358b8a6@pep-project.org>\r\n"
"Date: Thu, 28 Dec 2017 22:00:47 +0100\r\n"
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0)\r\n"
" Gecko/20100101 Thunderbird/52.5.0\r\n"
"MIME-Version: 1.0\r\n"
"Content-Type: text/plain; charset=utf-8\r\n"
"Content-Language: en-US\r\n"
"Content-Transfer-Encoding: 8bit\r\n"
"\r\n"
"-----BEGIN PGP MESSAGE-----\r\n"
"Charset: utf-8\r\n"
"\r\n"
"hQEQA30SSxlFRbxRAQgggvPrko4vJ988ylqdGF7/Jtw/61VddHg7rjOTG7yZiq2J\r\n"
"p0lXb0N9Bz8SON/m4NWWS5ij0Bj1wMdTgLowLxMz0PfCIyyiQIfqEBAXUcAOQh2f\r\n"
"Pg2iZbynrQ1T4M/D0BlIn2bfXb790Cni+o1OmWTCx4wC6AKtGvlonLAIsH1hUfs+\r\n"
"yKOyCCNaNSmyAPeF3F5v7iEO5Eez1R/UrtxcYj2QmCdVt5v0AuAlm5HVPJgj7wCd\r\n"
"MeRmK4a1+sM51CcCf6Tk9uZbIVrr/XkyGVPmmHTK8E4QmvmL6PGeuIitwqKe80/L\r\n"
"XH4ZYPXIxVU9o5HoSo3YJ3BSKLQzCoDRCD8JlCo08K6mrpuFAgwD42RJLbKIaR4B\r\n"
"EADNgisKiIku4SrBmBkryyKMYmOTW0QKnY/wfNselpzuj5cMpKA4e60x/wEQRIvC\r\n"
"m1ZO7LjhbVjNf6ws2FgytnTRf+8R/R8mp6/XIDeUvaBvUku5yoRjTeznFRwpj6yT\r\n"
"WfQMlLojI2fe+y5fHKIIjTpW5HOQQv7sZ4UzE+jRpRErRVq4UI49l7yTBnG0j75w\r\n"
"UZTt05OnJMQrCCiD7Fu9xDw5If3x884GehKpFGm6XqZ8V7NhwGk6mf62rZEouBQh\r\n"
"AhTu/irkz30PpWY3gGj2YF0PIaQmweb9u2izox1kTfq2xRfPLg/4cOgBKy1/Xeea\r\n"
"IVeaACAcoNdJaYuZCSe9CMbr5s7kusE22/6fB0L1itGr09EzhwGJS/+XSt0IwcJw\r\n"
"7XDUGtmYXuTy08wUKU9McxXJ8nlUkXF9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1MjFdmlPKrExe5+MY+Pr9ms+hxJrdBH736\r\n"
"K6dojmWUQKpJRzue2lWsfESLxIVeB+vmbg2zU3PflCmMIsRNh2US7vZj2WdgqSqz\r\n"
"wR2eTG4MgPVy4iiGOVT2JWS5t+KXm3kwUZTy9Twi6P1ebNm/B8KQwlutssdWip2q\r\n"
"hON1aFYa4L601zrHgow592PdBkRPQZGiXNHffCvHgsxBHsj4G4JWZhmIkEK/cIWl\r\n"
"RanlZdQG6UPHkoUomh7hauUUgcYe4FWt4NBKdiba36Y=\r\n"
"=1lFj\r\n"
"-----END PGP MESSAGE-----\r\n"
"\r\n";
PEP_SESSION session;
PEP_STATUS status1 = init(&session);
assert(status1 == PEP_STATUS_OK);
assert(session);
// import secret key
identity_list* pk = NULL;
status1 = import_key( session, private_key.c_str(), private_key.size(), &pk );
assert(status1 == PEP_STATUS_OK);
std::cout << "Imported " << identity_list_length(pk) << " private key(s)." << endl;
char* plaintext = nullptr;
stringlist_t* keys_used = nullptr;
PEP_rating rating;
PEP_decrypt_flags_t dec_flags;
PEP_STATUS status2 = MIME_decrypt_message(session, mimetext.c_str(), mimetext.length(),
&plaintext, &keys_used, &rating, &dec_flags);
std::cout << "MIME_decrypt_message returned " << std::dec << status2 << std::hex << " (0x" << status2 << ")" << std::dec << endl;
assert(status2 == PEP_DECRYPTED);
assert(plaintext);
pEp_free(plaintext);
identity_list* il = pk;
while(il)
{
std::cout << "Delete test key \"" << il->ident->fpr << "\"" << endl;
delete_keypair( session, il->ident->fpr );
il = il->next;
}
free_identity_list(pk);
}
int main() {
cout << "\n*** message_api_test ***\n\n";
test_MIME_decrypt_message();
PEP_SESSION session;
@ -170,14 +322,35 @@ int main() {
cout << dec_msg << endl;
cout << "\nTesting encrypt_message() with enc_format = PEP_enc_none\n\n";
message *msg7 = new_message(PEP_dir_outgoing);
pEp_identity * me7 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
identity_list *to7 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
msg7->from = me7;
msg7->to = to7;
msg7->shortmsg = strdup("My Subject");
msg7->longmsg = strdup("This is some text.\n");
message *enc7 = nullptr;
PEP_STATUS status9 = encrypt_message(session, msg7, NULL, &enc7, PEP_enc_none, 0);
std::cout << "encrypt_message returned " << std::dec << status9 << std::hex << " (0x" << status9 << ")" << std::dec << endl;
assert(status9 == PEP_UNENCRYPTED);
assert(enc7 == nullptr);
assert(msg7->shortmsg && msg7->longmsg);
cout << msg7->shortmsg << "\n";
cout << msg7->longmsg << "\n";
assert(strcmp(msg7->shortmsg, "My Subject") == 0);
assert(strcmp(msg7->longmsg, "This is some text.\n") == 0);
cout << "freeing messages…\n";
cout << "\nfreeing messages…\n";
free_message(msg7);
free_message(msg6);
free_message(msg5);
free_message(msg4);
free_message(msg3);
free_message(msg2);
free_message(enc_msg2);
free_message(msg6);
free_message(msg5);
cout << "done.\n";
free(enc_msg);

@ -0,0 +1,13 @@
# Usage
To execute these tests, install p≡p Python adapter from
<https://letsencrypt.pep.foundation/dev/repos/pEpPythonAdapter/>
These tests are meant to be run using py.test <https://pytest.org> and
pytest-xdist <https://pypi.python.org/pypi/pytest-xdist>
You can run setup_test.py before running the tests if the initial setup is
failing.
To remove all generated files run setup_test.py -r

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# this file is under GNU General Public License 3.0
# Copyleft 2017, p≡p foundation
from setup_test import create_homes
def pytest_runtest_setup(item):
create_homes()

@ -0,0 +1,7 @@
# --boxed run each test in an own process
# -v verbose output
# -n 2 two parallel tasks
[pytest]
addopts = --boxed -v -n 2 test_handshake.py

@ -0,0 +1,123 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# this file is under GNU General Public License 3.0
# Copyleft 2017, p≡p foundation
#import vimpdb; vimpdb.set_trace()
"""
This script is setting up the test environment by creating two home directories
for simulation of message exchange between two pp parties.
The directories are created in the current directory.
"""
import os
import shutil
from multiprocessing import Process
from time import sleep
realhome = os.path.expanduser("~")
mydir = os.path.abspath(os.path.curdir)
def link_if_exists(dirname, arthome):
"link directory from home to artificial home"
orig = os.path.join(realhome, dirname)
if os.path.exists(orig):
if not os.path.exists(dirname):
os.symlink(orig, dirname, True)
def create_own_identities(mydir, arthome, username):
"create own identities as part of the test setup"
os.environ["HOME"] = os.path.join(mydir, arthome)
os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
import pEp
me = pEp.Identity()
me.address = arthome + "@peptest.ch"
me.username = username
pEp.myself(me)
print(repr(me))
def link_file(filename):
"sym-link file to version in parent directory"
src = os.path.join(os.pardir, filename)
if not os.path.exists(filename):
os.symlink(src, filename, False)
def create_home(mydir, arthome, username):
"create an artificial home directory for testing"
os.chdir(mydir)
os.makedirs(arthome, exist_ok=True)
os.chdir(arthome)
link_if_exists("bin", arthome)
link_if_exists("include", arthome)
link_if_exists("lib", arthome)
link_if_exists("share", arthome)
link_if_exists(".local", arthome)
link_if_exists("Library", arthome) # this may exist on macOS
p = Process(target=create_own_identities, args=(mydir, arthome, username))
p.start()
p.join()
with open(".ready", "w"): pass
def create_homes():
"create two artificial home directories for the two parties"
try:
os.stat("test1")
except:
create_home(mydir, "test1", "Alice One")
create_home(mydir, "test2", "Bob Two")
else:
while True:
try:
os.stat("test2/.ready")
except:
sleep(1)
else:
break
def remove_homes():
"""remove formerly created artificial home directories including their
contents"""
os.chdir(mydir)
shutil.rmtree("test1", ignore_errors=True)
shutil.rmtree("test2", ignore_errors=True)
shutil.rmtree("__pycache__", ignore_errors=True)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-r', '--remove', action="store_true",
help=remove_homes.__doc__)
args = parser.parse_args()
if args.remove:
remove_homes()
else:
create_homes()

@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
# this file is under GNU General Public License 3.0
# Copyleft 2017, p≡p foundation
from transport import *
def setup_gnupg():
assert os.environ["GNUPGHOME"] != ""
mydir = os.path.dirname(os.path.realpath(__file__))
class Test1:
def setup_method(self):
arthome = "test1"
os.environ["HOME"] = os.path.join(mydir, arthome)
os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
os.chdir(os.path.join(mydir, arthome))
@property
def me(self):
# because of flaws of py.test these two statements are necessary
setup_gnupg() # work around a bug with initializing os.environ
import pEp # after that import pEp module, not before
i = pEp.Identity()
i.address = "test1@peptest.ch"
i.username = "Alice One"
pEp.myself(i)
return i
@property
def you(self):
setup_gnupg() ; import pEp
i = pEp.Identity()
i.address = "test2@peptest.ch"
i.username = "Bob Two"
pEp.update_identity(i)
return i
def test_handshake(self):
setup_gnupg() ; import pEp
msg = pEp.Message(1)
msg.from_ = self.me
msg.to = [self.you]
msg.shortmsg = "Subject line"
msg.longmsg = "Message Text\n"
enc = msg.encrypt()
send_message("test2", str(enc))
txt = wait_for_message()
enc = pEp.Message(txt)
assert enc.from_.address == "test2@peptest.ch"
inc, keys, rating, consumed, flags = enc.decrypt()
assert rating == 6
msg = pEp.Message(1)
msg.from_ = self.me
msg.to = [self.you]
msg.shortmsg = "Subject line complete"
msg.longmsg = "Message Text complete\n"
enc = msg.encrypt()
send_message("test2", str(enc))
class Test2:
def setup_method(self):
arthome = "test2"
os.environ["HOME"] = os.path.join(mydir, arthome)
os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
os.chdir(os.path.join(mydir, arthome))
@property
def me(self):
setup_gnupg() ; import pEp
i = pEp.Identity()
i.address = "test2@peptest.ch"
i.username = "Bob Two"
pEp.myself(i)
return i
@property
def you(self):
setup_gnupg() ; import pEp
i = pEp.Identity()
i.address = "test1@peptest.ch"
i.username = "Alice One"
pEp.update_identity(i)
return i
def test_handshake(self):
setup_gnupg() ; import pEp
txt = wait_for_message()
msg = pEp.Message(txt)
msg.decrypt()
assert msg.from_.address == self.you.address
out = pEp.Message(1)
out.from_ = self.me
out.to = [self.you]
out.shortmsg = "Subject Back"
out.longmsg = "Text Back\n"
enc = out.encrypt()
send_message("test1", str(enc))
txt = wait_for_message()
msg = pEp.Message(txt)
msg.decrypt()
assert msg.from_.address == self.you.address

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
# this file is under GNU General Public License 3.0
# Copyleft 2017, p≡p foundation
"""
This module is implementing a basic message transport. Messages are written
into the artificial home of the receiver and deleted when read.
"""
import os
import time
from glob import glob
timeout = 5
def send_message(to, msg):
"send message by creating a file in recipient's artificial home"
recipient_dir = os.path.join(os.pardir, to)
filename = '{:024x}'.format(int(time.monotonic() * 10000000000)) + \
os.extsep + "eml"
dotpath = os.path.join(recipient_dir, "." + filename)
path = os.path.join(recipient_dir, filename)
with open(dotpath, "w") as file:
file.write(msg)
os.rename(dotpath, path)
def recv_message(inbox=None):
"""receive message by returning the first .eml files content in artificial
home"""
if inbox:
filename = glob(os.path.join(os.pardir, inbox, "*.eml"))[0]
else:
filename = glob("*.eml")[0]
with open(filename, "r") as file:
msg = file.read()
os.remove(filename)
return msg
def wait_for_message():
"wait until a message arrives and return the message"
found = False
for i in range(timeout):
try:
msg = recv_message()
except IndexError:
time.sleep(1)
else:
found = True
break
if not found:
raise RuntimeError("timeout")
return msg
Loading…
Cancel
Save