merge default branch into mine rok-mac
authorRoker <roker@pep-project.org>
Sun, 26 Jun 2016 18:04:25 +0200
branchrok-mac
changeset 767ea2cc8609026
parent 733 efb147632c7a
parent 766 c6012809cc49
child 780 ec353138b14b
merge default branch into mine
src/Makefile
     1.1 --- a/Makefile	Mon Jun 13 09:06:20 2016 +0200
     1.2 +++ b/Makefile	Sun Jun 26 18:04:25 2016 +0200
     1.3 @@ -3,6 +3,7 @@
     1.4  all:
     1.5  	$(MAKE) -C asn.1 generate
     1.6  	$(MAKE) -C asn.1
     1.7 +	$(MAKE) -C sync
     1.8  	$(MAKE) -C src all
     1.9  
    1.10  .PHONY: clean build_test test package install uninstall db
     2.1 --- a/README.txt	Mon Jun 13 09:06:20 2016 +0200
     2.2 +++ b/README.txt	Sun Jun 26 18:04:25 2016 +0200
     2.3 @@ -118,5 +118,5 @@
     2.4  You have to import all the test keys into your local gpg instance:
     2.5  
     2.6  	cd test
     2.7 -	cat *.asc | gpg --import
     2.8 +	cat 0x*.asc *_sec.asc| gpg --import
     2.9  
     3.1 --- a/asn.1/Makefile	Mon Jun 13 09:06:20 2016 +0200
     3.2 +++ b/asn.1/Makefile	Sun Jun 26 18:04:25 2016 +0200
     3.3 @@ -16,14 +16,14 @@
     3.4  libasn1.a: $(ALL_OBJECTS)
     3.5  	ar -rc $@ $(ALL_OBJECTS)
     3.6  
     3.7 -generate: DeviceGroup-Protocol.c
     3.8 +generate: Sync-Protocols.c
     3.9  	rm -f converter-sample.c
    3.10  
    3.11  %.o: %.c %.h
    3.12  	$(CC) $(CFLAGS) $(OPTIMIZE) -I. -I$(ASN1C_INCLUDE) -c $< -o $@
    3.13  
    3.14 -DeviceGroup-Protocol.c: devicegroup.asn1
    3.15 -	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 $<
    3.16 +Sync-Protocols.c: protocols.asn1 devicegroup.asn1 pEp.asn1
    3.17 +	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1 $<
    3.18  
    3.19  .PHONY: clean
    3.20  
     4.1 --- a/asn.1/devicegroup.asn1	Mon Jun 13 09:06:20 2016 +0200
     4.2 +++ b/asn.1/devicegroup.asn1	Sun Jun 26 18:04:25 2016 +0200
     4.3 @@ -4,6 +4,7 @@
     4.4  
     4.5  BEGIN
     4.6  
     4.7 +EXPORTS DeviceGroup-Protocol;
     4.8  IMPORTS Identity, KeyList, Header FROM PEP;
     4.9  
    4.10  Beacon ::= SEQUENCE {
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/asn.1/protocols.asn1	Sun Jun 26 18:04:25 2016 +0200
     5.3 @@ -0,0 +1,14 @@
     5.4 +SYNC
     5.5 +
     5.6 +DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
     5.7 +
     5.8 +BEGIN
     5.9 +
    5.10 +IMPORTS DeviceGroup-Protocol FROM DEVICEGROUP;
    5.11 +
    5.12 +Sync-Protocols ::= CHOICE {
    5.13 +    deviceGroup [APPLICATION 1] DeviceGroup-Protocol
    5.14 +}
    5.15 +
    5.16 +END
    5.17 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/build-linux/Makefile	Sun Jun 26 18:04:25 2016 +0200
     6.3 @@ -0,0 +1,320 @@
     6.4 +#------------------------------------------------------------------------------#
     6.5 +# Makefile to build libEtpan GPGME, GnuPG and deps for use with pEpEngine 
     6.6 +#  based on pEpJNIAdapter/android/external/Makefile
     6.7 +#------------------------------------------------------------------------------#
     6.8 +
     6.9 +all: build 
    6.10 +
    6.11 +build: libetpan-install gnupg-install gpgme-install
    6.12 +
    6.13 +PREFIX ?= $(HOME)
    6.14 +
    6.15 +CFLAGS = 
    6.16 +LDFLAGS = 
    6.17 +
    6.18 +#------------------------------------------------------------------------------#
    6.19 +# libgpg-error
    6.20 +
    6.21 +EXTERNAL_GIT_REPOS += libgpg-error|git://git.gnupg.org/libgpg-error.git?libgpg-error-1.20
    6.22 +
    6.23 +libgpg-error/configure: libgpg-error.src.stamp libgpg-error/configure.ac 
    6.24 +	cd libgpg-error && ./autogen.sh
    6.25 +
    6.26 +libgpg-error/Makefile: libgpg-error/configure 
    6.27 +	cd libgpg-error && \
    6.28 +		./configure \
    6.29 +			CFLAGS="$(CFLAGS)" \
    6.30 +			LDFLAGS="$(LDFLAGS)" \
    6.31 +			--disable-doc \
    6.32 +			--disable-languages \
    6.33 +			--prefix=$(PREFIX)
    6.34 +	ls -l libgpg-error/libtool
    6.35 +
    6.36 +libgpg-error/src/.libs/libgpg-error.so: libgpg-error/Makefile 
    6.37 +	$(MAKE) -C libgpg-error
    6.38 +
    6.39 +libgpg-error-build: libgpg-error/src/.libs/libgpg-error.so
    6.40 +
    6.41 +$(PREFIX)/lib/libgpg-error.so: libgpg-error/src/.libs/libgpg-error.so
    6.42 +	$(MAKE) -C libgpg-error prefix=$(PREFIX) install
    6.43 +	ls -l $(PREFIX)/lib/libgpg-error.so*
    6.44 +
    6.45 +libgpg-error-install: $(PREFIX)/lib/libgpg-error.so
    6.46 +
    6.47 +#------------------------------------------------------------------------------#
    6.48 +# libgcrypt
    6.49 +
    6.50 +EXTERNAL_GIT_REPOS += libgcrypt|git://git.gnupg.org/libgcrypt.git?libgcrypt-1.6.4
    6.51 +
    6.52 +libgcrypt/configure: libgcrypt.src.stamp libgcrypt/configure.ac 
    6.53 +	cd libgcrypt && ./autogen.sh
    6.54 +
    6.55 +libgcrypt/Makefile: libgcrypt/configure 
    6.56 +	cd libgcrypt && \
    6.57 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
    6.58 +			./configure \
    6.59 +				--enable-maintainer-mode \
    6.60 +				--with-gpg-error-prefix=$(PREFIX) \
    6.61 +				--prefix=$(PREFIX)
    6.62 +
    6.63 +libgcrypt/src/.libs/libgcrypt.so: $(PREFIX)/lib/libgpg-error.so libgcrypt/Makefile
    6.64 +	$(MAKE) -C libgcrypt
    6.65 +
    6.66 +$(PREFIX)/lib/libgcrypt.so: libgcrypt/src/.libs/libgcrypt.so
    6.67 +	$(MAKE) -C libgcrypt prefix=$(PREFIX) install
    6.68 +	ls -l $(PREFIX)/lib/libgcrypt.so
    6.69 +
    6.70 +libgcrypt-build: libgcrypt/src/.libs/libgcrypt.so
    6.71 +
    6.72 +libgcrypt-install: $(PREFIX)/lib/libgcrypt.so
    6.73 +
    6.74 +#------------------------------------------------------------------------------#
    6.75 +# libassuan
    6.76 +
    6.77 +EXTERNAL_GIT_REPOS += libassuan|git://git.gnupg.org/libassuan.git?libassuan-2.3.0
    6.78 +
    6.79 +libassuan/configure: libassuan.src.stamp libassuan/configure.ac 
    6.80 +	cd libassuan && ./autogen.sh && autoreconf --install --force --verbose
    6.81 +
    6.82 +libassuan/Makefile: libassuan/configure
    6.83 +	cd libassuan && \
    6.84 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
    6.85 +			./configure \
    6.86 +				--enable-maintainer-mode \
    6.87 +				--with-gpg-error-prefix=$(PREFIX) \
    6.88 +				--prefix=$(PREFIX)
    6.89 +
    6.90 +libassuan/src/.libs/libassuan.so: $(PREFIX)/lib/libgpg-error.so libassuan/Makefile
    6.91 +	$(MAKE) -C libassuan
    6.92 +
    6.93 +$(PREFIX)/lib/libassuan.so: libassuan/src/.libs/libassuan.so
    6.94 +	$(MAKE) -C libassuan prefix=$(PREFIX) install
    6.95 +	ls -l $(PREFIX)/lib/libassuan.so
    6.96 +
    6.97 +libassuan-build: libassuan/src/.libs/libassuan.so
    6.98 +
    6.99 +libassuan-install: $(PREFIX)/lib/libassuan.so
   6.100 +
   6.101 +#------------------------------------------------------------------------------#
   6.102 +# libksba
   6.103 +
   6.104 +EXTERNAL_GIT_REPOS += libksba|git://git.gnupg.org/libksba.git?libksba-1.3.3
   6.105 +
   6.106 +libksba/configure: libksba.src.stamp libksba/configure.ac 
   6.107 +	cd libksba && ./autogen.sh
   6.108 +
   6.109 +libksba/Makefile: $(PREFIX)/lib/libgpg-error.so libksba/configure
   6.110 +	cd libksba && \
   6.111 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
   6.112 +			./configure \
   6.113 +				--enable-maintainer-mode \
   6.114 +				--with-gpg-error-prefix=$(PREFIX) \
   6.115 +				--prefix=$(PREFIX)
   6.116 +
   6.117 +libksba/src/.libs/libksba.so: libksba/Makefile
   6.118 +	$(MAKE) -C libksba
   6.119 +
   6.120 +$(PREFIX)/lib/libksba.so: libksba/src/.libs/libksba.so
   6.121 +	$(MAKE) -C libksba prefix=$(PREFIX) install
   6.122 +	ls -l $(PREFIX)/lib/libksba.so
   6.123 +
   6.124 +libksba-build: libksba/src/.libs/libksba.so
   6.125 +
   6.126 +libksba-install: $(PREFIX)/lib/libksba.so
   6.127 +
   6.128 +#------------------------------------------------------------------------------#
   6.129 +# curl
   6.130 +
   6.131 +EXTERNAL_GIT_REPOS += curl|https://github.com/bagder/curl?curl-7_45_0
   6.132 +
   6.133 +curl/configure: curl.src.stamp curl/configure.ac 
   6.134 +	cd curl && ./buildconf
   6.135 +
   6.136 +curl/Makefile: curl/configure
   6.137 +	cd curl && \
   6.138 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
   6.139 +			./configure \
   6.140 +				--prefix=$(PREFIX) \
   6.141 +				--with-gnu-ld \
   6.142 +				--disable-imap \
   6.143 +				--disable-ldap \
   6.144 +				--disable-pop3 \
   6.145 +				--disable-rtsp \
   6.146 +				--disable-smtp
   6.147 +
   6.148 +curl/lib/.libs/libcurl.so: curl/Makefile
   6.149 +	$(MAKE) -C curl
   6.150 +
   6.151 +$(PREFIX)/lib/libcurl.so: curl/lib/.libs/libcurl.so
   6.152 +	$(MAKE) -C curl prefix=$(PREFIX) install
   6.153 +	ls -l $(PREFIX)/lib/libcurl.so
   6.154 +
   6.155 +curl-build: curl/lib/.libs/libcurl.so
   6.156 +
   6.157 +curl-install: $(PREFIX)/lib/libcurl.so
   6.158 +
   6.159 +
   6.160 +#------------------------------------------------------------------------------#
   6.161 +# gnupg
   6.162 +
   6.163 +EXTERNAL_GIT_REPOS += gnupg|git://git.gnupg.org/gnupg.git?gnupg-2.0.29
   6.164 +
   6.165 +gnupg/configure: gnupg.src.stamp gnupg/configure.ac 
   6.166 +	-sed -i '/^tests/d' gnupg/configure.ac
   6.167 +	-sed -i 's/tests = tests/tests =/' gnupg/Makefile.am
   6.168 +	cd gnupg && ./autogen.sh
   6.169 +
   6.170 +gnupg/Makefile: gnupg/configure
   6.171 +	cd gnupg && \
   6.172 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
   6.173 +			./configure \
   6.174 +				--enable-maintainer-mode \
   6.175 +				--with-gpg-error-prefix=$(PREFIX) \
   6.176 +				--with-libgcrypt-prefix=$(PREFIX) \
   6.177 +				--with-libassuan-prefix=$(PREFIX) \
   6.178 +				--with-ksba-prefix=$(PREFIX) \
   6.179 +				--with-libcurl=$(PREFIX) \
   6.180 +				--disable-agent \
   6.181 +				--disable-scdaemon \
   6.182 +				--disable-ldap \
   6.183 +				--disable-doc \
   6.184 +				--disable-gpgsm \
   6.185 +				--prefix=$(PREFIX)
   6.186 +
   6.187 +gnupg/g10/gpg2: $(PREFIX)/lib/libgpg-error.so $(PREFIX)/lib/libgcrypt.so $(PREFIX)/lib/libksba.so $(PREFIX)/lib/libassuan.so $(PREFIX)/lib/libcurl.so gnupg/Makefile
   6.188 +	$(MAKE) -C gnupg
   6.189 +
   6.190 +$(PREFIX)/bin/gpg2: gnupg/g10/gpg2 gnupg/configure
   6.191 +	$(MAKE) -C gnupg prefix=$(PREFIX) install
   6.192 +	ls -l $(PREFIX)/bin/gpg2
   6.193 +
   6.194 +gnupg-build: gnupg/g10/gpg2
   6.195 +
   6.196 +gnupg-install: $(PREFIX)/bin/gpg2
   6.197 +
   6.198 +#------------------------------------------------------------------------------#
   6.199 +# gpgme
   6.200 +
   6.201 +EXTERNAL_GIT_REPOS += gpgme|git://git.gnupg.org/gpgme.git?gpgme-1.6.0
   6.202 +
   6.203 +gpgme/configure: gpgme.src.stamp gpgme/configure.ac 
   6.204 +	cd gpgme && ./autogen.sh 
   6.205 +
   6.206 +gpgme/Makefile: gpgme/configure
   6.207 +	cd gpgme && \
   6.208 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
   6.209 +			./configure \
   6.210 +				--enable-maintainer-mode \
   6.211 +				--with-gpg-error-prefix=$(PREFIX) \
   6.212 +				--with-libassuan-prefix=$(PREFIX) \
   6.213 +				--enable-fixed-path=$(PREFIX)/bin \
   6.214 +				--without-g13 \
   6.215 +				--disable-glibtest \
   6.216 +				--disable-gpg-test \
   6.217 +				--disable-gpgsm-test \
   6.218 +				--disable-gpgconf-test \
   6.219 +				--disable-parallel-test \
   6.220 +				--disable-g13-test \
   6.221 +				--prefix=$(PREFIX)
   6.222 +
   6.223 +
   6.224 +gpgme/src/.libs/libgpgme.so: gpgme/Makefile
   6.225 +	$(MAKE) -C gpgme
   6.226 +
   6.227 +$(PREFIX)/lib/libgpgme.so: gpgme/src/.libs/libgpgme.so
   6.228 +	$(MAKE) -C gpgme prefix=$(PREFIX) install
   6.229 +
   6.230 +gpgme-build: gpgme/src/.libs/libgpgme.so
   6.231 +
   6.232 +gpgme-install: $(PREFIX)/bin/gpg2 $(PREFIX)/lib/libgpgme.so
   6.233 +
   6.234 +#------------------------------------------------------------------------------#
   6.235 +# libetpan
   6.236 +
   6.237 +EXTERNAL_GIT_REPOS += libetpan|https://github.com/fdik/libetpan.git?HEAD
   6.238 +
   6.239 +libetpan/configure: libetpan.src.stamp
   6.240 +	cd libetpan && ./autogen.sh
   6.241 +
   6.242 +libetpan/Makefile: libetpan/configure
   6.243 +	cd libetpan && \
   6.244 +		CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
   6.245 +			./configure \
   6.246 +				--prefix=$(PREFIX)
   6.247 +
   6.248 +libetpan/src/.libs/libetpan.so: libetpan/Makefile
   6.249 +	$(MAKE) -C libetpan
   6.250 +
   6.251 +$(PREFIX)/lib/libetpan.so: libetpan/src/.libs/libetpan.so
   6.252 +	$(MAKE) -C libetpan install
   6.253 +
   6.254 +libetpan-build: libetpan/src/.libs/libetpan.so
   6.255 +
   6.256 +libetpan-install: $(PREFIX)/lib/libetpan.so
   6.257 +
   6.258 +#------------------------------------------------------------------------------#
   6.259 +# Clone update and archive external projects GIT repos
   6.260 +# Local clone is in external/$project.git while 
   6.261 +# selected commit is archived in external/$project
   6.262 +
   6.263 +define per_repo_targets
   6.264 +$(1).git.stamp:
   6.265 +	git clone $(2) $(1).git
   6.266 +	touch $(1).git.stamp
   6.267 +
   6.268 +$(1).git_update: $(1).git.stamp
   6.269 +	cd $(1).git; git pull
   6.270 +	touch $(1).git.stamp
   6.271 +
   6.272 +$(1).src.stamp: $(1).git.stamp
   6.273 +	rm -rf $(1)
   6.274 +	mkdir $(1)
   6.275 +	(cd $(1).git; git archive --format=tar $(3)) | tar -C $(1) -x
   6.276 +	touch $(1).src.stamp
   6.277 +
   6.278 +$(1)-src: $(1).src.stamp
   6.279 +
   6.280 +$(1)-clean: 
   6.281 +	rm -rf $(1)
   6.282 +	rm -f $(1).src.stamp
   6.283 +
   6.284 +EXTERNAL_LOCAL_GITS += $(1).git.stamp
   6.285 +EXTERNAL_LOCAL_GITS_UPDATE += $(1).git_update
   6.286 +EXTERNAL_SRCS += $(1)-src
   6.287 +EXTERNAL_SRCS_CLEAN += $(1)-clean
   6.288 +endef
   6.289 +
   6.290 +define per_repo
   6.291 +$(call per_repo_targets,\
   6.292 +    $(1),\
   6.293 +    $(word 1,$(subst ?, ,$(2))),\
   6.294 +    $(word 2,$(subst ?, ,$(2))))
   6.295 +endef
   6.296 +
   6.297 +$(foreach repo, $(EXTERNAL_GIT_REPOS), $(eval $(call per_repo,\
   6.298 +    $(word 1,$(subst |, ,$(repo))),\
   6.299 +    $(word 2,$(subst |, ,$(repo))))))
   6.300 +
   6.301 +git_clones: $(EXTERNAL_LOCAL_GITS)
   6.302 +
   6.303 +git_update: $(EXTERNAL_LOCAL_GITS_UPDATE)
   6.304 +
   6.305 +#------------------------------------------------------------------------------#
   6.306 +# clean
   6.307 +
   6.308 +clean: $(EXTERNAL_SRCS_CLEAN) clean-install libetpan-cleanzip
   6.309 +
   6.310 +#------------------------------------------------------------------------------#
   6.311 +
   6.312 +.PHONY = clean clean-install libetpan-cleanzip\
   6.313 +	libgpg-error-build libgpg-error-install \
   6.314 +	libgcrypt-build libgcrypt-install \
   6.315 +	libassuan-build libassuan-install \
   6.316 +	libksba-build libksba-install \
   6.317 +	gnupg-build  gnupg-install\
   6.318 +	gpgme-build  gpgme-install\
   6.319 +	curl-build curl-install \
   6.320 +	clean-install \
   6.321 +    $(EXTERNAL_LOCAL_GITS_UPDATE) $(EXTERNAL_SRCS) $(EXTERNAL_SRCS_CLEAN) \
   6.322 +	showsetup
   6.323 +
     7.1 --- a/src/Makefile	Mon Jun 13 09:06:20 2016 +0200
     7.2 +++ b/src/Makefile	Sun Jun 26 18:04:25 2016 +0200
     7.3 @@ -30,7 +30,7 @@
     7.4  CFLAGS?=-I$(GPGME_IN)/include $(OPTIMIZE) -fPIC -pedantic \
     7.5  	-DSYSTEM_DB=\"$(SYSTEM_DB)\" -DLIBGPGME=\"$(LIBGPGME)\" \
     7.6  	-DSQLITE_THREADSAFE=1 -D_GNU_SOURCE -I../asn.1
     7.7 -LDFLAGS?=-L$(GPGME_IN)/lib -shared -lc -ldl -letpan -lsqlite3 -lpthread -L../asn.1 -lasn1
     7.8 +LDFLAGS?=-L$(GPGME_IN)/lib -shared -lc -ldl -letpan -lpthread -L../asn.1 -lasn1
     7.9  
    7.10  else
    7.11  $(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
     8.1 --- a/src/cryptotech.h	Mon Jun 13 09:06:20 2016 +0200
     8.2 +++ b/src/cryptotech.h	Sun Jun 26 18:04:25 2016 +0200
     8.3 @@ -48,7 +48,7 @@
     8.4      );
     8.5  
     8.6  typedef PEP_STATUS (*import_key_t)(PEP_SESSION session, const char *key_data,
     8.7 -        size_t size);
     8.8 +        size_t size, identity_list **private_keys);
     8.9  
    8.10  typedef PEP_STATUS (*recv_key_t)(PEP_SESSION session, const char *pattern);
    8.11  
     9.1 --- a/src/etpan_mime.c	Mon Jun 13 09:06:20 2016 +0200
     9.2 +++ b/src/etpan_mime.c	Sun Jun 26 18:04:25 2016 +0200
     9.3 @@ -315,9 +315,12 @@
     9.4      content = NULL;
     9.5      mime_fields = NULL;
     9.6  
     9.7 -    r = mailmime_set_body_text(mime, data, length);
     9.8 -    if (r != 0)
     9.9 -        goto enomem;
    9.10 +    if(length > 0)
    9.11 +    {
    9.12 +        r = mailmime_set_body_text(mime, data, length);
    9.13 +        if (r != 0)
    9.14 +            goto enomem;
    9.15 +    }
    9.16  
    9.17      return mime;
    9.18  
    10.1 --- a/src/identity_list.h	Mon Jun 13 09:06:20 2016 +0200
    10.2 +++ b/src/identity_list.h	Sun Jun 26 18:04:25 2016 +0200
    10.3 @@ -7,12 +7,6 @@
    10.4  #endif
    10.5  
    10.6  
    10.7 -typedef struct _identity_list {
    10.8 -    pEp_identity *ident;
    10.9 -    struct _identity_list *next;
   10.10 -} identity_list;
   10.11 -
   10.12 -
   10.13  // new_identity_list() - allocate a new identity list
   10.14  //
   10.15  //  parameters:
    11.1 --- a/src/keymanagement.c	Mon Jun 13 09:06:20 2016 +0200
    11.2 +++ b/src/keymanagement.c	Sun Jun 26 18:04:25 2016 +0200
    11.3 @@ -56,6 +56,56 @@
    11.4      return ai == fpras && bi == fprbs;
    11.5  }
    11.6  
    11.7 +PEP_STATUS elect_key(
    11.8 +        PEP_SESSION session, pEp_identity * identity
    11.9 +    )
   11.10 +{
   11.11 +    PEP_STATUS status;
   11.12 +    stringlist_t *keylist;
   11.13 +    char *_fpr = NULL;
   11.14 +    identity->comm_type = PEP_ct_unknown;
   11.15 +
   11.16 +    status = find_keys(session, identity->address, &keylist);
   11.17 +    assert(status != PEP_OUT_OF_MEMORY);
   11.18 +    if (status == PEP_OUT_OF_MEMORY)
   11.19 +        return PEP_OUT_OF_MEMORY;
   11.20 +
   11.21 +    stringlist_t *_keylist;
   11.22 +    for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
   11.23 +        PEP_comm_type _comm_type_key;
   11.24 +
   11.25 +        status = get_key_rating(session, _keylist->value, &_comm_type_key);
   11.26 +        assert(status != PEP_OUT_OF_MEMORY);
   11.27 +        if (status == PEP_OUT_OF_MEMORY) {
   11.28 +            free_stringlist(keylist);
   11.29 +            return PEP_OUT_OF_MEMORY;
   11.30 +        }
   11.31 +
   11.32 +        if (_comm_type_key != PEP_ct_compromized &&
   11.33 +            _comm_type_key != PEP_ct_unknown)
   11.34 +        {
   11.35 +            if (identity->comm_type == PEP_ct_unknown ||
   11.36 +                _comm_type_key > identity->comm_type)
   11.37 +            {
   11.38 +                identity->comm_type = _comm_type_key;
   11.39 +                _fpr = _keylist->value;
   11.40 +            }
   11.41 +        }
   11.42 +    }
   11.43 +
   11.44 +    if (_fpr) {
   11.45 +        free(identity->fpr);
   11.46 +
   11.47 +        identity->fpr = strdup(_fpr);
   11.48 +        if (identity->fpr == NULL) {
   11.49 +            free_stringlist(keylist);
   11.50 +            return PEP_OUT_OF_MEMORY;
   11.51 +        }
   11.52 +    }
   11.53 +    free_stringlist(keylist);
   11.54 +    return PEP_STATUS_OK;
   11.55 +}
   11.56 +
   11.57  DYNAMIC_API PEP_STATUS update_identity(
   11.58          PEP_SESSION session, pEp_identity * identity
   11.59      )
   11.60 @@ -115,7 +165,9 @@
   11.61              if (identity->fpr == NULL)
   11.62                  return PEP_OUT_OF_MEMORY;
   11.63              if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
   11.64 -                identity->comm_type = _comm_type_key;
   11.65 +                PEP_STATUS status = elect_key(session, identity);
   11.66 +                if (status != PEP_STATUS_OK)
   11.67 +                    return status;
   11.68              }
   11.69              else {
   11.70                  identity->comm_type = stored_identity->comm_type;
   11.71 @@ -162,49 +214,9 @@
   11.72              identity->comm_type = _comm_type_key;
   11.73          }
   11.74          else /* EMPTYSTR(identity->fpr) */ {
   11.75 -            PEP_STATUS status;
   11.76 -            stringlist_t *keylist;
   11.77 -            char *_fpr = NULL;
   11.78 -            identity->comm_type = PEP_ct_unknown;
   11.79 -
   11.80 -            status = find_keys(session, identity->address, &keylist);
   11.81 -            assert(status != PEP_OUT_OF_MEMORY);
   11.82 -            if (status == PEP_OUT_OF_MEMORY)
   11.83 -                return PEP_OUT_OF_MEMORY;
   11.84 -
   11.85 -            stringlist_t *_keylist;
   11.86 -            for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
   11.87 -                PEP_comm_type _comm_type_key;
   11.88 -
   11.89 -                status = get_key_rating(session, _keylist->value, &_comm_type_key);
   11.90 -                assert(status != PEP_OUT_OF_MEMORY);
   11.91 -                if (status == PEP_OUT_OF_MEMORY) {
   11.92 -                    free_stringlist(keylist);
   11.93 -                    return PEP_OUT_OF_MEMORY;
   11.94 -                }
   11.95 -
   11.96 -                if (_comm_type_key != PEP_ct_compromized &&
   11.97 -                    _comm_type_key != PEP_ct_unknown)
   11.98 -                {
   11.99 -                    if (identity->comm_type == PEP_ct_unknown ||
  11.100 -                        _comm_type_key > identity->comm_type)
  11.101 -                    {
  11.102 -                        identity->comm_type = _comm_type_key;
  11.103 -                        _fpr = _keylist->value;
  11.104 -                    }
  11.105 -                }
  11.106 -            }
  11.107 -
  11.108 -            if (_fpr) {
  11.109 -                free(identity->fpr);
  11.110 -
  11.111 -                identity->fpr = strdup(_fpr);
  11.112 -                if (identity->fpr == NULL) {
  11.113 -                    free_stringlist(keylist);
  11.114 -                    return PEP_OUT_OF_MEMORY;
  11.115 -                }
  11.116 -            }
  11.117 -            free_stringlist(keylist);
  11.118 +            PEP_STATUS status = elect_key(session, identity);
  11.119 +            if (status != PEP_STATUS_OK)
  11.120 +                return status;
  11.121          }
  11.122      }
  11.123  
  11.124 @@ -220,8 +232,8 @@
  11.125                  return PEP_OUT_OF_MEMORY;
  11.126          }
  11.127  
  11.128 -        // Identity doesn't get stored if is was just about checking existing
  11.129 -        // user by address (i.e. no user id but already stored)
  11.130 +        // Identity doesn't get stored if call was just about checking existing
  11.131 +        // user by address (i.e. no user id given but already stored)
  11.132          if (!(_no_user_id && stored_identity))
  11.133          {
  11.134              status = set_identity(session, identity);
    12.1 --- a/src/message_api.c	Mon Jun 13 09:06:20 2016 +0200
    12.2 +++ b/src/message_api.c	Sun Jun 26 18:04:25 2016 +0200
    12.3 @@ -842,32 +842,21 @@
    12.4  
    12.5  static bool is_key(const bloblist_t *bl)
    12.6  {
    12.7 -    bool result = false;
    12.8 -
    12.9 -    // workaround for Apple Mail bugs
   12.10 -    if (is_mime_type(bl, "application/x-apple-msg-attachment")) {
   12.11 -        if (is_fileending(bl, ".asc")) {
   12.12 -            result = true;
   12.13 -        }
   12.14 -    }
   12.15 -    else if (bl->mime_type == NULL ||
   12.16 -                is_mime_type(bl, "application/octet-stream")) {
   12.17 -        if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
   12.18 -                is_fileending(bl, ".key") || is_fileending(bl, ".asc")) {
   12.19 -            result = true;
   12.20 -        }
   12.21 -    }
   12.22 -    else if (is_mime_type(bl, "application/pgp-keys")) {
   12.23 -        result = true;
   12.24 -    }
   12.25 -    else if (is_mime_type(bl, "text/plain")) {
   12.26 -        if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
   12.27 -                is_fileending(bl, ".key") || is_fileending(bl, ".asc")) {
   12.28 -            result = true;
   12.29 -        }
   12.30 -    }
   12.31 -
   12.32 -    return result;
   12.33 +    return (// workaround for Apple Mail bugs
   12.34 +            (is_mime_type(bl, "application/x-apple-msg-attachment") &&
   12.35 +             is_fileending(bl, ".asc")) ||
   12.36 +            // as binary, by file name
   12.37 +            ((bl->mime_type == NULL ||
   12.38 +              is_mime_type(bl, "application/octet-stream")) &&
   12.39 +             (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
   12.40 +                    is_fileending(bl, ".key") || is_fileending(bl, ".asc"))) ||
   12.41 +            // explicit mime type 
   12.42 +            is_mime_type(bl, "application/pgp-keys") ||
   12.43 +            // as text, by file name
   12.44 +            (is_mime_type(bl, "text/plain") &&
   12.45 +             (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
   12.46 +                    is_fileending(bl, ".key") || is_fileending(bl, ".asc")))
   12.47 +           );
   12.48  }
   12.49  
   12.50  static void remove_attached_keys(message *msg)
   12.51 @@ -894,7 +883,11 @@
   12.52      }
   12.53  }
   12.54  
   12.55 -bool import_attached_keys(PEP_SESSION session, message *msg)
   12.56 +bool import_attached_keys(
   12.57 +        PEP_SESSION session, 
   12.58 +        const message *msg,
   12.59 +        identity_list **private_idents
   12.60 +    )
   12.61  {
   12.62      assert(session);
   12.63      assert(msg);
   12.64 @@ -902,17 +895,14 @@
   12.65      bool remove = false;
   12.66  
   12.67      bloblist_t *bl;
   12.68 -    for (bl = msg->attachments; bl && bl->value; bl = bl->next) {
   12.69 -        assert(bl && bl->value && bl->size);
   12.70 -        if (is_key(bl)) {
   12.71 -            import_key(session, bl->value, bl->size);
   12.72 +    for (bl = msg->attachments; bl && bl->value; bl = bl->next) 
   12.73 +    {
   12.74 +        if (bl && bl->value && bl->size && is_key(bl)) 
   12.75 +        {
   12.76 +            import_key(session, bl->value, bl->size, private_idents);
   12.77              remove = true;
   12.78          }
   12.79      }
   12.80 -
   12.81 -    if (msg->from && msg->from->user_id && msg->from->address)
   12.82 -        update_identity(session, msg->from);
   12.83 -
   12.84      return remove;
   12.85  }
   12.86  
   12.87 @@ -1184,12 +1174,14 @@
   12.88      return status;
   12.89  }
   12.90  
   12.91 -DYNAMIC_API PEP_STATUS decrypt_message(
   12.92 +DYNAMIC_API PEP_STATUS _decrypt_message(
   12.93          PEP_SESSION session,
   12.94          message *src,
   12.95          message **dst,
   12.96          stringlist_t **keylist,
   12.97 -        PEP_color *color
   12.98 +        PEP_color *color,
   12.99 +        PEP_decrypt_flags_t *flags, 
  12.100 +        identity_list **private_il
  12.101      )
  12.102  {
  12.103      PEP_STATUS status = PEP_STATUS_OK;
  12.104 @@ -1206,11 +1198,21 @@
  12.105      assert(dst);
  12.106      assert(keylist);
  12.107      assert(color);
  12.108 +    assert(flags);
  12.109  
  12.110 -    if (!(session && src && dst && keylist && color))
  12.111 +    if (!(session && src && dst && keylist && color && flags))
  12.112          return PEP_ILLEGAL_VALUE;
  12.113  
  12.114 -    bool imported_keys = import_attached_keys(session, src);
  12.115 +    *flags = 0;
  12.116 +
  12.117 +    // Private key in unencrypted mail are ignored -> NULL
  12.118 +    bool imported_keys = import_attached_keys(session, src, NULL);
  12.119 +
  12.120 +    // Update src->from in case we just imported a key
  12.121 +    // we would need to check signature
  12.122 +    if(src->from && src->from->user_id && src->from->address)
  12.123 +        update_identity(session, src->from);
  12.124 +
  12.125      PEP_cryptotech crypto = determine_encryption_format(src);
  12.126  
  12.127      *dst = NULL;
  12.128 @@ -1244,6 +1246,8 @@
  12.129  
  12.130      decrypt_status = status;
  12.131  
  12.132 +    bool imported_private_key_address = false; 
  12.133 +
  12.134      if (ptext) {
  12.135          switch (src->enc_format) {
  12.136              case PEP_enc_PGP_MIME:
  12.137 @@ -1376,14 +1380,34 @@
  12.138                  // BUG: must implement more
  12.139                  NOT_IMPLEMENTED
  12.140          }
  12.141 -        
  12.142 -        imported_keys = import_attached_keys(session, msg);
  12.143 -        
  12.144 -        if (decrypt_status == PEP_DECRYPTED) {
  12.145 +       
  12.146 +        // check for private key in decrypted message attachement while inporting
  12.147 +        identity_list *_private_il = NULL;
  12.148 +        imported_keys = import_attached_keys(session, msg, &_private_il);
  12.149 +        if (_private_il && 
  12.150 +            identity_list_length(_private_il) == 1 &&
  12.151 +            _private_il->ident->address)
  12.152 +        {
  12.153 +            imported_private_key_address = true;
  12.154 +        }
  12.155 +
  12.156 +        if(private_il && imported_private_key_address){
  12.157 +            *private_il = _private_il;
  12.158 +        }else{
  12.159 +            free_identity_list(_private_il);
  12.160 +        }
  12.161 +         
  12.162 +        if(decrypt_status == PEP_DECRYPTED){
  12.163 +
  12.164 +            // TODO optimize if import_attached_keys didn't import any key
  12.165              
  12.166              // In case message did decrypt, but no valid signature could be found
  12.167              // then retry decrypt+verify after importing key.
  12.168 -            // TODO optimize if import_attached_keys didn't import any key
  12.169 +
  12.170 +            // Update msg->from in case we just imported a key
  12.171 +            // we would need to check signature
  12.172 +            if(msg->from && msg->from->user_id && msg->from->address)
  12.173 +                 update_identity(session, msg->from);
  12.174              
  12.175              char *re_ptext = NULL;
  12.176              size_t re_psize;
  12.177 @@ -1439,6 +1463,24 @@
  12.178              }
  12.179          }
  12.180      }
  12.181 +    else
  12.182 +    {
  12.183 +        *color = decrypt_color(decrypt_status);
  12.184 +        goto pep_error;
  12.185 +    }
  12.186 +
  12.187 +    // Case of own key imported from own trusted message
  12.188 +    if (// Message have been reliably decrypted 
  12.189 +        msg &&
  12.190 +        *color >= PEP_rating_green &&
  12.191 +        imported_private_key_address &&
  12.192 +        // to is [own]
  12.193 +        msg->to->ident->user_id &&
  12.194 +        strcmp(msg->to->ident->user_id, PEP_OWN_USERID) == 0 
  12.195 +        )
  12.196 +    {
  12.197 +        *flags |= PEP_decrypt_flag_own_private_key;
  12.198 +    }
  12.199  
  12.200      if (msg) {
  12.201          decorate_message(msg, *color, _keylist);
  12.202 @@ -1461,6 +1503,54 @@
  12.203      return status;
  12.204  }
  12.205  
  12.206 +DYNAMIC_API PEP_STATUS decrypt_message(
  12.207 +        PEP_SESSION session,
  12.208 +        message *src,
  12.209 +        message **dst,
  12.210 +        stringlist_t **keylist,
  12.211 +        PEP_color *color,
  12.212 +        PEP_decrypt_flags_t *flags 
  12.213 +    )
  12.214 +{
  12.215 +    return _decrypt_message( session, src, dst, keylist, color, flags, NULL );
  12.216 +}
  12.217 +
  12.218 +DYNAMIC_API PEP_STATUS own_message_private_key_details(
  12.219 +        PEP_SESSION session,
  12.220 +        message *msg,
  12.221 +        pEp_identity **ident 
  12.222 +    )
  12.223 +{
  12.224 +    assert(session);
  12.225 +    assert(msg);
  12.226 +    assert(ident);
  12.227 +
  12.228 +    if (!(session && msg && ident))
  12.229 +        return PEP_ILLEGAL_VALUE;
  12.230 +
  12.231 +    message *dst; 
  12.232 +    stringlist_t *keylist;
  12.233 +    PEP_color color;
  12.234 +    PEP_decrypt_flags_t flags; 
  12.235 +
  12.236 +    *ident = NULL;
  12.237 +
  12.238 +    identity_list *private_il = NULL;
  12.239 +    PEP_STATUS status = _decrypt_message(session, msg,  &dst, &keylist, &color, &flags, &private_il);
  12.240 +
  12.241 +    if (status == PEP_STATUS_OK &&
  12.242 +        flags & PEP_decrypt_flag_own_private_key &&
  12.243 +        private_il)
  12.244 +    {
  12.245 +        *ident = identity_dup(private_il->ident);
  12.246 +    }
  12.247 +
  12.248 +    free_identity_list(private_il);
  12.249 +
  12.250 +    return status;
  12.251 +
  12.252 +}
  12.253 +
  12.254  DYNAMIC_API PEP_STATUS outgoing_message_color(
  12.255          PEP_SESSION session,
  12.256          message *msg,
    13.1 --- a/src/message_api.h	Mon Jun 13 09:06:20 2016 +0200
    13.2 +++ b/src/message_api.h	Sun Jun 26 18:04:25 2016 +0200
    13.3 @@ -10,7 +10,11 @@
    13.4  #endif
    13.5  
    13.6  
    13.7 -bool import_attached_keys(PEP_SESSION session, message *msg);
    13.8 +bool import_attached_keys(
    13.9 +        PEP_SESSION session, 
   13.10 +        const message *msg,
   13.11 +        identity_list **private_idents
   13.12 +    );
   13.13  void attach_own_key(PEP_SESSION session, message *msg);
   13.14  PEP_cryptotech determine_encryption_format(message *msg);
   13.15  
   13.16 @@ -64,6 +68,12 @@
   13.17      PEP_rating_under_attack = -3
   13.18  } PEP_color;
   13.19  
   13.20 +typedef enum _PEP_decrypt_flags {
   13.21 +    PEP_decrypt_flag_own_private_key = 0x1
   13.22 +} PEP_decrypt_flags; 
   13.23 +
   13.24 +typedef uint32_t PEP_decrypt_flags_t;
   13.25 +
   13.26  // decrypt_message() - decrypt message in memory
   13.27  //
   13.28  //  parameters:
   13.29 @@ -72,6 +82,7 @@
   13.30  //      dst (out)           pointer to new decrypted message or NULL on failure
   13.31  //      keylist (out)       stringlist with keyids
   13.32  //      color (out)         color for the message
   13.33 +//      flags (out)         flags to signal special message features
   13.34  //
   13.35  //  return value:
   13.36  //      error status or PEP_STATUS_OK on success
   13.37 @@ -88,9 +99,36 @@
   13.38          message *src,
   13.39          message **dst,
   13.40          stringlist_t **keylist,
   13.41 -        PEP_color *color
   13.42 -    );
   13.43 +        PEP_color *color,
   13.44 +        PEP_decrypt_flags_t *flags 
   13.45 +);
   13.46  
   13.47 +// own_message_private_key_details() - details on own key in own message
   13.48 +//
   13.49 +//  parameters:
   13.50 +//      session (in)        session handle
   13.51 +//      msg (in)            message to decrypt
   13.52 +//      ident (out)         identity containing uid, address and fpr of key
   13.53 +//
   13.54 +//  note:
   13.55 +//      In order to obtain details about key to be possibly imported
   13.56 +//      as a replacement of key currently used as own identity, 
   13.57 +//      application passes message that have been previously flagged by 
   13.58 +//      decrypt_message() as own message containing own key to this function
   13.59 +//
   13.60 +//  return value:
   13.61 +//      error status or PEP_STATUS_OK on success
   13.62 +//
   13.63 +//	caveat:
   13.64 +//	    the ownership of msg remains with the caller
   13.65 +//	    the ownership of ident goes to the caller
   13.66 +//	    msg MUST be encrypted so that this function can check own signature
   13.67 +
   13.68 +DYNAMIC_API PEP_STATUS own_message_private_key_details(
   13.69 +        PEP_SESSION session,
   13.70 +        message *msg,
   13.71 +        pEp_identity **ident 
   13.72 +);
   13.73  
   13.74  // outgoing_message_color() - get color for an outgoing message
   13.75  //
    14.1 --- a/src/mime.c	Mon Jun 13 09:06:20 2016 +0200
    14.2 +++ b/src/mime.c	Sun Jun 26 18:04:25 2016 +0200
    14.3 @@ -693,8 +693,8 @@
    14.4  
    14.5          bloblist_t *_a;
    14.6          for (_a = msg->attachments; _a != NULL; _a = _a->next) {
    14.7 -            assert(_a->value);
    14.8 -            assert(_a->size);
    14.9 +            //assert(_a->value);
   14.10 +            //assert(_a->size);
   14.11  
   14.12              status = mime_attachment(_a, &submime);
   14.13              if (status != PEP_STATUS_OK)
    15.1 --- a/src/pEpEngine.c	Mon Jun 13 09:06:20 2016 +0200
    15.2 +++ b/src/pEpEngine.c	Sun Jun 26 18:04:25 2016 +0200
    15.3 @@ -1151,7 +1151,12 @@
    15.4      return session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr, comm_type);
    15.5  }
    15.6  
    15.7 -DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size)
    15.8 +DYNAMIC_API PEP_STATUS import_key(
    15.9 +        PEP_SESSION session,
   15.10 +        const char *key_data,
   15.11 +        size_t size,
   15.12 +        identity_list **private_keys
   15.13 +    )
   15.14  {
   15.15      assert(session);
   15.16      assert(key_data);
   15.17 @@ -1159,7 +1164,7 @@
   15.18      if (!(session && key_data))
   15.19          return PEP_ILLEGAL_VALUE;
   15.20  
   15.21 -    return session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size);
   15.22 +    return session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size, private_keys);
   15.23  }
   15.24  
   15.25  DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
    16.1 --- a/src/pEpEngine.h	Mon Jun 13 09:06:20 2016 +0200
    16.2 +++ b/src/pEpEngine.h	Sun Jun 26 18:04:25 2016 +0200
    16.3 @@ -388,6 +388,11 @@
    16.4      bool me;                    // if this is the local user herself/himself
    16.5  } pEp_identity;
    16.6  
    16.7 +typedef struct _identity_list {
    16.8 +    pEp_identity *ident;
    16.9 +    struct _identity_list *next;
   16.10 +} identity_list;
   16.11 +
   16.12  
   16.13  // new_identity() - allocate memory and set the string and size fields
   16.14  //
   16.15 @@ -550,7 +555,12 @@
   16.16  //      PEP_OUT_OF_MEMORY       out of memory
   16.17  //      PEP_ILLEGAL_VALUE       there is no key data to import
   16.18  
   16.19 -DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size);
   16.20 +DYNAMIC_API PEP_STATUS import_key(
   16.21 +        PEP_SESSION session,
   16.22 +        const char *key_data,
   16.23 +        size_t size,
   16.24 +        identity_list **private_keys
   16.25 +    );
   16.26  
   16.27  
   16.28  // export_key() - export ascii armored key
    17.1 --- a/src/pEp_internal.h	Mon Jun 13 09:06:20 2016 +0200
    17.2 +++ b/src/pEp_internal.h	Sun Jun 26 18:04:25 2016 +0200
    17.3 @@ -126,7 +126,7 @@
    17.4      messageToSend_t messageToSend;
    17.5      showHandshake_t showHandshake;
    17.6  
    17.7 -    // sync state machine
    17.8 +    // state machines
    17.9      DeviceState_state sync_state;
   17.10  
   17.11      // runtime config
    18.1 --- a/src/pgp_gpg.c	Mon Jun 13 09:06:20 2016 +0200
    18.2 +++ b/src/pgp_gpg.c	Sun Jun 26 18:04:25 2016 +0200
    18.3 @@ -11,7 +11,7 @@
    18.4  static void *gpgme;
    18.5  static struct gpg_s gpg;
    18.6  
    18.7 -static bool ensure_config_values(stringlist_t *keys, stringlist_t *values)
    18.8 +static bool ensure_config_values(stringlist_t *keys, stringlist_t *values, const char* config_file_path)
    18.9  {
   18.10      static char buf[MAX_LINELENGTH];
   18.11      int r;
   18.12 @@ -21,7 +21,7 @@
   18.13      unsigned int i;
   18.14      unsigned int found = 0;
   18.15  
   18.16 -    f = Fopen(gpg_conf(), "r");
   18.17 +    f = Fopen(config_file_path, "r");
   18.18      if (f == NULL && errno == ENOMEM)
   18.19          return false;
   18.20  
   18.21 @@ -57,10 +57,10 @@
   18.22                  }
   18.23              }
   18.24          } while (!feof(f));
   18.25 -        f = Freopen(gpg_conf(), "a", f);
   18.26 +        f = Freopen(config_file_path, "a", f);
   18.27      }
   18.28      else {
   18.29 -        f = Fopen(gpg_conf(), "w");
   18.30 +        f = Fopen(config_file_path, "w");
   18.31      }
   18.32  
   18.33      assert(f);
   18.34 @@ -81,6 +81,7 @@
   18.35      return true;
   18.36  }
   18.37  
   18.38 +
   18.39  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
   18.40  {
   18.41      PEP_STATUS status = PEP_STATUS_OK;
   18.42 @@ -106,8 +107,8 @@
   18.43  
   18.44          stringlist_add(conf_keys, "personal-digest-preferences");
   18.45          stringlist_add(conf_values, "SHA256 SHA512 SHA384 SHA224");
   18.46 -        
   18.47 -        bResult = ensure_config_values(conf_keys, conf_values);
   18.48 +
   18.49 +        bResult = ensure_config_values(conf_keys, conf_values, gpg_conf());
   18.50  
   18.51          free_stringlist(conf_keys);
   18.52          free_stringlist(conf_values);
   18.53 @@ -118,6 +119,22 @@
   18.54              goto pep_error;
   18.55          }
   18.56  
   18.57 +        conf_keys = new_stringlist("default-cache-ttl");
   18.58 +        conf_values = new_stringlist("300");
   18.59 +
   18.60 +        stringlist_add(conf_keys, "max-cache-ttl");
   18.61 +        stringlist_add(conf_values, "1200");
   18.62 +
   18.63 +        bResult = ensure_config_values(conf_keys, conf_values, gpg_agent_conf());
   18.64 +
   18.65 +        free_stringlist(conf_keys);
   18.66 +        free_stringlist(conf_values);
   18.67 +
   18.68 +        assert(bResult);
   18.69 +        if(!bResult){
   18.70 +            status = PEP_INIT_NO_GPG_HOME; /* FIXME: Wrong error here? */
   18.71 +            goto pep_error;
   18.72 +        }
   18.73  
   18.74          gpgme = dlopen(LIBGPGME, RTLD_LAZY);
   18.75          if (gpgme == NULL) {
   18.76 @@ -257,6 +274,11 @@
   18.77              dlsym(gpgme, "gpgme_op_import");
   18.78          assert(gpg.gpgme_op_import);
   18.79  
   18.80 +        gpg.gpgme_op_import_result
   18.81 +            = (gpgme_op_import_result_t) (intptr_t) dlsym(gpgme,
   18.82 +            "gpgme_op_import_result");
   18.83 +        assert(gpg.gpgme_op_import_result);
   18.84 +
   18.85          gpg.gpgme_op_export = (gpgme_op_export_t) (intptr_t)
   18.86              dlsym(gpgme, "gpgme_op_export");
   18.87          assert(gpg.gpgme_op_export);
   18.88 @@ -456,8 +478,7 @@
   18.89                              // This is meant to get signer's primary 
   18.90                              // key fingerprint, using subkey's.
   18.91  
   18.92 -                            gpgme_key_t key;
   18.93 -                            memset(&key,0,sizeof(key));
   18.94 +                            gpgme_key_t key = NULL;
   18.95  
   18.96                              gpgme_error = gpg.gpgme_get_key(session->ctx,
   18.97                                  gpgme_signature->fpr, &key, 0);
   18.98 @@ -1013,13 +1034,17 @@
   18.99      return PEP_STATUS_OK;
  18.100  }
  18.101  
  18.102 -PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data, size_t size)
  18.103 +PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
  18.104 +                              size_t size, identity_list **private_idents)
  18.105  {
  18.106      gpgme_error_t gpgme_error;
  18.107      gpgme_data_t dh;
  18.108  
  18.109      assert(session);
  18.110      assert(key_data);
  18.111 +   
  18.112 +    if(private_idents) 
  18.113 +        *private_idents = NULL;
  18.114  
  18.115      gpgme_error = gpg.gpgme_data_new_from_mem(&dh, key_data, size, 0);
  18.116      gpgme_error = _GPGERR(gpgme_error);
  18.117 @@ -1037,10 +1062,67 @@
  18.118          return PEP_UNKNOWN_ERROR;
  18.119      }
  18.120  
  18.121 +    gpgme_import_result_t gpgme_import_result;
  18.122 +
  18.123      gpgme_error = gpg.gpgme_op_import(session->ctx, dh);
  18.124      gpgme_error = _GPGERR(gpgme_error);
  18.125      switch (gpgme_error) {
  18.126      case GPG_ERR_NO_ERROR:
  18.127 +        if(private_idents) 
  18.128 +        {
  18.129 +            gpgme_import_result =
  18.130 +                gpg.gpgme_op_import_result(session->ctx);
  18.131 +            assert(gpgme_import_result);
  18.132 +            gpgme_import_status_t import;
  18.133 +            for (import = gpgme_import_result->imports; 
  18.134 +                 import; 
  18.135 +                 import = import->next)
  18.136 +             {
  18.137 +                if (import &&
  18.138 +                    import->result == GPG_ERR_NO_ERROR &&
  18.139 +                    import->status & GPGME_IMPORT_SECRET )
  18.140 +                {
  18.141 +                    gpgme_key_t key = NULL;
  18.142 +
  18.143 +                    gpgme_error = gpg.gpgme_get_key(session->ctx,
  18.144 +                        import->fpr, &key, 0);
  18.145 +                    gpgme_error = _GPGERR(gpgme_error);
  18.146 +                    assert(gpgme_error != GPG_ERR_ENOMEM);
  18.147 +                    if (gpgme_error == GPG_ERR_ENOMEM) {
  18.148 +                        gpg.gpgme_data_release(dh);
  18.149 +                        return PEP_OUT_OF_MEMORY;
  18.150 +                    }
  18.151 +                    
  18.152 +                    if (gpgme_error == GPG_ERR_NO_ERROR &&  
  18.153 +                        key && key->uids && 
  18.154 +                        key->uids->email && key->uids->name)
  18.155 +                    {
  18.156 +                        pEp_identity *ident = new_identity(
  18.157 +                             key->uids->email, import->fpr, NULL, key->uids->name);
  18.158 +
  18.159 +                        gpg.gpgme_key_unref(key);
  18.160 +
  18.161 +                        if (ident == NULL) {
  18.162 +                            gpg.gpgme_data_release(dh);
  18.163 +                            return PEP_OUT_OF_MEMORY;
  18.164 +                        }
  18.165 +
  18.166 +                        *private_idents = identity_list_add(*private_idents, ident);
  18.167 +
  18.168 +                        if (*private_idents == NULL) {
  18.169 +                            gpg.gpgme_data_release(dh);
  18.170 +                            return PEP_OUT_OF_MEMORY;
  18.171 +                        }
  18.172 +                    }
  18.173 +                    else 
  18.174 +                    {
  18.175 +                        gpg.gpgme_key_unref(key);
  18.176 +                        gpg.gpgme_data_release(dh);
  18.177 +                        return PEP_UNKNOWN_ERROR;
  18.178 +                    }
  18.179 +                }
  18.180 +            }
  18.181 +        }
  18.182          break;
  18.183      case GPG_ERR_INV_VALUE:
  18.184          assert(0);
    19.1 --- a/src/pgp_gpg.h	Mon Jun 13 09:06:20 2016 +0200
    19.2 +++ b/src/pgp_gpg.h	Sun Jun 26 18:04:25 2016 +0200
    19.3 @@ -41,7 +41,10 @@
    19.4      );
    19.5  
    19.6  PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
    19.7 -        size_t size);
    19.8 +                              size_t size, identity_list **private_idents);
    19.9 +
   19.10 +PEP_STATUS pgp_import_private_keydata(PEP_SESSION session, const char *key_data,
   19.11 +                                      size_t size, identity_list **private_idents);
   19.12  
   19.13  PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern);
   19.14  PEP_STATUS pgp_send_key(PEP_SESSION session, const char *pattern);
    20.1 --- a/src/pgp_gpg_internal.h	Mon Jun 13 09:06:20 2016 +0200
    20.2 +++ b/src/pgp_gpg_internal.h	Sun Jun 26 18:04:25 2016 +0200
    20.3 @@ -55,6 +55,7 @@
    20.4      const gpgme_key_t KEY, int ALLOW_SECRET);
    20.5  typedef gpgme_error_t(*gpgme_op_import_t)(gpgme_ctx_t CTX,
    20.6      gpgme_data_t KEYDATA);
    20.7 +typedef gpgme_import_result_t(*gpgme_op_import_result_t)(gpgme_ctx_t CTX);
    20.8  typedef gpgme_error_t(*gpgme_op_export_t)(gpgme_ctx_t CTX,
    20.9      const char *PATTERN, gpgme_export_mode_t MODE, gpgme_data_t KEYDATA);
   20.10  typedef gpgme_error_t(*gpgme_set_keylist_mode_t)(gpgme_ctx_t CTX,
   20.11 @@ -106,6 +107,7 @@
   20.12      gpgme_op_genkey_result_t gpgme_op_genkey_result;
   20.13      gpgme_op_delete_t gpgme_op_delete;
   20.14      gpgme_op_import_t gpgme_op_import;
   20.15 +    gpgme_op_import_result_t gpgme_op_import_result;
   20.16      gpgme_op_export_t gpgme_op_export;
   20.17      gpgme_set_keylist_mode_t gpgme_set_keylist_mode;
   20.18      gpgme_get_keylist_mode_t gpgme_get_keylist_mode;
    21.1 --- a/src/platform_unix.c	Mon Jun 13 09:06:20 2016 +0200
    21.2 +++ b/src/platform_unix.c	Sun Jun 26 18:04:25 2016 +0200
    21.3 @@ -113,6 +113,7 @@
    21.4  
    21.5  static const char *gpg_conf_path = ".gnupg";
    21.6  static const char *gpg_conf_name = "gpg.conf";
    21.7 +static const char *gpg_agent_conf_name = "gpg-agent.conf";
    21.8  static const char *gpg_conf_empty = "# Created by pEpEngine\n";
    21.9  
   21.10  static bool ensure_gpg_home(const char **conf, const char **home){
   21.11 @@ -186,6 +187,51 @@
   21.12      return true;
   21.13  }
   21.14  
   21.15 +static bool ensure_gpg_agent_conf(const char **agent_conf){
   21.16 +    static char agent_path[MAX_PATH];
   21.17 +    static bool done = false;
   21.18 +
   21.19 +    if (!done) {
   21.20 +        const char *dirname;
   21.21 +
   21.22 +        if (!ensure_gpg_home(NULL, &dirname)) /* Then dirname won't be set. */
   21.23 +            return false;
   21.24 +
   21.25 +        char *p;
   21.26 +        p = stpncpy(agent_path, dirname, MAX_PATH);
   21.27 +        
   21.28 +        size_t len = MAX_PATH - (p - agent_path) - 2;
   21.29 +
   21.30 +        if (len < strlen(gpg_agent_conf_name))
   21.31 +        {
   21.32 +            assert(0);
   21.33 +            return false;
   21.34 +        }
   21.35 +
   21.36 +        *p++ = '/';
   21.37 +     
   21.38 +        strncpy(p, gpg_agent_conf_name, len);
   21.39 +
   21.40 +        if(access(agent_path, F_OK)){ 
   21.41 +            int fd;
   21.42 +            if(access(dirname, F_OK )) { 
   21.43 +                mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR);
   21.44 +            }
   21.45 +
   21.46 +            fd = open(agent_path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
   21.47 +
   21.48 +            if(fd>0) {
   21.49 +                write(fd, gpg_conf_empty, strlen(gpg_conf_empty));
   21.50 +                close(fd);
   21.51 +            }
   21.52 +        }
   21.53 +        done = true;
   21.54 +    }
   21.55 +    if(agent_conf) *agent_conf=agent_path;
   21.56 +
   21.57 +    return true;
   21.58 +}
   21.59 +
   21.60  const char *gpg_conf(void)
   21.61  {
   21.62      const char *conf;
   21.63 @@ -201,3 +247,11 @@
   21.64          return home;
   21.65      return NULL;
   21.66  }
   21.67 +
   21.68 +const char *gpg_agent_conf(void)
   21.69 +{
   21.70 +    const char *agent_conf;
   21.71 +    if(ensure_gpg_agent_conf(&agent_conf))
   21.72 +        return agent_conf;
   21.73 +    return NULL;
   21.74 +}
    22.1 --- a/src/platform_unix.h	Mon Jun 13 09:06:20 2016 +0200
    22.2 +++ b/src/platform_unix.h	Sun Jun 26 18:04:25 2016 +0200
    22.3 @@ -11,6 +11,7 @@
    22.4  const char *unix_local_db(void);
    22.5  
    22.6  const char *gpg_conf(void);
    22.7 +const char *gpg_agent_conf(void);
    22.8  const char *gpg_home(void);
    22.9  
   22.10  #ifdef ANDROID
    23.1 --- a/src/platform_windows.cpp	Mon Jun 13 09:06:20 2016 +0200
    23.2 +++ b/src/platform_windows.cpp	Sun Jun 26 18:04:25 2016 +0200
    23.3 @@ -190,6 +190,15 @@
    23.4      return path.c_str();
    23.5  }
    23.6  
    23.7 +const char *gpg_agent_conf(void)
    23.8 +{
    23.9 +    static string agent_path;
   23.10 +    if (agent_path.length() == 0)
   23.11 +        agent_path = managementPath("%APPDATA%\\gnupg", "gpg-agent.conf");
   23.12 +    return agent_path.c_str();
   23.13 +}
   23.14 +
   23.15 +
   23.16  long random(void)
   23.17  {
   23.18      unsigned int r;
    24.1 --- a/src/sync_actions.c	Mon Jun 13 09:06:20 2016 +0200
    24.2 +++ b/src/sync_actions.c	Sun Jun 26 18:04:25 2016 +0200
    24.3 @@ -32,6 +32,7 @@
    24.4      Beacon_t *msg = NULL;
    24.5      char *payload = NULL;
    24.6      message *_message = NULL;
    24.7 +    pEp_identity *me = NULL;
    24.8  
    24.9      assert(session);
   24.10      assert(!partner);
   24.11 @@ -55,7 +56,7 @@
   24.12  
   24.13      msg->state = (long) state;
   24.14  
   24.15 -    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
   24.16 +    me = new_identity(NULL, NULL, NULL, NULL);
   24.17      if (!me)
   24.18          goto enomem;
   24.19      status = myself(session, me);
   24.20 @@ -81,6 +82,9 @@
   24.21          goto error;
   24.22      payload = NULL;
   24.23  
   24.24 +    free_identity(me);
   24.25 +    me = NULL;
   24.26 +
   24.27      status = session->messageToSend(session->sync_obj, _message);
   24.28  
   24.29      free_message(_message);
   24.30 @@ -94,6 +98,7 @@
   24.31      ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
   24.32      free(payload);
   24.33      free_message(_message);
   24.34 +    free_identity(me);
   24.35      return status;
   24.36  }
   24.37  
   24.38 @@ -118,6 +123,7 @@
   24.39      HandshakeRequest_t *msg = NULL;
   24.40      char *payload = NULL;
   24.41      message *_message = NULL;
   24.42 +    pEp_identity *me = NULL;
   24.43  
   24.44      assert(session);
   24.45      assert(partner);
   24.46 @@ -141,7 +147,7 @@
   24.47  
   24.48      msg->state = (long) state;
   24.49  
   24.50 -    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
   24.51 +    me = new_identity(NULL, NULL, NULL, NULL);
   24.52      if (!me)
   24.53          goto enomem;
   24.54      status = myself(session, me);
   24.55 @@ -170,6 +176,9 @@
   24.56          goto error;
   24.57      payload = NULL;
   24.58  
   24.59 +    free_identity(me);
   24.60 +    me = NULL;
   24.61 +
   24.62      status = session->messageToSend(session->sync_obj, _message);
   24.63  
   24.64      free_message(_message);
   24.65 @@ -183,6 +192,7 @@
   24.66      ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
   24.67      free(payload);
   24.68      free_message(_message);
   24.69 +    free_identity(me);
   24.70      return status;
   24.71  }
   24.72  
   24.73 @@ -315,6 +325,7 @@
   24.74      GroupKeys_t *msg = NULL;
   24.75      char *payload = NULL;
   24.76      message *_message = NULL;
   24.77 +    pEp_identity *me = NULL;
   24.78  
   24.79      assert(session);
   24.80      assert(!partner);
   24.81 @@ -338,7 +349,7 @@
   24.82  
   24.83      msg->state = (long) state;
   24.84  
   24.85 -    pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
   24.86 +    me = new_identity(NULL, NULL, NULL, NULL);
   24.87      if (!me)
   24.88          goto enomem;
   24.89      status = myself(session, me);
   24.90 @@ -364,6 +375,9 @@
   24.91          goto error;
   24.92      payload = NULL;
   24.93  
   24.94 +    free_identity(me);
   24.95 +    me = NULL;
   24.96 +
   24.97      status = session->messageToSend(session->sync_obj, _message);
   24.98  
   24.99      free_message(_message);
  24.100 @@ -377,6 +391,7 @@
  24.101      ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
  24.102      free(payload);
  24.103      free_message(_message);
  24.104 +    free_identity(me);
  24.105      return status;
  24.106  }
  24.107  
    25.1 --- a/src/sync_driver.c	Mon Jun 13 09:06:20 2016 +0200
    25.2 +++ b/src/sync_driver.c	Sun Jun 26 18:04:25 2016 +0200
    25.3 @@ -4,7 +4,7 @@
    25.4  #include "pEp_internal.h"
    25.5  
    25.6  
    25.7 -PEP_STATUS fsm_DeviceState_inject(
    25.8 +DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    25.9          PEP_SESSION session,
   25.10          DeviceState_event event,
   25.11          Identity partner,
   25.12 @@ -13,7 +13,6 @@
   25.13  {
   25.14      PEP_STATUS status = PEP_STATUS_OK;
   25.15  
   25.16 -    session->sync_state = InitState;
   25.17      session->sync_state = fsm_DeviceState(session, session->sync_state,
   25.18              event, partner, state_partner);
   25.19  
    26.1 --- a/src/sync_fsm.c	Mon Jun 13 09:06:20 2016 +0200
    26.2 +++ b/src/sync_fsm.c	Sun Jun 26 18:04:25 2016 +0200
    26.3 @@ -16,7 +16,7 @@
    26.4              case Init:
    26.5                  return Sole;
    26.6          default:
    26.7 -            return invalid_event;
    26.8 +            return (DeviceState_state) invalid_event;
    26.9          }
   26.10          break;
   26.11      
   26.12 @@ -35,7 +35,7 @@
   26.13                  sendHandshakeRequest(session, state, partner);
   26.14                  return HandshakingSole;
   26.15          default:
   26.16 -            return invalid_event;
   26.17 +            return (DeviceState_state) invalid_event;
   26.18          }
   26.19          break;
   26.20      
   26.21 @@ -50,7 +50,7 @@
   26.22              case HandshakeAccepted:
   26.23                  return WaitForGroupKeys;
   26.24          default:
   26.25 -            return invalid_event;
   26.26 +            return (DeviceState_state) invalid_event;
   26.27          }
   26.28          break;
   26.29      
   26.30 @@ -65,7 +65,7 @@
   26.31                  reject(session, state, partner);
   26.32                  return Sole;
   26.33          default:
   26.34 -            return invalid_event;
   26.35 +            return (DeviceState_state) invalid_event;
   26.36          }
   26.37          break;
   26.38      
   26.39 @@ -88,12 +88,12 @@
   26.40                  reject(session, state, NULL);
   26.41                  break;
   26.42          default:
   26.43 -            return invalid_event;
   26.44 +            return (DeviceState_state) invalid_event;
   26.45          }
   26.46          break;
   26.47      
   26.48          default:
   26.49 -            return invalid_state;
   26.50 +            return (DeviceState_state) invalid_state;
   26.51      }
   26.52  
   26.53      return state;
    27.1 --- a/src/sync_fsm.h	Mon Jun 13 09:06:20 2016 +0200
    27.2 +++ b/src/sync_fsm.h	Sun Jun 26 18:04:25 2016 +0200
    27.3 @@ -16,14 +16,14 @@
    27.4  // error values
    27.5  
    27.6  typedef enum _fsm_error {
    27.7 -    invalid_state = -1,
    27.8 -    invalid_event = -2
    27.9 +    invalid_state = -2,
   27.10 +    invalid_event = -3
   27.11  } fsm_error;
   27.12  
   27.13  // states
   27.14  
   27.15  typedef enum _DeviceState_state {
   27.16 -    DeviceState_state_NONE = 0,
   27.17 +    DeviceState_state_NONE = -1,
   27.18      InitState, 
   27.19      Sole, 
   27.20      HandshakingSole, 
   27.21 @@ -34,7 +34,7 @@
   27.22  // events
   27.23  
   27.24  typedef enum _DeviceState_event {
   27.25 -    DeviceState_event_NONE = 0,
   27.26 +    DeviceState_event_NONE = -1,
   27.27      Beacon = 1,
   27.28      HandshakeRequest = 2,
   27.29      GroupKeys = 3,
   27.30 @@ -68,7 +68,7 @@
   27.31  
   27.32  // driver
   27.33  
   27.34 -PEP_STATUS fsm_DeviceState_inject(
   27.35 +DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
   27.36          PEP_SESSION session,
   27.37          DeviceState_event event,
   27.38          Identity partner,
    28.1 --- a/sync/Makefile	Mon Jun 13 09:06:20 2016 +0200
    28.2 +++ b/sync/Makefile	Sun Jun 26 18:04:25 2016 +0200
    28.3 @@ -5,10 +5,10 @@
    28.4  skeleton: ../src/sync_actions.c.skeleton
    28.5  
    28.6  ../src/sync_actions.c.skeleton: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    28.7 -	$(YML2PROC) -I$(YML_PATH) -y gen_actions_skeleton.ysl2 $< -o $@
    28.8 +	$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
    28.9  
   28.10  ../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
   28.11 -	$(YML2PROC) -I$(YML_PATH) -y gen_statemachine.ysl2 $< -o $@
   28.12 +	$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
   28.13  
   28.14  .PHONY: clean
   28.15  
    29.1 --- a/sync/gen_actions_skeleton.ysl2	Mon Jun 13 09:06:20 2016 +0200
    29.2 +++ b/sync/gen_actions_skeleton.ysl2	Sun Jun 26 18:04:25 2016 +0200
    29.3 @@ -130,6 +130,7 @@
    29.4              «$name»_t *msg = NULL;
    29.5              char *payload = NULL;
    29.6              message *_message = NULL;
    29.7 +            pEp_identity *me = NULL;
    29.8  
    29.9              `` call "paramcheck" with "partner", "parm/partner";
   29.10  
   29.11 @@ -150,7 +151,7 @@
   29.12  
   29.13              msg->state = (long) state;
   29.14  
   29.15 -            pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
   29.16 +            me = new_identity(NULL, NULL, NULL, NULL);
   29.17              if (!me)
   29.18                  goto enomem;
   29.19              status = myself(session, me);
   29.20 @@ -185,6 +186,9 @@
   29.21                  goto error;
   29.22              payload = NULL;
   29.23  
   29.24 +            free_identity(me);
   29.25 +            me = NULL;
   29.26 +
   29.27              status = session->messageToSend(session->sync_obj, _message);
   29.28  
   29.29              free_message(_message);
   29.30 @@ -198,6 +202,7 @@
   29.31              ASN_STRUCT_FREE(asn_DEF_«$name», msg);
   29.32              free(payload);
   29.33              free_message(_message);
   29.34 +            free_identity(me);
   29.35              return status;
   29.36          }
   29.37  
    30.1 --- a/sync/gen_statemachine.ysl2	Mon Jun 13 09:06:20 2016 +0200
    30.2 +++ b/sync/gen_statemachine.ysl2	Sun Jun 26 18:04:25 2016 +0200
    30.3 @@ -30,21 +30,21 @@
    30.4          // error values
    30.5  
    30.6          typedef enum _fsm_error {
    30.7 -            invalid_state = -1,
    30.8 -            invalid_event = -2
    30.9 +            invalid_state = -2,
   30.10 +            invalid_event = -3
   30.11          } fsm_error;
   30.12  
   30.13          // states
   30.14  
   30.15          typedef enum _«@name»_state {
   30.16 -            «@name»_state_NONE = 0,
   30.17 +            «@name»_state_NONE = -1,
   30.18          `` for "func:distinctName(state)" |> «@name»`if "position()!=last()" > , `
   30.19          } «@name»_state;
   30.20  
   30.21          // events
   30.22  
   30.23          typedef enum _«@name»_event {
   30.24 -            «@name»_event_NONE = 0,
   30.25 +            «@name»_event_NONE = -1,
   30.26          ||
   30.27          for "func:distinctName(state/event[not(not(/protocol/fsm/tag/@name=@name))])" {
   30.28              const "name", "@name";
   30.29 @@ -93,7 +93,7 @@
   30.30          #include "pEp_internal.h"
   30.31  
   30.32  
   30.33 -        PEP_STATUS fsm_«@name»_inject(
   30.34 +        DYNAMIC_API PEP_STATUS fsm_«@name»_inject(
   30.35                  PEP_SESSION session,
   30.36                  «@name»_event event,
   30.37                  Identity partner,
   30.38 @@ -102,7 +102,6 @@
   30.39          {
   30.40              PEP_STATUS status = PEP_STATUS_OK;
   30.41  
   30.42 -            session->sync_state = InitState;
   30.43              session->sync_state = fsm_«@name»(session, session->sync_state,
   30.44                      event, partner, state_partner);
   30.45  
   30.46 @@ -126,7 +125,7 @@
   30.47              switch (state) {
   30.48                  `` apply "state"
   30.49                  default:
   30.50 -                    return invalid_state;
   30.51 +                    return («@name»_state) invalid_state;
   30.52              }
   30.53  
   30.54              return state;
   30.55 @@ -141,7 +140,7 @@
   30.56          switch (event) {
   30.57          `` apply "event", 2
   30.58          default:
   30.59 -            return invalid_event;
   30.60 +            return («../@name»_state) invalid_event;
   30.61          }
   30.62          break;
   30.63  
    31.1 --- a/sync/sync.fsm	Mon Jun 13 09:06:20 2016 +0200
    31.2 +++ b/sync/sync.fsm	Sun Jun 26 18:04:25 2016 +0200
    31.3 @@ -78,6 +78,7 @@
    31.4                  do reject partner;
    31.5          }
    31.6  
    31.7 +        tag InitState 0;
    31.8          tag Beacon 1;
    31.9          tag HandshakeRequest 2;
   31.10          tag GroupKeys 3;
    32.1 --- a/test/Makefile	Mon Jun 13 09:06:20 2016 +0200
    32.2 +++ b/test/Makefile	Sun Jun 26 18:04:25 2016 +0200
    32.3 @@ -5,7 +5,7 @@
    32.4  LD?=$(CXX)
    32.5  LDFLAGS?=-L$(HOME)/lib
    32.6  LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
    32.7 -CXXFLAGS?=-g -O0 -I../src -I../asn.1
    32.8 +CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
    32.9  # CXXFLAGS=-O3 -DNDEBUG
   32.10  
   32.11  ifeq ("$(OPENPGP)","NETPGP")
   32.12 @@ -32,6 +32,9 @@
   32.13  %_test_run : %_test
   32.14  	LD_LIBRARY_PATH=~/lib:../src ./$<
   32.15  
   32.16 +%_test_lldb : %_test
   32.17 +	LD_LIBRARY_PATH=~/lib:../src lldb ./$<
   32.18 +
   32.19  unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   32.20  
   32.21  install:
    33.1 --- a/test/message_api_test.cc	Mon Jun 13 09:06:20 2016 +0200
    33.2 +++ b/test/message_api_test.cc	Sun Jun 26 18:04:25 2016 +0200
    33.3 @@ -15,7 +15,7 @@
    33.4      PEP_SESSION session;
    33.5      
    33.6      cout << "calling init()\n";
    33.7 -    PEP_STATUS status1 = init(&session);   
    33.8 +    PEP_STATUS status1 = init(&session);
    33.9      assert(status1 == PEP_STATUS_OK);
   33.10      assert(session);
   33.11      cout << "init() completed.\n";
   33.12 @@ -24,16 +24,19 @@
   33.13  
   33.14      cout << "creating message…\n";
   33.15      pEp_identity * me2 = new_identity("outlooktest@dingens.org", NULL, PEP_OWN_USERID, "Outlook Test");
   33.16 +    // pEp_identity * me2 = new_identity("test@nokey.plop", NULL, PEP_OWN_USERID, "Test no key");
   33.17      me2->me = true;
   33.18      identity_list *to2 = new_identity_list(new_identity("vb@dingens.org", NULL, "42", "Volker Birk"));
   33.19 +    // identity_list *to2 = new_identity_list(new_identity("still@nokey.blup", NULL, "42", "Still no key"));
   33.20      message *msg2 = new_message(PEP_dir_outgoing);
   33.21      assert(msg2);
   33.22      msg2->from = me2;
   33.23      msg2->to = to2;
   33.24      msg2->shortmsg = strdup("hello, world");
   33.25 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   33.26      cout << "message created.\n";
   33.27  
   33.28 -    char *text2;
   33.29 +    char *text2 = nullptr;
   33.30      PEP_STATUS status2 = mime_encode_message(msg2, false, &text2);
   33.31      assert(status2 == PEP_STATUS_OK);
   33.32      assert(text2);
   33.33 @@ -44,9 +47,10 @@
   33.34      free(text2);
   33.35  
   33.36      cout << "encrypting message as MIME multipart…\n";
   33.37 -    message *enc_msg2;
   33.38 +    message *enc_msg2 = nullptr;
   33.39      cout << "calling encrypt_message()\n";
   33.40      status2 = encrypt_message(session, msg2, NULL, &enc_msg2, PEP_enc_PGP_MIME);
   33.41 +    cout << "encrypt_message() returns " << status2 << '.' << endl;
   33.42      assert(status2 == PEP_STATUS_OK);
   33.43      assert(enc_msg2);
   33.44      cout << "message encrypted.\n";
   33.45 @@ -58,43 +62,77 @@
   33.46      cout << "encrypted:\n\n";
   33.47      cout << text2 << "\n";
   33.48  
   33.49 -    message *msg3;
   33.50 +    message *msg3 = nullptr;
   33.51      PEP_STATUS status3 = mime_decode_message(text2, strlen(text2), &msg3);
   33.52      assert(status3 == PEP_STATUS_OK);
   33.53 -    string string3 = text2;
   33.54 -    free(text2);
   33.55 +    const string string3 = text2;
   33.56 +    //free(text2);
   33.57  
   33.58      unlink("msg4.asc");
   33.59      ofstream outFile3("msg4.asc");
   33.60      outFile3.write(string3.c_str(), string3.size());
   33.61      outFile3.close();
   33.62  
   33.63 -    message *msg4;
   33.64 -    stringlist_t *keylist4;
   33.65 +    message *msg4 = nullptr;
   33.66 +    stringlist_t *keylist4 = nullptr;
   33.67      PEP_color color;
   33.68 -    PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &color);
   33.69 +    PEP_decrypt_flags_t flags;
   33.70 +    
   33.71 +    PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &color, &flags);
   33.72      assert(status4 == PEP_STATUS_OK);
   33.73      assert(msg4);
   33.74      assert(keylist4);
   33.75      assert(color);
   33.76  
   33.77      cout << "keys used:";
   33.78 -    stringlist_t *kl4;
   33.79 -    for (kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
   33.80 +    for (stringlist_t* kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
   33.81 +    {
   33.82          cout << " " << kl4->value;
   33.83 +    }
   33.84      cout << "\n\n";
   33.85  
   33.86      free_stringlist(keylist4);
   33.87  
   33.88 +    cout << "opening msg_no_key.asc for reading\n";
   33.89 +    ifstream inFile3 ("msg_no_key.asc");
   33.90 +    assert(inFile3.is_open());
   33.91 +
   33.92 +    string text3;
   33.93 +
   33.94 +    cout << "reading msg_no_key.asc sample\n";
   33.95 +    while (!inFile3.eof()) {
   33.96 +        static string line;
   33.97 +        getline(inFile3, line);
   33.98 +        text3 += line + "\r\n";
   33.99 +    }
  33.100 +    inFile3.close();
  33.101 +
  33.102 +    message *msg5 = nullptr;
  33.103 +    PEP_STATUS status5 = mime_decode_message(text3.c_str(), text3.length(), &msg5);
  33.104 +    assert(status5 == PEP_STATUS_OK);
  33.105 +
  33.106 +    message *msg6 = nullptr;
  33.107 +    stringlist_t *keylist5 = nullptr;
  33.108 +    PEP_color color2;
  33.109 +    PEP_decrypt_flags_t flags2;
  33.110 +    PEP_STATUS status6 = decrypt_message(session, msg5, &msg6, &keylist5, &color2, &flags2);
  33.111 +    assert(status6 == PEP_DECRYPT_NO_KEY);
  33.112 +    assert(msg6 == NULL);
  33.113 +    assert(keylist5 == NULL);
  33.114 +    assert(color2 == PEP_rating_have_no_key);
  33.115 +    cout << "color :" << color2 << "\n";
  33.116 +    free_stringlist(keylist5);
  33.117 +
  33.118      cout << "freeing messages…\n";
  33.119      free_message(msg4);
  33.120      free_message(msg3);
  33.121      free_message(msg2);
  33.122      free_message(enc_msg2);
  33.123 +    free_message(msg6);
  33.124 +    free_message(msg5);
  33.125      cout << "done.\n";
  33.126  
  33.127      cout << "calling release()\n";
  33.128      release(session);
  33.129      return 0;
  33.130  }
  33.131 -
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/msg_no_key.asc	Sun Jun 26 18:04:25 2016 +0200
    34.3 @@ -0,0 +1,86 @@
    34.4 +From: Test no key <test@nokey.plop>
    34.5 +To: Still no key <still@nokey.blup>
    34.6 +Subject: pEp
    34.7 +X-pEp-Version: 1.0
    34.8 +MIME-Version: 1.0
    34.9 +Content-Type: multipart/encrypted; boundary="74b0dc5119495cff2ae8944a625558ec"; 
   34.10 + protocol="application/pgp-encrypted"
   34.11 +
   34.12 +--74b0dc5119495cff2ae8944a625558ec
   34.13 +Content-Type: application/pgp-encrypted
   34.14 +
   34.15 +Version: 1
   34.16 +--74b0dc5119495cff2ae8944a625558ec
   34.17 +Content-Type: application/octet-stream
   34.18 +Content-Transfer-Encoding: 7bit
   34.19 +Content-Disposition: inline; filename="msg.asc"
   34.20 +
   34.21 +-----BEGIN PGP MESSAGE-----
   34.22 +
   34.23 +hQEMA3RCTrevwG3jAQf/ajRuor6jilyO5RvQqkhTH5EIl70QbRKCFv+R09/JVY3J
   34.24 ++UmpmZUWR91STplFyHWap2bIPnmLi7iTYhJf2n7w5NmDVju4fykw8rVl+khShdZu
   34.25 +harEilWGdiKnPoux/iBeicflLSiKI5hoR/kk2XPPvyDCCFUIwF3md96W+PFom3mv
   34.26 +asgJ5wUGW2VXIx608pP0iRh6Nb6adtcShggK2ClBYMfLvHXZ6J/hxAJLa03geIWR
   34.27 +rsPEsYvGHlF8pkpnJj1SqbIL5Wl1SDjzxvd3xj19O+ykOtcs+1SDIL8ieup1xBUy
   34.28 +2dnTaWbNwl/i6YkyFWFH03pj0g1UH5U0j60BAVHdBIUBDAPkhdA1fp/D8QEH/32c
   34.29 +Bvfo7YSQ4Lh2yLAJbNsw9vi6Pn+FeNQRLFJK0ncnUMHEywIQTXrhRPOI52Y1Dl5C
   34.30 +JlRbba1e3APOClWr1h12kF+7eTNTPjcnAK+qifzCZgqudL47eMbZQUdc/ycBHsML
   34.31 +5Am1LoDnaRIGUoNVJyrH2sQCov3tSCMcaQ4RoCkDwNef6iLYEtBh+jE9mIIOr5fE
   34.32 +6iLwAigzOh4zx94znCv58nV7jp6wWbCGCRjMTQEI3bLiwv6qVwzTYOoch719LYen
   34.33 ++lRMufz+JwQpn8Uj4d8HYNB3Dzn+WMPORG0ANxO7s1CT1a8GwEEX3Kxc4McxLWX0
   34.34 +4KH5dsV1Sb2u7pM1vqTS6wGi6x3rXCef/fD52xGy4yoBputlqT7esWa7yptmlhwD
   34.35 +nnP40nDubynyKCnxzEHpoLDsmULyDlZqXEFSjLOBxFu/sBfm2uzZ47MR/Eod5rEB
   34.36 +tzcXOBDS8Hc/yr5bRBoKxXoLdcocZtTnczgFNcaTlRy219DkqvUM8DQfkPcsWqBE
   34.37 +Thn83B92nkQbm/so3oRNAUdm3Z8w2a3wZao+WB73OYKgB3ugXf52L6GWTWOOxn1H
   34.38 +VXqxTJokGMCBomIsBJn300gEDXwNJhyYWGHpYPp9am/Ym/ZamwnKSfQlh8+d4z63
   34.39 +8NM78UHJWKUNnn7yP8Vd4zc05fYQFyxM1mXS2YlW5Ch5DkOOu0XNSam2f/9W/7xd
   34.40 +9WMtgKGQ33h+vqmnJ6gpzyUSfJ8QRcYzuCMxW0rPLIrxnP/V5+lV0GqaIkMyQxCH
   34.41 +OvaclLOTvsW9gNRAkUFxvfPdwq3pTim8GSd2oCxETIaBI2xca2NQ6NtKjddbADbV
   34.42 +mbPdyJHKahEVuAXLQ8KVmdcvEjaJYt+Mch14p439vxo611VNYTaSOuoqEeB9VYEP
   34.43 +8TkP80l7d7q9iJ9mF1jw/+ykdpDWPGn3zECeg2vXCvksqtyMJ/XeflYxge3H8LRZ
   34.44 +DUwDa5crXH5Iq7pSwdzWvVTzjkBZzawY3zJGMTpnnb4EdTQldBdHQxCgTHMBWn7f
   34.45 +6FqFXmMAHJC3nYs8ysFmfGLIiOjdedGc3O95oMFcYjzHafKc6LH1GGkNCDRXYC8M
   34.46 +mJm3lpDxkCselGXeHBopuxLFmmv8xZ2vdu454r69lMIDgE2huEdsNyTzKc3aG00B
   34.47 +jE5etwcxGEFRAbHS4EvYY63DwCYr4Qh7uKh7jID2skT8zGPQitPOYBuOJ/2h0thK
   34.48 +e3Ztohf+P/VSYIipXZP6dCYNRTVoaPFfKA9+OyLXWccADpmqXJe8wCQ397Eo2gNW
   34.49 +Yl6P57cCHn8mW7SIWwePmSnYAHn0uAkpIYked6p5vNHX/6xHjXLeeFTVC3ZK5gFh
   34.50 +6C2xEvLh41ACLPdeqM3ANXWiZDYnkZ9LlwV2EZywTI6urd+OcslGuRf1lrfnFDWm
   34.51 +K2w4PKxhoziizxrn6OjAzF+d9iqn0VOLh1H9PuMVbHwEO8vhYH0vfyjxkXUdLBgK
   34.52 +nSXZ9BPv9IL1CYhhN6hFiP1Va8SteHDhmMzRLZ9hjkTdLEP5Lu+AVwH0FkviaAan
   34.53 +s5gGdFe+pOmmkuC5s589XTpIGGug60z2u38SoN0LvtSPene7Wh1nNyzVPiyaFR1L
   34.54 +r78VH3BfUWHEVfGcAlNjajHWFZoCMHjKUPvlcMURls6ZfQwhF/3RGs1X2F6Ts1LO
   34.55 +CaoU4R+iKAgzfSYBKfCKbkjbBXAfq17IBohXcVZZlbKUbKUlGLdxqHWppI5wYJki
   34.56 +ME5iHyoM5HZYHWnsi76fA3sHrwifIuFTl85EZQgR2OUJb3tn3g1ckz5sTscUm2Af
   34.57 +fquWYyPcfF4MyVfbbxjTvVqg0JUAwSXY3t+b1JGBlnrmcu0JBprEuYL60KWmNh+p
   34.58 +jawapj1Cu7GXBrWanEjhZrLKZF3GO3SCBKnINLnWTxWOxO3aSBskGkiNTjMUtWur
   34.59 +7V37A2OKmVTZccTzWzHfppHmsBdvdflMNz1aYy+YgC3YF/5/gDBSsStQoECiZQDx
   34.60 +oENYxI9p6qXepgl0HAeagvWoX82/iKf42mMXdgjPRM+hd0vXvzI1KubQ641b6DUZ
   34.61 +JYYdMFcCW1LfbFb8+/9vF7orFSYIqVW75SLNcb9MMas5KoOcHWrJIK3vHyV+w6fI
   34.62 +8tNzkcvUCMRyiCBkq74JXt1a/yalNjtMvXqU7W3dhTQeZ4OwbYSx0wHJWVjk0o3d
   34.63 +dIl9Y0ig+QJF6MDYOw5NQ/ys3iNhDZVurgFk3eIncFoIHB4k9QovGQNUA/F2qtyR
   34.64 +BtVFYiS5aIQ7tosWWTb7FbBlSTZV1rO8YDi/oQ3XiVLV0ZDan68lQfOO8pE6oIQ+
   34.65 +ZaWXi1jK2koJjV4Vc7+NqLw0FhEuJME7EFI+iuIg8aXKQxP3H0vsdq71L/qxSIcb
   34.66 +V7RnSCDEZPbfssuShzegOkdVWn4u+5lF2ZB6vtt5/noOuopfup1DLBe9OTs8PEg8
   34.67 +JawLixRqWE5njDCVWxinmoovvlaWkshG+2C9+Pc0R6MB1j3G3HdOV03jk+yrAQ2S
   34.68 +hwXmkWEHhhKbF6tdamKJan2ahO/wuW4DSYiAc64ys1bpWctipgaDodgmXa1KkEan
   34.69 +44cQMf0yISdBex8uKqddQDplNxojT1ysky824X3vnApYjZ1O9/9EnQRn9BYuHdIL
   34.70 +8zat3qQAJO0cS0qAnQquoWzPzq7rumHxn248+mox6hD7Bxr+j6lbwyZRnaCcWFbu
   34.71 +11LUs0+pXDB+tKR6iGbuBuLLnj87LtjfzgkpDvlogBiaTFylJ+z4mfvpco05DfmU
   34.72 +CPyLr8LNIm6C3BVWDotgfVzIpsVuLGn+0JGB32RwYK79ngiFbgzjyTpGoIrPSAlr
   34.73 +gcrPR2XpXKMqOIktxJXMNWkBEg0w0ho7pviRCev+/yIxFV5zBNNUYYux1iAJPInQ
   34.74 +HDODyPFxC3YkRiFsw1c1GxI0dWdefQD7ClS8PFDrMIUeuPZMMt1TwUDB49uJqI7i
   34.75 ++n4MSfrxk1VTdSBH6dGk34ryoymMRwdLFcMyjNOICeCBnvmbc8qbBNg1hnr1Mbaz
   34.76 +pJl0dVXorszIZtx0EdE4KXu0+F8+LED6ASSH4lYLlsKirZkfDuTCE88d6MIIpjpb
   34.77 +wOm9ZP7Cb7YbCtFDm1pUF/L/J4TMnPjhufGdXbHwX1E1rB8pcnsShOLJrIhZWeq/
   34.78 +TWl9kmfbcM6OZVzedz1Eq9H5GE5BT/yTNmlrVR5Z2a7xwjbxE6uP+SPhx3Tga4Us
   34.79 +ivBOudkcifSy44AxjYOhPLaFxygs7We4JLIn0WOB6D7hvRDjL4osOKRiqJ5G56kZ
   34.80 +pZ6wGXUUZJzdUAuPPl2mAyxkpErZTXe3ENMFh3vU7YF3ovWgT7en6sRlVV6aCBc+
   34.81 +VNyM6OHFQlMeMowLWacONMQCVKsbMsOtLgBKryqTXugIBJclSV8vDy0zhuQoeQ1B
   34.82 +hUeA4uxoljnTkr5bLnBeKbC8vpViC2cHKsnmDX0cpE/ybyvXAHhbKHGbW912gylv
   34.83 +5V2h/Sct/wleXYYHBTQTsZpbQjAZmn8R8LUfG6H1Ig4CfH8oeBIkjaSt4z9zUBsp
   34.84 +0FdLyughCihVz98UJGVDh/H4fQIyXytqycFwF/mst//GXH9/VzJwRcqUz7MKQxoO
   34.85 +Pd2Y0r3rz5hfj78l1NOXYgdpEzLvQkyQbujU8foJJOxA0pRYlLN9Xr3AoQ==
   34.86 +=uymV
   34.87 +-----END PGP MESSAGE-----
   34.88 +
   34.89 +--74b0dc5119495cff2ae8944a625558ec--
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/no_key.asc	Sun Jun 26 18:04:25 2016 +0200
    35.3 @@ -0,0 +1,56 @@
    35.4 +-----BEGIN PGP PRIVATE KEY BLOCK-----
    35.5 +
    35.6 +lQOYBFdifLABCADG3TqnFQ8npE/XboLx7tv3kU/+qI5aI9fmJ4xZaiyc++/9YXeH
    35.7 +uUN5cTUpzSLIsrVuKDRn7hXorrok92ELrFhL5DbSfn0np6SLxr53821cmJKh2PxQ
    35.8 +3ucA8Mu/QgXE21HeVFGAbaLMaDm4B+0Tp3PAKNDnHNpWtc6+EQGCib4yW6HQ5+9e
    35.9 +aJhglGPbXGr2qanREDiyshuDCaDPrgrs+5CQnUR+vwNfPv7ovyPX7BLmxpaP0gve
   35.10 +4ehpYaK0rUpzvXCNbHt+Shu40aXa0uRU8JajF3tvisJwsXkZcpqVJsP+OGWka7rp
   35.11 +ikicjT0FOCBCYskjTRMfptQnfMF2z7J9yb4ZABEBAAEAB/9EV4IRKpUXOAoyTKnW
   35.12 +sBJLTdaSe2XUh43qbDv4/JqRZqmux+C2tY4BPc0Z7QQfuf7M+Sctcm54FRgmnRdu
   35.13 +Vg/QIQFQLKUhTCUp3ibV/UPftxVpZrMrrbbwpVA4Dd4CrabAg/SwcL0qh0USwDKS
   35.14 +9xC6AKzuSAWnF/sRabG9pU3GawkV5s9bjSCAWuZBQhL0aELGREE8ap+R3bBfz5Et
   35.15 +ModEKGtJwqp/5nRl8NdiO9qNE71MVKFwskSuLNKxPSmi6OBUgCa14713lq0AJdho
   35.16 +RxpOrTI/dhNXBZBhPOsnFTla7V4Z9dPkqoRDyfpki1dmFRSunJILmoR2zSFzWZQo
   35.17 +xts7BADbA8JkCdJClweAK0EyyRE8EzIzgz6QEwj4rHym2ZpQdPrNsKyndQA8PBkF
   35.18 +l9NbeagthSq5je0Ho7McDMX4YeCj2vgKrUu6LNZLb5585AEO5keG8JGeFQv/55Uz
   35.19 +cumrDvgNZLMWrIOi+Ez+wPvwSTNL8z45gxIDS4kD4QsopnH/GwQA6HJXcg8MNy72
   35.20 +bN9+rcZ0Q64RT6f4k8q82QTLTEbw973XswQ4yTJWTuoU5a9AbXFsYS/G8Jhxd3aJ
   35.21 +kdKaaUMaBaTq6/iSc/H+Z3DlNT1wpWDC6yx6UV+ho2xaX0MybM+wohe/E5y7b6/9
   35.22 +XHeDEx1r/r7eUE2syuNhBSMGAkUbptsEAKGFOM6cz44tONKfiJhYVe7M770Rbbld
   35.23 +dmH5AIhw6PFGtlM40DRiMiwLe5VH2ymyoTJ3cKg3Cd51Etgk8ph+w3VwUNh6C3Br
   35.24 +BDTbBpVG7B5CLRVFG+M+CV/UFKzCoR2lt2WEzviweI85IrKM7awyi34vM3uytoKA
   35.25 +savQ6HgApiehNQq0HVRlc3Qgbm8ga2V5IDx0ZXN0QG5va2V5LnBsb3A+iQE3BBMB
   35.26 +CgAhBQJXYnywAhsDBQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJEAwGnPcHfiud
   35.27 +2iUH/iYCQVb4I2PIExOKPZZPFcoFFBrnifR+99G1X9bS65pTsN8aQ3h25DU1YvOY
   35.28 +tGhOFlx1qEBBy0YKzVMrmEl8HfZsqcjnJWvTmAcddENJQZ0ODJRnJC9JhSB5PUfR
   35.29 +X5+QG4At6pdxexKoEbZYsZf3QF8IzUlvybucl9t5sCMd2PBpscmLV2qbR6amivq4
   35.30 +WaBlu8oyenNTGKjGY4g5Xm2hchem87DFnyycY3bOYlWFBQrDe0Dr1Vkk5q7taErf
   35.31 +E561X06HKO2ee6EjHj0+fCKPsY/wbIAMSpwTJ5eFcXILxsH9C+KEt5JYrwe+vlrY
   35.32 +VGt2ytaUD//x+QZ8aHu4SzrqDnedA5gEV2J8sAEIALoZLH5f8bFukM495mR1symr
   35.33 +8cd6PI/Fqze1I3zDOt2cZ+ZdvhCSTAHNi+J9jj1/QG6HxvHp0y9XKjyLOsAiDUJ8
   35.34 +32cEmSdyH+TPWiBSyj+DVyJkQVuUB5++qjJJd53hOoC6/Y7yoCDE1vTaetwzxgAr
   35.35 ++30FjvmTg7uFzLEwclRL1n77x8dzUHqhL6OxTVGtEezF+rE4MYv4bElNp4AgsEaZ
   35.36 +XR4kKxwTE97nmBR78nmXuor2TsyUfLtlpuIE2jkQTDI+YZCAPsVrDy7/uTGtKeoa
   35.37 +8qvnINvl64uy3QZBTpGAL/dtwDjwgl8rO5SAOUs76UAQs+KNpAa1Ne2+Bx9GBlMA
   35.38 +EQEAAQAH/Rxrp8iNAoOkbRJHkHNF07IeLkiBOdUtzPOEWFe/a7Kt0OL07LKUhRhp
   35.39 +ZF7slIJ+d+qUFc/wHm5xE2Q3pyXx4rCFaDYlakuvOYEKIat6DqUbJn18GMx8PkXT
   35.40 +1SOPkL2tyJohny5A44TdoC5jXLawZCFhQNZbuPVoj9+y6WB4vkfHzTGy2y68hmbU
   35.41 +rKm0l8iqvelC4FP8WWNoVDcn992OJ0s/hsMjWAGE0h7KoDi/c50ZZ0JND2VuNMUk
   35.42 +FYH99q15wXQ4a6n9hC7wg632UW+O3MOdCCW9Wfve8DiyHuQ53ytQ7vto/fFKq3aY
   35.43 +TuKvUu4zjsPevVfyTxXXIdq1KfHgYqEEANbRRMXa3w20qutiid9K4Cj72vy4Ba7u
   35.44 +mg8Az65o6V1r1lykFzI4XP3+uSRDaeWt3GTQPtX3hanv/u6VdKqxyPhHsUoy+SqG
   35.45 +S/xqR08x1u55ySFfISNL9UU1tklbi5MJLxljTq2eVg4CSY41kFFllqmNBGro16zJ
   35.46 +I3tHla3Kx6c5BADdxnBWyOWjLyCnTJkK44YPxKXs5kT58zcNaILFxtVA6glKG1vb
   35.47 +7i1STOtYKFD6sI8k7zYXC09kzzuucO5ubh2yiapfUFVZ8WpF+ulM2ANX3n8/+yRL
   35.48 +Y9H886gcwVF3QqyZGh2jyyJoMIS04ePpQZxkJ2fbVM+V3tLKNFglT+6t6wP+Pbus
   35.49 +Pk4P/ALuJx8XIUe9wvMaKBXBeq1fEOKszhP3kTEPAgq0Xc2gHUULNvaBpz003o+t
   35.50 +87j9pMvCsN/bkZcFDvUCEL7Y55gZT8nhRq96JfRZFazXToq8OtlT6C4TJ1bx0KB6
   35.51 +MhWyHRjXWXRJ9406H+S9MnZA+5Ndjm0m7bExNyBLa4kBHwQYAQoACQUCV2J8sAIb
   35.52 +DAAKCRAMBpz3B34rnU9KB/99tygAltB4L2xLz/lOwvigD45Y3D54NKGvR+XtMUnP
   35.53 +lpsoL08KW1S7hugRGNrVMXy5BnTjDOY/IjCPGG2pkw9ZBvDev1ZR/9SFi8Qtp0Wv
   35.54 ++wKZHHGLo6s5FJ13JjwW7eGUsKDjlHl7ET6NZZxBuRS4cuFbnrgBmA3ugVKX0TLK
   35.55 +6sYoiubAZkanpJIusZeqT3cdZZV86B3urVDQqPwMkF+UBw/yBA3e2z7JFwhrzFnl
   35.56 +TZ05Tvx6m6NCxIWQh6ck34c+fQdcLSy8DF/dK0DKmMf5pIgJB7UVbVC5zuEoCa/i
   35.57 +/TBCkEmrTYZDJGv46Dx+ytdjKBHc1SvDyHYpMm1Z/b0d
   35.58 +=NB6+
   35.59 +-----END PGP PRIVATE KEY BLOCK-----
    36.1 --- a/test/pEpEngineTest.cc	Mon Jun 13 09:06:20 2016 +0200
    36.2 +++ b/test/pEpEngineTest.cc	Sun Jun 26 18:04:25 2016 +0200
    36.3 @@ -1,286 +1,285 @@
    36.4 -#include <iostream>
    36.5 -#include <fstream>
    36.6 -#include <string>
    36.7 -
    36.8 -#include <assert.h>
    36.9 -#include <string.h>
   36.10 -
   36.11 -#include "../src/pEpEngine.h"
   36.12 -#include "../src/keymanagement.h"
   36.13 -
   36.14 -using namespace std;
   36.15 -
   36.16 -void ReadFileIntoMem(const char *fname, char* &buffer, size_t &length){
   36.17 -    buffer = NULL;
   36.18 -    length = 0;
   36.19 -	cout << "opening " << fname << " for reading\n";
   36.20 -	ifstream txtFile (fname, ifstream::binary);
   36.21 -	assert(txtFile.is_open());
   36.22 -    if (txtFile) {
   36.23 -        // get length of file:
   36.24 -        txtFile.seekg (0, txtFile.end);
   36.25 -        length = txtFile.tellg();
   36.26 -        txtFile.seekg (0, txtFile.beg);
   36.27 -
   36.28 -        buffer = new char [length+1];
   36.29 -
   36.30 -        cout << "Reading " << length << " characters... ";
   36.31 -        txtFile.read (buffer,length);
   36.32 -        buffer[length]='\0';
   36.33 -
   36.34 -        if (txtFile)
   36.35 -          cout << "all characters read successfully.\n";
   36.36 -        else
   36.37 -          cout << "error: only " << txtFile.gcount() << " could be read\n";
   36.38 -        txtFile.close();
   36.39 -    }
   36.40 -
   36.41 -	txtFile.close();
   36.42 -    assert(buffer);
   36.43 -    assert(length);
   36.44 -}
   36.45 -
   36.46 -int main(int argc, char* argv[])
   36.47 -{
   36.48 -	PEP_SESSION session;
   36.49 -
   36.50 -	cout << "calling init()\n";
   36.51 -	PEP_STATUS init_result = init(&session);
   36.52 -	
   36.53 -    cout << "returning from init() with result == " << init_result << "\n";
   36.54 -	assert(init_result == PEP_STATUS_OK);
   36.55 -
   36.56 -    PEP_SESSION second_session;
   36.57 -    cout << "second session test\n";
   36.58 -    PEP_STATUS second_init_result = init(&second_session);
   36.59 -	cout << "returning from second init() with result == " << second_init_result << "\n";
   36.60 -    assert(second_init_result == PEP_STATUS_OK);
   36.61 -    assert(second_session);
   36.62 -    cout << "dropping second session\n";
   36.63 -	release(second_session);
   36.64 -
   36.65 -	cout << "logging test\n";
   36.66 -	log_event(session, "log test", "pEp Enginge Test", "This is a logging test sample.", "please ignore this line");
   36.67 -
   36.68 -    // Our test user :
   36.69 -    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
   36.70 -    //         6FF00E97
   36.71 -    // A9411D176FF00E97
   36.72 -    // 
   36.73 -    // Other peers :
   36.74 -    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org> 
   36.75 -    //         C9C2EE39
   36.76 -    // 59BFF488C9C2EE39
   36.77 -    // 
   36.78 -    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
   36.79 -    //         70DCF575
   36.80 -    // 135CD6D170DCF575
   36.81 -
   36.82 -    const char *kflist[] = {
   36.83 -        "0x6FF00E97.asc",
   36.84 -        "0xC9C2EE39.asc",
   36.85 -        "0x70DCF575.asc",
   36.86 -        NULL
   36.87 -    };
   36.88 -    const char** kf = kflist;
   36.89 -    while(*kf){
   36.90 -        char * k_user_buffer = NULL;
   36.91 -        size_t k_user_length = 0;
   36.92 -        ReadFileIntoMem(*kf, k_user_buffer, k_user_length);
   36.93 -        cout << "import_key(" << *kf << ")\n";
   36.94 -        PEP_STATUS import_status = import_key(session, k_user_buffer, k_user_length);
   36.95 -        assert(import_status == PEP_STATUS_OK);
   36.96 -        cout << "successfully imported key\n";
   36.97 -        delete[] k_user_buffer;
   36.98 -        kf++;
   36.99 -    }
  36.100 -
  36.101 -    char * cipher_buffer = NULL;
  36.102 -    size_t cipher_length = 0;
  36.103 -    ReadFileIntoMem("msg.asc", cipher_buffer, cipher_length);
  36.104 -
  36.105 -	cout << "\n" << cipher_buffer;
  36.106 -
  36.107 -	char *buf_text = NULL;
  36.108 -	size_t buf_size = 0;
  36.109 -	stringlist_t *keylist;
  36.110 -
  36.111 -    cout << "calling decrypt_and_verify()\n";
  36.112 -    PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer, cipher_length, &buf_text, &buf_size, &keylist);
  36.113 -
  36.114 -    cout << "returning from decrypt_and_verify() with result == 0x" << std::hex << decrypt_result << "\n";
  36.115 -    assert(decrypt_result == PEP_DECRYPTED_AND_VERIFIED);
  36.116 -    assert(buf_text);
  36.117 -    assert(keylist);
  36.118 -
  36.119 -    for (stringlist_t *_keylist=keylist; _keylist!=NULL; _keylist=_keylist->next) {
  36.120 -        assert(_keylist->value);
  36.121 -        cout << "signed with " << _keylist->value << "\n";
  36.122 -    }
  36.123 -
  36.124 -    free_stringlist(keylist);
  36.125 -    buf_text[buf_size] = 0;
  36.126 -    string plain(buf_text);
  36.127 -    pEp_free(buf_text);
  36.128 -    cout << "\n" << plain;
  36.129 -
  36.130 -    char * t1_buffer = NULL;
  36.131 -    size_t t1_length = 0;
  36.132 -    ReadFileIntoMem("t1.txt", t1_buffer, t1_length);
  36.133 -
  36.134 -    char * sig_buffer = NULL;
  36.135 -    size_t sig_length = 0;
  36.136 -    ReadFileIntoMem("signature.asc", sig_buffer, sig_length);
  36.137 -
  36.138 -    cout << "\ncalling verify_text()\n";
  36.139 -    PEP_STATUS verify_result = verify_text(session, t1_buffer, t1_length, sig_buffer, sig_length, &keylist);
  36.140 -    cout << "returning from verify_text() with result == " << verify_result << "\n";
  36.141 -    assert(verify_result == PEP_VERIFIED || verify_result == PEP_VERIFIED_AND_TRUSTED);
  36.142 -    assert(keylist->value);
  36.143 -    cout << "signed with " << keylist->value << "\n";
  36.144 -    free_stringlist(keylist);
  36.145 -
  36.146 -    char * t2_buffer = NULL;
  36.147 -    size_t t2_length = 0;
  36.148 -    ReadFileIntoMem("t2.txt", t2_buffer, t2_length);
  36.149 -
  36.150 -    cout << "\ncalling verify_text()\n";
  36.151 -    verify_result = verify_text(session, t2_buffer, t2_length, sig_buffer, sig_length, &keylist);
  36.152 -    assert(verify_result == PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
  36.153 -    free_stringlist(keylist);
  36.154 -
  36.155 -    keylist = new_stringlist("A9411D176FF00E97");
  36.156 -    stringlist_add(keylist, "59BFF488C9C2EE39");
  36.157 -    stringlist_add(keylist, "135CD6D170DCF575");
  36.158 -
  36.159 -	buf_text = NULL;
  36.160 -	buf_size = 0;
  36.161 -
  36.162 -    cout << "\ncalling encrypt_and_sign()\n";
  36.163 -    PEP_STATUS encrypt_result = encrypt_and_sign(session, keylist, plain.c_str(), plain.length(), &buf_text, &buf_size);
  36.164 -    cout << "returning from encrypt_and_sign() with result == " << encrypt_result << "\n";
  36.165 -    assert(encrypt_result == PEP_STATUS_OK);
  36.166 -    free_stringlist(keylist);
  36.167 -
  36.168 -    buf_text[buf_size] = 0;
  36.169 -    string cipher2(buf_text);
  36.170 -    cout << "\n" << cipher2;
  36.171 -    pEp_free(buf_text);
  36.172 -
  36.173 -    delete[] cipher_buffer;
  36.174 -    delete[] t1_buffer;
  36.175 -    delete[] sig_buffer;
  36.176 -    delete[] t2_buffer;
  36.177 -
  36.178 -	cout << "\nfinding English trustword for 2342...\n";
  36.179 -	char * word;
  36.180 -	size_t wsize;
  36.181 -	trustword(session, 2342, "en", &word, &wsize);
  36.182 -	assert(word);
  36.183 -	cout << "the trustword for 2342 is " << word << "\n";
  36.184 -    pEp_free(word);
  36.185 -
  36.186 -    string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
  36.187 -    char * words;
  36.188 -
  36.189 -    cout << "\nfinding German trustwords for " << fingerprint << "...\n";
  36.190 -    trustwords(session, fingerprint.c_str(), "de", &words, &wsize, 5);
  36.191 -    assert(words);
  36.192 -    cout << words << "\n";
  36.193 -    pEp_free(words);
  36.194 -
  36.195 -	pEp_identity *identity;
  36.196 -
  36.197 -    identity = new_identity(
  36.198 -            "leon.schumacher@digitalekho.com",
  36.199 -            "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
  36.200 -            "23",
  36.201 -            "Leon Schumacher"
  36.202 -        );
  36.203 -	identity->comm_type = PEP_ct_pEp;
  36.204 -
  36.205 -	cout << "\nsetting identity...\n";
  36.206 -	PEP_STATUS pep_set_result = set_identity(session, identity);
  36.207 -	assert(pep_set_result == PEP_STATUS_OK);
  36.208 -    free_identity(identity);
  36.209 -	get_identity(session, "leon.schumacher@digitalekho.com", "23", &identity);
  36.210 -	assert(identity);
  36.211 -	cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << "\n";
  36.212 -
  36.213 -    PEP_STATUS get_trust_result = get_trust(session, identity);
  36.214 -    assert(get_trust_result == PEP_STATUS_OK);
  36.215 -    cout << "trust of " << identity->user_id << " is " << identity->comm_type << "\n";
  36.216 -
  36.217 -    free_identity(identity);
  36.218 -
  36.219 -    cout << "\ngenerating key for testuser\n";
  36.220 -    identity = new_identity(
  36.221 -            "testuser@pibit.ch",
  36.222 -            NULL,
  36.223 -            "423",
  36.224 -            "Alfred E. Neuman"
  36.225 -        );
  36.226 -    assert(identity);
  36.227 -    PEP_STATUS generate_status = generate_keypair(session, identity);
  36.228 -    cout << "generate_keypair() exits with " << generate_status << "\n";
  36.229 -    assert(generate_status == PEP_STATUS_OK);
  36.230 -    cout << "generated key is " << identity->fpr << "\n";
  36.231 -
  36.232 -    string key(identity->fpr);
  36.233 -    free_identity(identity);
  36.234 -
  36.235 -    char *key_data;
  36.236 -    size_t size;
  36.237 -
  36.238 -    cout << "export_key()\n\n";
  36.239 -    PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
  36.240 -    cout << "export_key() exits with " << export_status << "\n";
  36.241 -    assert(export_status == PEP_STATUS_OK);
  36.242 -    cout << key_data << "\n\n";
  36.243 -
  36.244 -    cout << "deleting key pair " << key.c_str() << "\n";
  36.245 -    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
  36.246 -    cout << "delete_keypair() exits with " << delete_status << "\n";
  36.247 -    assert(delete_status == PEP_STATUS_OK);
  36.248 -    
  36.249 -    cout << "import_key()\n";
  36.250 -    PEP_STATUS import_status = import_key(session, key_data, size);
  36.251 -    assert(import_status == PEP_STATUS_OK);
  36.252 -    cout << "successfully imported key\n";
  36.253 -
  36.254 -    pEp_free(key_data);
  36.255 -
  36.256 -    cout << "deleting key " << key.c_str() << " again\n";
  36.257 -    delete_status = delete_keypair(session, key.c_str());
  36.258 -    cout << "delete_keypair() exits with " << delete_status << "\n";
  36.259 -    assert(delete_status == PEP_STATUS_OK);
  36.260 -
  36.261 -    cout << "finding key for pep.test.john@pep-project.org\n";
  36.262 -    PEP_STATUS find_keys_status = find_keys(session, "pep.test.john@pep-project.org", &keylist);
  36.263 -    cout << "find_keys() exits with " << find_keys_status << "\n";
  36.264 -    assert(find_keys_status == PEP_STATUS_OK);
  36.265 -    assert(keylist);
  36.266 -    cout << "found: " << keylist->value << "\n";
  36.267 -    assert(keylist->next == NULL);
  36.268 -    free_stringlist(keylist);
  36.269 -
  36.270 -    cout << "searching for vb@ulm.ccc.de on keyserver\n";
  36.271 -    PEP_STATUS recv_key_status = recv_key(session, "vb@ulm.ccc.de");
  36.272 -    cout << "recv_key() exits with " << recv_key_status << "\n";
  36.273 -    assert(recv_key_status == PEP_STATUS_OK);
  36.274 -
  36.275 -    cout << "sending vb@ulm.ccc.de to keyserver\n";
  36.276 -    PEP_STATUS send_key_status = send_key(session, "vb@ulm.ccc.de");
  36.277 -    cout << "send_key() exits with " << send_key_status << "\n";
  36.278 -    assert(send_key_status == PEP_STATUS_OK);
  36.279 -
  36.280 -    PEP_comm_type tcomm_type;
  36.281 -    PEP_STATUS tstatus = get_key_rating(session, "59BFF488C9C2EE39", &tcomm_type);
  36.282 -    cout << "get_key_rating() exits with " << tstatus << "\n";
  36.283 -    assert(tstatus == PEP_STATUS_OK);
  36.284 -    assert(tcomm_type == PEP_ct_OpenPGP_unconfirmed);
  36.285 -    
  36.286 -	cout << "\ncalling release()\n";
  36.287 -	release(session);
  36.288 -	return 0;
  36.289 -}
  36.290 +#include <iostream>
  36.291 +#include <fstream>
  36.292 +#include <stdexcept>
  36.293 +#include <string>
  36.294 +#include <vector>
  36.295 +
  36.296 +#include <assert.h>
  36.297 +#include <string.h>
  36.298 +
  36.299 +#include "../src/pEpEngine.h"
  36.300 +#include "../src/keymanagement.h"
  36.301 +
  36.302 +
  36.303 +using namespace std;
  36.304 +
  36.305 +typedef std::string Buffer;
  36.306 +
  36.307 +// no C++11, yet? So do our own implementation:
  36.308 +namespace{
  36.309 +    std::string to_string(unsigned long u)
  36.310 +    {
  36.311 +        char buf[32];
  36.312 +        snprintf(buf,31, "%lu", u);
  36.313 +        return buf;
  36.314 +    }
  36.315 +}
  36.316 +
  36.317 +
  36.318 +Buffer ReadFileIntoMem(const char *fname){
  36.319 +    cout << "opening " << fname << " for reading\n";
  36.320 +    ifstream txtFile (fname, ifstream::binary);
  36.321 +    assert(txtFile.is_open());
  36.322 +    if (!txtFile)
  36.323 +    {
  36.324 +        throw std::runtime_error( "error: cannot open file \"" + std::string(fname) + "\"" );
  36.325 +    }
  36.326 +
  36.327 +    Buffer buffer;
  36.328 +
  36.329 +    // get length of file:
  36.330 +    txtFile.seekg (0, txtFile.end);
  36.331 +    const size_t length = txtFile.tellg();
  36.332 +    txtFile.seekg (0, txtFile.beg);
  36.333 +    buffer.resize(length);
  36.334 +
  36.335 +    cout << "Reading " << length << " characters... ";
  36.336 +    txtFile.read (&buffer[0], length);
  36.337 +
  36.338 +    if (!txtFile)
  36.339 +    {
  36.340 +        throw std::runtime_error( "error: only " + to_string(txtFile.gcount()) + " could be read from file" + fname );
  36.341 +    }
  36.342 +
  36.343 +    cout << "all characters read successfully." << std::endl;
  36.344 +    return buffer;
  36.345 +}
  36.346 +
  36.347 +
  36.348 +int main(int argc, char* argv[])
  36.349 +{
  36.350 +    PEP_SESSION session;
  36.351 +
  36.352 +    cout << "calling init()\n";
  36.353 +    PEP_STATUS init_result = init(&session);
  36.354 +    
  36.355 +    cout << "returning from init() with result == " << init_result << "\n";
  36.356 +    assert(init_result == PEP_STATUS_OK);
  36.357 +
  36.358 +    PEP_SESSION second_session;
  36.359 +    cout << "second session test\n";
  36.360 +    PEP_STATUS second_init_result = init(&second_session);
  36.361 +    cout << "returning from second init() with result == " << second_init_result << "\n";
  36.362 +    assert(second_init_result == PEP_STATUS_OK);
  36.363 +    assert(second_session);
  36.364 +    cout << "dropping second session\n";
  36.365 +    release(second_session);
  36.366 +
  36.367 +    cout << "logging test\n";
  36.368 +    log_event(session, "log test", "pEp Enginge Test", "This is a logging test sample.", "please ignore this line");
  36.369 +
  36.370 +    // Our test user :
  36.371 +    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
  36.372 +    //         6FF00E97
  36.373 +    // A9411D176FF00E97
  36.374 +    // 
  36.375 +    // Other peers :
  36.376 +    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org> 
  36.377 +    //         C9C2EE39
  36.378 +    // 59BFF488C9C2EE39
  36.379 +    // 
  36.380 +    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
  36.381 +    //         70DCF575
  36.382 +    // 135CD6D170DCF575
  36.383 +
  36.384 +    const char *kflist[] = {
  36.385 +        "0x6FF00E97.asc",
  36.386 +        "0xC9C2EE39.asc",
  36.387 +        "0x70DCF575.asc",
  36.388 +        NULL
  36.389 +    };
  36.390 +
  36.391 +    const char** kf = kflist;
  36.392 +    while(*kf){
  36.393 +        const Buffer k_user_buffer =  ReadFileIntoMem(*kf);
  36.394 +        cout << "import_key(" << *kf << ")\n";
  36.395 +        PEP_STATUS import_status = import_key(session, k_user_buffer.data(), k_user_buffer.size(), NULL);
  36.396 +        assert(import_status == PEP_STATUS_OK);
  36.397 +        cout << "successfully imported key\n";
  36.398 +        kf++;
  36.399 +    }
  36.400 +
  36.401 +    const Buffer cipher_buffer = ReadFileIntoMem("msg.asc");
  36.402 +    cout << "\n" << cipher_buffer.data();
  36.403 +
  36.404 +    char *buf_text = NULL;
  36.405 +    size_t buf_size = 0;
  36.406 +    stringlist_t *keylist;
  36.407 +
  36.408 +    cout << "calling decrypt_and_verify()\n";
  36.409 +    PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer.data(), cipher_buffer.size(), &buf_text, &buf_size, &keylist);
  36.410 +
  36.411 +    cout << "returning from decrypt_and_verify() with result == 0x" << std::hex << decrypt_result << "\n";
  36.412 +    assert(decrypt_result == PEP_DECRYPTED_AND_VERIFIED);
  36.413 +    assert(buf_text);
  36.414 +    assert(keylist);
  36.415 +
  36.416 +    for (stringlist_t *_keylist=keylist; _keylist!=NULL; _keylist=_keylist->next) {
  36.417 +        assert(_keylist->value);
  36.418 +        cout << "signed with " << _keylist->value << "\n";
  36.419 +    }
  36.420 +
  36.421 +    free_stringlist(keylist);
  36.422 +    buf_text[buf_size] = 0;
  36.423 +    const string plain(buf_text);
  36.424 +    pEp_free(buf_text);
  36.425 +    cout << "\n" << plain;
  36.426 +
  36.427 +    const Buffer t1_buffer = ReadFileIntoMem("t1.txt");
  36.428 +    const Buffer sig_buffer = ReadFileIntoMem("signature.asc");
  36.429 +
  36.430 +    cout << "\ncalling verify_text()\n";
  36.431 +    PEP_STATUS verify_result = verify_text(session, t1_buffer.data(), t1_buffer.size(), sig_buffer.data(), sig_buffer.size(), &keylist);
  36.432 +    cout << "returning from verify_text() with result == " << verify_result << "\n";
  36.433 +    assert(verify_result == PEP_VERIFIED || verify_result == PEP_VERIFIED_AND_TRUSTED);
  36.434 +    assert(keylist->value);
  36.435 +    cout << "signed with " << keylist->value << "\n";
  36.436 +    free_stringlist(keylist);
  36.437 +
  36.438 +    const Buffer t2_buffer = ReadFileIntoMem("t2.txt");
  36.439 +
  36.440 +    cout << "\ncalling verify_text()\n";
  36.441 +    verify_result = verify_text(session, t2_buffer.data(), t2_buffer.size(), sig_buffer.data(), sig_buffer.size(), &keylist);
  36.442 +    assert(verify_result == PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
  36.443 +    free_stringlist(keylist);
  36.444 +
  36.445 +    keylist = new_stringlist("A9411D176FF00E97");
  36.446 +    stringlist_add(keylist, "59BFF488C9C2EE39");
  36.447 +    stringlist_add(keylist, "135CD6D170DCF575");
  36.448 +
  36.449 +    buf_text = NULL;
  36.450 +    buf_size = 0;
  36.451 +
  36.452 +    cout << "\ncalling encrypt_and_sign()\n";
  36.453 +    PEP_STATUS encrypt_result = encrypt_and_sign(session, keylist, plain.c_str(), plain.length(), &buf_text, &buf_size);
  36.454 +    cout << "returning from encrypt_and_sign() with result == " << encrypt_result << "\n";
  36.455 +    assert(encrypt_result == PEP_STATUS_OK);
  36.456 +    free_stringlist(keylist);
  36.457 +
  36.458 +    buf_text[buf_size] = '\0';
  36.459 +    const string cipher2(buf_text);
  36.460 +    cout << "\n" << cipher2;
  36.461 +    pEp_free(buf_text);
  36.462 +
  36.463 +    cout << "\nfinding English trustword for 2342...\n";
  36.464 +    char * word = NULL;
  36.465 +    size_t wsize;
  36.466 +    trustword(session, 2342, "en", &word, &wsize);
  36.467 +    assert(word);
  36.468 +    cout << "the trustword for 2342 is " << word << "\n";
  36.469 +    pEp_free(word);
  36.470 +
  36.471 +    const string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
  36.472 +    char * words = NULL;
  36.473 +
  36.474 +    cout << "\nfinding German trustwords for " << fingerprint << "...\n";
  36.475 +    trustwords(session, fingerprint.c_str(), "de", &words, &wsize, 5);
  36.476 +    assert(words);
  36.477 +    cout << words << "\n";
  36.478 +    pEp_free(words);
  36.479 +
  36.480 +    pEp_identity* identity  = new_identity(
  36.481 +            "leon.schumacher@digitalekho.com",
  36.482 +            "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
  36.483 +            "23",
  36.484 +            "Leon Schumacher"
  36.485 +        );
  36.486 +    identity->comm_type = PEP_ct_pEp;
  36.487 +
  36.488 +    cout << "\nsetting identity...\n";
  36.489 +    PEP_STATUS pep_set_result = set_identity(session, identity);
  36.490 +    assert(pep_set_result == PEP_STATUS_OK);
  36.491 +    free_identity(identity);
  36.492 +    get_identity(session, "leon.schumacher@digitalekho.com", "23", &identity);
  36.493 +    assert(identity);
  36.494 +    cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << "\n";
  36.495 +
  36.496 +    PEP_STATUS get_trust_result = get_trust(session, identity);
  36.497 +    assert(get_trust_result == PEP_STATUS_OK);
  36.498 +    cout << "trust of " << identity->user_id << " is " << identity->comm_type << "\n";
  36.499 +
  36.500 +    free_identity(identity);
  36.501 +
  36.502 +    cout << "\ngenerating key for testuser\n";
  36.503 +    identity = new_identity(
  36.504 +            "testuser@pibit.ch",
  36.505 +            NULL,
  36.506 +            "423",
  36.507 +            "Alfred E. Neuman"
  36.508 +        );
  36.509 +
  36.510 +    assert(identity);
  36.511 +    PEP_STATUS generate_status = generate_keypair(session, identity);
  36.512 +    cout << "generate_keypair() exits with " << generate_status << "\n";
  36.513 +    assert(generate_status == PEP_STATUS_OK);
  36.514 +    cout << "generated key is " << identity->fpr << "\n";
  36.515 +
  36.516 +    const string key(identity->fpr);
  36.517 +    free_identity(identity);
  36.518 +
  36.519 +    char *key_data = NULL;
  36.520 +    size_t size = 0;
  36.521 +
  36.522 +    cout << "export_key()\n\n";
  36.523 +    PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
  36.524 +    cout << "export_key() exits with " << export_status << "\n";
  36.525 +    assert(export_status == PEP_STATUS_OK);
  36.526 +    cout << key_data << "\n\n";
  36.527 +
  36.528 +    cout << "deleting key pair " << key.c_str() << "\n";
  36.529 +    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
  36.530 +    cout << "delete_keypair() exits with " << delete_status << "\n";
  36.531 +    assert(delete_status == PEP_STATUS_OK);
  36.532 +    
  36.533 +    cout << "import_key()\n";
  36.534 +    PEP_STATUS import_status = import_key(session, key_data, size, NULL);
  36.535 +    assert(import_status == PEP_STATUS_OK);
  36.536 +    cout << "successfully imported key\n";
  36.537 +
  36.538 +    pEp_free(key_data);
  36.539 +    key_data=NULL;
  36.540 +
  36.541 +    cout << "deleting key " << key.c_str() << " again\n";
  36.542 +    delete_status = delete_keypair(session, key.c_str());
  36.543 +    cout << "delete_keypair() exits with " << delete_status << "\n";
  36.544 +    assert(delete_status == PEP_STATUS_OK);
  36.545 +
  36.546 +    cout << "finding key for pep.test.john@pep-project.org\n";
  36.547 +    PEP_STATUS find_keys_status = find_keys(session, "pep.test.john@pep-project.org", &keylist);
  36.548 +    cout << "find_keys() exits with " << find_keys_status << "\n";
  36.549 +    assert(find_keys_status == PEP_STATUS_OK);
  36.550 +    assert(keylist);
  36.551 +    cout << "found: " << keylist->value << "\n";
  36.552 +    assert(keylist->next == NULL);
  36.553 +    free_stringlist(keylist);
  36.554 +
  36.555 +    cout << "searching for vb@ulm.ccc.de on keyserver\n";
  36.556 +    PEP_STATUS recv_key_status = recv_key(session, "vb@ulm.ccc.de");
  36.557 +    cout << "recv_key() exits with " << recv_key_status << "\n";
  36.558 +    assert(recv_key_status == PEP_STATUS_OK);
  36.559 +
  36.560 +    cout << "sending vb@ulm.ccc.de to keyserver\n";
  36.561 +    PEP_STATUS send_key_status = send_key(session, "vb@ulm.ccc.de");
  36.562 +    cout << "send_key() exits with " << send_key_status << "\n";
  36.563 +    assert(send_key_status == PEP_STATUS_OK);
  36.564 +
  36.565 +    PEP_comm_type tcomm_type;
  36.566 +    PEP_STATUS tstatus = get_key_rating(session, "59BFF488C9C2EE39", &tcomm_type);
  36.567 +    cout << "get_key_rating() exits with " << tstatus << "\n";
  36.568 +    assert(tstatus == PEP_STATUS_OK);
  36.569 +    assert(tcomm_type == PEP_ct_OpenPGP_unconfirmed);
  36.570 +    
  36.571 +    cout << "\ncalling release()\n";
  36.572 +    release(session);
  36.573 +    return 0;
  36.574 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/still_no_key.asc	Sun Jun 26 18:04:25 2016 +0200
    37.3 @@ -0,0 +1,56 @@
    37.4 +-----BEGIN PGP PRIVATE KEY BLOCK-----
    37.5 +
    37.6 +lQOYBFdisVYBCAC32OZTBZdKW9RwRdMyGxm8yG0hYp3ZA8Z7bUBlQQDwOOT0K2YV
    37.7 +1v5DEXYTIovVe4HYY4sPqmM1atpmCM/RlyYbghSIUha5OaH3/GOv9+Yg9WomrF4b
    37.8 +tPtGIlikcp/n69t/468hX9kzHf916VxwgVT7cSaHN0U6lKsPti08z3fDJKjr+O7S
    37.9 +7p1bYp+Lc9vsqSLBdTCoaPjs4RM1z2TLPHowKRVjwAKX/IjwwD0B9lg6fuOXqb+v
   37.10 +YBfRF0OZ/O+TX+k68y9qHgH1BPxUJAoAR7D/JgJzlH+H0kvVsCSnpph3a+dxnFsr
   37.11 +FFU1V4XRUsZtoR6URuOp3+0iC+LFE1HPt7F3ABEBAAEAB/0Vz46rpMspEDHoy+/d
   37.12 +TufDxMdloYx2dYMzm2d7W7XfyfAno4pt5t6tWEH4zS1nu0pRQKX7yswQR0f3uO3m
   37.13 +wJbNxqXm8k4t1U+I2xF8i91qZZMdWW+ku9jfni2D/PFJk2qsBnf9bqCW9uUauP+1
   37.14 +fTJ2zhqzCfSVmZOdvpApWbesl9YGqN/LLYVMjWhDs/QVL/n4MkJCrixdvVVELJty
   37.15 +j5E4nV3Z8PfsMjEE3goDzrhU0urPYubWHr/NXBcSG9mzhx48zacEPQyqcrSLc8Yy
   37.16 +rWZGSHgjYGdtYmajFDF4r3kr6efE5p2PRF1sU757oMLXW/J1eOq9Tal2halK/Jvm
   37.17 +2zEJBADCkUMr9vkSOhkpz2zAXx2wdtZBWb1pqQ0ZNDEaHTi0hbzO9nrRtvCEV60d
   37.18 +08xJDSVUfGi+WAihF+Woyg2yVTmsdcsnCHUH2yhNcke1buXGowxW7zcCT+mfB4Mh
   37.19 +gNJ/SIWvMj0Ku/P2JzAfvzngAIMpSNkq213f3yHNuHftH00y/QQA8eUiZvX+ST4b
   37.20 +XpV21S9wrCMJRVhWDJWX4uiQ1mEhxmJUF5AcqdgN66vGV5ZzJolnIvejLvFqkDzN
   37.21 +ftGM7aXnwGDNKaxd+X3x67EFVbSX+0tRATqG8xFTQYQ6wd0CmDtongdA8PPSJjO/
   37.22 ++/iBdTCKQggMro82ABW8WqIxeVGFIoMEAI78UWIBKF1dr4Ol4hP3Je27v0Duw+zi
   37.23 +EywJ84GFI3P9TKS3bYpxqQ7ymeVVUwFCpZeJEMIvX/GwsWsy9yZX5DADik3gwfGw
   37.24 +M5b9J0VYGp7UXP9npHM3rx3lMdfPUTUcYM5X6D0oXbPB+zbt1sBV7mPJK4nZ++qG
   37.25 +VWe/1eI2D8uvSWi0H1N0aWxsIG5vIGtleSA8c3RpbGxAbm9rZXkuYmx1cD6JATcE
   37.26 +EwEKACEFAldisVYCGwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AACgkQOz+djmF7
   37.27 +X+NDFgf/Sp3BqUviZXCjxBMtL1XKWc8xouq/wnghfsURAKdUV9RXNghHTbAJftAb
   37.28 +SiQoTeGlhWWESMOJOq5rYbvIyzsVDqH2KeYCSJKucO09+viInrlw5Z9Sd7Mtp3+U
   37.29 +gMzE3mY9tJRy+OTv6B6KNDlplrTRhWpJkglLWKIB4qA0FZTRmcfub61+BOxgyiI0
   37.30 +KMCjxKYHH234T45ZELCT1XyBO5kZlItomrxQYpMkKIvDsm+ND73bi8rOafZaQoKj
   37.31 +ufG835AmGAvvFsiFm/AK98ZlI4rPNTfI6lHML1xozApi8Ga8Q/RSa/r5O6x3kdFb
   37.32 +DAutMCNn4F8i98v43f3M0KNlsOiJ450DmARXYrFWAQgAqnPL0cLdd1Tp0YB9RU0s
   37.33 +cwblmOBUaD3rN7lM0fqaw5eOqde0ZM75rhw/dvQH1pmC1AWHKo/3baqZLPAOHYr7
   37.34 +qlrGusEfm2SLuo6eGRi3InTIMB+dwaWaRuJDSQ+u0MAaCqEe3P7UijTZTVmj5DLL
   37.35 +lyCL2dh5x6HIe4jM9bJ1KjHmmMNurJ+zzIDxXyyZmQRGb8W6curR/KaiYP6sinMy
   37.36 +M+l7b9uhEqaLv9b0zOZjxSekfb6ICyVUvzJCONtEfaQ/QVK5XLMLhpbC4y27E7Vz
   37.37 +coa7381ewTrPaB6gS9R8/EgNGOQTIgYmestaZFeG/9UqtN+ox8+7a/XRVsm4PlE4
   37.38 +hwARAQABAAf9Gtey000NX2DUlD+DJXS/zpAu0WJn0yVdHiC6Q58O3EUecbTHHdD9
   37.39 +FOQx7Q5aZaXgf88sYrwv9OnsHAg50NaK8grq8jdo6NRur2m3kAWKYYy5MeA+Ebl9
   37.40 +5YfK8iiGw9eyF4EZa9KzBIjKEm+kFahs01c2xDmzrofVxfkx0xzQGAgTL3yGKEAM
   37.41 +S2Kr2J3nhejEOcEGjY2tvD1UMxZQCu6qpAyNU/lYBG8Fg3p67psUORWOBnAZkJNs
   37.42 +BTpsaVQR0/wja3x8efIjg41+W6O0NMQ7FE+vS2A9CBLOnKrLFw7jsVHQnk58MAnb
   37.43 +M3CPIusyhQXXOPrp0OnzfBA1hULF8EEKYQQAxvZXWFWuGoA1K5/Kn6nahHevYtkk
   37.44 +8rFb5uqIxTUqc2d0S/YJT2ksohyKwIa2wTWU51Dvi5WxmBJKAtWq96Xpvay99YgH
   37.45 +UZPw3xh5qi6Wv7JbhA/+lokURTxtyqofNcJDIAiGUwEryyjojhB1eEoV8mRfpL/B
   37.46 +78Uu7W/W1uY1rn8EANtRIvBnB1BrbTYpxH8n9V316BDTui6fCfb//2Ru5eJ/4ZSZ
   37.47 +dJ+8YncgoJAOrFDAT70xFp8tPwmJeak+PAMnt0ehLyZTzc4Dn1f3CTL/d9ZQmGau
   37.48 +w1hotJZBWgZAm10VI4UYuQkj3Iq20ENaY92XZMr40hlmmSeHAGXKy+hDlAH5A/9z
   37.49 +wP21mtgzGfLijeaXS9xzYQ5fgbWNJJ1bPALl1ZLGma/Ajbt8GgBgCSXnm8z9TYkt
   37.50 +j3R5PyFV3qTm+1L/JS3bepkGZnjy1Uqa0ZXIgKKOmYABuNJoFw1HfE47ZeZFwbmd
   37.51 +1MkC0L1eQqU1Dmz0Aq5Bj3yDuL5QOxBhxIb1wmrc2z6FiQEfBBgBCgAJBQJXYrFW
   37.52 +AhsMAAoJEDs/nY5he1/jekoH/1Bqm52W64DYJtGoxh0LOtTKYRk6fat1c1pzNctL
   37.53 +A2idl1ReT3XkI2pOZfDLXKiG4zHzUaOkO5P0a9oZxkUCRjuZjfHzaG/mmtCMJVPl
   37.54 +hcjD9Djzyw9HhXSubyWmMrbZ6uLaJfAs795b/ZXDkjghgN4IflEUX3NgqnIwciL/
   37.55 +8sdYE4olihmBHzcW5Pg8fQXXsGKeZfHdMnuMUrZk5htzkXN28FVcqrNHtSP+g3nw
   37.56 +YrOLfjw52fUDo7+SdGWUw0AUGYAFVoBdK38UkmWmhkeN8uqNI6/dqajzmMiMAwPQ
   37.57 +dvZ7djEg7DiKGSQ+dMVj9IzT27IuJqcXO+47fGHkU0iPpgI=
   37.58 +=3QWb
   37.59 +-----END PGP PRIVATE KEY BLOCK-----