Browse Source

Rolled back to revision 1982. Sorry all, checked in wrong branch to default

doc_update_sequoia
Krista Bennett 5 years ago
parent
commit
24ac9b0d2c
13 changed files with 456 additions and 505 deletions
  1. +1
    -0
      .hgignore
  2. +17
    -18
      Makefile
  3. +17
    -26
      Makefile.conf
  4. +1
    -2
      README.txt
  5. +15
    -17
      asn.1/Makefile
  6. +55
    -0
      build-config/Darwin.conf
  7. +54
    -0
      build-config/Linux.conf
  8. +88
    -0
      build-config/common.conf
  9. +11
    -7
      db/Makefile
  10. +44
    -56
      src/Makefile
  11. +87
    -327
      src/message_api.c
  12. +15
    -12
      sync/Makefile
  13. +51
    -40
      test/Makefile

+ 1
- 0
.hgignore View File

@ -3,6 +3,7 @@ syntax: regexp
^asn\.1/Makefile\.am\.sample$
^asn\.1/libasn1\.a$
.*xcuserdata/
^build/
syntax: glob
*.orig


+ 17
- 18
Makefile View File

@ -1,27 +1,33 @@
# this file is under GNU General Public License v3.0
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
include Makefile.conf
HERE_REL := $(notdir $(CURDIR))
# add it to the environment of all executed programs:
export YML_PATH
include Makefile.conf
# YML_PATH is needed in the environment of every call to a program of the YML2 distribution
export YML_PATH=$(YML2_PATH)
.PHONY: all
all:
$(MAKE) -C asn.1 generate
$(MAKE) -C asn.1
$(MAKE) -C sync
$(MAKE) -C src all
.PHONY: clean build_test test package install uninstall db
.PHONY: install
install: all
$(MAKE) -C src install
$(MAKE) -C asn.1 install
.PHONY: uninstall
uninstall:
$(MAKE) -C src uninstall
$(MAKE) -C asn.1 uninstall
.PHONY: clean
clean:
$(MAKE) -C src clean
$(MAKE) -C test clean
@ -29,26 +35,19 @@ clean:
$(MAKE) -C sync clean
$(MAKE) -C asn.1 clean
.PHONY: test
test: all
$(MAKE) -C test test
$(MAKE) -C test unit_tests
.PHONY: unit_tests
unit_tests: all
$(MAKE) -C test unit_tests
.PHONY: package
package: clean
cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 pEpEngine
cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 "$(HERE_REL)"
.PHONY: db
db:
$(MAKE) -C db db
windist:
ifneq ($(BUILD_FOR),Windoze)
@echo use BUILD_FOR=Windoze \(did you forget -e ?\)
else
make clean
$(MAKE) all
$(MAKE) -C test all
zip -j pEpEngine-dist.zip src/pEpEngine.h src/keymanagement.h src/pEpEngine.dll src/pEpEngine.def test/pEpEngineTest.exe test/*.asc test/*.key db/*.db test/*.txt test/*.asc src/*.sql
endif

+ 17
- 26
Makefile.conf View File

@ -1,30 +1,21 @@
# this file is in the Public Domain
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
BUILD_ON=$(shell uname)
BUILD_FOR=$(BUILD_ON)
OPTIMIZE=-g -Wall -O0 -fPIC -DDEBUG_ERRORSTACK
#OPTIMIZE=-O3 -Wall -DNDEBUG -std=c99
LD=$(CC)
#CC=gcc-mp-4.9 -std=c99 -fstrict-aliasing -Wstrict-aliasing=3
#LD=gcc-mp-4.9
SYSTEM_DB=/usr/local/share/pEp/system.db
PREFIX=$(HOME)
YML2PROC=$(HOME)/yml2/yml2proc
YML_OPTS=--encoding=utf8
YML_PATH=$(HOME)/yml2
ASN1C=asn1c
ASN1C_INCLUDE=/opt/local/share/asn1c
#ETPAN_IN=$(HOME)
#LIBGPGME=/opt/local/lib/libgpgme.11.dylib
# This file assembles all the make variables that a maintainer or dev may want to taylor to his or her needs on a given platform.
# C makros (not environment variables) to overwrite:
#
# DEFAULT_KEYSERVER - string with default keyserver
# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
# To use custom build configuration variables, put them in a new file with the path `build-config/<name>.conf`. Execute `export PLATFORM_OVERRIDE=<name>` before running make. If this environment variable is not set, make will load a default configuration for your platform.
#EXTRAMACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
BUILD_CONFIG:=$(dir $(lastword $(MAKEFILE_LIST)))build-config
# second instance for testing
#EXTRAMACROS=-DLOCAL_DB_FILENAME=\".pEp_management2.db\"
#TARGET=libpEpEngine2.dylib
include $(BUILD_CONFIG)/common.conf
# cross-compiling is currently not supported, but maybe you can hack something with `PLATFORM_OVERRIDE`
ifeq ($(BUILD_ON),$(BUILD_FOR))
include $(BUILD_CONFIG)/$(BUILD_ON).conf
else
$(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON))
endif
ifdef PLATFORM_OVERRIDE
include $(BUILD_CONFIG)/$(PLATFORM_OVERRIDE).conf
endif

+ 1
- 2
README.txt View File

@ -60,8 +60,7 @@ p≡p engine is depending on the following FOSS libraries:
* NetPGP/p≡p, see https://cacert.pep.foundation/dev/repos/netpgp-et/
* Asn1c, download from https://lionet.info/soft/asn1c-0.9.27.tar.gz
(Debian's version 0.9.24 does not work)
* Asn1c, download from https://lionet.info/soft/asn1c-0.9.27.tar.gz . Debian 8's v0.9.24 does not work. Debian 9's v0.9.27 generates non-POSIX code, that will cause issues when the engine is compiled with '-std=c99'. Thus, use v0.9.28 for best results.
* yml2, which needs lxml (where to get?)


+ 15
- 17
asn.1/Makefile View File

@ -1,37 +1,35 @@
# This file is under GNU General Public License 3.0
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
include ../Makefile.conf
ifeq ($(BUILD_ON),Linux)
ifeq ($(BUILD_FOR),Linux)
CC=gcc
CFLAGS?=-fPIC
else
$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
endif
ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
ALL_SOURCE=$(wildcard *.c)
ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
libasn1.a: $(ALL_OBJECTS)
ar -rc $@ $(ALL_OBJECTS)
ar -rc $@ $^
# "converter-sample.c" is the example file containing a "main()" function generated by ans1c.
.PHONY: generate
generate: Sync-Protocols.c
rm -f converter-sample.c
%.o: %.c %.h
$(CC) $(CFLAGS) $(OPTIMIZE) -I. -I$(ASN1C_INCLUDE) -c $< -o $@
$(CC) $(CFLAGS) $(CFLAGS_GENERATED) -I. $(ASN1C_INC) -c $< -o $@
Sync-Protocols.c: protocols.asn1 devicegroup.asn1 pEp.asn1
$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1 $<
Sync-Protocols.c: pEp.asn1 devicegroup.asn1 protocols.asn1
$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message $^
.PHONY: clean
clean:
rm -f *.a *.o *.c *.h *.sample
.PHONY: install
install: libasn1.a
cp $< $(PREFIX)/lib/
.PHONY: uninstall
uninstall:
rm -f $(PREFIX)/lib/libasn1.a

+ 55
- 0
build-config/Darwin.conf View File

@ -0,0 +1,55 @@
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
######### General #########
TARGET=libpEpEngine.dylib
######### C #########
# clang issues a warning when "-pthread" is used for linking. So, include it in CFLAGS, and not in CC
CC=clang -std=c99
CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
ifdef WARN
CFLAGS+= -Wall -pedantic
else
CFLAGS+= -w
endif
ifdef DEBUG
CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
else
CFLAGS+= -O3 -DNDEBUG
endif
CFLAGS_GENERATED=
######### C++ #########
# clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
CXX=clang -std=c++11
CXXFLAGS=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
ifdef WARN
CXXFLAGS+=
else
CXXFLAGS+= -w
endif
ifdef DEBUG
CXXFLAGS+= -O0 -g
else
CXXFLAGS+= -O3 -DNDEBUG
endif
######### C and C++ #########
######### YML2 #########
######### asn1c #########
######### libetpan #########
######### OpenPGP #########
LIBGPGME=libgpgme.dylib
GPGME_LIB=-L/opt/local/lib
GPGME_INC=-I/opt/local/include
######### Engine internals #########
######### Misc #########

+ 54
- 0
build-config/Linux.conf View File

@ -0,0 +1,54 @@
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
######### General #########
TARGET=libpEpEngine.so
######### C #########
CC=gcc -std=c99 -pthread
CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
ifdef WARN
CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
else
CFLAGS+= -w
endif
ifdef DEBUG
CFLAGS+= -Og -ggdb -DDEBUG_ERRORSTACK
else
CFLAGS+= -O3 -DNDEBUG
endif
# '-Wno-cpp' is required to suppress the warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" otherwise printed during the compilation of every asn1c-generated C file.
CFLAGS_GENERATED=-Wno-cpp
######### C++ #########
CXX=g++ -std=gnu++11 -pthread
CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
ifdef WARN
CXXFLAGS+=
else
CXXFLAGS+= -w
endif
ifdef DEBUG
CXXFLAGS+= -Og -ggdb
else
CXXFLAGS+= -O3 -DNDEBUG
endif
######### C and C++ #########
######### YML2 #########
######### asn1c #########
######### libetpan #########
######### OpenPGP #########
LIBGPGME=libgpgme.so.11
GPGME_LIB=
GPGME_INC=
######### Engine internals #########
######### Misc #########

+ 88
- 0
build-config/common.conf View File

@ -0,0 +1,88 @@
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
# General remark: to use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
######### General #########
BUILD_ON:=$(shell uname)
BUILD_FOR=$(BUILD_ON)
# Installation path prefix for libraries and binaries, except for system.db
PREFIX=$(HOME)
# Installation path for system.db
SYSTEM_DB=/usr/local/share/pEp/system.db
# Filename of the pEpEngine library
#TARGET This option is platform-specific
# If not empty, create a debug build
DEBUG=placeholder
# If not empty, print compiler warnings
WARN=placeholder
######### C #########
#CC This option is platform-specific
CPPFLAGS=
#CFLAGS This option is platform-specific
# Additional CFLAGS used for compiling ASN1C-generated code
#CFLAGS_GENERATED This option is platform-specific
######### C++ #########
#CXX This option is platform-specific
#CXXFLAGS This option is platform-specific
######### C and C++ #########
TARGET_ARCH=
# The following two variables will be appended to. You can thus not set them to a fixed value here.
LDFLAGS=
LDLIBS=
######### YML2 #########
YML2_PATH=$(HOME)/yml2
YML2_PROC=$(YML2_PATH)/yml2proc
YML2_OPTS=--encoding=utf8
######### asn1c #########
# asn1c binary
ASN1C=asn1c
# asn1c include search flag
ASN1C_INC=
#ASN1C_INC= -I$(HOME)/include
######### libetpan #########
# libetpan library search flag
ETPAN_LIB=-L$(PREFIX)/lib
# libetpan include search flag
ETPAN_INC=-I$(PREFIX)/include
######### OpenPGP #########
# Path of GPG binary
GPG_CMD=gpg
ifneq ($(shell which gpg2),)
GPG_CMD = gpg2
endif
# Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
OPENPGP=GPG
# Path of libGPGME binary
#LIBGPGME This option is platform-specific
# libGPGME library search flag
#GPGME_LIB= This option is platform-specific
# libGPGME include search flag
#GPGME_INC= This option is platform-specific
# NETPGP library search flag
NETPGP_LIB=
#NETPGP_LIB=-L$(PREFIX)/lib
# libGPGME include search flag
NETPGP_INC=
#NETPGP_INC=-I$(PREFIX)/include
######### Engine internals #########
# C macros (not environment variables) that can be overridden:
# DEFAULT_KEYSERVER - string with default keyserver
# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
# Example:
# EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
EXTRA_MACROS=
######### Misc #########
# FIXME Maybe include these variables here. Check how they are used throughout the project before setting them here
#LLDB_BIN

+ 11
- 7
db/Makefile View File

@ -1,22 +1,26 @@
# This file is under GNU General Public License 3.0
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
include ../Makefile.conf
.PHONY: db
db: system.db
dicos=$(wildcard *.csv)
DICOS = $(wildcard *.csv)
system.db: create_system_db.sql $(dicos)
# The 'mv' keeps a backup db around
system.db: create_system_db.sql $(DICOS)
-mv -f $@ $@~
sqlite3 -batch $@ < $<
for c in $(dicos); do echo $$c ; echo .import "$$c" wordlist | sqlite3 -batch -csv $@ ; done
.PHONY: clean install
for c in $(DICOS) ; do echo "$$c" ; echo .import "$$c" wordlist | sqlite3 -batch -csv $@ ; done
.PHONY: install
install: system.db
mkdir -p `dirname $(SYSTEM_DB)`
cp system.db $(SYSTEM_DB)
.PHONY: clean
clean:
rm -f system.db
rm -f system.db system.db~

+ 44
- 56
src/Makefile View File

@ -1,70 +1,55 @@
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
include ../Makefile.conf
ETPAN_IN?=$(HOME)
CFLAGS+= $(ETPAN_INC) -I../asn.1 -DSYSTEM_DB=\"$(SYSTEM_DB)\" $(EXTRA_MACROS)
LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -shared
LDLIBS+= -lc -lasn1 -letpan
ifeq ($(BUILD_ON),Darwin)
ifeq ($(BUILD_FOR),Darwin)
TARGET?=libpEpEngine.dylib
MACOSX_VERSION_MIN=10.6
LIBGPGME?=libgpgme.dylib
CC?=clang -std=c99 -pthread
LD?=clang
CFLAGS?= -I$(ETPAN_IN)/include -I/opt/local/include $(OPTIMIZE) -pedantic \
-DSYSTEM_DB=\"$(SYSTEM_DB)\" -I../asn.1 $(EXTRAMACROS)
LDFLAGS?= -lc -shared -arch x86_64 \
-L$(ETPAN_IN)/lib -L/usr/lib -L/opt/local/lib -letpan -lsqlite3 -L../asn.1 -lasn1 -lz -liconv
else
$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
ifeq ($(BUILD_FOR),Darwin)
CFLAGS+= -DSQLITE_THREADSAFE=1
#LDFLAGS+= -L/opt/local/lib
LDLIBS+= -lsqlite3 -lz -liconv
else
$(error I don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
else ifeq ($(BUILD_ON),Linux)
ifeq ($(BUILD_FOR),Linux)
TARGET=libpEpEngine.so
LIBGPGME?=libgpgme.so.11
CC=gcc -std=c99
CFLAGS?= -I$(ETPAN_IN)/include $(OPTIMIZE) -fPIC -pedantic -DSYSTEM_DB=\"$(SYSTEM_DB)\" \
-DSQLITE_THREADSAFE=1 -D_GNU_SOURCE -I../asn.1 $(EXTRAMACROS)
LDFLAGS?= -L$(ETPAN_IN)/lib -shared -lc -ldl -letpan -lpthread -L../asn.1 -lasn1 -luuid
else
$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
ifeq ($(BUILD_FOR),Linux)
CFLAGS+= -DSQLITE_THREADSAFE=1 -D_GNU_SOURCE
LDLIBS+= -ldl -luuid
else
$(error I don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
else
$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
$(error I don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
DEBUG?=NO
ifeq ("$(DEBUG)","NO")
CFLAGS+= -DNDEBUG
endif
OPENPGP?=GPG
ifeq ("$(OPENPGP)","GPG")
ifeq ($(OPENPGP),GPG)
NO_SOURCE=pgp_netpgp.c
GPGME_IN?=$(HOME)
CFLAGS+= -DUSE_GPG -I$(GPGME_IN)/include -DLIBGPGME=\"$(LIBGPGME)\"
#LDFLAGS+= -L$(GPGME_IN)/lib -lgpgme
else ifeq ("$(OPENPGP)","NETPGP")
CFLAGS+= -DUSE_GPG $(GPGME_INC) -DLIBGPGME=\"$(LIBGPGME)\"
LDFLAGS+= $(GPGME_LIB)
# No extra LDLIBS are needed here, because GPGME is dynamically loaded
else ifeq ($(OPENPGP),NETPGP)
NO_SOURCE=pgp_gpg.c
NETPGP_IN?=$(HOME)
CFLAGS+= -DUSE_NETPGP -I$(NETPGP_IN)/include
LDFLAGS+= -L$(NETPGP_IN)/lib -lnetpgp -lcurl
CFLAGS+= -DUSE_NETPGP $(NETGPG_INC)
LDFLAGS+= $(NETGPG_LIB)
LDLIBS+= -lnetpgp -lcurl
else
$(error Unknown OpenPGP library : $(OPENPGP))
$(error Unknown OpenPGP library: $(OPENPGP))
endif
ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
DEPENDS=$(subst .c,.d,$(ALL_SOURCE))
ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
.PHONY: all
all: $(TARGET)
include Makefile.protocols
-include Makefile.protocols
%.d: %.c
@set -e; rm -f $@; \
@ -72,29 +57,32 @@ include Makefile.protocols
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
-include $(DEPENDS)
#platform_windows.o: platform_windows.cpp
# $(CXX) $(CXX_FLAGS) -o $@ -c $<
# If only the goal 'clean' is given, do not generate and include the '%.d' files.
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
endif
$(TARGET): libpEpEngine.a
$(LD) $(ALL_OBJECTS) $(LDFLAGS) -o $@
$(CC) $(ALL_OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@
.PHONY: objects
objects: $(ALL_OBJECTS)
libpEpEngine.a: $(ALL_OBJECTS)
ar -r $@ $(ALL_OBJECTS)
ar -rc $@ $^
.PHONY: clean
clean:
rm -f *.d *.o *.a $(TARGET) *.dll *.so *.zip *.d.* *.def *~
.PHONY: install
install: $(TARGET)
mkdir -p "$(PREFIX)/lib/"
cp $< $(PREFIX)/lib/
mkdir -p $(PREFIX)/include/pEp
cp pEpEngine.h keymanagement.h message_api.h dynamic_api.h stringlist.h timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h cryptotech.h sync.h sync_fsm.h sync_app.h blacklist.h openpgp_compat.h $(PREFIX)/include/pEp/
.PHONY: uninstall
uninstall:
rm -f $(PREFIX)/lib/$(TARGET)
rm -rf $(PREFIX)/include/pEp

+ 87
- 327
src/message_api.c View File

@ -211,32 +211,6 @@ enomem:
return -1;
}
static void remove_msg_version_field(message* msg) {
assert(msg);
stringpair_list_t* msg_opt_flds_curr = msg->opt_fields;
stringpair_list_t** msg_opt_flds_prev_p = NULL;
while (msg_opt_flds_curr) {
char* fld_key = msg_opt_flds_curr->value->key;
if (fld_key) {
if (strcmp(fld_key, "X-pEp-Message-Version") == 0) {
if (!msg_opt_flds_prev_p) {
msg->opt_fields = msg_opt_flds_curr->next;
}
else {
(*msg_opt_flds_prev_p)->next = msg_opt_flds_curr->next;
}
msg_opt_flds_curr->next = NULL;
free_stringpair_list(msg_opt_flds_curr);
break;
}
*msg_opt_flds_prev_p = msg_opt_flds_curr;
msg_opt_flds_curr = msg_opt_flds_curr->next;
}
}
}
static PEP_STATUS copy_fields(message *dst, const message *src)
{
assert(dst);
@ -353,100 +327,6 @@ static PEP_STATUS copy_fields(message *dst, const message *src)
return PEP_STATUS_OK;
}
static message* extract_minimal_envelope(const message* src,
PEP_msg_direction direct) {
message* envelope = new_message(direct);
if (!envelope)
return NULL;
envelope->shortmsg = strdup("pEp");
if (!envelope->shortmsg)
return NULL;
if (src->from) {
envelope->from = identity_dup(src->from);
if (!envelope->from)
return NULL;
}
if (src->to) {
envelope->to = identity_list_dup(src->to);
if (!envelope->to)
return NULL;
}
if (src->cc) {
envelope->cc = identity_list_dup(src->cc);
if (!envelope->cc)
return NULL;
}
if (src->bcc) {
envelope->bcc = identity_list_dup(src->bcc);
if (!envelope->bcc)
return NULL;
}
/* DO WE WANT TO EXPOSE THIS??? */
if (src->reply_to) {
envelope->reply_to = identity_list_dup(src->reply_to);
if (!envelope->reply_to)
return NULL;
}
envelope->enc_format = src->enc_format;
return envelope;
}
static void add_message_version(
message* msg,
int major_version,
int minor_version
)
{
assert(msg);
char buf[8]; // xxx.xxx\0
if (major_version < 1000 && minor_version < 1000) {
int chars_set = sprintf(buf, "%d.%d", major_version, minor_version);
if (chars_set >= 3)
add_opt_field(msg, "X-pEp-Message-Version", buf);
}
}
static message* wrap_message_as_attachment(message* envelope,
const message* attachment) {
message* _envelope = NULL;
if (!envelope) {
_envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
envelope = _envelope;
}
char* message_text = NULL;
/* Turn message into a MIME-blob */
PEP_STATUS status = mime_encode_message(attachment, false, &message_text);
if (status != PEP_STATUS_OK) {
free(_envelope);
return NULL;
}
size_t message_len = strlen(message_text);
bloblist_t* message_blob = new_bloblist(message_text, message_len,
"message/rfc822", NULL);
envelope->attachments = message_blob;
add_message_version(envelope, 2, 0);
return envelope;
}
static message * clone_to_empty_message(const message * src)
{
PEP_STATUS status;
@ -483,6 +363,7 @@ static PEP_STATUS encrypt_PGP_MIME(
)
{
PEP_STATUS status = PEP_STATUS_OK;
bool free_ptext = false;
char *ptext = NULL;
char *ctext = NULL;
char *mimetext = NULL;
@ -490,12 +371,20 @@ static PEP_STATUS encrypt_PGP_MIME(
assert(dst->longmsg == NULL);
dst->enc_format = PEP_enc_PGP_MIME;
if (src->shortmsg) {
dst->shortmsg = strdup(src->shortmsg);
assert(dst->shortmsg);
if (dst->shortmsg == NULL)
goto enomem;
ptext = src->longmsg;
if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
if (session->unencrypted_subject) {
dst->shortmsg = strdup(src->shortmsg);
assert(dst->shortmsg);
if (dst->shortmsg == NULL)
goto enomem;
ptext = src->longmsg;
}
else {
ptext = combine_short_and_long(src->shortmsg, src->longmsg);
if (ptext == NULL)
goto enomem;
free_ptext = true;
}
}
else if (src->longmsg) {
ptext = src->longmsg;
@ -517,6 +406,10 @@ static PEP_STATUS encrypt_PGP_MIME(
if (status != PEP_STATUS_OK)
goto pep_error;
if (free_ptext){
free(ptext);
free_ptext=0;
}
free(_src);
assert(mimetext);
if (mimetext == NULL)
@ -1227,9 +1120,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
PEP_STATUS status = PEP_STATUS_OK;
message * msg = NULL;
stringlist_t * keys = NULL;
message* _src = NULL;
message* inner_message = NULL;
assert(session);
assert(src);
assert(dst);
@ -1241,14 +1132,6 @@ DYNAMIC_API PEP_STATUS encrypt_message(
if (src->dir == PEP_dir_incoming)
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
bool no_wrap_message = (flags & PEP_encrypt_flag_dont_raise_headers);
if (!no_wrap_message) {
PEP_STATUS wrap_status = encrypt_message(session, src, extra, &inner_message,
enc_format,
(flags ^ PEP_encrypt_flag_dont_raise_headers));
}
determine_encryption_format(src);
if (src->enc_format != PEP_enc_none)
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
@ -1364,29 +1247,21 @@ DYNAMIC_API PEP_STATUS encrypt_message(
return ADD_TO_LOG(PEP_UNENCRYPTED);
}
else {
if (no_wrap_message) {
msg = clone_to_empty_message(src);
_src = src;
}
else if (inner_message) {
_src = wrap_message_as_attachment(NULL, inner_message);
msg = clone_to_empty_message(_src);
}
msg = clone_to_empty_message(src);
if (msg == NULL)
goto enomem;
if (!(flags & PEP_encrypt_flag_force_no_attached_key))
attach_own_key(session, _src);
attach_own_key(session, src);
switch (enc_format) {
case PEP_enc_PGP_MIME:
case PEP_enc_PEP: // BUG: should be implemented extra
status = encrypt_PGP_MIME(session, _src, keys, msg, flags);
status = encrypt_PGP_MIME(session, src, keys, msg, flags);
break;
// This actually doesn't really make sense for message 2.0... See function comment below
case PEP_enc_pieces:
status = encrypt_PGP_in_pieces(session, _src, keys, msg, flags);
status = encrypt_PGP_in_pieces(session, src, keys, msg, flags);
break;
/* case PEP_enc_PEP:
@ -1417,8 +1292,8 @@ DYNAMIC_API PEP_STATUS encrypt_message(
if (msg) {
decorate_message(msg, PEP_rating_undefined, NULL);
if (_src->id) {
msg->id = strdup(_src->id);
if (src->id) {
msg->id = strdup(src->id);
assert(msg->id);
if (msg->id == NULL)
goto enomem;
@ -1426,7 +1301,6 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
*dst = msg;
// free_message(wrapped_msg);
return ADD_TO_LOG(status);
enomem:
@ -1435,8 +1309,7 @@ enomem:
pep_error:
free_stringlist(keys);
free_message(msg);
if (!no_wrap_message)
free_message(_src);
return ADD_TO_LOG(status);
}
@ -1559,60 +1432,8 @@ static bool is_a_pEpmessage(const message *msg)
return false;
}
static const char* pEpmessage_version_str(const message *msg)
{
char* retval = NULL;
for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
if (strcasecmp(i->value->key, "X-pEp-Message-Version") == 0) {
retval = i->value->value;
break;
}
}
return retval;
}
static int pEpmessage_major_version(const message *msg) {
const char* version_string = pEpmessage_version_str(msg);
if (!version_string)
return -1;
int ver_strlen = strlen(version_string);
if (ver_strlen < 3)
return -1;
const short MAX_MAJ_VERSION_DIGITS = 4; // I certainly hope...
char version_buf[MAX_MAJ_VERSION_DIGITS + 1];
int i = 0;
for ( ; i < MAX_MAJ_VERSION_DIGITS && i < ver_strlen; i++ ) {
if (version_string[i] == '.') {
version_buf[i] = '\0';
break;
}
version_buf[i] = version_string[i];
}
if (version_string[i] != '.')
return -1;
// ok, this is some chars + \0, but not necessarily numeric.
int retval = atoi(version_buf);
if (retval == 0 && version_buf[0] != 0)
return -1;
return retval;
}
static bool verify_explicit_message_version(const char* desired_version,
const message* msg) {
if (!desired_version || !msg)
return false;
const char* msg_version_str = pEpmessage_version_str(msg);
return (msg_version_str && (strcmp(desired_version, msg_version_str) == 0));
}
// update comm_type to pEp_ct_pEp if needed
static PEP_STATUS _update_identity_for_incoming_message(
PEP_SESSION session,
const message *src
@ -1840,29 +1661,6 @@ PEP_STATUS amend_rating_according_to_sender_and_recipients(
return status;
}
static void pull_up_longmsg_attachment(message* msg) {
bloblist_t* matt = msg->attachments;
if (matt) {
const char* inner_mime_type = matt->mime_type;
if (strcasecmp(inner_mime_type, "text/plain") == 0) {
free(msg->longmsg); /* in case of "" */
msg->longmsg = strndup(matt->value, matt->size);
bloblist_t* next_node = matt->next;
if (next_node) {
inner_mime_type = next_node->mime_type;
if (strcasecmp(inner_mime_type, "text/html") == 0) {
free(msg->longmsg_formatted);
msg->longmsg_formatted = strndup(next_node->value, next_node->size);
}
}
}
else if (strcasecmp(inner_mime_type, "text/html") == 0) {
free(msg->longmsg_formatted);
msg->longmsg_formatted = strndup(matt->value, matt->size);
}
}
}
DYNAMIC_API PEP_STATUS _decrypt_message(
PEP_SESSION session,
@ -1883,11 +1681,6 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
size_t psize;
stringlist_t *_keylist = NULL;
// this will only ever be non-null if the message passed in is an
// outer message wrapping an inner one.
message* inner_message = NULL;
int inner_major_version = -1;
assert(session);
assert(src);
assert(dst);
@ -1947,6 +1740,7 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
char* slong = src->longmsg;
char* sform = src->longmsg_formatted;
bloblist_t* satt = src->attachments;
if ((!slong || slong[0] == '\0')
&& (!sform || sform[0] == '\0')) {
@ -2019,55 +1813,32 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
if (status != PEP_STATUS_OK)
goto pep_error;
int msg_major_version = pEpmessage_major_version(src);
/* Check for message version greater than 1 - if it is, it
means that this is an outer message containing an inner
message. The inner message has unencrypted headers, and
if ITS version == 1 (or is not present), it is the
innermost message.
If version > 1, the outer message is just one layer of
a multilayer message, and we only strip one layer
and return the next one.
If version == 1 (or none indicated), there are two possibilities:
either the inner message is a forwarded message, or it is the real message
which needs to be pulled up for evaluation.
This should, in fact, not be difficult to determine, as a legitimately
wrapped inner message will have a version 2 outer message, whereas
an attachment will have a version 1 (or unspecified) outer message.
*/
if (msg_major_version > 1) {
/* This is an outer message - get the inner message */
status = mime_decode_message(msg->attachments->value,
msg->attachments->size,
&inner_message);
if (status != PEP_STATUS_OK)
goto pep_error;
// FIXME: Deal with keys... we care about the outer and inner layers
// but how?
inner_major_version = pEpmessage_major_version(inner_message);
if (inner_major_version < 2) {
// raise message, combine address lists, etc
}
else {
// raise message, check against outer address lists
}
}
char* mlong = msg->longmsg;
char* mform = msg->longmsg_formatted;
bloblist_t* matt = msg->attachments;
if ((!mlong || mlong[0] == '\0') && (!mform || mform[0] == '\0')) {
pull_up_longmsg_attachment(msg);
if ((!mlong || mlong[0] == '\0')
&& (!mform || mform[0] == '\0')) {
if (matt) {
const char* inner_mime_type = matt->mime_type;
if (strcasecmp(inner_mime_type, "text/plain") == 0) {
free(mlong); /* in case of "" */
msg->longmsg = strndup(matt->value, matt->size);
bloblist_t* next_node = matt->next;
if (next_node) {
inner_mime_type = next_node->mime_type;
if (strcasecmp(inner_mime_type, "text/html") == 0) {
free(mform);
msg->longmsg_formatted = strndup(next_node->value, next_node->size);
}
}
}
else if (strcasecmp(inner_mime_type, "text/html") == 0) {
free(mform);
msg->longmsg_formatted = strndup(matt->value, matt->size);
}
}
if (msg->shortmsg) {
free(src->shortmsg);
src->shortmsg = strdup(msg->shortmsg);
@ -2097,8 +1868,6 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
}
}
}
/* Ok, so either way, detached sig or not, we should have decrypted and verified our PGP MIME encoded message if it was possible. */
break;
case PEP_enc_pieces:
@ -2195,57 +1964,48 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
case PEP_enc_PGP_MIME:
case PEP_enc_pieces:
case PEP_enc_PGP_MIME_Outlook1:
if (inner_message) {
/* we don't need to lift the subject etc, since the inner message has the real one */
if (inner_major_version < 2) {
// We need to verify that recips/sender are the same or combined or some such
}
status = copy_fields(msg, src);
if (status != PEP_STATUS_OK)
{
GOTO(pep_error);
}
else {
status = copy_fields(msg, src);
if (status != PEP_STATUS_OK)
{
GOTO(pep_error);
}
if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
{
char * shortmsg;
char * longmsg;
if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
{
char * shortmsg;
char * longmsg;
int r = separate_short_and_long(msg->longmsg, &shortmsg,
&longmsg);
if (r == -1)
goto enomem;
int r = separate_short_and_long(msg->longmsg, &shortmsg,
&longmsg);
if (r == -1)
goto enomem;
if (shortmsg == NULL) {
if (src->shortmsg == NULL)
shortmsg = strdup("");
else {
// FIXME: is msg->shortmsg always a copy of
// src->shortmsg already?
// if so, we need to change the logic so
// that in this case, we don't free msg->shortmsg
// and do this strdup, etc.
shortmsg = strdup(src->shortmsg);
}
if (shortmsg == NULL) {
if (src->shortmsg == NULL)
shortmsg = strdup("");
else {
// FIXME: is msg->shortmsg always a copy of
// src->shortmsg already?
// if so, we need to change the logic so
// that in this case, we don't free msg->shortmsg
// and do this strdup, etc.
shortmsg = strdup(src->shortmsg);
}
}
free(msg->shortmsg);
free(msg->longmsg);
free(msg->shortmsg);
free(msg->longmsg);
msg->shortmsg = shortmsg;
msg->longmsg = longmsg;
}
else {
msg->shortmsg = strdup(src->shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL)
goto enomem;
}
msg->shortmsg = shortmsg;
msg->longmsg = longmsg;
}
else {
msg->shortmsg = strdup(src->shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL)
goto enomem;
}
break;
default:
@ -2269,7 +2029,7 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
free_identity_list(_private_il);
}
if (decrypt_status == PEP_DECRYPTED){
if(decrypt_status == PEP_DECRYPTED){
// TODO optimize if import_attached_keys didn't import any key


+ 15
- 12
sync/Makefile View File

@ -1,35 +1,38 @@
# This file is under GNU General Public License 3.0
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
include ../Makefile.conf
.PHONY: all
all: .codegen
# Currently not in use, kept for historic reasons
skeleton: .actions
.codegen: .statemachines .actions
cp -f generated/*.* ../src
touch .codegen
touch $@
.actions: devicegroup.fsm gen_actions.ysl2 fsm.yml2 functions.ysl2
$(YML2PROC) $(YML_OPTS) -y gen_actions.ysl2 $< -o $@
$(YML2_PROC) $(YML2_OPTS) -y gen_actions.ysl2 $< -o $@
.statemachines: devicegroup.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
$(YML2PROC) $(YML_OPTS) -y gen_statemachine.ysl2 $< -o $@
$(YML2_PROC) $(YML2_OPTS) -y gen_statemachine.ysl2 $< -o $@
.PHONY: clean
clean:
rm -f *.xml *.xsl \
$(pathsub generated/%, ../src/% $(wildcard generated/*.*)) \
../generated/* ../skeletons/* .statemachines .actions *.dot *.svg
rm -f *.xml *.xsl *.dot *.svg \
$(patsubst generated/%,../src/%,$(wildcard generated/*.*)) \
../generated/* ../skeletons/* .statemachines .actions .codegen \
generated/Makefile.protocols
%.xml: %.fsm
yml2c $< -o $@
$(YML2_PATH)/yml2c $< -o $@
%.dot: devicegroup.fsm gen_dot.ysl2
$(YML2PROC) $(YML_OPTS) -y gen_dot.ysl2 $<
%.dot: gen_dot.ysl2 devicegroup.fsm
$(YML2_PROC) $(YML2_OPTS) -y $^
%.svg: %.dot
dot -Tsvg -o $@ $<

+ 51
- 40
test/Makefile View File

@ -1,59 +1,65 @@
# This file is under GNU General Public License 3.0
# Copyright 2017, pEp Foundation
# This file is part of pEpEngine
# This file may be used under the terms of the GNU General Public License version 3
# see LICENSE.txt
HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
HERE:=$(CURDIR)
include ../Makefile.conf
CC?=g++ -std=gnu++11 -pthread
CXX?=g++ -std=gnu++11 -pthread
LD?=$(CXX)
LDFLAGS?=-L$(HOME)/lib
LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
TARGET=pEpEngineTest
unexport GNUPGHOME
TEST_HOME=$(HERE)/test_home
TEST_GNUPGHOME=$(TEST_HOME)/.gnupg
LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
ifeq ($(BUILD_FOR),Linux)
LDLIBS+= -luuid
LDLIBS+= -luuid
endif
CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
# CXXFLAGS=-O3 -DNDEBUG
ifeq ("$(OPENPGP)","NETPGP")
LDLIBS+= -lnetpgp
ifeq ($(OPENPGP),NETPGP)
LDLIBS+= -lnetpgp
endif
TARGET=pEpEngineTest
ifeq ($(shell uname),Darwin)
LIBPATH=DYLD_LIBRARY_PATH
LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
else
LIBPATH=LD_LIBRARY_PATH
LLDB_BIN=lldb
endif
# Create a list of the extra library paths for the loader. I do not assume that the engine (and its dependencies) are installed for testing.
# Note that += can not be used here, as it changes the amount of whitespace
EXTRA_LIB_PATHS=../src:
ifdef ETPAN_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
endif
ifdef GPGME_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
endif
ifdef NETPGP_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
endif
# Remove trailing ':'
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME)
UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
.PHONY: all
all: $(TARGET) $(UNIT_TESTS)
.PHONY: clean
# don't delete .o files!
.PRECIOUS: %.o
unexport GNUPGHOME;
TEST_HOME=$(HERE)/test_home
TEST_GNUPGHOME=$(TEST_HOME)/.gnupg
ifeq ($(shell which gpg2), )
GPG_CMD = gpg
else
GPG_CMD = gpg2
endif
ifeq ($(shell uname), Darwin)
LIBPATH = DYLD_LIBRARY_PATH
LLDB_BIN = /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
else
LIBPATH = LD_LIBRARY_PATH
LLDB_BIN = lldb
endif
TEST_CMD_PFX = $(LIBPATH)=$(HOME)/lib:../src HOME=$(TEST_HOME)
.PHONY: test_home_
test_home_:
-gpgconf --kill gpg-agent
-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
@ -62,15 +68,17 @@ test_home_:
mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
.PHONY: clean
clean:
rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
test: pEpEngineTest test_home_
$(TEST_CMD_PFX) ./pEpEngineTest
.PHONY: test
test: $(TARGET) test_home_
$(TEST_CMD_PFX) ./$<
%_test : %_test.o test_util.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
%_run : % test_home_
$(TEST_CMD_PFX) ./$<
@ -84,7 +92,10 @@ test: pEpEngineTest test_home_
%_gdb : % test_home_
$(TEST_CMD_PFX) gdb ./$<
.PHONY: unit_tests
unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
# Installs the engine, not the test binaries
.PHONY: install
install:
make -C .. install
$(MAKE) -C .. install

Loading…
Cancel
Save