merged in default ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Mon, 20 Nov 2017 16:04:50 +0100
branchENGINE-289
changeset 2287026ab4dae779
parent 2191 e3d0dac4b1cf
parent 2286 15e51d4abd15
child 2288 8aee10631677
merged in default
src/sync.c
src/sync.h
src/sync_actions.c
src/sync_impl.c
src/sync_impl.h
sync/Makefile
sync/devicegroup.fsm
sync/fsm.yml2
sync/functions.ysl2
sync/gen_actions.ysl2
sync/gen_dot.ysl2
sync/gen_statemachine.ysl2
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
sync/generated/sync_send_actions.c
sync/skeletons/sync_actions.c
     1.1 --- a/.hgignore	Tue Oct 24 11:22:00 2017 +0200
     1.2 +++ b/.hgignore	Mon Nov 20 16:04:50 2017 +0100
     1.3 @@ -5,6 +5,7 @@
     1.4  .*xcuserdata/
     1.5  ^build/
     1.6  ^local.conf
     1.7 +^test_home/
     1.8  
     1.9  syntax: glob
    1.10  *.orig
     2.1 --- a/.hgtags	Tue Oct 24 11:22:00 2017 +0200
     2.2 +++ b/.hgtags	Mon Nov 20 16:04:50 2017 +0100
     2.3 @@ -3,3 +3,4 @@
     2.4  2b4d6c760ad771d9917cd6f0f96c4ab379d75d1d 0.7.0
     2.5  a1ba15c1ac041c780e52e759db6b77d116f29c72 0.8.0
     2.6  3efe9ded2561d3f6d406acbcbcee01b823cb4de8 for_Outlook-1.1.10
     2.7 +fa00137505b8528c77efe8df40963f5fef452cad 0.9.0 release
     3.1 --- a/Makefile	Tue Oct 24 11:22:00 2017 +0200
     3.2 +++ b/Makefile	Mon Nov 20 16:04:50 2017 +0100
     3.3 @@ -5,10 +5,22 @@
     3.4  
     3.5  HERE_REL := $(notdir $(CURDIR))
     3.6  
     3.7 -include Makefile.conf
     3.8 +include default.conf
     3.9 +
    3.10 +ifneq ($(wildcard local.conf),)
    3.11 +    $(info ================================================)
    3.12 +    $(info Overrides in \`local.conf\` are used.)
    3.13 +    $(info ================================================)
    3.14 +endif
    3.15 +
    3.16 +ifdef BUILD_CONFIG
    3.17 +    $(info ================================================)
    3.18 +    $(info Overrides in \`$(BUILD_CONFIG)\` are used.)
    3.19 +    $(info ================================================)
    3.20 +endif
    3.21  
    3.22  .PHONY: all
    3.23 -all: _override_info
    3.24 +all:
    3.25  	$(MAKE) -C asn.1 generate
    3.26  	$(MAKE) -C asn.1
    3.27  	$(MAKE) -C sync
    3.28 @@ -20,17 +32,18 @@
    3.29  	$(MAKE) -C asn.1 install
    3.30  
    3.31  .PHONY: uninstall
    3.32 -uninstall: _override_info
    3.33 +uninstall:
    3.34  	$(MAKE) -C src uninstall
    3.35  	$(MAKE) -C asn.1 uninstall
    3.36  
    3.37  .PHONY: clean
    3.38 -clean: _override_info
    3.39 +clean:
    3.40  	$(MAKE) -C src clean
    3.41  	$(MAKE) -C test clean
    3.42  	$(MAKE) -C db clean
    3.43  	$(MAKE) -C sync clean
    3.44  	$(MAKE) -C asn.1 clean
    3.45 +	rm -rf test_home
    3.46  
    3.47  .PHONY: test
    3.48  test: all
    3.49 @@ -46,24 +59,5 @@
    3.50  	cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 "$(HERE_REL)"
    3.51  
    3.52  .PHONY: db
    3.53 -db: _override_info
    3.54 +db:
    3.55  	$(MAKE) -C db db
    3.56 -
    3.57 -.PHONY: _override_info
    3.58 -_override_info: _local_conf_info _build_config_info
    3.59 -
    3.60 -.PHONY: _local_conf_info
    3.61 -_local_conf_info:
    3.62 -ifneq ($(wildcard local.conf),)
    3.63 -	@echo "================================================"
    3.64 -	@echo "Overrides in \`local.conf\` are used."
    3.65 -	@echo "================================================"
    3.66 -endif
    3.67 -
    3.68 -.PHONY: _build_config_info
    3.69 -_build_config_info:
    3.70 -ifdef BUILD_CONFIG
    3.71 -	@echo "================================================"
    3.72 -	@echo "Overrides in \`$(BUILD_CONFIG)\` are used."
    3.73 -	@echo "================================================"
    3.74 -endif
     4.1 --- a/Makefile.conf	Tue Oct 24 11:22:00 2017 +0200
     4.2 +++ b/Makefile.conf	Mon Nov 20 16:04:50 2017 +0100
     4.3 @@ -3,233 +3,107 @@
     4.4  # This file may be used under the terms of the GNU General Public License version 3
     4.5  # see LICENSE.txt
     4.6  
     4.7 -# This file gives an overview over all the parameters that can be easily customized for a build.
     4.8 -# There are three ways in which you can customize your build:
     4.9 -# 1) Edit the variable assignments in this file
    4.10 -# 2) Create `local.conf` and fill it with variable assignments.
    4.11 -#    These `local.conf` takes precedence over the assignments below.
    4.12 -# 3) Set the environment variable `BUILD_CONFIG` to an absolute path.
    4.13 -#    The variable assignments found at the path indicated by `BUILD_CONFIG` take precedence over the assignments below and the assignments in `local.conf`.
    4.14 -# If nothing is changed according to these 3 methods, a default configuration for your platform will be used for the build.
    4.15 -
    4.16 -HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
    4.17  
    4.18  ######### General #########
    4.19  # To use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
    4.20  # All the *_INC and *_LIB variables are command line flags, not paths.
    4.21  # Thus, all *_INC variables' values must start with "-I", and all *_LIB variables' values must start with "-L".
    4.22  
    4.23 -BUILD_ON:=$(shell uname)
    4.24 +#BUILD_ON:=$(shell uname)
    4.25  
    4.26  # This variable specifies the platform that the engine should be cross-compiled for.
    4.27 -BUILD_FOR=$(BUILD_ON)
    4.28 -
    4.29 -# Cross-compiling is currently not supported.
    4.30 -# Maybe you can hack something with `local.conf`.
    4.31 -ifneq ($(BUILD_ON),$(BUILD_FOR))
    4.32 -    $(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON).)
    4.33 -endif
    4.34 +#BUILD_FOR=$(BUILD_ON)
    4.35  
    4.36  # Installation path prefix for libraries and binaries, except for system.db
    4.37 -PREFIX=$(HOME)
    4.38 +#PREFIX=$(HOME)
    4.39  
    4.40  # Installation path for system.db
    4.41 -SYSTEM_DB=/usr/local/share/pEp/system.db
    4.42 +#SYSTEM_DB=/usr/local/share/pEp/system.db
    4.43  
    4.44  # Filename of the pEpEngine library
    4.45 -ifeq ($(BUILD_FOR),Linux)
    4.46 -    TARGET=libpEpEngine.so
    4.47 -else ifeq ($(BUILD_FOR),Darwin)
    4.48 -    TARGET=libpEpEngine.dylib
    4.49 -endif
    4.50 -
    4.51 -# If empty, create a release build.
    4.52 -# Otherwise, create a debug build.
    4.53 -# This variable is ineffective in your local.conf file.
    4.54 -DEBUG=YES
    4.55 -
    4.56 -# If empty, suppress compiler warnings.
    4.57 -# Otherwise, print warnings.
    4.58 -# This variable is ineffective in your local.conf file.
    4.59 -WARN=placeholder
    4.60 +#TARGET=libpEpEngine.so
    4.61  
    4.62  
    4.63  ######### C and C++ #########
    4.64 -TARGET_ARCH=
    4.65 +#TARGET_ARCH=
    4.66 +
    4.67  # The following two variables will be appended to.
    4.68  # You can thus not set them to a fixed value here.
    4.69 -ifeq ($(BUILD_FOR),Linux)
    4.70 -    LDFLAGS=
    4.71 -else ifeq ($(BUILD_FOR),Darwin)
    4.72 -    # "-bind_at_load" helps find symbol resolution errors faster
    4.73 -    LDFLAGS=-bind_at_load
    4.74 -endif
    4.75 +#LDFLAGS=
    4.76  
    4.77 -LDLIBS=
    4.78 +#LDLIBS=
    4.79  
    4.80  
    4.81  ######### C #########
    4.82 -ifeq ($(BUILD_FOR),Linux)
    4.83 -    CC=gcc -std=c99 -pthread
    4.84 -else ifeq ($(BUILD_FOR),Darwin)
    4.85 -    # clang issues a warning when "-pthread" is used for linking.
    4.86 -    # So, include it in CFLAGS, and not in CC
    4.87 -    CC=clang -std=c99
    4.88 -endif
    4.89 +#CC=
    4.90  
    4.91 -ifeq ($(BUILD_FOR),Linux)
    4.92 -    CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
    4.93 -else ifeq ($(BUILD_FOR),Darwin)
    4.94 -    CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
    4.95 -endif
    4.96 +#CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
    4.97  
    4.98 -CPPFLAGS=
    4.99 +#CPPFLAGS=
   4.100  
   4.101 -# The flag -DNDEBUG will always be removed from CFLAGS for compiling tests.
   4.102 -# The tests do not work properly, if compiled with -DNDEBUG
   4.103 -ifeq ($(BUILD_FOR),Linux)
   4.104 -    ifdef WARN
   4.105 -        CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
   4.106 -    else
   4.107 -        CFLAGS+= -w
   4.108 -    endif
   4.109 -    ifdef DEBUG
   4.110 -        CFLAGS+= -Og -ggdb -DDEBUG_ERRORSTACK
   4.111 -    else
   4.112 -        CFLAGS+= -O3 -DNDEBUG
   4.113 -    endif
   4.114 -else ifeq ($(BUILD_FOR),Darwin)
   4.115 -    ifdef WARN
   4.116 -        # FIXME Remove 'no-extended-offsetof' after ENGINE-236 is closed.
   4.117 -        CFLAGS+= -Wall -pedantic -Wno-extended-offsetof
   4.118 -    else
   4.119 -        CFLAGS+= -w
   4.120 -    endif
   4.121 -    ifdef DEBUG
   4.122 -        CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
   4.123 -    else
   4.124 -        CFLAGS+= -O3 -DNDEBUG
   4.125 -    endif
   4.126 -endif
   4.127 +#CFLAGS+= -w -O3 -DNDEBUG
   4.128  
   4.129  # Additional CFLAGS used for compiling ASN1C-generated code
   4.130 -ifeq ($(BUILD_FOR),Linux)
   4.131 -    # The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
   4.132 -    #   _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
   4.133 -    # otherwise printed during the compilation of every asn1c-generated C file.
   4.134 -    # It's a glibc specific warning, only present in few versions around ~2.19.
   4.135 -    # See https://lwn.net/Articles/590381/ for a discussion.
   4.136 -    CFLAGS_GENERATED=-D_DEFAULT_SOURCE
   4.137 -else ifeq ($(BUILD_FOR),Darwin)
   4.138 -    CFLAGS_GENERATED=
   4.139 -endif
   4.140 +#CFLAGS_GENERATED=-D_DEFAULT_SOURCE
   4.141  
   4.142  
   4.143  ######### C++ #########
   4.144 -ifeq ($(BUILD_FOR),Linux)
   4.145 -    CXX=g++ -std=gnu++11 -pthread
   4.146 -else ifeq ($(BUILD_FOR),Darwin)
   4.147 -    # clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
   4.148 -    CXX=clang -std=c++11
   4.149 -endif
   4.150 +#CXX=g++ -std=gnu++11 -pthread
   4.151  
   4.152 -# The flag -DNDEBUG will always be removed from CXXFLAGS for compiling tests.
   4.153 -# The tests do not work properly, if compiled with -DNDEBUG
   4.154 -ifeq ($(BUILD_FOR),Linux)
   4.155 -    CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
   4.156 -    ifdef WARN
   4.157 -        CXXFLAGS+=
   4.158 -    else
   4.159 -        CXXFLAGS+= -w
   4.160 -    endif
   4.161 -    ifdef DEBUG
   4.162 -        CXXFLAGS+= -Og -ggdb
   4.163 -    else
   4.164 -        CXXFLAGS+= -O3 -DNDEBUG
   4.165 -    endif
   4.166 -else ifeq ($(BUILD_FOR),Darwin)
   4.167 -    CXXFLAGS=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
   4.168 -    ifdef WARN
   4.169 -        CXXFLAGS+=
   4.170 -    else
   4.171 -        CXXFLAGS+= -w
   4.172 -    endif
   4.173 -    ifdef DEBUG
   4.174 -        CXXFLAGS+= -O0 -g
   4.175 -    else
   4.176 -        CXXFLAGS+= -O3 -DNDEBUG
   4.177 -    endif
   4.178 -endif
   4.179 +#CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC) -w -O3 -DNDEBUG
   4.180  
   4.181  
   4.182  ######### YML2 #########
   4.183 -YML2_PATH=$(HOME)/yml2
   4.184 +#YML2_PATH=$(HOME)/yml2
   4.185  
   4.186 -YML2_PROC=$(YML2_PATH)/yml2proc
   4.187 +#YML2_PROC=$(YML2_PATH)/yml2proc
   4.188  
   4.189 -YML2_OPTS=--encoding=utf8
   4.190 +#YML2_OPTS=--encoding=utf8
   4.191  
   4.192 -# YML_PATH is needed in the environment of every call to a program of the YML2 distribution
   4.193 -export YML_PATH=$(YML2_PATH)
   4.194  
   4.195  ######### asn1c #########
   4.196  # asn1c binary
   4.197 -ASN1C=asn1c
   4.198 +#ASN1C=asn1c
   4.199  
   4.200  # asn1c include search flag
   4.201 -ASN1C_INC=
   4.202  #ASN1C_INC=-I$(HOME)/include
   4.203  
   4.204  
   4.205  ######### libetpan #########
   4.206  # libetpan library search flag
   4.207 -ETPAN_LIB=-L$(PREFIX)/lib
   4.208 +#ETPAN_LIB=-L$(PREFIX)/lib
   4.209  
   4.210  # libetpan include search flag
   4.211 -ETPAN_INC=-I$(PREFIX)/include
   4.212 +#ETPAN_INC=-I$(PREFIX)/include
   4.213  
   4.214  
   4.215  ######### sqlite3 #########
   4.216  # If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
   4.217  # Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
   4.218 -SQLITE3_FROM_OS=placeholder
   4.219 +#SQLITE3_FROM_OS=placeholder
   4.220  
   4.221  
   4.222  ######### OpenPGP #########
   4.223  # Path of GPG binary
   4.224  # gpgconf is not available for old version of GPG, for example GPG 2.0.30. Override this variable, if you compile the engine for such an old version.
   4.225 -GPG_CMD:=$(shell gpgconf --list-components | awk -F: '/^gpg:/ { print $$3; exit 0; }')
   4.226 +#GPG_CMD:=$(shell gpgconf --list-components | awk -F: '/^gpg:/ { print $$3; exit 0; }')
   4.227  
   4.228  # Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
   4.229 -OPENPGP=GPG
   4.230 +#OPENPGP=GPG
   4.231  
   4.232  # Path of libGPGME binary
   4.233 -ifeq ($(BUILD_FOR),Linux)
   4.234 -    LIBGPGME=libgpgme.so.11
   4.235 -else ifeq ($(BUILD_FOR),Darwin)
   4.236 -    LIBGPGME=libgpgme.dylib
   4.237 -endif
   4.238 +#LIBGPGME=libgpgme.so.11
   4.239  
   4.240  # libGPGME library search flag
   4.241 -ifeq ($(BUILD_FOR),Linux)
   4.242 -    GPGME_LIB=
   4.243 -else ifeq ($(BUILD_FOR),Darwin)
   4.244 -    GPGME_LIB=-L$(HOME)/lib
   4.245 -endif
   4.246 +#GPGME_LIB=
   4.247  
   4.248  # libGPGME include search flag
   4.249 -ifeq ($(BUILD_FOR),Linux)
   4.250 -    GPGME_INC=
   4.251 -else ifeq ($(BUILD_FOR),Darwin)
   4.252 -    GPGME_INC=-I$(HOME)/include
   4.253 -endif
   4.254 +#GPGME_INC=
   4.255  
   4.256  # NETPGP library search flag
   4.257 -NETPGP_LIB=
   4.258  #NETPGP_LIB=-L$(PREFIX)/lib
   4.259  
   4.260  # libGPGME include search flag
   4.261 -NETPGP_INC=
   4.262  #NETPGP_INC=-I$(PREFIX)/include
   4.263  
   4.264  
   4.265 @@ -239,17 +113,4 @@
   4.266  # CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
   4.267  # Example:
   4.268  #    EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
   4.269 -EXTRA_MACROS=
   4.270 -
   4.271 -
   4.272 -######### Misc #########
   4.273 -# FIXME Maybe include these variables here.
   4.274 -# Check how they are used throughout the project before setting them here
   4.275 -#LLDB_BIN
   4.276 -
   4.277 -
   4.278 --include $(HERE)/local.conf
   4.279 -
   4.280 -ifdef BUILD_CONFIG
   4.281 -    -include $(BUILD_CONFIG)
   4.282 -endif
   4.283 +#EXTRA_MACROS=
     5.1 --- a/asn.1/Makefile	Tue Oct 24 11:22:00 2017 +0200
     5.2 +++ b/asn.1/Makefile	Mon Nov 20 16:04:50 2017 +0100
     5.3 @@ -3,7 +3,7 @@
     5.4  # This file may be used under the terms of the GNU General Public License version 3
     5.5  # see LICENSE.txt
     5.6  
     5.7 -include ../Makefile.conf
     5.8 +include ../default.conf
     5.9  
    5.10  ALL_SOURCE=$(wildcard *.c)
    5.11  ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
     6.1 --- a/build-windows/pEpEngine.vcxproj	Tue Oct 24 11:22:00 2017 +0200
     6.2 +++ b/build-windows/pEpEngine.vcxproj	Mon Nov 20 16:04:50 2017 +0100
     6.3 @@ -43,12 +43,12 @@
     6.4    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     6.5      <LinkIncremental>true</LinkIncremental>
     6.6      <RunCodeAnalysis>false</RunCodeAnalysis>
     6.7 -    <IncludePath>$(ProjectDir)\..\..\libetpan\build-windows\include;C:\Program Files %28x86%29\GNU\GnuPG\include;$(IncludePath);$(ProjectDir)\asn.1;%ASN1C%\share\asn1c</IncludePath>
     6.8 +	<IncludePath>$(ProjectDir)\..\..\libetpan\build-windows\include;C:\Program Files %28x86%29\GnuPG\include;$(IncludePath);$(ProjectDir)\asn.1;%ASN1C%\share\asn1c</IncludePath>
     6.9      <LibraryPath>$(ProjectDir)\..\..\libetpan\build-windows\Debug;$(LibraryPath)</LibraryPath>
    6.10    </PropertyGroup>
    6.11    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    6.12      <LinkIncremental>false</LinkIncremental>
    6.13 -    <IncludePath>$(ProjectDir)\..\..\libetpan\build-windows\include;C:\Program Files %28x86%29\GNU\GnuPG\include;$(IncludePath);$(ProjectDir)\asn.1;%ASN1C%\share\asn1c</IncludePath>
    6.14 +	<IncludePath>$(ProjectDir)\..\..\libetpan\build-windows\include;C:\Program Files %28x86%29\GnuPG\include;$(IncludePath);$(ProjectDir)\asn.1;%ASN1C%\share\asn1c</IncludePath>
    6.15      <LibraryPath>$(ProjectDir)\..\..\libetpan\build-windows\Release;$(LibraryPath)</LibraryPath>
    6.16    </PropertyGroup>
    6.17    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     7.1 --- a/db/Makefile	Tue Oct 24 11:22:00 2017 +0200
     7.2 +++ b/db/Makefile	Mon Nov 20 16:04:50 2017 +0100
     7.3 @@ -3,7 +3,7 @@
     7.4  # This file may be used under the terms of the GNU General Public License version 3
     7.5  # see LICENSE.txt
     7.6  
     7.7 -include ../Makefile.conf
     7.8 +include ../default.conf
     7.9  
    7.10  .PHONY: db
    7.11  db: system.db
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/default.conf	Mon Nov 20 16:04:50 2017 +0100
     8.3 @@ -0,0 +1,264 @@
     8.4 +# Copyright 2017, pEp Foundation
     8.5 +# This file is part of pEpEngine
     8.6 +# This file may be used under the terms of the GNU General Public License version 3
     8.7 +# see LICENSE.txt
     8.8 +
     8.9 +# This file sets all the make variables that allow you to customize a build.
    8.10 +# There are 4 ways in which you can customize your build:
    8.11 +# 1) Edit the variable assignments in this file (this is a tracked file, so your repository will be dirty)
    8.12 +# 2) Edit the variable assignments in `Makefile.conf` (which is a tracked file, so your repository will be dirty)
    8.13 +# 3) Create `local.conf` and fill it with variable assignments.
    8.14 +# 4) Set the environment variable `BUILD_CONFIG` to an absolute path.
    8.15 +#    The variable assignments found in the make file at the path indicated by `BUILD_CONFIG` will be evaluated.
    8.16 +# Customization options are applied in the order given above. Later variable assignments take precedence over earlier ones.
    8.17 +# It is possible to use multiple variants simultaniously.
    8.18 +# If nothing is changed according to these 4 methods, a default configuration for your platform (specified below) will be used for the build.
    8.19 +
    8.20 +
    8.21 +######### Header #########
    8.22 +HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
    8.23 +
    8.24 +
    8.25 +######### General #########
    8.26 +# To use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
    8.27 +# All the *_INC and *_LIB variables are command line flags, not paths.
    8.28 +# Thus, all *_INC variables' values must start with "-I", and all *_LIB variables' values must start with "-L".
    8.29 +
    8.30 +BUILD_ON:=$(shell uname)
    8.31 +
    8.32 +# This variable specifies the platform that the engine should be cross-compiled for.
    8.33 +BUILD_FOR=$(BUILD_ON)
    8.34 +
    8.35 +# Cross-compiling is currently not supported.
    8.36 +# Maybe you can hack something with `local.conf`.
    8.37 +ifneq ($(BUILD_ON),$(BUILD_FOR))
    8.38 +    $(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON).)
    8.39 +endif
    8.40 +
    8.41 +# Installation path prefix for libraries and binaries, except for system.db
    8.42 +PREFIX=$(HOME)
    8.43 +
    8.44 +# Installation path for system.db
    8.45 +SYSTEM_DB=/usr/local/share/pEp/system.db
    8.46 +
    8.47 +# Filename of the pEpEngine library
    8.48 +ifeq ($(BUILD_FOR),Linux)
    8.49 +    TARGET=libpEpEngine.so
    8.50 +else ifeq ($(BUILD_FOR),Darwin)
    8.51 +    TARGET=libpEpEngine.dylib
    8.52 +endif
    8.53 +
    8.54 +# If empty, create a release build.
    8.55 +# Otherwise, create a debug build.
    8.56 +# This variable is ineffective in your local.conf file.
    8.57 +DEBUG=YES
    8.58 +
    8.59 +# If empty, suppress compiler warnings.
    8.60 +# Otherwise, print warnings.
    8.61 +# This variable is ineffective in your local.conf file.
    8.62 +WARN=placeholder
    8.63 +
    8.64 +
    8.65 +######### C and C++ #########
    8.66 +TARGET_ARCH=
    8.67 +# The following two variables will be appended to.
    8.68 +# You can thus not set them to a fixed value here.
    8.69 +ifeq ($(BUILD_FOR),Linux)
    8.70 +    LDFLAGS=
    8.71 +else ifeq ($(BUILD_FOR),Darwin)
    8.72 +    # "-bind_at_load" helps find symbol resolution errors faster
    8.73 +    LDFLAGS=-bind_at_load
    8.74 +endif
    8.75 +
    8.76 +LDLIBS=
    8.77 +
    8.78 +
    8.79 +######### C #########
    8.80 +ifeq ($(BUILD_FOR),Linux)
    8.81 +    CC=gcc -std=c99 -pthread
    8.82 +else ifeq ($(BUILD_FOR),Darwin)
    8.83 +    # clang issues a warning when "-pthread" is used for linking.
    8.84 +    # So, include it in CFLAGS, and not in CC
    8.85 +    CC=clang -std=c99
    8.86 +endif
    8.87 +
    8.88 +ifeq ($(BUILD_FOR),Linux)
    8.89 +    CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
    8.90 +else ifeq ($(BUILD_FOR),Darwin)
    8.91 +    CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
    8.92 +endif
    8.93 +
    8.94 +CPPFLAGS=
    8.95 +
    8.96 +# The flag -DNDEBUG will always be removed from CFLAGS for compiling tests.
    8.97 +# The tests do not work properly, if compiled with -DNDEBUG
    8.98 +ifeq ($(BUILD_FOR),Linux)
    8.99 +    ifdef WARN
   8.100 +        CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
   8.101 +    else
   8.102 +        CFLAGS+= -w
   8.103 +    endif
   8.104 +    ifdef DEBUG
   8.105 +        CFLAGS+= -Og -ggdb -DDEBUG_ERRORSTACK
   8.106 +    else
   8.107 +        CFLAGS+= -O3 -DNDEBUG
   8.108 +    endif
   8.109 +else ifeq ($(BUILD_FOR),Darwin)
   8.110 +    ifdef WARN
   8.111 +        # FIXME Remove 'no-extended-offsetof' after ENGINE-236 is closed.
   8.112 +        CFLAGS+= -Wall -pedantic -Wno-extended-offsetof
   8.113 +    else
   8.114 +        CFLAGS+= -w
   8.115 +    endif
   8.116 +    ifdef DEBUG
   8.117 +        CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
   8.118 +    else
   8.119 +        CFLAGS+= -O3 -DNDEBUG
   8.120 +    endif
   8.121 +endif
   8.122 +
   8.123 +# Additional CFLAGS used for compiling ASN1C-generated code
   8.124 +ifeq ($(BUILD_FOR),Linux)
   8.125 +    # The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
   8.126 +    #   _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
   8.127 +    # otherwise printed during the compilation of every asn1c-generated C file.
   8.128 +    # It's a glibc specific warning, only present in few versions around ~2.19.
   8.129 +    # See https://lwn.net/Articles/590381/ for a discussion.
   8.130 +    CFLAGS_GENERATED=-D_DEFAULT_SOURCE
   8.131 +else ifeq ($(BUILD_FOR),Darwin)
   8.132 +    CFLAGS_GENERATED=
   8.133 +endif
   8.134 +
   8.135 +
   8.136 +######### C++ #########
   8.137 +ifeq ($(BUILD_FOR),Linux)
   8.138 +    CXX=g++ -std=gnu++11 -pthread
   8.139 +else ifeq ($(BUILD_FOR),Darwin)
   8.140 +    # clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
   8.141 +    CXX=clang -std=c++11
   8.142 +endif
   8.143 +
   8.144 +# The flag -DNDEBUG will always be removed from CXXFLAGS for compiling tests.
   8.145 +# The tests do not work properly, if compiled with -DNDEBUG
   8.146 +ifeq ($(BUILD_FOR),Linux)
   8.147 +    CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
   8.148 +    ifdef WARN
   8.149 +        CXXFLAGS+=
   8.150 +    else
   8.151 +        CXXFLAGS+= -w
   8.152 +    endif
   8.153 +    ifdef DEBUG
   8.154 +        CXXFLAGS+= -Og -ggdb
   8.155 +    else
   8.156 +        CXXFLAGS+= -O3 -DNDEBUG
   8.157 +    endif
   8.158 +else ifeq ($(BUILD_FOR),Darwin)
   8.159 +    CXXFLAGS=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
   8.160 +    ifdef WARN
   8.161 +        CXXFLAGS+=
   8.162 +    else
   8.163 +        CXXFLAGS+= -w
   8.164 +    endif
   8.165 +    ifdef DEBUG
   8.166 +        CXXFLAGS+= -O0 -g
   8.167 +    else
   8.168 +        CXXFLAGS+= -O3 -DNDEBUG
   8.169 +    endif
   8.170 +endif
   8.171 +
   8.172 +
   8.173 +######### YML2 #########
   8.174 +YML2_PATH=$(HOME)/yml2
   8.175 +
   8.176 +YML2_PROC=$(YML2_PATH)/yml2proc
   8.177 +
   8.178 +YML2_OPTS=--encoding=utf8
   8.179 +
   8.180 +
   8.181 +######### asn1c #########
   8.182 +# asn1c binary
   8.183 +ASN1C=asn1c
   8.184 +
   8.185 +# asn1c include search flag
   8.186 +ASN1C_INC=
   8.187 +#ASN1C_INC=-I$(HOME)/include
   8.188 +
   8.189 +
   8.190 +######### libetpan #########
   8.191 +# libetpan library search flag
   8.192 +ETPAN_LIB=-L$(PREFIX)/lib
   8.193 +
   8.194 +# libetpan include search flag
   8.195 +ETPAN_INC=-I$(PREFIX)/include
   8.196 +
   8.197 +
   8.198 +######### sqlite3 #########
   8.199 +# If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
   8.200 +# Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
   8.201 +SQLITE3_FROM_OS=placeholder
   8.202 +
   8.203 +
   8.204 +######### OpenPGP #########
   8.205 +# Path of GPG binary
   8.206 +# gpgconf is not available for old version of GPG, for example GPG 2.0.30. Override this variable, if you compile the engine for such an old version.
   8.207 +GPG_CMD:=$(shell gpgconf --list-components | awk -F: '/^gpg:/ { print $$3; exit 0; }')
   8.208 +
   8.209 +# Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
   8.210 +OPENPGP=GPG
   8.211 +
   8.212 +# Path of libGPGME binary
   8.213 +ifeq ($(BUILD_FOR),Linux)
   8.214 +    LIBGPGME=libgpgme.so.11
   8.215 +else ifeq ($(BUILD_FOR),Darwin)
   8.216 +    LIBGPGME=libgpgme.dylib
   8.217 +endif
   8.218 +
   8.219 +# libGPGME library search flag
   8.220 +ifeq ($(BUILD_FOR),Linux)
   8.221 +    GPGME_LIB=
   8.222 +else ifeq ($(BUILD_FOR),Darwin)
   8.223 +    GPGME_LIB=-L$(HOME)/lib
   8.224 +endif
   8.225 +
   8.226 +# libGPGME include search flag
   8.227 +ifeq ($(BUILD_FOR),Linux)
   8.228 +    GPGME_INC=
   8.229 +else ifeq ($(BUILD_FOR),Darwin)
   8.230 +    GPGME_INC=-I$(HOME)/include
   8.231 +endif
   8.232 +
   8.233 +# NETPGP library search flag
   8.234 +NETPGP_LIB=
   8.235 +#NETPGP_LIB=-L$(PREFIX)/lib
   8.236 +
   8.237 +# libGPGME include search flag
   8.238 +NETPGP_INC=
   8.239 +#NETPGP_INC=-I$(PREFIX)/include
   8.240 +
   8.241 +
   8.242 +######### Engine internals #########
   8.243 +# C macros (not environment variables) that can be overridden:
   8.244 +# DEFAULT_KEYSERVER - string with default keyserver
   8.245 +# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
   8.246 +# Example:
   8.247 +#    EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
   8.248 +EXTRA_MACROS=
   8.249 +
   8.250 +
   8.251 +######### Misc #########
   8.252 +# FIXME Maybe include these variables here.
   8.253 +# Check how they are used throughout the project before setting them here
   8.254 +#LLDB_BIN
   8.255 +
   8.256 +
   8.257 +######### Footer #########
   8.258 +include $(HERE)/Makefile.conf
   8.259 +
   8.260 +-include $(HERE)/local.conf
   8.261 +
   8.262 +ifdef BUILD_CONFIG
   8.263 +    include $(BUILD_CONFIG)
   8.264 +endif
   8.265 +
   8.266 +# YML_PATH is needed in the environment of every call to a program of the YML2 distribution
   8.267 +export YML_PATH=$(YML2_PATH)
     9.1 --- a/doc/build-debian.md	Tue Oct 24 11:22:00 2017 +0200
     9.2 +++ b/doc/build-debian.md	Mon Nov 20 16:04:50 2017 +0100
     9.3 @@ -64,30 +64,25 @@
     9.4  mkdir ~/code/pep-engine/build
     9.5  ~~~
     9.6  
     9.7 -Note: Everything PLATFORM_OVERRIDE-related is currenty outdated. Do not rely on the documentation here!
     9.8 +Edit the build configuration to your needs in `Makefile.conf`, or create a `local.conf` that sets any of the make variables documented in `Makefile.conf`. All the default values for the build configuration variables on each platform are documented in `default.conf`.
     9.9  
    9.10 -For an explanation of the mechanics of `PLATFORM_OVERRIDE`, see the inline comments in `Makefile.conf`.
    9.11 -In this guide, the platform-specific configuration will be called `local`.
    9.12 -The installation directory will be a subdirectory of the repository.
    9.13 -This is useful for testing only.
    9.14 +If a dependency is not found in your system's default include or library paths, you will have to specify the according paths in a make variable. Typically, this has to be done at least for YML2, libetpan and asn1c.
    9.15 +
    9.16 +For a more detailed explanation of the mechanics of these build configuration files, and overriding defaults, see the comments in `default.conf`.
    9.17 +
    9.18 +Below is a sample `./local.conf` file, for orientation.
    9.19  
    9.20  ~~~
    9.21 -export PLATFORM_OVERRIDE=local
    9.22 -~~~
    9.23 -
    9.24 -`./build-config/local.conf`:
    9.25 -
    9.26 -~~~
    9.27 -PREFIX=$(HOME)/code/pep-engine/build
    9.28 +PREFIX=$(HOME)/engine/build
    9.29  SYSTEM_DB=$(PREFIX)/share/pEp/system.db
    9.30  
    9.31 -YML2_PATH=$(HOME)/code/yml2
    9.32 +YML2_PATH=$(HOME)/yml2
    9.33  
    9.34 -ETPAN_LIB=-L$(HOME)/code/libetpan/build/lib
    9.35 -ETPAN_INC=-I$(HOME)/code/libetpan/build/include
    9.36 +ETPAN_LIB=-L$(HOME)/libetpan/build/lib
    9.37 +ETPAN_INC=-I$(HOME)/libetpan/build/include
    9.38  
    9.39 -ASN1C=$(HOME)/code/asn1c/build/bin/asn1c
    9.40 -ASN1C_INC=-I$(HOME)/code/asn1c/build/share
    9.41 +ASN1C=$(HOME)/asn1c/build/bin/asn1c
    9.42 +ASN1C_INC=-I$(HOME)/asn1c/build/share/asn1c
    9.43  ~~~
    9.44  
    9.45  The engine is built as follows:
    10.1 --- a/doc/build-macos.md	Tue Oct 24 11:22:00 2017 +0200
    10.2 +++ b/doc/build-macos.md	Mon Nov 20 16:04:50 2017 +0100
    10.3 @@ -76,21 +76,16 @@
    10.4  mkdir ~/code/pep-engine/build
    10.5  ~~~
    10.6  
    10.7 -Note: Everything PLATFORM_OVERRIDE-related is currenty outdated. Do not rely on the documentation here!
    10.8 +Edit the build configuration to your needs in `Makefile.conf`, or create a `local.conf` that sets any of the make variables documented in `Makefile.conf`. All the default values for the build configuration variables on each platform are documented in `default.conf`.
    10.9  
   10.10 -For an explanation of the mechanics of `PLATFORM_OVERRIDE`, see the inline comments in `Makefile.conf`.
   10.11 -In this guide, the platform-specific configuration will be called `local`.
   10.12 -The installation directory will be a subdirectory of the repository.
   10.13 -This is useful for testing only.
   10.14 +If a dependency is not found in your system's default include or library paths, you will have to specify the according paths in a make variable. Typically, this has to be done at least for YML2, and libetpan.
   10.15 +
   10.16 +For a more detailed explanation of the mechanics of these build configuration files, and overriding defaults, see the comments in `default.conf`.
   10.17 +
   10.18 +Below is a sample `./local.conf` file, for orientation.
   10.19  
   10.20  ~~~
   10.21 -export PLATFORM_OVERRIDE=local
   10.22 -~~~
   10.23 -
   10.24 -`./build-config/local.conf`:
   10.25 -
   10.26 -~~~
   10.27 -PREFIX=$(HOME)/code/pep-engine/build
   10.28 +PREFIX=$(HOME)/code/engine/build
   10.29  SYSTEM_DB=$(PREFIX)/share/pEp/system.db
   10.30  
   10.31  YML2_PATH=$(HOME)/code/yml2
   10.32 @@ -98,8 +93,8 @@
   10.33  ETPAN_LIB=-L$(HOME)/code/libetpan/build/lib
   10.34  ETPAN_INC=-I$(HOME)/code/libetpan/build/include
   10.35  
   10.36 -GPGME_LIB=-L$(HOME)/code/gpgme/build/lib
   10.37 -GPGME_INC=-I$(HOME)/code/gpgme/build/include
   10.38 +GPGME_LIB=-L$(HOME)/lib
   10.39 +GPGME_INC=-I$(HOME)/include
   10.40  ~~~
   10.41  
   10.42  The engine is built as follows:
    11.1 --- a/src/Makefile	Tue Oct 24 11:22:00 2017 +0200
    11.2 +++ b/src/Makefile	Mon Nov 20 16:04:50 2017 +0100
    11.3 @@ -3,7 +3,7 @@
    11.4  # This file may be used under the terms of the GNU General Public License version 3
    11.5  # see LICENSE.txt
    11.6  
    11.7 -include ../Makefile.conf
    11.8 +include ../default.conf
    11.9  
   11.10  CFLAGS+= $(ETPAN_INC) -I../asn.1 -DSYSTEM_DB=\"$(SYSTEM_DB)\" $(EXTRA_MACROS)
   11.11  LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -shared
    12.1 --- a/src/etpan_mime.c	Tue Oct 24 11:22:00 2017 +0200
    12.2 +++ b/src/etpan_mime.c	Mon Nov 20 16:04:50 2017 +0100
    12.3 @@ -284,7 +284,8 @@
    12.4          pEp_rid_list_t* resource,
    12.5          const char * mime_type,
    12.6          char * data,
    12.7 -        size_t length
    12.8 +        size_t length,
    12.9 +        bool transport_encode
   12.10      )
   12.11  {
   12.12      char * disposition_name = NULL;
   12.13 @@ -330,10 +331,14 @@
   12.14      if (content == NULL)
   12.15          goto enomem;
   12.16  
   12.17 -    encoding_type = MAILMIME_MECHANISM_BASE64;
   12.18 -    encoding = mailmime_mechanism_new(encoding_type, NULL);
   12.19 -    if (encoding == NULL)
   12.20 -        goto enomem;
   12.21 +    encoding = NULL;
   12.22 +
   12.23 +    if (transport_encode) {
   12.24 +        encoding_type = MAILMIME_MECHANISM_BASE64;
   12.25 +        encoding = mailmime_mechanism_new(encoding_type, NULL);
   12.26 +        if (encoding == NULL)
   12.27 +            goto enomem;
   12.28 +    }
   12.29  
   12.30      mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
   12.31              disposition, NULL);
    13.1 --- a/src/etpan_mime.h	Tue Oct 24 11:22:00 2017 +0200
    13.2 +++ b/src/etpan_mime.h	Mon Nov 20 16:04:50 2017 +0100
    13.3 @@ -29,7 +29,8 @@
    13.4          pEp_rid_list_t* resource,
    13.5          const char * mime_type,
    13.6          char * data,
    13.7 -        size_t length
    13.8 +        size_t length,
    13.9 +        bool transport_encode
   13.10      );
   13.11  
   13.12  struct mailmime * part_multiple_new(const char *type);
    14.1 --- a/src/keymanagement.c	Tue Oct 24 11:22:00 2017 +0200
    14.2 +++ b/src/keymanagement.c	Mon Nov 20 16:04:50 2017 +0100
    14.3 @@ -12,7 +12,6 @@
    14.4  #include "pEp_internal.h"
    14.5  #include "keymanagement.h"
    14.6  
    14.7 -#include "sync_fsm.h"
    14.8  #include "blacklist.h"
    14.9  
   14.10  #ifndef EMPTYSTR
   14.11 @@ -555,8 +554,6 @@
   14.12          }
   14.13      }
   14.14     
   14.15 -    bool new_key_generated = false;
   14.16 -
   14.17      if (EMPTYSTR(identity->fpr) || revoked)
   14.18      {
   14.19          if(!do_keygen){
   14.20 @@ -581,7 +578,6 @@
   14.21              return ADD_TO_LOG(status);
   14.22          }
   14.23  
   14.24 -        new_key_generated = true;
   14.25          
   14.26          if(revoked)
   14.27          {
   14.28 @@ -621,15 +617,6 @@
   14.29          return status;
   14.30      }
   14.31  
   14.32 -    if(new_key_generated)
   14.33 -    {
   14.34 -        // if a state machine for keysync is in place, inject notify
   14.35 -        status = inject_DeviceState_event(session, KeyGen, NULL, NULL);
   14.36 -        if (status == PEP_OUT_OF_MEMORY){
   14.37 -            return PEP_OUT_OF_MEMORY;
   14.38 -        }
   14.39 -    }
   14.40 -
   14.41      return ADD_TO_LOG(PEP_STATUS_OK);
   14.42  }
   14.43  
   14.44 @@ -850,7 +837,6 @@
   14.45          case SQLITE_ROW:
   14.46              count = sqlite3_column_int(session->own_key_is_listed, 0);
   14.47              *listed = count > 0;
   14.48 -            status = PEP_STATUS_OK;
   14.49              break;
   14.50              
   14.51          default:
    15.1 --- a/src/message_api.c	Tue Oct 24 11:22:00 2017 +0200
    15.2 +++ b/src/message_api.c	Mon Nov 20 16:04:50 2017 +0100
    15.3 @@ -6,7 +6,6 @@
    15.4  
    15.5  #include "platform.h"
    15.6  #include "mime.h"
    15.7 -#include "sync_fsm.h"
    15.8  
    15.9  #include <assert.h>
   15.10  #include <string.h>
   15.11 @@ -21,6 +20,63 @@
   15.12  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
   15.13  #endif
   15.14  
   15.15 +static bool is_a_pEpmessage(const message *msg)
   15.16 +{
   15.17 +    for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
   15.18 +        if (strcasecmp(i->value->key, "X-pEp-Version") == 0)
   15.19 +            return true;
   15.20 +    }
   15.21 +    return false;
   15.22 +}
   15.23 +
   15.24 +static bool is_wrapper(message* src) {
   15.25 +    bool retval = false;
   15.26 +    
   15.27 +    if (src) {
   15.28 +        unsigned char pepstr[] = PEP_SUBJ_STRING;
   15.29 +        if (is_a_pEpmessage(src) || (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0 ||
   15.30 +            _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0) ||
   15.31 +            (strcmp(src->shortmsg, "p=p") == 0)) {
   15.32 +            char* plaintext = src->longmsg;
   15.33 +            if (plaintext) {
   15.34 +                const char *line_end = strchr(plaintext, '\n');
   15.35 +
   15.36 +                if (line_end != NULL) {
   15.37 +                    size_t n = line_end - plaintext;
   15.38 +                    
   15.39 +                    char* copycat = calloc(n + 1, 1);
   15.40 +                    
   15.41 +                    if (copycat) {
   15.42 +                        strlcpy(copycat, plaintext, n+1);
   15.43 +                        
   15.44 +                        if (strstr(copycat, PEP_MSG_WRAP_KEY) && strstr(copycat, "OUTER"))
   15.45 +                            retval = true;
   15.46 +                        
   15.47 +                        free(copycat);
   15.48 +                    }
   15.49 +                }
   15.50 +            }
   15.51 +        }
   15.52 +    }
   15.53 +    return retval;
   15.54 +}
   15.55 +
   15.56 +
   15.57 +static stringpair_t* search_optfields(const message* msg, const char* key) {
   15.58 +    stringpair_list_t* opt_fields = msg->opt_fields;
   15.59 +    
   15.60 +    const stringpair_list_t* curr;
   15.61 +    
   15.62 +    for (curr = opt_fields; curr && curr->value; curr = curr->next) {
   15.63 +        if (curr->value->key) {
   15.64 +            if (strcasecmp(curr->value->key, key) == 0)
   15.65 +                return curr->value;
   15.66 +        }
   15.67 +    } 
   15.68 +    
   15.69 +    return NULL;
   15.70 +}
   15.71 +
   15.72  static char * keylist_to_string(const stringlist_t *keylist)
   15.73  {
   15.74      if (keylist) {
   15.75 @@ -134,12 +190,14 @@
   15.76  static void decorate_message(
   15.77      message *msg,
   15.78      PEP_rating rating,
   15.79 -    stringlist_t *keylist
   15.80 +    stringlist_t *keylist,
   15.81 +    bool add_version
   15.82      )
   15.83  {
   15.84      assert(msg);
   15.85  
   15.86 -    replace_opt_field(msg, "X-pEp-Version", PEP_VERSION);
   15.87 +    if (add_version)
   15.88 +        replace_opt_field(msg, "X-pEp-Version", PEP_VERSION);
   15.89  
   15.90      if (rating != PEP_rating_undefined)
   15.91          replace_opt_field(msg, "X-EncStatus", rating_to_string(rating));
   15.92 @@ -296,7 +354,11 @@
   15.93          }
   15.94      }
   15.95      free(msg->shortmsg);
   15.96 +#ifdef WIN32
   15.97 +    msg->shortmsg = strdup("pEp");
   15.98 +#else
   15.99      msg->shortmsg = strdup((char*)pepstr);
  15.100 +#endif    
  15.101      
  15.102      if (!msg->shortmsg)
  15.103          return PEP_OUT_OF_MEMORY;
  15.104 @@ -691,7 +753,7 @@
  15.105      return PEP_STATUS_OK;
  15.106  }
  15.107  
  15.108 -
  15.109 +// FIXME: error mem leakage
  15.110  static message* extract_minimal_envelope(const message* src, 
  15.111                                           PEP_msg_direction direct) {
  15.112                                                   
  15.113 @@ -701,35 +763,59 @@
  15.114          
  15.115      envelope->shortmsg = _pep_subj_copy();
  15.116      if (!envelope->shortmsg)
  15.117 -        return NULL;
  15.118 +        goto enomem;
  15.119  
  15.120      if (src->from) {
  15.121          envelope->from = identity_dup(src->from);
  15.122          if (!envelope->from)
  15.123 -            return NULL;
  15.124 +            goto enomem;
  15.125      }
  15.126  
  15.127      if (src->to) {
  15.128          envelope->to = identity_list_dup(src->to);
  15.129          if (!envelope->to)
  15.130 -            return NULL;
  15.131 +            goto enomem;
  15.132      }
  15.133  
  15.134      if (src->cc) {
  15.135          envelope->cc = identity_list_dup(src->cc);
  15.136          if (!envelope->cc)
  15.137 -            return NULL;
  15.138 +            goto enomem;
  15.139      }
  15.140  
  15.141      if (src->bcc) {
  15.142          envelope->bcc = identity_list_dup(src->bcc);
  15.143          if (!envelope->bcc)
  15.144 -            return NULL;
  15.145 +            goto enomem;
  15.146      }
  15.147  
  15.148 +    // For Outlook Force-Encryption
  15.149 +    // const char* pull_keys[] = {"pEp-auto-consume",
  15.150 +    //                            "pEp-force-protection",
  15.151 +    //                            "X-pEp-Never-Unsecure"};
  15.152 +    // int pull_keys_len = 3; // UPDATE WHEN MORE ADDED ABOVE
  15.153 +    // 
  15.154 +    // int i = 0;
  15.155 +    // stringpair_t* opt_add = NULL;    
  15.156 +    // for( ; i < pull_keys_len; i++) {        
  15.157 +    //     opt_add = search_optfields(src, pull_keys[i]);
  15.158 +    //     stringpair_list_t* add_ptr = NULL;
  15.159 +    //     if (opt_add) {
  15.160 +    //         add_ptr = stringpair_list_add(src->opt_fields, stringpair_dup(opt_add));
  15.161 +    //         if (!add_ptr)
  15.162 +    //             goto enomem;
  15.163 +    //     }
  15.164 +    //     opt_add = NULL;
  15.165 +    //     add_ptr = NULL;
  15.166 +    // }
  15.167 +        
  15.168      envelope->enc_format = src->enc_format;        
  15.169      
  15.170      return envelope;
  15.171 +    
  15.172 +enomem:
  15.173 +    free(envelope);
  15.174 +    return NULL;
  15.175  }
  15.176  
  15.177  static message * clone_to_empty_message(const message * src)
  15.178 @@ -775,10 +861,8 @@
  15.179          _envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
  15.180          status = generate_message_id(_envelope);
  15.181          
  15.182 -        if (status != PEP_STATUS_OK) {
  15.183 -            free(_envelope);
  15.184 -            return NULL;
  15.185 -        }
  15.186 +        if (status != PEP_STATUS_OK)
  15.187 +            goto enomem;
  15.188          
  15.189          attachment->longmsg = encapsulate_message_wrap_info("INNER", attachment->longmsg);
  15.190          _envelope->longmsg = encapsulate_message_wrap_info("OUTER", _envelope->longmsg);
  15.191 @@ -786,6 +870,19 @@
  15.192      else {
  15.193          _envelope->longmsg = encapsulate_message_wrap_info("TRANSPORT", _envelope->longmsg);
  15.194      }
  15.195 +    
  15.196 +    if (!attachment->id || attachment->id[0] == '\0') {
  15.197 +        free(attachment->id);
  15.198 +        if (!_envelope->id) {
  15.199 +            status = generate_message_id(_envelope);
  15.200 +        
  15.201 +            if (status != PEP_STATUS_OK)
  15.202 +                goto enomem;
  15.203 +        }
  15.204 +            
  15.205 +        attachment->id = strdup(_envelope->id);
  15.206 +    }
  15.207 +    
  15.208      char* message_text = NULL;
  15.209  
  15.210      /* prevent introduction of pEp in inner message */
  15.211 @@ -797,7 +894,7 @@
  15.212      }
  15.213              
  15.214      /* Turn message into a MIME-blob */
  15.215 -    status = mime_encode_message(attachment, false, &message_text);
  15.216 +    status = _mime_encode_message_internal(attachment, false, &message_text, true);
  15.217          
  15.218      if (status != PEP_STATUS_OK)
  15.219          goto enomem;
  15.220 @@ -814,9 +911,9 @@
  15.221      
  15.222  enomem:
  15.223      if (!envelope) {
  15.224 -        free(_envelope);
  15.225 -        return NULL;
  15.226 +        free_message(_envelope);
  15.227      }
  15.228 +    return NULL;    
  15.229  }
  15.230  
  15.231  static PEP_STATUS encrypt_PGP_MIME(
  15.232 @@ -848,7 +945,8 @@
  15.233      _src->longmsg_formatted = src->longmsg_formatted;
  15.234      _src->attachments = src->attachments;
  15.235      _src->enc_format = PEP_enc_none;
  15.236 -    status = mime_encode_message(_src, true, &mimetext);
  15.237 +    bool mime_encode = !is_wrapper(_src);
  15.238 +    status = _mime_encode_message_internal(_src, true, &mimetext, mime_encode);
  15.239      assert(status == PEP_STATUS_OK);
  15.240      if (status != PEP_STATUS_OK)
  15.241          goto pep_error;
  15.242 @@ -858,6 +956,7 @@
  15.243          free_ptext=0;
  15.244      }
  15.245      free(_src);
  15.246 +    _src = NULL;
  15.247      assert(mimetext);
  15.248      if (mimetext == NULL)
  15.249          goto pep_error;
  15.250 @@ -901,6 +1000,7 @@
  15.251  pep_error:
  15.252      if (free_ptext)
  15.253          free(ptext);
  15.254 +    free(_src);
  15.255      free(ctext);
  15.256      return status;
  15.257  }
  15.258 @@ -1433,7 +1533,7 @@
  15.259          if (!session->passive_mode && 
  15.260              !(flags & PEP_encrypt_flag_force_no_attached_key)) {
  15.261              attach_own_key(session, src);
  15.262 -            decorate_message(src, PEP_rating_undefined, NULL);
  15.263 +            decorate_message(src, PEP_rating_undefined, NULL, true);
  15.264          }
  15.265          return ADD_TO_LOG(PEP_UNENCRYPTED);
  15.266      }
  15.267 @@ -1496,7 +1596,7 @@
  15.268      }
  15.269  
  15.270      if (msg) {
  15.271 -        decorate_message(msg, PEP_rating_undefined, NULL);
  15.272 +        decorate_message(msg, PEP_rating_undefined, NULL, true);
  15.273          if (_src->id) {
  15.274              msg->id = strdup(_src->id);
  15.275              assert(msg->id);
  15.276 @@ -1639,17 +1739,6 @@
  15.277      return ADD_TO_LOG(status);
  15.278  }
  15.279  
  15.280 -static bool is_a_pEpmessage(const message *msg)
  15.281 -{
  15.282 -    for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
  15.283 -        if (strcasecmp(i->value->key, "X-pEp-Version") == 0)
  15.284 -            return true;
  15.285 -    }
  15.286 -    return false;
  15.287 -}
  15.288 -
  15.289 -// update comm_type to pEp_ct_pEp if needed
  15.290 -
  15.291  static PEP_STATUS _update_identity_for_incoming_message(
  15.292          PEP_SESSION session,
  15.293          const message *src
  15.294 @@ -1878,41 +1967,6 @@
  15.295      return status;
  15.296  }
  15.297  
  15.298 -static PEP_STATUS check_for_sync_msg(PEP_SESSION session, 
  15.299 -                                     message* src,
  15.300 -                                     PEP_rating* rating, 
  15.301 -                                     PEP_decrypt_flags_t* flags,
  15.302 -                                     stringlist_t** keylist) {
  15.303 -    assert(session);
  15.304 -    assert(src);
  15.305 -    assert(rating);
  15.306 -    assert(keylist);
  15.307 -    
  15.308 -    if (session->sync_session->inject_sync_msg){
  15.309 -        PEP_STATUS status = receive_DeviceState_msg(session, src, *rating, *keylist);
  15.310 -        if (status == PEP_MESSAGE_CONSUME ||
  15.311 -            status == PEP_MESSAGE_IGNORE) {
  15.312 -            *flags |= (status == PEP_MESSAGE_IGNORE) ?
  15.313 -                        PEP_decrypt_flag_ignore :
  15.314 -                        PEP_decrypt_flag_consume;
  15.315 -        }
  15.316 -        else if (status != PEP_STATUS_OK) {
  15.317 -            return ADD_TO_LOG(status);
  15.318 -        }
  15.319 -    }
  15.320 -    return PEP_STATUS_OK;
  15.321 -}
  15.322 -
  15.323 -static PEP_STATUS sync_if_no_key(PEP_STATUS decrypt_status, PEP_SESSION session) {
  15.324 -    if (decrypt_status == PEP_DECRYPT_NO_KEY) {
  15.325 -        PEP_STATUS sync_status = inject_DeviceState_event(session, CannotDecrypt, NULL, NULL);
  15.326 -        if (sync_status == PEP_OUT_OF_MEMORY){
  15.327 -            return PEP_OUT_OF_MEMORY;
  15.328 -        }
  15.329 -    }
  15.330 -    return PEP_STATUS_OK;
  15.331 -}
  15.332 -
  15.333  // FIXME: Do we need to remove the attachment? I think we do...
  15.334  static bool pull_up_attached_main_msg(message* src) {
  15.335      char* slong = src->longmsg;
  15.336 @@ -1946,6 +2000,8 @@
  15.337      return false;
  15.338  }
  15.339  
  15.340 +
  15.341 +
  15.342  static PEP_STATUS unencapsulate_hidden_fields(message* src, message* msg,
  15.343                                                char** msg_wrap_info) {
  15.344      if (!src)
  15.345 @@ -1958,7 +2014,6 @@
  15.346      if (change_source_in_place)
  15.347          msg = src;
  15.348          
  15.349 -//    const char* version_string = get_message_version_string(src);
  15.350      
  15.351      switch (src->enc_format) {
  15.352          case PEP_enc_PGP_MIME:
  15.353 @@ -1974,7 +2029,8 @@
  15.354                  
  15.355              // FIXME: This is a mess. Talk with VB about how far we go to identify
  15.356              if (is_a_pEpmessage(src) || (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0 ||
  15.357 -                _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0))
  15.358 +                _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0) ||
  15.359 +                (strcmp(src->shortmsg, "p=p") == 0))
  15.360              {
  15.361                  char * shortmsg = NULL;
  15.362                  char * longmsg = NULL;
  15.363 @@ -1994,7 +2050,8 @@
  15.364                  if (!(*msg_wrap_info || change_source_in_place)) {
  15.365                      if (!shortmsg || 
  15.366                          (src->shortmsg != NULL && strcmp(src->shortmsg, "pEp") != 0 &&
  15.367 -                         _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0)) {
  15.368 +                         _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0 &&
  15.369 +                        strcmp(src->shortmsg, "p=p") != 0)) {
  15.370                               
  15.371                          if (shortmsg != NULL)
  15.372                              free(shortmsg);                        
  15.373 @@ -2036,16 +2093,49 @@
  15.374  
  15.375  }
  15.376  
  15.377 +static PEP_STATUS get_crypto_text(message* src, char** crypto_text, size_t* text_size) {
  15.378 +                
  15.379 +    // this is only here because of how NOT_IMPLEMENTED works            
  15.380 +    PEP_STATUS status = PEP_STATUS_OK;
  15.381 +                    
  15.382 +    switch (src->enc_format) {
  15.383 +        case PEP_enc_PGP_MIME:
  15.384 +            *crypto_text = src->attachments->next->value;
  15.385 +            *text_size = src->attachments->next->size;
  15.386 +            break;
  15.387 +
  15.388 +        case PEP_enc_PGP_MIME_Outlook1:
  15.389 +            *crypto_text = src->attachments->value;
  15.390 +            *text_size = src->attachments->size;
  15.391 +            break;
  15.392 +
  15.393 +        case PEP_enc_pieces:
  15.394 +            *crypto_text = src->longmsg;
  15.395 +            *text_size = strlen(*crypto_text);
  15.396 +            break;
  15.397 +
  15.398 +        default:
  15.399 +            NOT_IMPLEMENTED
  15.400 +    }
  15.401 +    
  15.402 +    return status;
  15.403 +}
  15.404 +
  15.405 +
  15.406  static PEP_STATUS verify_decrypted(PEP_SESSION session,
  15.407 +                                   message* src,
  15.408                                     message* msg, 
  15.409 -                                   pEp_identity* sender,
  15.410                                     char* plaintext, 
  15.411                                     size_t plaintext_size,
  15.412                                     stringlist_t** keylist,
  15.413                                     PEP_STATUS* decrypt_status,
  15.414                                     PEP_cryptotech crypto) {
  15.415 +                                       
  15.416 +    pEp_identity* sender = src->from;
  15.417 +
  15.418      bloblist_t* detached_sig = NULL;
  15.419      PEP_STATUS status = _get_detached_signature(msg, &detached_sig);
  15.420 +    stringlist_t *verify_keylist = NULL;
  15.421      
  15.422      if (detached_sig) {
  15.423          char* dsig_text = detached_sig->value;
  15.424 @@ -2054,21 +2144,36 @@
  15.425          char* stext = NULL;
  15.426  
  15.427          status = _get_signed_text(plaintext, plaintext_size, &stext, &ssize);
  15.428 -        stringlist_t *verify_keylist = NULL;
  15.429  
  15.430          if (ssize > 0 && stext) {
  15.431              status = cryptotech[crypto].verify_text(session, stext,
  15.432                                                      ssize, dsig_text, dsig_size,
  15.433                                                      &verify_keylist);
  15.434 -
  15.435 -            if (status == PEP_VERIFIED || status == PEP_VERIFIED_AND_TRUSTED)
  15.436 -            {
  15.437 -                *decrypt_status = PEP_DECRYPTED_AND_VERIFIED;
  15.438 -            
  15.439 -                status = combine_keylists(session, &verify_keylist, keylist, sender);
  15.440 -            }
  15.441 +        }
  15.442 +        
  15.443 +        if (status == PEP_VERIFIED || status == PEP_VERIFIED_AND_TRUSTED)
  15.444 +        {
  15.445 +            *decrypt_status = PEP_DECRYPTED_AND_VERIFIED;
  15.446 +        
  15.447 +            status = combine_keylists(session, &verify_keylist, keylist, sender);
  15.448          }
  15.449      }
  15.450 +    else {
  15.451 +        size_t csize, psize;
  15.452 +        char* ctext;
  15.453 +        char* ptext;
  15.454 +        get_crypto_text(src, &ctext, &csize);
  15.455 +        // reverify - we may have imported a key in the meantime
  15.456 +        // status = cryptotech[crypto].verify_text(session, ctext,
  15.457 +        //                                         csize, NULL, 0,
  15.458 +        //                                         &verify_keylist);
  15.459 +        free_stringlist(*keylist);
  15.460 +        *decrypt_status = decrypt_and_verify(session, ctext, csize,
  15.461 +                                            NULL, 0,
  15.462 +                                            &ptext, &psize, keylist);
  15.463 +        return PEP_STATUS_OK;
  15.464 +    }
  15.465 +
  15.466      return status;
  15.467  }
  15.468  
  15.469 @@ -2167,34 +2272,6 @@
  15.470      return status;
  15.471  }
  15.472  
  15.473 -static PEP_STATUS get_crypto_text(message* src, char** crypto_text, size_t* text_size) {
  15.474 -                
  15.475 -    // this is only here because of how NOT_IMPLEMENTED works            
  15.476 -    PEP_STATUS status = PEP_STATUS_OK;
  15.477 -                    
  15.478 -    switch (src->enc_format) {
  15.479 -        case PEP_enc_PGP_MIME:
  15.480 -            *crypto_text = src->attachments->next->value;
  15.481 -            *text_size = src->attachments->next->size;
  15.482 -            break;
  15.483 -
  15.484 -        case PEP_enc_PGP_MIME_Outlook1:
  15.485 -            *crypto_text = src->attachments->value;
  15.486 -            *text_size = src->attachments->size;
  15.487 -            break;
  15.488 -
  15.489 -        case PEP_enc_pieces:
  15.490 -            *crypto_text = src->longmsg;
  15.491 -            *text_size = strlen(*crypto_text);
  15.492 -            break;
  15.493 -
  15.494 -        default:
  15.495 -            NOT_IMPLEMENTED
  15.496 -    }
  15.497 -    
  15.498 -    return status;
  15.499 -}
  15.500 -
  15.501  static PEP_STATUS import_priv_keys_from_decrypted_msg(PEP_SESSION session,
  15.502                                                        message* src, 
  15.503                                                        message* msg,
  15.504 @@ -2296,11 +2373,6 @@
  15.505  
  15.506          if (imported_keys)
  15.507              remove_attached_keys(src);
  15.508 -
  15.509 -        status = check_for_sync_msg(session, src, rating, flags, keylist);
  15.510 -        
  15.511 -        if (status != PEP_STATUS_OK)
  15.512 -            return ADD_TO_LOG(status);
  15.513                                      
  15.514          pull_up_attached_main_msg(src);
  15.515          
  15.516 @@ -2321,10 +2393,6 @@
  15.517  
  15.518      decrypt_status = status;
  15.519      
  15.520 -    /* inject appropriate sync message if we couldn't decrypt due to no key */
  15.521 -    if (sync_if_no_key(decrypt_status, session) == PEP_OUT_OF_MEMORY)
  15.522 -        goto pep_error;
  15.523 -
  15.524      bool imported_private_key_address = false;
  15.525  
  15.526      if (ptext) { 
  15.527 @@ -2357,7 +2425,7 @@
  15.528                          GOTO(pep_error);            
  15.529                                                                   
  15.530                      status = verify_decrypted(session,
  15.531 -                                              msg, src->from,
  15.532 +                                              src, msg,
  15.533                                                ptext, psize,
  15.534                                                &_keylist,
  15.535                                                &decrypt_status,
  15.536 @@ -2386,6 +2454,7 @@
  15.537  
  15.538          if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
  15.539              char* wrap_info = NULL;
  15.540 +            
  15.541              status = unencapsulate_hidden_fields(src, msg, &wrap_info);
  15.542  
  15.543  //            bool is_transport_wrapper = false;
  15.544 @@ -2426,6 +2495,11 @@
  15.545                                      if (wrap_info) {
  15.546                                          // useless check, but just in case we screw up?
  15.547                                          if (strcmp(wrap_info, "INNER") == 0) {
  15.548 +                                            if (status != PEP_STATUS_OK) {
  15.549 +                                                free_message(inner_message);
  15.550 +                                                GOTO(pep_error);
  15.551 +                                            }
  15.552 +                                                
  15.553                                              // THIS is our message
  15.554                                              // FIXME: free msg, but check references
  15.555                                              src = msg = inner_message;
  15.556 @@ -2470,7 +2544,9 @@
  15.557  
  15.558          if (status != PEP_STATUS_OK)
  15.559              GOTO(pep_error);
  15.560 -            
  15.561 +        
  15.562 +        /* We decrypted ok, hallelujah. */
  15.563 +        msg->enc_format = PEP_enc_none;    
  15.564      } 
  15.565      else {
  15.566          // We did not get a plaintext out of the decryption process.
  15.567 @@ -2498,18 +2574,11 @@
  15.568      if (msg) {
  15.569          
  15.570          /* add pEp-related status flags to header */
  15.571 -        decorate_message(msg, *rating, _keylist);
  15.572 +        decorate_message(msg, *rating, _keylist, false);
  15.573          
  15.574          if (imported_keys)
  15.575              remove_attached_keys(msg);
  15.576 -            
  15.577 -        if (*rating >= PEP_rating_reliable) { 
  15.578 -            status = check_for_sync_msg(session, src, rating, flags, &_keylist);
  15.579 -        
  15.580 -            if (status != PEP_STATUS_OK)
  15.581 -                goto pep_error;
  15.582 -        }
  15.583 -        
  15.584 +                    
  15.585          if (src->id && src != msg) {
  15.586              msg->id = strdup(src->id);
  15.587              assert(msg->id);
  15.588 @@ -3055,8 +3124,8 @@
  15.589          GOTO(pep_error);
  15.590      }
  15.591  
  15.592 -    dec_msg->enc_format = PEP_enc_none; // is this the right thing to do? FIXME
  15.593 -    status = mime_encode_message(dec_msg, false, mime_plaintext);
  15.594 +    // FIXME: test with att
  15.595 +    status = _mime_encode_message_internal(dec_msg, false, mime_plaintext, false);
  15.596  
  15.597      if (status == PEP_STATUS_OK)
  15.598      {
    16.1 --- a/src/mime.c	Tue Oct 24 11:22:00 2017 +0200
    16.2 +++ b/src/mime.c	Mon Nov 20 16:04:50 2017 +0100
    16.3 @@ -100,7 +100,8 @@
    16.4  
    16.5  static PEP_STATUS mime_attachment(
    16.6          bloblist_t *blob,
    16.7 -        struct mailmime **result
    16.8 +        struct mailmime **result,
    16.9 +        bool transport_encode
   16.10      )
   16.11  {
   16.12      PEP_STATUS status = PEP_STATUS_OK;
   16.13 @@ -121,7 +122,7 @@
   16.14          mime_type = blob->mime_type;
   16.15  
   16.16      pEp_rid_list_t* resource = parse_uri(blob->filename);
   16.17 -    mime = get_file_part(resource, mime_type, blob->value, blob->size);
   16.18 +    mime = get_file_part(resource, mime_type, blob->value, blob->size, transport_encode);
   16.19      free_rid_list(resource);
   16.20      
   16.21      assert(mime);
   16.22 @@ -144,7 +145,8 @@
   16.23          const char *plaintext,
   16.24          const char *htmltext,
   16.25          bloblist_t *attachments,
   16.26 -        struct mailmime **result
   16.27 +        struct mailmime **result,
   16.28 +        bool transport_encode
   16.29      )
   16.30  {
   16.31      PEP_STATUS status = PEP_STATUS_OK;
   16.32 @@ -166,8 +168,9 @@
   16.33  
   16.34      pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
   16.35      
   16.36 +    int encoding_type = (transport_encode ? MAILMIME_MECHANISM_QUOTED_PRINTABLE : 0);
   16.37      submime = get_text_part(NULL, "text/plain", plaintext, strlen(plaintext),
   16.38 -            MAILMIME_MECHANISM_QUOTED_PRINTABLE);
   16.39 +            encoding_type);
   16.40      free_rid_list(resource);
   16.41      resource = NULL;
   16.42      
   16.43 @@ -222,7 +225,7 @@
   16.44  
   16.45  //    resource = new_rid_node(PEP_RID_FILENAME, "msg.html");
   16.46      submime = get_text_part(NULL, "text/html", htmltext, strlen(htmltext),
   16.47 -            MAILMIME_MECHANISM_QUOTED_PRINTABLE);
   16.48 +            encoding_type);
   16.49      free_rid_list(resource);
   16.50      resource = NULL;
   16.51      
   16.52 @@ -243,7 +246,7 @@
   16.53      for (_a = attachments; _a != NULL; _a = _a->next) {
   16.54          if (_a->disposition != PEP_CONTENT_DISP_INLINE)
   16.55              continue;
   16.56 -        status = mime_attachment(_a, &submime);
   16.57 +        status = mime_attachment(_a, &submime, transport_encode);
   16.58          if (status != PEP_STATUS_OK)
   16.59              return PEP_UNKNOWN_ERROR; // FIXME
   16.60  
   16.61 @@ -273,6 +276,8 @@
   16.62      return status;
   16.63  }
   16.64  
   16.65 +
   16.66 +// FIXME: maybe need to add transport_encode field here
   16.67  static struct mailimf_mailbox * identity_to_mailbox(const pEp_identity *ident)
   16.68  {
   16.69      char *_username = NULL;
   16.70 @@ -384,17 +389,22 @@
   16.71      return NULL;
   16.72  }
   16.73  
   16.74 -static clist * stringlist_to_clist(stringlist_t *sl)
   16.75 +static clist * stringlist_to_clist(stringlist_t *sl, bool transport_encode)
   16.76  {
   16.77      clist * cl = clist_new();
   16.78      assert(cl);
   16.79      if (cl == NULL)
   16.80          return NULL;
   16.81  
   16.82 +    if (!sl || ((!sl->value || sl->value[0] == '\0') && sl->next == NULL))
   16.83 +        return cl;
   16.84 +        
   16.85      stringlist_t *_sl;
   16.86      for (_sl = sl; _sl; _sl = _sl->next) {
   16.87          int r;
   16.88 -        char * value = mailmime_encode_subject_header("utf-8", _sl->value, 0);
   16.89 +        char * value = (transport_encode ?
   16.90 +                        mailmime_encode_subject_header("utf-8", _sl->value, 0) :
   16.91 +                        strdup(_sl->value));
   16.92          assert(value);
   16.93          if (value == NULL) {
   16.94              clist_free(cl);
   16.95 @@ -412,14 +422,20 @@
   16.96      return cl;
   16.97  }
   16.98  
   16.99 -static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **result)
  16.100 +static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **result,
  16.101 +                               bool transport_encode)
  16.102  {
  16.103      PEP_STATUS status = PEP_STATUS_OK;
  16.104      struct mailimf_fields * fields = NULL;
  16.105      int r;
  16.106      clist * fields_list = NULL;
  16.107      unsigned char pepstr[] = PEP_SUBJ_STRING; // unsigned due to UTF-8 byte fun
  16.108 -    char *subject = msg->shortmsg ? msg->shortmsg : (char*)pepstr;
  16.109 +#ifdef WIN32
  16.110 +    char* altstr = "pEp";
  16.111 +#else
  16.112 +    char* altstr = (char*)pepstr;
  16.113 +#endif        
  16.114 +    char *subject = msg->shortmsg ? msg->shortmsg : altstr;
  16.115  
  16.116      assert(msg);
  16.117      assert(msg->from);
  16.118 @@ -487,7 +503,9 @@
  16.119      }
  16.120  
  16.121      /* if (subject) */ {
  16.122 -        char *_subject = mailmime_encode_subject_header("utf-8", subject, 1);
  16.123 +        char *_subject = (transport_encode ? 
  16.124 +                          mailmime_encode_subject_header("utf-8", subject, 1) :
  16.125 +                          strdup(subject));
  16.126          if (_subject == NULL)
  16.127              goto enomem;
  16.128  
  16.129 @@ -539,7 +557,7 @@
  16.130      }
  16.131  
  16.132      if (msg->in_reply_to) {
  16.133 -        clist *in_reply_to = stringlist_to_clist(msg->in_reply_to);
  16.134 +        clist *in_reply_to = stringlist_to_clist(msg->in_reply_to, transport_encode);
  16.135          if (in_reply_to == NULL)
  16.136              goto enomem;
  16.137  
  16.138 @@ -552,7 +570,7 @@
  16.139      }
  16.140  
  16.141      if (msg->references) {
  16.142 -        clist *references = stringlist_to_clist(msg->references);
  16.143 +        clist *references = stringlist_to_clist(msg->references, transport_encode);
  16.144          if (references == NULL)
  16.145              goto enomem;
  16.146  
  16.147 @@ -565,7 +583,7 @@
  16.148      }
  16.149  
  16.150      if (msg->keywords) {
  16.151 -        clist *keywords = stringlist_to_clist(msg->keywords);
  16.152 +        clist *keywords = stringlist_to_clist(msg->keywords, transport_encode);
  16.153          if (keywords == NULL)
  16.154              goto enomem;
  16.155  
  16.156 @@ -578,8 +596,9 @@
  16.157      }
  16.158  
  16.159      if (msg->comments) {
  16.160 -        char *comments = mailmime_encode_subject_header("utf-8", msg->comments,
  16.161 -                0);
  16.162 +        char *comments = (transport_encode ?
  16.163 +                          mailmime_encode_subject_header("utf-8", msg->comments, 0) :
  16.164 +                          strdup(msg->comments));
  16.165          if (comments == NULL)
  16.166              goto enomem;
  16.167  
  16.168 @@ -597,7 +616,9 @@
  16.169              char *key = _l->value->key;
  16.170              char *value = _l->value->value;
  16.171              if (key && value) {
  16.172 -                char *_value = mailmime_encode_subject_header("utf-8", value, 0);
  16.173 +                char *_value = (transport_encode ?
  16.174 +                                mailmime_encode_subject_header("utf-8", value, 0) :
  16.175 +                                strdup(value));
  16.176                  if (_value == NULL)
  16.177                      goto enomem;
  16.178  
  16.179 @@ -695,7 +716,8 @@
  16.180  static PEP_STATUS mime_encode_message_plain(
  16.181          const message *msg,
  16.182          bool omit_fields,
  16.183 -        struct mailmime **result
  16.184 +        struct mailmime **result,
  16.185 +        bool transport_encode
  16.186      )
  16.187  {
  16.188      struct mailmime * mime = NULL;
  16.189 @@ -717,7 +739,8 @@
  16.190          /* first, we need to strip out the inlined attachments to ensure this
  16.191             gets set up correctly */
  16.192             
  16.193 -        status = mime_html_text(plaintext, htmltext, msg->attachments, &mime);
  16.194 +        status = mime_html_text(plaintext, htmltext, msg->attachments, &mime,
  16.195 +                                transport_encode);
  16.196                  
  16.197          if (status != PEP_STATUS_OK)
  16.198              goto pep_error;
  16.199 @@ -726,13 +749,15 @@
  16.200          pEp_rid_list_t* resource = NULL;
  16.201          if (is_PGP_message_text(plaintext)) {
  16.202              resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
  16.203 +            int encoding_type = (transport_encode ? MAILMIME_MECHANISM_7BIT : 0);
  16.204              mime = get_text_part(resource, "application/octet-stream", plaintext,
  16.205 -                    strlen(plaintext), MAILMIME_MECHANISM_7BIT);
  16.206 +                    strlen(plaintext), encoding_type);
  16.207          }
  16.208          else {
  16.209              resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
  16.210 +            int encoding_type = (transport_encode ? MAILMIME_MECHANISM_QUOTED_PRINTABLE : 0);
  16.211              mime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
  16.212 -                    MAILMIME_MECHANISM_QUOTED_PRINTABLE);
  16.213 +                    encoding_type);
  16.214          }
  16.215          free_rid_list(resource);
  16.216          
  16.217 @@ -776,7 +801,7 @@
  16.218              if (_a->disposition == PEP_CONTENT_DISP_INLINE)
  16.219                  continue;
  16.220  
  16.221 -            status = mime_attachment(_a, &submime);
  16.222 +            status = mime_attachment(_a, &submime, transport_encode);
  16.223              if (status != PEP_STATUS_OK)
  16.224                  goto pep_error;
  16.225  
  16.226 @@ -892,6 +917,16 @@
  16.227          char **mimetext
  16.228      )
  16.229  {
  16.230 +    return _mime_encode_message_internal(msg, omit_fields, mimetext, true);
  16.231 +}
  16.232 +
  16.233 +PEP_STATUS _mime_encode_message_internal(
  16.234 +        const message * msg,
  16.235 +        bool omit_fields,
  16.236 +        char **mimetext,
  16.237 +        bool transport_encode
  16.238 +    )
  16.239 +{
  16.240      PEP_STATUS status = PEP_STATUS_OK;
  16.241      struct mailmime * msg_mime = NULL;
  16.242      struct mailmime * mime = NULL;
  16.243 @@ -909,11 +944,11 @@
  16.244  
  16.245      switch (msg->enc_format) {
  16.246          case PEP_enc_none:
  16.247 -            status = mime_encode_message_plain(msg, omit_fields, &mime);
  16.248 +            status = mime_encode_message_plain(msg, omit_fields, &mime, transport_encode);
  16.249              break;
  16.250  
  16.251          case PEP_enc_pieces:
  16.252 -            status = mime_encode_message_plain(msg, omit_fields, &mime);
  16.253 +            status = mime_encode_message_plain(msg, omit_fields, &mime, transport_encode);
  16.254              break;
  16.255  
  16.256          case PEP_enc_S_MIME:
  16.257 @@ -946,7 +981,7 @@
  16.258      mime = NULL;
  16.259  
  16.260      if (!omit_fields) {
  16.261 -        status = build_fields(msg, &fields);
  16.262 +        status = build_fields(msg, &fields, transport_encode);
  16.263          if (status != PEP_STATUS_OK)
  16.264              goto pep_error;
  16.265  
    17.1 --- a/src/mime.h	Tue Oct 24 11:22:00 2017 +0200
    17.2 +++ b/src/mime.h	Mon Nov 20 16:04:50 2017 +0100
    17.3 @@ -78,6 +78,15 @@
    17.4          message **msg
    17.5      );
    17.6  
    17.7 +/* sometimes we don't want to transport encode */
    17.8 +PEP_STATUS _mime_encode_message_internal(
    17.9 +        const message * msg,
   17.10 +        bool omit_fields,
   17.11 +        char **mimetext,
   17.12 +        bool transport_encode
   17.13 +    );
   17.14 +
   17.15 +
   17.16  #ifdef __cplusplus
   17.17  }
   17.18  #endif
    18.1 --- a/src/pEpEngine.c	Tue Oct 24 11:22:00 2017 +0200
    18.2 +++ b/src/pEpEngine.c	Mon Nov 20 16:04:50 2017 +0100
    18.3 @@ -6,7 +6,6 @@
    18.4  #include "cryptotech.h"
    18.5  #include "transport.h"
    18.6  #include "blacklist.h"
    18.7 -#include "sync_fsm.h"
    18.8  
    18.9  #include <time.h>
   18.10  #include <stdlib.h>
   18.11 @@ -826,8 +825,6 @@
   18.12          out_last = true;
   18.13  
   18.14      if (session) {
   18.15 -        if (session->sync_state != DeviceState_state_NONE)
   18.16 -            unregister_sync_callbacks(session);
   18.17  
   18.18          if (session->db) {
   18.19              if (session->log)
    19.1 --- a/src/pEp_internal.h	Tue Oct 24 11:22:00 2017 +0200
    19.2 +++ b/src/pEp_internal.h	Mon Nov 20 16:04:50 2017 +0100
    19.3 @@ -359,10 +359,14 @@
    19.4  
    19.5  // This is just a horrible example of C type madness. UTF-8 made me do it.
    19.6  static inline char* _pep_subj_copy() {
    19.7 +#ifndef WIN32
    19.8      unsigned char pepstr[] = PEP_SUBJ_STRING;
    19.9      void* retval = calloc(1, sizeof(unsigned char)*PEP_SUBJ_BYTELEN + 1);
   19.10      memcpy(retval, pepstr, PEP_SUBJ_BYTELEN);
   19.11      return (char*)retval;
   19.12 +#else
   19.13 +    return strdup("pEp");
   19.14 +#endif
   19.15  }
   19.16  
   19.17  // These are globals used in generating message IDs and should only be
    20.1 --- a/src/platform_windows.cpp	Tue Oct 24 11:22:00 2017 +0200
    20.2 +++ b/src/platform_windows.cpp	Mon Nov 20 16:04:50 2017 +0100
    20.3 @@ -18,6 +18,7 @@
    20.4  #include <stdexcept>
    20.5  #include "platform_windows.h"
    20.6  #include <fcntl.h>
    20.7 +#include <tchar.h>
    20.8  #include <sys\stat.h>
    20.9  
   20.10  #ifndef WC_ERR_INVALID_CHARS
   20.11 @@ -141,12 +142,12 @@
   20.12  
   20.13  	// Look up GnuPG installation in current user scope
   20.14  	bool result = readRegistryString(HKEY_CURRENT_USER,
   20.15 -		TEXT("SOFTWARE\\GNU\\GnuPG"), TEXT("Install Directory"), path,
   20.16 +		TEXT("SOFTWARE\\GnuPG"), TEXT("Install Directory"), path,
   20.17  		PATH_BUF_SIZE, NULL);
   20.18  	// If not found in current user, look up in local machine
   20.19  	if (!result)
   20.20  		result = readRegistryString(HKEY_LOCAL_MACHINE,
   20.21 -			TEXT("SOFTWARE\\GNU\\GnuPG"), TEXT("Install Directory"), path,
   20.22 +			TEXT("SOFTWARE\\GnuPG"), TEXT("Install Directory"), path,
   20.23  			PATH_BUF_SIZE, NULL);
   20.24  	assert(result);
   20.25  	if (!result)
   20.26 @@ -159,6 +160,21 @@
   20.27          return NULL;
   20.28  
   20.29  	HMODULE module = LoadLibrary(utf16_string(filename).c_str());
   20.30 +
   20.31 +    if (module == NULL) {
   20.32 +        SetDllDirectory(NULL);
   20.33 +                    
   20.34 +		_tcscat_s(path, TEXT("\\bin"));
   20.35 +        
   20.36 +        SetDllDirectory(TEXT(""));
   20.37 +        _result = SetDllDirectory(path);
   20.38 +        assert(_result != 0);
   20.39 +        if (_result == 0)
   20.40 +            return NULL;
   20.41 +
   20.42 +    	module = LoadLibrary(utf16_string(filename).c_str());
   20.43 +    }
   20.44 +    
   20.45      SetDllDirectory(NULL);
   20.46  	if (module == NULL)
   20.47  		return NULL;
    21.1 --- a/sync/Makefile	Tue Oct 24 11:22:00 2017 +0200
    21.2 +++ b/sync/Makefile	Mon Nov 20 16:04:50 2017 +0100
    21.3 @@ -3,7 +3,7 @@
    21.4  # This file may be used under the terms of the GNU General Public License version 3
    21.5  # see LICENSE.txt
    21.6  
    21.7 -include ../Makefile.conf
    21.8 +include ../default.conf
    21.9  
   21.10  .PHONY: all
   21.11  all: .codegen
    22.1 --- a/test/Makefile	Tue Oct 24 11:22:00 2017 +0200
    22.2 +++ b/test/Makefile	Mon Nov 20 16:04:50 2017 +0100
    22.3 @@ -5,7 +5,7 @@
    22.4  
    22.5  HERE:=$(CURDIR)
    22.6  
    22.7 -include ../Makefile.conf
    22.8 +include ../default.conf
    22.9  
   22.10  TARGET=pEpEngineTest
   22.11  
   22.12 @@ -94,7 +94,7 @@
   22.13  	$(TEST_CMD_PFX) ./$<
   22.14  
   22.15  %_test : %_test.o test_util.o
   22.16 -	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
   22.17 +	$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
   22.18  
   22.19  %_run : % test_home_
   22.20  	$(TEST_CMD_PFX) ./$<
    23.1 --- a/test/test_keys/priv/pep-test-carol-0x42A85A42_priv.asc	Tue Oct 24 11:22:00 2017 +0200
    23.2 +++ b/test/test_keys/priv/pep-test-carol-0x42A85A42_priv.asc	Mon Nov 20 16:04:50 2017 +0100
    23.3 @@ -20,38 +20,38 @@
    23.4  B+ooj3I+sq29km3CoYHzZZLc80pnYeTBB7k1piGJ9tK3uLlT5B/uXnSAi1XpjWXV
    23.5  xqht1Lqq1Y2Z7zAyHFz57QtjZ9YziMRt9+x1ul2wgtIbUcIy6YePhoNDaBBuOxYE
    23.6  gwvcjkfMrA93Q5q0QXBFcCBUZXN0IENhcm9sIChUZXN0IERvIE5vdCBVc2UpIDxw
    23.7 -ZXAtdGVzdC1jYXJvbEBwZXAtcHJvamVjdC5vcmc+iQE/BBMBCAApBQJYHG/IAhsD
    23.8 -BQkB4TOABwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQh73f+0KoWkKhqgf9
    23.9 -GYC5HC4ndpauSw71xQQD0Y52zuh4MSWpd6N/ck5IptzBcyjIIhwZ+CL1oVnCKSOw
   23.10 -w1MrsEaTXsgqShayXrbxqNr7ZotzLtGWePRF9SRoWZ4KMkpKDZof73osa0MP8Nf1
   23.11 -wN6hX+OYJzPxWpyG57NJ4yJbEDkEgvFMFyPcGbisqhi/Nueps3JkNFwu0baq4+Cv
   23.12 -nV+ovvzfrheVf4Tctt/eP6dp/8151sa97+FvZKG4pbvcapsxUr0JE/442UvfwZS4
   23.13 -7knPV4pBTk4anXQvfHlBA/t+gdeHsadVtsrdtbfcYUyiU6zIadgU0fBcoUBSjIM/
   23.14 -dejimlVMKEYlyiPOpVUx6p0DmARYHG/IAQgAxPlSwgYXs+lTvVGjyfq+X9wV1/w/
   23.15 -GWpPwZaUIGPP7YD6aMAu7Va/QELc3tvmx1Cyrpr3ChGXn4VuAQu9o71ILAhTQFLt
   23.16 -VqvemhDN2AUrQTecsJNiL8gbGQeiU4NXTiKSl8WxMTvEkRnSk8fWsRypIrm7fb36
   23.17 -+WVl/DBhF2xHyfU3Og5TQFVPeCv6ZSoAxhGq8ZqTMXpqCc4nuELId2kkwQDd+Gqb
   23.18 -rNco5sA1Wb1u7Vz30JQJXVKSkb01sOvMzNLYXdsX70kNGRTQu/8VQ20Bujb3HX0S
   23.19 -UzGEhNnuNrIOEwG1ht8Tr8UsSGdW7XNkdmbcpclrXSwcGzk8MeQRL8suPwARAQAB
   23.20 -AAf/YdF3WcdwyfXbki8S6eFN3YkMiABKzbJP/VFsKlGnFslwkcivBUqJG76YtUv7
   23.21 -ZYwb0D5A5I0sARpgMMDF4qTDTKqtvUnxd5NOrrAdqWOXwYF+nOn0Xso/OsThxht5
   23.22 -peHhbuHMRyjpSy3Jt34MjlQvYoFeLOnF00iZxw23icxKMm5nf62AcHyxJfW4lsSO
   23.23 -tOq46Y5d8eubqD01MwVAVad+s5Zmo7gWeR3TZK/uuiTZLTHTX37AVr2w+vgWYai7
   23.24 -uXoDQ6cVPxoFuFAajBjfMLLHJRZiyoW3OQU5NalEcnCZqcwAO4beiVuMOGFm+vym
   23.25 -IF9w8VMwJi9dBAmF4sbOOX0E8QQA3+10z7Q9XrzIhv4S54YpToorBJ+KDR02CP/L
   23.26 -bwcrpgll8GqqiVtTTHnnKkBFSWh+TT1UGtm0upy3qwlkr8wQFIi5TQhJOTh8/2+1
   23.27 -dVZhDc4MgU+yEVh/cRZ0DAvWzFqQ2d1WeB5lBXJa9zeuLP5k3V+WCWUYfh4y+Ks1
   23.28 -ig/iGFsEAOEvlS/O4YMP4D6+yOatPyM/wCthVPQ7Uu/aud4YgaxAagA97Cpo483O
   23.29 -d7NxSU2iW8564WrsZ4ZOFeBIjCb5ou8k63rn4tPwBvBNqSsPN0dhLljJps62Chum
   23.30 -4ubHcLzFD2qaZCQx4l2FCJ552glZ+sghBqVuVbIxQ8pj/PktIYbtBACY86nXYTOF
   23.31 -V3iMBn4IQsvki2ICHvZMD5w+XWyGoAo4tJ3QHCT4L6B+SqchOgQ5Tk22AZ6gsi/J
   23.32 -OojaZALwEOCYMF6K+LUZRtSx2hWDIyOWAC6Q2DoOxZBwyrNr8p9hmD4MYEbVemVZ
   23.33 -ECLs2ir1OfRZ32aX+G/77yy5yVlNv5H4vznliQElBBgBCAAPBQJYHG/IAhsMBQkB
   23.34 -4TOAAAoJEIe93/tCqFpCK38IAJqmjL+y86gt2fSi1Pp/APOsYE6PtD808V7LqHoq
   23.35 -5Nz819EgkseEuDlwL83cUCb+1T+foLavrrrceufrWSRnsORZtLUcmAu/in4mO94l
   23.36 -f3cJP0Ky4kx6RD972Ow7YuhQh1jig6f/hLXHiPpt146B4vaGH5rPIfhlCZ4S1nyd
   23.37 -1FAZkF0FBTL/lNKhM5ZUm4KUWpxyUd8r/U6qR+1QDKXJL13IhCwHPvcJZoJ7vcah
   23.38 -0hprcdGmHgiw2g5HwnZm2Mks4QKIGzth5Cn84v91DW0WCBLQXJ4k+4lZjMSqYftb
   23.39 -JDFeqQYg12L75zQRz7H/dtWNuM3LmGtr54zGxuSwCKsxVqw=
   23.40 -=fJqj
   23.41 +ZXAtdGVzdC1jYXJvbEBwZXAtcHJvamVjdC5vcmc+iQE5BBMBCAAjAhsDBwsJCAcD
   23.42 +AgEGFQgCCQoLBBYCAwECHgECF4AFAloAN58ACgkQh73f+0KoWkKcawf/e0GXipLg
   23.43 +zxO2S7g1YLZqfdA6Wwp6J3X6TYaQSgm7K7Jq52pDzRlXEg51DM4n8V287PdW51bW
   23.44 +LodepDe5UhOzBtFFcjo9/9nMiMWRQY8yB/Iwz+qazkrem5Ula3g6Gs59Ti/KQ2pS
   23.45 +7SjJMFgvRJN2lHIWjct1wMNnIY9RZR6j0lsF0F9hqqbbgQCCZsTsxpXnzXbigM0k
   23.46 +BH91KhErpaqpd9jo3lNT6c7ZsgmJgTGl7EiS/eY/mei0R/uavtmYuwOhkJlLVABF
   23.47 +VQkQayXHdxRLe1Ktmagrhu77GlNJGNGNAS9CkXM2P8RqSfmn59jCUe6dJcwlzv8N
   23.48 +mDDjTR59CLkEvp0DmARYHG/IAQgAxPlSwgYXs+lTvVGjyfq+X9wV1/w/GWpPwZaU
   23.49 +IGPP7YD6aMAu7Va/QELc3tvmx1Cyrpr3ChGXn4VuAQu9o71ILAhTQFLtVqvemhDN
   23.50 +2AUrQTecsJNiL8gbGQeiU4NXTiKSl8WxMTvEkRnSk8fWsRypIrm7fb36+WVl/DBh
   23.51 +F2xHyfU3Og5TQFVPeCv6ZSoAxhGq8ZqTMXpqCc4nuELId2kkwQDd+GqbrNco5sA1
   23.52 +Wb1u7Vz30JQJXVKSkb01sOvMzNLYXdsX70kNGRTQu/8VQ20Bujb3HX0SUzGEhNnu
   23.53 +NrIOEwG1ht8Tr8UsSGdW7XNkdmbcpclrXSwcGzk8MeQRL8suPwARAQABAAf/YdF3
   23.54 +WcdwyfXbki8S6eFN3YkMiABKzbJP/VFsKlGnFslwkcivBUqJG76YtUv7ZYwb0D5A
   23.55 +5I0sARpgMMDF4qTDTKqtvUnxd5NOrrAdqWOXwYF+nOn0Xso/OsThxht5peHhbuHM
   23.56 +RyjpSy3Jt34MjlQvYoFeLOnF00iZxw23icxKMm5nf62AcHyxJfW4lsSOtOq46Y5d
   23.57 +8eubqD01MwVAVad+s5Zmo7gWeR3TZK/uuiTZLTHTX37AVr2w+vgWYai7uXoDQ6cV
   23.58 +PxoFuFAajBjfMLLHJRZiyoW3OQU5NalEcnCZqcwAO4beiVuMOGFm+vymIF9w8VMw
   23.59 +Ji9dBAmF4sbOOX0E8QQA3+10z7Q9XrzIhv4S54YpToorBJ+KDR02CP/Lbwcrpgll
   23.60 +8GqqiVtTTHnnKkBFSWh+TT1UGtm0upy3qwlkr8wQFIi5TQhJOTh8/2+1dVZhDc4M
   23.61 +gU+yEVh/cRZ0DAvWzFqQ2d1WeB5lBXJa9zeuLP5k3V+WCWUYfh4y+Ks1ig/iGFsE
   23.62 +AOEvlS/O4YMP4D6+yOatPyM/wCthVPQ7Uu/aud4YgaxAagA97Cpo483Od7NxSU2i
   23.63 +W8564WrsZ4ZOFeBIjCb5ou8k63rn4tPwBvBNqSsPN0dhLljJps62Chum4ubHcLzF
   23.64 +D2qaZCQx4l2FCJ552glZ+sghBqVuVbIxQ8pj/PktIYbtBACY86nXYTOFV3iMBn4I
   23.65 +Qsvki2ICHvZMD5w+XWyGoAo4tJ3QHCT4L6B+SqchOgQ5Tk22AZ6gsi/JOojaZALw
   23.66 +EOCYMF6K+LUZRtSx2hWDIyOWAC6Q2DoOxZBwyrNr8p9hmD4MYEbVemVZECLs2ir1
   23.67 +OfRZ32aX+G/77yy5yVlNv5H4vznliQEfBBgBCAAJAhsMBQJaADefAAoJEIe93/tC
   23.68 +qFpC8KgH/2oTSDtTLjut9a0M3Kb3FwlRV8CCweF+6s3iQkB9GyBsMbz6vZslxQX+
   23.69 +i48GFLOwVT+rpgeaSyzssRa61jDMvGW5JQr6NAEuZoGvIiS1a1ATgAVqBwNbES29
   23.70 +N/1zMTs+eWiItsE26+gCaZpDIEFPyOWncyJEBNbYZAt8TetbqB8kj2h8tMdDBaTV
   23.71 +Ib4ncEx5B5zbMhRHpd1kYCC6MbtNp0vtzEChFbPChcNYTT2EJ9vIMenxMERsSoZD
   23.72 +HaKeWOvd3+vEDUqDDhPEmA5fFxXUxACkwQQwzfmjcv+sRFWxFEpylBTrzArlMHqa
   23.73 +ELSlP85lFN7w4th8CtDCtVzyRAqSJqg=
   23.74 +=yUDc
   23.75  -----END PGP PRIVATE KEY BLOCK-----
    24.1 --- a/test/test_keys/pub/pep-test-carol-0x42A85A42_pub.asc	Tue Oct 24 11:22:00 2017 +0200
    24.2 +++ b/test/test_keys/pub/pep-test-carol-0x42A85A42_pub.asc	Mon Nov 20 16:04:50 2017 +0100
    24.3 @@ -7,24 +7,24 @@
    24.4  +GhV+HNmfrZ66k0fmEfWvqlQT8ZP6u/v7WjrBmc10mBfw5U5itwl3lManFtc8RpD
    24.5  9xqUgJY83cFNBdmViTRbzoa2VrVPMAh3CoyLABEBAAG0QXBFcCBUZXN0IENhcm9s
    24.6  IChUZXN0IERvIE5vdCBVc2UpIDxwZXAtdGVzdC1jYXJvbEBwZXAtcHJvamVjdC5v
    24.7 -cmc+iQE/BBMBCAApBQJYHG/IAhsDBQkB4TOABwsJCAcDAgEGFQgCCQoLBBYCAwEC
    24.8 -HgECF4AACgkQh73f+0KoWkKhqgf9GYC5HC4ndpauSw71xQQD0Y52zuh4MSWpd6N/
    24.9 -ck5IptzBcyjIIhwZ+CL1oVnCKSOww1MrsEaTXsgqShayXrbxqNr7ZotzLtGWePRF
   24.10 -9SRoWZ4KMkpKDZof73osa0MP8Nf1wN6hX+OYJzPxWpyG57NJ4yJbEDkEgvFMFyPc
   24.11 -Gbisqhi/Nueps3JkNFwu0baq4+CvnV+ovvzfrheVf4Tctt/eP6dp/8151sa97+Fv
   24.12 -ZKG4pbvcapsxUr0JE/442UvfwZS47knPV4pBTk4anXQvfHlBA/t+gdeHsadVtsrd
   24.13 -tbfcYUyiU6zIadgU0fBcoUBSjIM/dejimlVMKEYlyiPOpVUx6rkBDQRYHG/IAQgA
   24.14 -xPlSwgYXs+lTvVGjyfq+X9wV1/w/GWpPwZaUIGPP7YD6aMAu7Va/QELc3tvmx1Cy
   24.15 -rpr3ChGXn4VuAQu9o71ILAhTQFLtVqvemhDN2AUrQTecsJNiL8gbGQeiU4NXTiKS
   24.16 -l8WxMTvEkRnSk8fWsRypIrm7fb36+WVl/DBhF2xHyfU3Og5TQFVPeCv6ZSoAxhGq
   24.17 -8ZqTMXpqCc4nuELId2kkwQDd+GqbrNco5sA1Wb1u7Vz30JQJXVKSkb01sOvMzNLY
   24.18 -XdsX70kNGRTQu/8VQ20Bujb3HX0SUzGEhNnuNrIOEwG1ht8Tr8UsSGdW7XNkdmbc
   24.19 -pclrXSwcGzk8MeQRL8suPwARAQABiQElBBgBCAAPBQJYHG/IAhsMBQkB4TOAAAoJ
   24.20 -EIe93/tCqFpCK38IAJqmjL+y86gt2fSi1Pp/APOsYE6PtD808V7LqHoq5Nz819Eg
   24.21 -kseEuDlwL83cUCb+1T+foLavrrrceufrWSRnsORZtLUcmAu/in4mO94lf3cJP0Ky
   24.22 -4kx6RD972Ow7YuhQh1jig6f/hLXHiPpt146B4vaGH5rPIfhlCZ4S1nyd1FAZkF0F
   24.23 -BTL/lNKhM5ZUm4KUWpxyUd8r/U6qR+1QDKXJL13IhCwHPvcJZoJ7vcah0hprcdGm
   24.24 -Hgiw2g5HwnZm2Mks4QKIGzth5Cn84v91DW0WCBLQXJ4k+4lZjMSqYftbJDFeqQYg
   24.25 -12L75zQRz7H/dtWNuM3LmGtr54zGxuSwCKsxVqw=
   24.26 -=cMV7
   24.27 +cmc+iQE5BBMBCAAjAhsDBwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AFAloAN58A
   24.28 +CgkQh73f+0KoWkKcawf/e0GXipLgzxO2S7g1YLZqfdA6Wwp6J3X6TYaQSgm7K7Jq
   24.29 +52pDzRlXEg51DM4n8V287PdW51bWLodepDe5UhOzBtFFcjo9/9nMiMWRQY8yB/Iw
   24.30 +z+qazkrem5Ula3g6Gs59Ti/KQ2pS7SjJMFgvRJN2lHIWjct1wMNnIY9RZR6j0lsF
   24.31 +0F9hqqbbgQCCZsTsxpXnzXbigM0kBH91KhErpaqpd9jo3lNT6c7ZsgmJgTGl7EiS
   24.32 +/eY/mei0R/uavtmYuwOhkJlLVABFVQkQayXHdxRLe1Ktmagrhu77GlNJGNGNAS9C
   24.33 +kXM2P8RqSfmn59jCUe6dJcwlzv8NmDDjTR59CLkEvrkBDQRYHG/IAQgAxPlSwgYX
   24.34 +s+lTvVGjyfq+X9wV1/w/GWpPwZaUIGPP7YD6aMAu7Va/QELc3tvmx1Cyrpr3ChGX
   24.35 +n4VuAQu9o71ILAhTQFLtVqvemhDN2AUrQTecsJNiL8gbGQeiU4NXTiKSl8WxMTvE
   24.36 +kRnSk8fWsRypIrm7fb36+WVl/DBhF2xHyfU3Og5TQFVPeCv6ZSoAxhGq8ZqTMXpq
   24.37 +Cc4nuELId2kkwQDd+GqbrNco5sA1Wb1u7Vz30JQJXVKSkb01sOvMzNLYXdsX70kN
   24.38 +GRTQu/8VQ20Bujb3HX0SUzGEhNnuNrIOEwG1ht8Tr8UsSGdW7XNkdmbcpclrXSwc
   24.39 +Gzk8MeQRL8suPwARAQABiQEfBBgBCAAJAhsMBQJaADefAAoJEIe93/tCqFpC8KgH
   24.40 +/2oTSDtTLjut9a0M3Kb3FwlRV8CCweF+6s3iQkB9GyBsMbz6vZslxQX+i48GFLOw
   24.41 +VT+rpgeaSyzssRa61jDMvGW5JQr6NAEuZoGvIiS1a1ATgAVqBwNbES29N/1zMTs+
   24.42 +eWiItsE26+gCaZpDIEFPyOWncyJEBNbYZAt8TetbqB8kj2h8tMdDBaTVIb4ncEx5
   24.43 +B5zbMhRHpd1kYCC6MbtNp0vtzEChFbPChcNYTT2EJ9vIMenxMERsSoZDHaKeWOvd
   24.44 +3+vEDUqDDhPEmA5fFxXUxACkwQQwzfmjcv+sRFWxFEpylBTrzArlMHqaELSlP85l
   24.45 +FN7w4th8CtDCtVzyRAqSJqg=
   24.46 +=9g7B
   24.47  -----END PGP PUBLIC KEY BLOCK-----
    25.1 --- a/test/test_util.cc	Tue Oct 24 11:22:00 2017 +0200
    25.2 +++ b/test/test_util.cc	Mon Nov 20 16:04:50 2017 +0100
    25.3 @@ -18,6 +18,19 @@
    25.4  	return sstr.str();
    25.5  }
    25.6  
    25.7 +void dump_out(const char* filename, const char* outdata)
    25.8 +{
    25.9 +	std::ofstream outfile(filename);
   25.10 +	if(!outfile)
   25.11 +	{
   25.12 +		throw std::runtime_error("Cannot open output file!");
   25.13 +	}
   25.14 +	
   25.15 +	outfile << outdata;
   25.16 +    outfile.close();
   25.17 +}
   25.18 +
   25.19 +
   25.20  const char* tl_status_string(PEP_STATUS status) {
   25.21      switch (status) {
   25.22          case PEP_STATUS_OK:
    26.1 --- a/test/test_util.h	Tue Oct 24 11:22:00 2017 +0200
    26.2 +++ b/test/test_util.h	Mon Nov 20 16:04:50 2017 +0100
    26.3 @@ -6,6 +6,10 @@
    26.4  // throws std::runtime_error() if the file cannot be read. Empty file is not an error.
    26.5  std::string slurp(const std::string& filename);
    26.6  
    26.7 +// dumps char* to file
    26.8 +// throws std::runtime_error() if the file cannot be opened.
    26.9 +void dump_out(const char* filename, const char* outdata);
   26.10 +
   26.11  // Returns the string value of the input rating enum value. 
   26.12  const char* tl_rating_string(PEP_rating rating);
   26.13