merged in default ENGINE-157
authorKrista Grothoff <krista@pep-project.org>
Mon, 09 Jan 2017 10:28:02 +0100
branchENGINE-157
changeset 1533ca90b6245a51
parent 1531 262db6c39241
parent 1527 75d56a822caa
child 1534 69a4e0933b0d
merged in default
build-android/build.sh
db/dic2csv.py
db/mkpass
db/trustwords.py
src/keymanagement.c
src/pgp_gpg.c
test/blacklist_accept_new_key_test.cc
test/blacklist_test.cc
     1.1 --- a/Makefile	Mon Jan 09 10:23:55 2017 +0100
     1.2 +++ b/Makefile	Mon Jan 09 10:28:02 2017 +0100
     1.3 @@ -1,3 +1,6 @@
     1.4 +# this file is under GNU General Public License v3.0
     1.5 +# see LICENSE.txt
     1.6 +
     1.7  include Makefile.conf
     1.8  
     1.9  # add it to the environment of all executed programs:
     2.1 --- a/Makefile.conf	Mon Jan 09 10:23:55 2017 +0100
     2.2 +++ b/Makefile.conf	Mon Jan 09 10:28:02 2017 +0100
     2.3 @@ -1,3 +1,5 @@
     2.4 +# this file is in the Public Domain
     2.5 +
     2.6  BUILD_ON=$(shell uname)
     2.7  BUILD_FOR=$(BUILD_ON)
     2.8  OPTIMIZE=-g -Wall -O0 -fPIC
     3.1 --- a/README-OSX.md	Mon Jan 09 10:23:55 2017 +0100
     3.2 +++ b/README-OSX.md	Mon Jan 09 10:28:02 2017 +0100
     3.3 @@ -1,3 +1,5 @@
     3.4 +# this file is under Creative Commons License 3.0 cc-by-sa
     3.5 +
     3.6  # Building for OS X/macOS
     3.7  
     3.8  See also README.txt for general information.
     4.1 --- a/README.txt	Mon Jan 09 10:23:55 2017 +0100
     4.2 +++ b/README.txt	Mon Jan 09 10:28:02 2017 +0100
     4.3 @@ -1,3 +1,5 @@
     4.4 +# this file is under Creative Commons License 3.0 cc-by-sa
     4.5 +
     4.6  p≡p Engine
     4.7  ==========
     4.8  
     5.1 --- a/TODO.txt	Mon Jan 09 10:23:55 2017 +0100
     5.2 +++ b/TODO.txt	Mon Jan 09 10:28:02 2017 +0100
     5.3 @@ -1,3 +1,5 @@
     5.4 +# this file is in the Public Domain
     5.5 +
     5.6  - add required Debian packages to build pEp (or where to find non-debian-packaged software, like "libetpan/mailmime_encode.h"
     5.7  - add build instructions and required "brew" packages for Mac OS X.
     5.8  - describe, how to configure pEpEngine to use self-compiled libetpan (in $HOME/local/ or the like)
     6.1 --- a/asn.1/Makefile	Mon Jan 09 10:23:55 2017 +0100
     6.2 +++ b/asn.1/Makefile	Mon Jan 09 10:28:02 2017 +0100
     6.3 @@ -1,3 +1,6 @@
     6.4 +# This file is under GNU General Public License 3.0
     6.5 +# see LICENSE.txt
     6.6 +
     6.7  include ../Makefile.conf
     6.8  
     6.9  ifeq ($(BUILD_ON),Linux)
     7.1 --- a/asn.1/devicegroup.asn1	Mon Jan 09 10:23:55 2017 +0100
     7.2 +++ b/asn.1/devicegroup.asn1	Mon Jan 09 10:28:02 2017 +0100
     7.3 @@ -1,3 +1,6 @@
     7.4 +/* This file is under GNU General Public License 3.0 */
     7.5 +/* see LICENSE.txt */
     7.6 +
     7.7  DEVICEGROUP
     7.8      { iso(1) org(3) dod(6) internet(1) private(4) enterprise(1) pEp (47878) sync(1) keysync(1) }
     7.9  
     8.1 --- a/asn.1/pEp.asn1	Mon Jan 09 10:23:55 2017 +0100
     8.2 +++ b/asn.1/pEp.asn1	Mon Jan 09 10:28:02 2017 +0100
     8.3 @@ -1,3 +1,6 @@
     8.4 +/* This file is under GNU General Public License 3.0 */
     8.5 +/* see LICENSE.txt */
     8.6 +
     8.7  PEP
     8.8      { iso(1) org(3) dod(6) internet(1) private(4) enterprise(1) pEp(47878) basic(0) }
     8.9  
     9.1 --- a/asn.1/pEpEngineASN1/ReadMe.txt	Mon Jan 09 10:23:55 2017 +0100
     9.2 +++ b/asn.1/pEpEngineASN1/ReadMe.txt	Mon Jan 09 10:28:02 2017 +0100
     9.3 @@ -1,3 +1,7 @@
     9.4 +# This file is in the Public Domain
     9.5 +# All other files in this directory are under GNU General Public License 3.0
     9.6 +# see LICENSE.txt
     9.7 +
     9.8  ========================================================================
     9.9      STATIC LIBRARY : pEpEngineASN1 Project Overview
    9.10  ========================================================================
    10.1 --- a/asn.1/protocols.asn1	Mon Jan 09 10:23:55 2017 +0100
    10.2 +++ b/asn.1/protocols.asn1	Mon Jan 09 10:28:02 2017 +0100
    10.3 @@ -1,3 +1,6 @@
    10.4 +/* This file is under GNU General Public License 3.0 */
    10.5 +/* see LICENSE.txt */
    10.6 +
    10.7  SYNC
    10.8  
    10.9  DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
    11.1 --- a/build-android/build.sh	Mon Jan 09 10:23:55 2017 +0100
    11.2 +++ b/build-android/build.sh	Mon Jan 09 10:28:02 2017 +0100
    11.3 @@ -1,5 +1,8 @@
    11.4  #!/bin/sh
    11.5  
    11.6 +# This file is under GNU General Public License 3.0
    11.7 +# see LICENSE.txt
    11.8 +
    11.9  set -e
   11.10  
   11.11  build_version=1
    12.1 --- a/build-android/jni/Android.mk	Mon Jan 09 10:23:55 2017 +0100
    12.2 +++ b/build-android/jni/Android.mk	Mon Jan 09 10:28:02 2017 +0100
    12.3 @@ -1,5 +1,8 @@
    12.4 -# Copyright (C) 2015 pEp
    12.5 +# Copyleft 2015 pEp foundation
    12.6  #
    12.7 +# This file is under GNU General Public License 3.0
    12.8 +# see LICENSE.txt
    12.9 +
   12.10  LOCAL_PATH := $(call my-dir)
   12.11  $(warning $(LOCAL_PATH))
   12.12  
    13.1 --- a/build-linux/Makefile	Mon Jan 09 10:23:55 2017 +0100
    13.2 +++ b/build-linux/Makefile	Mon Jan 09 10:28:02 2017 +0100
    13.3 @@ -1,3 +1,6 @@
    13.4 +# This file is under GNU General Public License 3.0
    13.5 +# see LICENSE.txt
    13.6 +
    13.7  #------------------------------------------------------------------------------#
    13.8  # Makefile to build libEtpan GPGME, GnuPG and deps for use with pEpEngine 
    13.9  #  based on pEpJNIAdapter/android/external/Makefile
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/build-mac/README.txt	Mon Jan 09 10:28:02 2017 +0100
    14.3 @@ -0,0 +1,3 @@
    14.4 +# all files in this directory are under GNU General Public License 3.0
    14.5 +# see LICENSE.txt
    14.6 +
    15.1 --- a/build-mac/build.sh	Mon Jan 09 10:23:55 2017 +0100
    15.2 +++ b/build-mac/build.sh	Mon Jan 09 10:28:02 2017 +0100
    15.3 @@ -1,5 +1,8 @@
    15.4  #!/bin/bash
    15.5  
    15.6 +# This file is under GNU General Public License 3.0
    15.7 +# see LICENSE.txt
    15.8 +
    15.9  #
   15.10  # Invoke with `sh build.sh`
   15.11  #
    16.1 --- a/build-mac/build_libcurl_dist.sh	Mon Jan 09 10:23:55 2017 +0100
    16.2 +++ b/build-mac/build_libcurl_dist.sh	Mon Jan 09 10:28:02 2017 +0100
    16.3 @@ -1,5 +1,8 @@
    16.4  #!/bin/bash
    16.5  
    16.6 +# This file is under GNU General Public License 3.0
    16.7 +# see LICENSE.txt
    16.8 +
    16.9  export DEVROOT=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
   16.10  DFT_DIST_DIR=../libcurl-ios-dist
   16.11  DIST_DIR=${DIST_DIR:-$DFT_DIST_DIR}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/build-windows/README.txt	Mon Jan 09 10:28:02 2017 +0100
    17.3 @@ -0,0 +1,3 @@
    17.4 +# all files in this directory are under GNU General Public License 3.0
    17.5 +# see LICENSE.txt
    17.6 +
    18.1 --- a/db/Makefile	Mon Jan 09 10:23:55 2017 +0100
    18.2 +++ b/db/Makefile	Mon Jan 09 10:28:02 2017 +0100
    18.3 @@ -1,3 +1,6 @@
    18.4 +# This file is under GNU General Public License 3.0
    18.5 +# see LICENSE.txt
    18.6 +
    18.7  include ../Makefile.conf
    18.8  
    18.9  db: system.db
    19.1 --- a/db/create_system_db.sql	Mon Jan 09 10:23:55 2017 +0100
    19.2 +++ b/db/create_system_db.sql	Mon Jan 09 10:28:02 2017 +0100
    19.3 @@ -1,3 +1,6 @@
    19.4 +-- This file is under GNU General Public License 3.0
    19.5 +-- See LICENSE.txt
    19.6 +
    19.7  -- DDL
    19.8  
    19.9  CREATE TABLE i18n_language (
    20.1 --- a/db/csv2csv.py	Mon Jan 09 10:23:55 2017 +0100
    20.2 +++ b/db/csv2csv.py	Mon Jan 09 10:28:02 2017 +0100
    20.3 @@ -1,5 +1,9 @@
    20.4  #! /usr/bin/env python3
    20.5  
    20.6 +# This file is under GNU General Public License 3.0
    20.7 +# see LICENSE.txt
    20.8 +
    20.9 +
   20.10  from argparse import ArgumentParser
   20.11  from fileinput import FileInput, hook_encoded
   20.12  import re, itertools, sys
    21.1 --- a/db/dic2csv.py	Mon Jan 09 10:23:55 2017 +0100
    21.2 +++ b/db/dic2csv.py	Mon Jan 09 10:28:02 2017 +0100
    21.3 @@ -1,5 +1,9 @@
    21.4  #! /usr/bin/env python3
    21.5  
    21.6 +# This file is under GNU General Public License 3.0
    21.7 +# see LICENSE.txt
    21.8 +
    21.9 +
   21.10  from argparse import ArgumentParser
   21.11  from fileinput import FileInput, hook_encoded
   21.12  import re, itertools, sys
    22.1 --- a/db/make_systemdb.cmd	Mon Jan 09 10:23:55 2017 +0100
    22.2 +++ b/db/make_systemdb.cmd	Mon Jan 09 10:28:02 2017 +0100
    22.3 @@ -1,3 +1,4 @@
    22.4 +@rem this file is in the Public Domain
    22.5  @echo off
    22.6  
    22.7  if exist system.db del /f system.db
    23.1 --- a/db/mkpass	Mon Jan 09 10:23:55 2017 +0100
    23.2 +++ b/db/mkpass	Mon Jan 09 10:28:02 2017 +0100
    23.3 @@ -1,5 +1,9 @@
    23.4  #!/bin/sh
    23.5  
    23.6 +# This file is under GNU General Public License 3.0
    23.7 +# see LICENSE.txt
    23.8 +
    23.9 +
   23.10  if [ $1/ == / ] ; then
   23.11      lang=en
   23.12  else
    24.1 --- a/db/sort.py	Mon Jan 09 10:23:55 2017 +0100
    24.2 +++ b/db/sort.py	Mon Jan 09 10:28:02 2017 +0100
    24.3 @@ -1,5 +1,9 @@
    24.4  #! /usr/bin/env python3
    24.5  
    24.6 +# This file is under GNU General Public License 3.0
    24.7 +# see LICENSE.txt
    24.8 +
    24.9 +
   24.10  from argparse import ArgumentParser
   24.11  from fileinput import FileInput, hook_encoded
   24.12  import re, itertools, sys
    25.1 --- a/db/trustwords.py	Mon Jan 09 10:23:55 2017 +0100
    25.2 +++ b/db/trustwords.py	Mon Jan 09 10:28:02 2017 +0100
    25.3 @@ -1,5 +1,9 @@
    25.4  #!/usr/bin/env python3
    25.5  
    25.6 +# This file is under GNU General Public License 3.0
    25.7 +# see LICENSE.txt
    25.8 +
    25.9 +
   25.10  from sqlite3 import connect
   25.11  from os import environ
   25.12  from argparse import ArgumentParser
    26.1 --- a/macports_env.sh	Mon Jan 09 10:23:55 2017 +0100
    26.2 +++ b/macports_env.sh	Mon Jan 09 10:28:02 2017 +0100
    26.3 @@ -1,3 +1,5 @@
    26.4 +# this file is in the Public Domain
    26.5 +
    26.6  # Typical pure MacPorts environment
    26.7  
    26.8  # Restrict to MacPorts
    27.1 --- a/src/asn1_helper.c	Mon Jan 09 10:23:55 2017 +0100
    27.2 +++ b/src/asn1_helper.c	Mon Jan 09 10:28:02 2017 +0100
    27.3 @@ -1,3 +1,6 @@
    27.4 +// This file is under GNU General Public License 3.0
    27.5 +// see LICENSE.txt
    27.6 +
    27.7  #include "asn1_helper.h"
    27.8  #include <assert.h>
    27.9  #include <stdlib.h>
    28.1 --- a/src/asn1_helper.h	Mon Jan 09 10:23:55 2017 +0100
    28.2 +++ b/src/asn1_helper.h	Mon Jan 09 10:28:02 2017 +0100
    28.3 @@ -1,3 +1,6 @@
    28.4 +// This file is under GNU General Public License 3.0
    28.5 +// see LICENSE.txt
    28.6 +
    28.7  #pragma once
    28.8  
    28.9  #include <string.h>
    29.1 --- a/src/baseprotocol.c	Mon Jan 09 10:23:55 2017 +0100
    29.2 +++ b/src/baseprotocol.c	Mon Jan 09 10:28:02 2017 +0100
    29.3 @@ -1,3 +1,6 @@
    29.4 +// This file is under GNU General Public License 3.0
    29.5 +// see LICENSE.txt
    29.6 +
    29.7  #include "pEp_internal.h"
    29.8  #include "message_api.h"
    29.9  
    30.1 --- a/src/baseprotocol.h	Mon Jan 09 10:23:55 2017 +0100
    30.2 +++ b/src/baseprotocol.h	Mon Jan 09 10:28:02 2017 +0100
    30.3 @@ -1,3 +1,6 @@
    30.4 +// This file is under GNU General Public License 3.0
    30.5 +// see LICENSE.txt
    30.6 +
    30.7  #pragma once
    30.8  
    30.9  #include "message.h"
    31.1 --- a/src/blacklist.c	Mon Jan 09 10:23:55 2017 +0100
    31.2 +++ b/src/blacklist.c	Mon Jan 09 10:28:02 2017 +0100
    31.3 @@ -1,3 +1,6 @@
    31.4 +// This file is under GNU General Public License 3.0
    31.5 +// see LICENSE.txt
    31.6 +
    31.7  #include "pEp_internal.h"
    31.8  #include "blacklist.h"
    31.9  
    32.1 --- a/src/blacklist.h	Mon Jan 09 10:23:55 2017 +0100
    32.2 +++ b/src/blacklist.h	Mon Jan 09 10:28:02 2017 +0100
    32.3 @@ -1,3 +1,6 @@
    32.4 +// This file is under GNU General Public License 3.0
    32.5 +// see LICENSE.txt
    32.6 +
    32.7  #pragma once
    32.8  
    32.9  #include "pEpEngine.h"
    33.1 --- a/src/bloblist.c	Mon Jan 09 10:23:55 2017 +0100
    33.2 +++ b/src/bloblist.c	Mon Jan 09 10:28:02 2017 +0100
    33.3 @@ -1,3 +1,6 @@
    33.4 +// This file is under GNU General Public License 3.0
    33.5 +// see LICENSE.txt
    33.6 +
    33.7  #include "pEp_internal.h"
    33.8  
    33.9  #include <stdlib.h>
    34.1 --- a/src/bloblist.h	Mon Jan 09 10:23:55 2017 +0100
    34.2 +++ b/src/bloblist.h	Mon Jan 09 10:28:02 2017 +0100
    34.3 @@ -1,3 +1,6 @@
    34.4 +// This file is under GNU General Public License 3.0
    34.5 +// see LICENSE.txt
    34.6 +
    34.7  #pragma once
    34.8  
    34.9  #include "dynamic_api.h"
    35.1 --- a/src/cryptotech.c	Mon Jan 09 10:23:55 2017 +0100
    35.2 +++ b/src/cryptotech.c	Mon Jan 09 10:28:02 2017 +0100
    35.3 @@ -1,3 +1,6 @@
    35.4 +// This file is under GNU General Public License 3.0
    35.5 +// see LICENSE.txt
    35.6 +
    35.7  #include "pEp_internal.h"
    35.8  
    35.9  #ifdef USE_GPG
    36.1 --- a/src/cryptotech.h	Mon Jan 09 10:23:55 2017 +0100
    36.2 +++ b/src/cryptotech.h	Mon Jan 09 10:28:02 2017 +0100
    36.3 @@ -1,3 +1,6 @@
    36.4 +// This file is under GNU General Public License 3.0
    36.5 +// see LICENSE.txt
    36.6 +
    36.7  #pragma once
    36.8  
    36.9  #include "pEpEngine.h"
    37.1 --- a/src/dynamic_api.h	Mon Jan 09 10:23:55 2017 +0100
    37.2 +++ b/src/dynamic_api.h	Mon Jan 09 10:28:02 2017 +0100
    37.3 @@ -1,3 +1,6 @@
    37.4 +// This file is under GNU General Public License 3.0
    37.5 +// see LICENSE.txt
    37.6 +
    37.7  #pragma once
    37.8  
    37.9  #ifdef WIN32
    38.1 --- a/src/email.c	Mon Jan 09 10:23:55 2017 +0100
    38.2 +++ b/src/email.c	Mon Jan 09 10:28:02 2017 +0100
    38.3 @@ -1,3 +1,6 @@
    38.4 +// This file is under GNU General Public License 3.0
    38.5 +// see LICENSE.txt
    38.6 +
    38.7  #include "email.h"
    38.8  
    38.9  PEP_STATUS email_sendto(PEP_SESSION session, const message *msg)
    39.1 --- a/src/email.h	Mon Jan 09 10:23:55 2017 +0100
    39.2 +++ b/src/email.h	Mon Jan 09 10:28:02 2017 +0100
    39.3 @@ -1,3 +1,6 @@
    39.4 +// This file is under GNU General Public License 3.0
    39.5 +// see LICENSE.txt
    39.6 +
    39.7  #pragma once
    39.8  
    39.9  #include "transport.h"
    40.1 --- a/src/etpan_mime.c	Mon Jan 09 10:23:55 2017 +0100
    40.2 +++ b/src/etpan_mime.c	Mon Jan 09 10:28:02 2017 +0100
    40.3 @@ -1,3 +1,6 @@
    40.4 +// This file is under GNU General Public License 3.0
    40.5 +// see LICENSE.txt
    40.6 +
    40.7  #include "etpan_mime.h"
    40.8  #ifndef mailmime_param_new_with_data
    40.9  #include <libetpan/mailprivacy_tools.h>
    41.1 --- a/src/etpan_mime.h	Mon Jan 09 10:23:55 2017 +0100
    41.2 +++ b/src/etpan_mime.h	Mon Jan 09 10:28:02 2017 +0100
    41.3 @@ -1,3 +1,6 @@
    41.4 +// This file is under GNU General Public License 3.0
    41.5 +// see LICENSE.txt
    41.6 +
    41.7  #pragma once
    41.8  
    41.9  #include <libetpan/libetpan.h>
    42.1 --- a/src/identity_list.c	Mon Jan 09 10:23:55 2017 +0100
    42.2 +++ b/src/identity_list.c	Mon Jan 09 10:28:02 2017 +0100
    42.3 @@ -1,3 +1,6 @@
    42.4 +// This file is under GNU General Public License 3.0
    42.5 +// see LICENSE.txt
    42.6 +
    42.7  #include "pEp_internal.h"
    42.8  
    42.9  #include <stdlib.h>
    43.1 --- a/src/identity_list.h	Mon Jan 09 10:23:55 2017 +0100
    43.2 +++ b/src/identity_list.h	Mon Jan 09 10:28:02 2017 +0100
    43.3 @@ -1,3 +1,6 @@
    43.4 +// This file is under GNU General Public License 3.0
    43.5 +// see LICENSE.txt
    43.6 +
    43.7  #pragma once
    43.8  
    43.9  #include "pEpEngine.h"
    44.1 --- a/src/keymanagement.c	Mon Jan 09 10:23:55 2017 +0100
    44.2 +++ b/src/keymanagement.c	Mon Jan 09 10:28:02 2017 +0100
    44.3 @@ -1,3 +1,6 @@
    44.4 +// This file is under GNU General Public License 3.0
    44.5 +// see LICENSE.txt
    44.6 +
    44.7  #include "platform.h"
    44.8  
    44.9  #include <string.h>
    45.1 --- a/src/keymanagement.h	Mon Jan 09 10:23:55 2017 +0100
    45.2 +++ b/src/keymanagement.h	Mon Jan 09 10:28:02 2017 +0100
    45.3 @@ -1,3 +1,6 @@
    45.4 +// This file is under GNU General Public License 3.0
    45.5 +// see LICENSE.txt
    45.6 +
    45.7  #pragma once
    45.8  
    45.9  #include "pEpEngine.h"
    46.1 --- a/src/map_asn1.c	Mon Jan 09 10:23:55 2017 +0100
    46.2 +++ b/src/map_asn1.c	Mon Jan 09 10:28:02 2017 +0100
    46.3 @@ -1,3 +1,6 @@
    46.4 +// This file is under GNU General Public License 3.0
    46.5 +// see LICENSE.txt
    46.6 +
    46.7  #include "pEp_internal.h"
    46.8  #include "map_asn1.h"
    46.9  
    47.1 --- a/src/map_asn1.h	Mon Jan 09 10:23:55 2017 +0100
    47.2 +++ b/src/map_asn1.h	Mon Jan 09 10:28:02 2017 +0100
    47.3 @@ -1,3 +1,6 @@
    47.4 +// This file is under GNU General Public License 3.0
    47.5 +// see LICENSE.txt
    47.6 +
    47.7  #pragma once
    47.8  
    47.9  #include "pEpEngine.h"
    48.1 --- a/src/message.c	Mon Jan 09 10:23:55 2017 +0100
    48.2 +++ b/src/message.c	Mon Jan 09 10:28:02 2017 +0100
    48.3 @@ -1,3 +1,6 @@
    48.4 +// This file is under GNU General Public License 3.0
    48.5 +// see LICENSE.txt
    48.6 +
    48.7  #include "pEp_internal.h"
    48.8  
    48.9  #include <stdlib.h>
    49.1 --- a/src/message.h	Mon Jan 09 10:23:55 2017 +0100
    49.2 +++ b/src/message.h	Mon Jan 09 10:28:02 2017 +0100
    49.3 @@ -1,3 +1,6 @@
    49.4 +// This file is under GNU General Public License 3.0
    49.5 +// see LICENSE.txt
    49.6 +
    49.7  #pragma once
    49.8  
    49.9  #include <time.h>
    50.1 --- a/src/message_api.c	Mon Jan 09 10:23:55 2017 +0100
    50.2 +++ b/src/message_api.c	Mon Jan 09 10:28:02 2017 +0100
    50.3 @@ -1,3 +1,6 @@
    50.4 +// This file is under GNU General Public License 3.0
    50.5 +// see LICENSE.txt
    50.6 +
    50.7  #include "pEp_internal.h"
    50.8  #include "message_api.h"
    50.9  
   50.10 @@ -2225,7 +2228,7 @@
   50.11  }
   50.12  
   50.13  DYNAMIC_API PEP_STATUS get_trustwords(
   50.14 -    PEP_SESSION session, pEp_identity* id1, pEp_identity* id2,
   50.15 +    PEP_SESSION session, const pEp_identity* id1, const pEp_identity* id2,
   50.16      const char* lang, char **words, size_t *wsize, bool full
   50.17  )
   50.18  {
    51.1 --- a/src/message_api.h	Mon Jan 09 10:23:55 2017 +0100
    51.2 +++ b/src/message_api.h	Mon Jan 09 10:28:02 2017 +0100
    51.3 @@ -1,3 +1,6 @@
    51.4 +// This file is under GNU General Public License 3.0
    51.5 +// see LICENSE.txt
    51.6 +
    51.7  #pragma once
    51.8  
    51.9  #include "pEpEngine.h"
   51.10 @@ -332,7 +335,7 @@
   51.11  //
   51.12  
   51.13  DYNAMIC_API PEP_STATUS get_trustwords(
   51.14 -    PEP_SESSION session, pEp_identity* id1, pEp_identity* id2,
   51.15 +    PEP_SESSION session, const pEp_identity* id1, const pEp_identity* id2,
   51.16      const char* lang, char **words, size_t *wsize, bool full
   51.17  );
   51.18  
    52.1 --- a/src/mime.c	Mon Jan 09 10:23:55 2017 +0100
    52.2 +++ b/src/mime.c	Mon Jan 09 10:28:02 2017 +0100
    52.3 @@ -1,3 +1,6 @@
    52.4 +// This file is under GNU General Public License 3.0
    52.5 +// see LICENSE.txt
    52.6 +
    52.7  #include "pEp_internal.h"
    52.8  #include "mime.h"
    52.9  
    53.1 --- a/src/mime.h	Mon Jan 09 10:23:55 2017 +0100
    53.2 +++ b/src/mime.h	Mon Jan 09 10:28:02 2017 +0100
    53.3 @@ -1,3 +1,6 @@
    53.4 +// This file is under GNU General Public License 3.0
    53.5 +// see LICENSE.txt
    53.6 +
    53.7  #pragma once
    53.8  
    53.9  #include "message.h"
    54.1 --- a/src/openpgp_compat.c	Mon Jan 09 10:23:55 2017 +0100
    54.2 +++ b/src/openpgp_compat.c	Mon Jan 09 10:28:02 2017 +0100
    54.3 @@ -1,3 +1,6 @@
    54.4 +// This file is under GNU General Public License 3.0
    54.5 +// see LICENSE.txt
    54.6 +
    54.7  #include "pEp_internal.h"
    54.8  #include "dynamic_api.h"
    54.9  #include "openpgp_compat.h"
    55.1 --- a/src/openpgp_compat.h	Mon Jan 09 10:23:55 2017 +0100
    55.2 +++ b/src/openpgp_compat.h	Mon Jan 09 10:28:02 2017 +0100
    55.3 @@ -1,3 +1,6 @@
    55.4 +// This file is under GNU General Public License 3.0
    55.5 +// see LICENSE.txt
    55.6 +
    55.7  // openpgp_compat.h
    55.8  //
    55.9  // These functions are the exposure of non-generic PGP-specific functionality (largely related to PGP
    56.1 --- a/src/pEpEngine.c	Mon Jan 09 10:23:55 2017 +0100
    56.2 +++ b/src/pEpEngine.c	Mon Jan 09 10:28:02 2017 +0100
    56.3 @@ -1,3 +1,6 @@
    56.4 +// This file is under GNU General Public License 3.0
    56.5 +// see LICENSE.txt
    56.6 +
    56.7  #include "pEp_internal.h"
    56.8  #include "dynamic_api.h"
    56.9  #include "cryptotech.h"
   56.10 @@ -7,6 +10,179 @@
   56.11  
   56.12  static int init_count = -1;
   56.13  
   56.14 +// sql manipulation statements
   56.15 +static const char *sql_log = 
   56.16 +    "insert into log (title, entity, description, comment)"
   56.17 +     "values (?1, ?2, ?3, ?4);";
   56.18 +
   56.19 +static const char *sql_trustword = 
   56.20 +    "select id, word from wordlist where lang = lower(?1) "
   56.21 +    "and id = ?2 ;";
   56.22 +
   56.23 +static const char *sql_get_identity =  
   56.24 +    "select fpr, username, comm_type, lang,"
   56.25 +    "   identity.flags | pgp_keypair.flags"
   56.26 +    "   from identity"
   56.27 +    "   join person on id = identity.user_id"
   56.28 +    "   join pgp_keypair on fpr = identity.main_key_id"
   56.29 +    "   join trust on id = trust.user_id"
   56.30 +    "       and pgp_keypair_fpr = identity.main_key_id"
   56.31 +    "   where address = ?1 and identity.user_id = ?2;";
   56.32 +
   56.33 +// Set person, but if already exist, only update.
   56.34 +// if main_key_id already set, don't touch.
   56.35 +static const char *sql_set_person = 
   56.36 +    "insert or replace into person (id, username, lang, main_key_id, device_group)"
   56.37 +    "  values (?1, ?2, ?3,"
   56.38 +    "    (select coalesce((select main_key_id from person "
   56.39 +    "      where id = ?1), upper(replace(?4,' ','')))),"
   56.40 +    "    (select device_group from person where id = ?1)) ;";
   56.41 +
   56.42 +static const char *sql_set_device_group = 
   56.43 +    "update person set device_group = ?1 "
   56.44 +    "where id = '" PEP_OWN_USERID "';";
   56.45 +
   56.46 +// TODO leave group
   56.47 +
   56.48 +static const char *sql_get_device_group = 
   56.49 +    "select device_group from person "
   56.50 +    "where id = '" PEP_OWN_USERID "';";
   56.51 +
   56.52 +static const char *sql_set_pgp_keypair = 
   56.53 +    "insert or replace into pgp_keypair (fpr) "
   56.54 +    "values (upper(replace(?1,' ',''))) ;";
   56.55 +
   56.56 +static const char *sql_set_identity = 
   56.57 +    "insert or replace into identity ("
   56.58 +    " address, main_key_id, "
   56.59 +    " user_id, flags"
   56.60 +    ") values ("
   56.61 +    " ?1,"
   56.62 +    " upper(replace(?2,' ','')),"
   56.63 +    " ?3,"
   56.64 +    // " (select"
   56.65 +    // "   coalesce("
   56.66 +    // "    (select flags from identity"
   56.67 +    // "     where address = ?1 and"
   56.68 +    // "           user_id = ?3),"
   56.69 +    // "    0)"
   56.70 +    // " ) | (?4 & 255)"
   56.71 +    /* set_identity ignores previous flags, and doesn't filter machine flags */
   56.72 +    " ?4"
   56.73 +    ");";
   56.74 +        
   56.75 +static const char *sql_set_identity_flags = 
   56.76 +    "update identity set flags = "
   56.77 +    "    ((?1 & 255) | (select flags from identity"
   56.78 +    "                   where address = ?2 and user_id = ?3)) "
   56.79 +    "where address = ?2 and user_id = ?3 ;";
   56.80 +
   56.81 +static const char *sql_unset_identity_flags = 
   56.82 +    "update identity set flags = "
   56.83 +    "    ( ~(?1 & 255) & (select flags from identity"
   56.84 +    "                   where address = ?2 and user_id = ?3)) "
   56.85 +    "where address = ?2 and user_id = ?3 ;";
   56.86 +
   56.87 +static const char *sql_set_trust =
   56.88 +    "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type) "
   56.89 +    "values (?1, upper(replace(?2,' ','')), ?3) ;";
   56.90 +
   56.91 +static const char *sql_get_trust = 
   56.92 +    "select comm_type from trust where user_id = ?1 "
   56.93 +    "and pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
   56.94 +
   56.95 +static const char *sql_least_trust = 
   56.96 +    "select min(comm_type) from trust where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
   56.97 +
   56.98 +static const char *sql_mark_as_compromized = 
   56.99 +    "update trust not indexed set comm_type = 15"
  56.100 +    " where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
  56.101 +
  56.102 +static const char *sql_crashdump = 
  56.103 +    "select timestamp, title, entity, description, comment"
  56.104 +    " from log order by timestamp desc limit ?1 ;";
  56.105 +
  56.106 +static const char *sql_languagelist = 
  56.107 +    "select i18n_language.lang, name, phrase" 
  56.108 +    " from i18n_language join i18n_token using (lang) where i18n_token.id = 1000;" ;
  56.109 +
  56.110 +static const char *sql_i18n_token = 
  56.111 +    "select phrase from i18n_token where lang = lower(?1) and id = ?2 ;";
  56.112 +
  56.113 +
  56.114 +// blacklist
  56.115 +static const char *sql_blacklist_add = 
  56.116 +    "insert or replace into blacklist_keys (fpr) values (upper(replace(?1,' ',''))) ;"
  56.117 +    "delete from identity where main_key_id = upper(replace(?1,' ','')) ;"
  56.118 +    "delete from pgp_keypair where fpr = upper(replace(?1,' ','')) ;";
  56.119 +
  56.120 +static const char *sql_blacklist_delete =
  56.121 +    "delete from blacklist_keys where fpr = upper(replace(?1,' ','')) ;";
  56.122 +
  56.123 +static const char *sql_blacklist_is_listed = 
  56.124 +    "select count(*) from blacklist_keys where fpr = upper(replace(?1,' ','')) ;";
  56.125 +
  56.126 +static const char *sql_blacklist_retrieve = 
  56.127 +    "select * from blacklist_keys ;";
  56.128 +                
  56.129 +
  56.130 +// Own keys
  56.131 +static const char *sql_own_key_is_listed = 
  56.132 +    "select count(*) from ("
  56.133 +    " select main_key_id from person "
  56.134 +    "   where main_key_id = upper(replace(?1,' ',''))"
  56.135 +    "    and id = '" PEP_OWN_USERID "' "
  56.136 +    " union "
  56.137 +    "  select main_key_id from identity "
  56.138 +    "   where main_key_id = upper(replace(?1,' ',''))"
  56.139 +    "    and user_id = '" PEP_OWN_USERID "' );";
  56.140 +
  56.141 +static const char *sql_own_identities_retrieve =  
  56.142 +    "select address, fpr, username, "
  56.143 +    "   lang, identity.flags | pgp_keypair.flags"
  56.144 +    "   from identity"
  56.145 +    "   join person on id = identity.user_id"
  56.146 +    "   join pgp_keypair on fpr = identity.main_key_id"
  56.147 +    "   join trust on id = trust.user_id"
  56.148 +    "       and pgp_keypair_fpr = identity.main_key_id"
  56.149 +    "   where identity.user_id = '" PEP_OWN_USERID "'"
  56.150 +    "       and (identity.flags & ?1) = 0;";
  56.151 +        
  56.152 +static const char *sql_own_keys_retrieve =  
  56.153 +    "select fpr from own_keys"
  56.154 +    "   natural join identity"
  56.155 +    "   where (identity.flags & ?1) = 0;";
  56.156 +
  56.157 +static const char *sql_set_own_key = 
  56.158 +    "insert or replace into own_keys (address, user_id, fpr)"
  56.159 +    " values (?1, '" PEP_OWN_USERID "', upper(replace(?2,' ','')));";
  56.160 +
  56.161 +
  56.162 +// Sequence
  56.163 +static const char *sql_sequence_value1 = 
  56.164 +    "insert or replace into sequences (name, value, own) "
  56.165 +    "values (?1, "
  56.166 +    "(select coalesce((select value + 1 from sequences "
  56.167 +    "where name = ?1), 1 )), ?2) ; ";
  56.168 +
  56.169 +static const char *sql_sequence_value2 = 
  56.170 +    "select value, own from sequences where name = ?1 ;";
  56.171 +
  56.172 +static const char *sql_sequence_value3 = 
  56.173 +    "update sequences set value = ?2, own = ?3 where name = ?1 ;";
  56.174 +        
  56.175 +// Revocation tracking
  56.176 +static const char *sql_set_revoked =
  56.177 +    "insert or replace into revoked_keys ("
  56.178 +    "    revoked_fpr, replacement_fpr, revocation_date) "
  56.179 +    "values (upper(replace(?1,' ','')),"
  56.180 +    "        upper(replace(?2,' ','')),"
  56.181 +    "        ?3) ;";
  56.182 +        
  56.183 +static const char *sql_get_revoked = 
  56.184 +    "select revoked_fpr, revocation_date from revoked_keys"
  56.185 +    "    where replacement_fpr = upper(replace(?1,' ','')) ;";
  56.186 +
  56.187  static int user_version(void *_version, int count, char **text, char **name)
  56.188  {
  56.189      assert(_version);
  56.190 @@ -24,44 +200,6 @@
  56.191  {
  56.192      PEP_STATUS status = PEP_STATUS_OK;
  56.193      int int_result;
  56.194 -    static const char *sql_log;
  56.195 -    static const char *sql_trustword;
  56.196 -    static const char *sql_get_identity;
  56.197 -    static const char *sql_set_person;
  56.198 -    static const char *sql_set_device_group;
  56.199 -    static const char *sql_get_device_group;
  56.200 -    static const char *sql_set_pgp_keypair;
  56.201 -    static const char *sql_set_identity;
  56.202 -    static const char *sql_set_identity_flags;
  56.203 -    static const char *sql_unset_identity_flags;
  56.204 -    static const char *sql_set_trust;
  56.205 -    static const char *sql_get_trust;
  56.206 -    static const char *sql_least_trust;
  56.207 -    static const char *sql_mark_as_compromized;
  56.208 -    static const char *sql_crashdump;
  56.209 -    static const char *sql_languagelist;
  56.210 -    static const char *sql_i18n_token;
  56.211 -
  56.212 -    // blacklist
  56.213 -    static const char *sql_blacklist_add;
  56.214 -    static const char *sql_blacklist_delete;
  56.215 -    static const char *sql_blacklist_is_listed;
  56.216 -    static const char *sql_blacklist_retrieve;
  56.217 -    
  56.218 -    // Own keys
  56.219 -    static const char *sql_own_key_is_listed;
  56.220 -    static const char *sql_own_identities_retrieve;
  56.221 -    static const char *sql_own_keys_retrieve;
  56.222 -    static const char *sql_set_own_key;
  56.223 -
  56.224 -    // Sequence
  56.225 -    static const char *sql_sequence_value1;
  56.226 -    static const char *sql_sequence_value2;
  56.227 -    static const char *sql_sequence_value3;
  56.228 -
  56.229 -    // Revocation tracking
  56.230 -    static const char *sql_set_revoked;
  56.231 -    static const char *sql_get_revoked;
  56.232      
  56.233      bool in_first = false;
  56.234  
  56.235 @@ -317,142 +455,6 @@
  56.236              assert(int_result == SQLITE_OK);
  56.237          }
  56.238  
  56.239 -        sql_log = "insert into log (title, entity, description, comment)"
  56.240 -                  "values (?1, ?2, ?3, ?4);";
  56.241 -
  56.242 -        sql_get_identity =  "select fpr, username, comm_type, lang,"
  56.243 -                            "   identity.flags | pgp_keypair.flags"
  56.244 -                            "   from identity"
  56.245 -                            "   join person on id = identity.user_id"
  56.246 -                            "   join pgp_keypair on fpr = identity.main_key_id"
  56.247 -                            "   join trust on id = trust.user_id"
  56.248 -                            "       and pgp_keypair_fpr = identity.main_key_id"
  56.249 -                            "   where address = ?1 and identity.user_id = ?2;";
  56.250 -
  56.251 -        sql_trustword = "select id, word from wordlist where lang = lower(?1) "
  56.252 -                       "and id = ?2 ;";
  56.253 -
  56.254 -        // Set person, but if already exist, only update.
  56.255 -        // if main_key_id already set, don't touch.
  56.256 -        sql_set_person = "insert or replace into person (id, username, lang, main_key_id, device_group)"
  56.257 -                         "  values (?1, ?2, ?3,"
  56.258 -                         "    (select coalesce((select main_key_id from person "
  56.259 -                         "      where id = ?1), upper(replace(?4,' ','')))),"
  56.260 -                         "    (select device_group from person where id = ?1)) ;";
  56.261 -
  56.262 -        sql_set_device_group = "update person set device_group = ?1 "
  56.263 -                               "where id = '" PEP_OWN_USERID "';";
  56.264 -
  56.265 -        sql_get_device_group = "select device_group from person "
  56.266 -                               "where id = '" PEP_OWN_USERID "';";
  56.267 -
  56.268 -        sql_set_pgp_keypair = "insert or replace into pgp_keypair (fpr) "
  56.269 -                              "values (upper(replace(?1,' ',''))) ;";
  56.270 -
  56.271 -        sql_set_identity = "insert or replace into identity ("
  56.272 -                           " address, main_key_id, "
  56.273 -                           " user_id, flags"
  56.274 -                           ") values ("
  56.275 -                           " ?1,"
  56.276 -                           " upper(replace(?2,' ','')),"
  56.277 -                           " ?3,"
  56.278 -                           // " (select"
  56.279 -                           // "   coalesce("
  56.280 -                           // "    (select flags from identity"
  56.281 -                           // "     where address = ?1 and"
  56.282 -                           // "           user_id = ?3),"
  56.283 -                           // "    0)"
  56.284 -                           // " ) | (?4 & 255)"
  56.285 -                           /* set_identity ignores previous flags, and doesn't filter machine flags */
  56.286 -                           " ?4"
  56.287 -                           ");";
  56.288 -        
  56.289 -        sql_set_identity_flags = "update identity set flags = "
  56.290 -                                 "    ((?1 & 255) | (select flags from identity"
  56.291 -                                 "                   where address = ?2 and user_id = ?3)) "
  56.292 -                                 "where address = ?2 and user_id = ?3 ;";
  56.293 -
  56.294 -        sql_unset_identity_flags = 
  56.295 -                                 "update identity set flags = "
  56.296 -                                 "    ( ~(?1 & 255) & (select flags from identity"
  56.297 -                                 "                   where address = ?2 and user_id = ?3)) "
  56.298 -                                 "where address = ?2 and user_id = ?3 ;";
  56.299 -
  56.300 -        sql_set_trust = "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type) "
  56.301 -                        "values (?1, upper(replace(?2,' ','')), ?3) ;";
  56.302 -
  56.303 -        sql_get_trust = "select comm_type from trust where user_id = ?1 "
  56.304 -                        "and pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
  56.305 -
  56.306 -        sql_least_trust = "select min(comm_type) from trust where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
  56.307 -
  56.308 -        sql_mark_as_compromized = "update trust not indexed set comm_type = 15"
  56.309 -                                  " where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
  56.310 -
  56.311 -        sql_crashdump = "select timestamp, title, entity, description, comment"
  56.312 -                        " from log order by timestamp desc limit ?1 ;";
  56.313 -
  56.314 -        sql_languagelist = "select i18n_language.lang, name, phrase from i18n_language join i18n_token using (lang) where i18n_token.id = 1000;" ;
  56.315 -
  56.316 -        sql_i18n_token = "select phrase from i18n_token where lang = lower(?1) and id = ?2 ;";
  56.317 -
  56.318 -        // blacklist
  56.319 -
  56.320 -        sql_blacklist_add = "insert or replace into blacklist_keys (fpr) values (upper(replace(?1,' ',''))) ;"
  56.321 -                            "delete from identity where main_key_id = upper(replace(?1,' ','')) ;"
  56.322 -                            "delete from pgp_keypair where fpr = upper(replace(?1,' ','')) ;";
  56.323 -
  56.324 -        sql_blacklist_delete = "delete from blacklist_keys where fpr = upper(replace(?1,' ','')) ;";
  56.325 -
  56.326 -        sql_blacklist_is_listed = "select count(*) from blacklist_keys where fpr = upper(replace(?1,' ','')) ;";
  56.327 -
  56.328 -        sql_blacklist_retrieve = "select * from blacklist_keys ;";
  56.329 -                
  56.330 -        // Own keys
  56.331 -        
  56.332 -        sql_own_key_is_listed = "select count(*) from ("
  56.333 -                                " select main_key_id from person "
  56.334 -                                "   where main_key_id = upper(replace(?1,' ',''))"
  56.335 -                                "    and id = '" PEP_OWN_USERID "' "
  56.336 -                                " union "
  56.337 -                                "  select main_key_id from identity "
  56.338 -                                "   where main_key_id = upper(replace(?1,' ',''))"
  56.339 -                                "    and user_id = '" PEP_OWN_USERID "' );";
  56.340 -
  56.341 -        sql_own_identities_retrieve =  
  56.342 -                            "select address, fpr, username, "
  56.343 -                            "   lang, identity.flags | pgp_keypair.flags"
  56.344 -                            "   from identity"
  56.345 -                            "   join person on id = identity.user_id"
  56.346 -                            "   join pgp_keypair on fpr = identity.main_key_id"
  56.347 -                            "   join trust on id = trust.user_id"
  56.348 -                            "       and pgp_keypair_fpr = identity.main_key_id"
  56.349 -                            "   where identity.user_id = '" PEP_OWN_USERID "'"
  56.350 -                            "       and (identity.flags & ?1) = 0;";
  56.351 -        
  56.352 -        sql_own_keys_retrieve =  
  56.353 -                            "select fpr from own_keys"
  56.354 -                            "   natural join identity"
  56.355 -                            "   where (identity.flags & ?1) = 0;";
  56.356 -
  56.357 -        sql_set_own_key = "insert or replace into own_keys (address, user_id, fpr)"
  56.358 -                          " values (?1, '" PEP_OWN_USERID "', upper(replace(?2,' ','')));";
  56.359 -
  56.360 -        sql_sequence_value1 = "insert or replace into sequences (name, value, own) "
  56.361 -                              "values (?1, "
  56.362 -                              "(select coalesce((select value + 1 from sequences "
  56.363 -                              "where name = ?1), 1 )), ?2) ; ";
  56.364 -        sql_sequence_value2 = "select value, own from sequences where name = ?1 ;";
  56.365 -        sql_sequence_value3 = "update sequences set value = ?2, own = ?3 where name = ?1 ;";
  56.366 -        
  56.367 -        sql_set_revoked =     "insert or replace into revoked_keys ("
  56.368 -                              "    revoked_fpr, replacement_fpr, revocation_date) "
  56.369 -                              "values (upper(replace(?1,' ','')),"
  56.370 -                              "        upper(replace(?2,' ','')),"
  56.371 -                              "        ?3) ;";
  56.372 -        
  56.373 -        sql_get_revoked =     "select revoked_fpr, revocation_date from revoked_keys"
  56.374 -                              "    where replacement_fpr = upper(replace(?1,' ','')) ;";
  56.375      }
  56.376  
  56.377      int_result = sqlite3_prepare_v2(_session->db, sql_log,
    57.1 --- a/src/pEpEngine.h	Mon Jan 09 10:23:55 2017 +0100
    57.2 +++ b/src/pEpEngine.h	Mon Jan 09 10:28:02 2017 +0100
    57.3 @@ -1,3 +1,6 @@
    57.4 +// This file is under GNU General Public License 3.0
    57.5 +// see LICENSE.txt
    57.6 +
    57.7  #pragma once
    57.8  
    57.9  #ifdef __cplusplus
    58.1 --- a/src/pEp_internal.h	Mon Jan 09 10:23:55 2017 +0100
    58.2 +++ b/src/pEp_internal.h	Mon Jan 09 10:28:02 2017 +0100
    58.3 @@ -1,3 +1,6 @@
    58.4 +// This file is under GNU General Public License 3.0
    58.5 +// see LICENSE.txt
    58.6 +
    58.7  #define PEP_ENGINE_VERSION "0.8.0"
    58.8  
    58.9  // maximum attachment size to import as key 1MB, maximum of 20 attachments
   58.10 @@ -51,6 +54,7 @@
   58.11  #include <string.h>
   58.12  #include <assert.h>
   58.13  #include <stdio.h>
   58.14 +#include <ctype.h>
   58.15  
   58.16  #include "sqlite3.h"
   58.17  
   58.18 @@ -167,3 +171,43 @@
   58.19      log_event(session, (TITLE), (ENTITY), (DESC), "debug");
   58.20  #endif
   58.21  
   58.22 +// Space tolerant and case insensitive fingerprint string compare
   58.23 +static inline int _same_fpr(
   58.24 +        const char* fpra,
   58.25 +        size_t fpras,
   58.26 +        const char* fprb,
   58.27 +        size_t fprbs
   58.28 +    )
   58.29 +{
   58.30 +    size_t ai = 0;
   58.31 +    size_t bi = 0;
   58.32 +    
   58.33 +    do
   58.34 +    {
   58.35 +        if(fpra[ai] == 0 || fprb[bi] == 0)
   58.36 +        {
   58.37 +            return 0;
   58.38 +        }
   58.39 +        else if(fpra[ai] == ' ')
   58.40 +        {
   58.41 +            ai++;
   58.42 +        }
   58.43 +        else if(fprb[bi] == ' ')
   58.44 +        {
   58.45 +            bi++;
   58.46 +        }
   58.47 +        else if(toupper(fpra[ai]) == toupper(fprb[bi]))
   58.48 +        {
   58.49 +            ai++;
   58.50 +            bi++;
   58.51 +        }
   58.52 +        else
   58.53 +        {
   58.54 +            return 0;
   58.55 +        }
   58.56 +        
   58.57 +    }
   58.58 +    while(ai < fpras && bi < fprbs);
   58.59 +    
   58.60 +    return ai == fpras && bi == fprbs;
   58.61 +}
    59.1 --- a/src/pgp_gpg.c	Mon Jan 09 10:23:55 2017 +0100
    59.2 +++ b/src/pgp_gpg.c	Mon Jan 09 10:28:02 2017 +0100
    59.3 @@ -1,3 +1,6 @@
    59.4 +// This file is under GNU General Public License 3.0
    59.5 +// see LICENSE.txt
    59.6 +
    59.7  #include "platform.h"
    59.8  #include "pEp_internal.h"
    59.9  #include "pgp_gpg.h"
   59.10 @@ -1531,12 +1534,27 @@
   59.11              case GPG_ERR_NO_ERROR:
   59.12                  assert(key);
   59.13                  assert(key->subkeys);
   59.14 -                char *fpr = key->subkeys->fpr;
   59.15 -                assert(fpr);
   59.16 -                _k = stringlist_add(_k, fpr);
   59.17 -                assert(_k);
   59.18 -                if (_k != NULL)
   59.19 +                if(!key->subkeys)
   59.20                      break;
   59.21 +                assert(key->uids);
   59.22 +                gpgme_user_id_t kuid = key->uids;
   59.23 +                // check that at least one uid's email matches pattern exactly
   59.24 +                while(kuid) {
   59.25 +                    if(kuid->email && strcmp(kuid->email, pattern) == 0){
   59.26 +                        char *fpr = key->subkeys->fpr;
   59.27 +                        assert(fpr);
   59.28 +                        _k = stringlist_add(_k, fpr);
   59.29 +                        assert(_k);
   59.30 +                        if (_k == NULL){
   59.31 +                            free_stringlist(_keylist);
   59.32 +                            gpg.gpgme_op_keylist_end(session->ctx);
   59.33 +                            return PEP_OUT_OF_MEMORY;
   59.34 +                        }
   59.35 +                        break;
   59.36 +                    }
   59.37 +                    kuid = kuid->next;
   59.38 +                }
   59.39 +                break;
   59.40              case GPG_ERR_ENOMEM:
   59.41                  free_stringlist(_keylist);
   59.42                  gpg.gpgme_op_keylist_end(session->ctx);
    60.1 --- a/src/pgp_gpg.h	Mon Jan 09 10:23:55 2017 +0100
    60.2 +++ b/src/pgp_gpg.h	Mon Jan 09 10:28:02 2017 +0100
    60.3 @@ -1,3 +1,6 @@
    60.4 +// This file is under GNU General Public License 3.0
    60.5 +// see LICENSE.txt
    60.6 +
    60.7  #pragma once
    60.8  
    60.9  #include "pEpEngine.h"
    61.1 --- a/src/pgp_gpg_internal.h	Mon Jan 09 10:23:55 2017 +0100
    61.2 +++ b/src/pgp_gpg_internal.h	Mon Jan 09 10:28:02 2017 +0100
    61.3 @@ -1,3 +1,6 @@
    61.4 +// This file is under GNU General Public License 3.0
    61.5 +// see LICENSE.txt
    61.6 +
    61.7  #pragma once
    61.8  
    61.9  #include <gpgme.h>
    62.1 --- a/src/pgp_netpgp.c	Mon Jan 09 10:23:55 2017 +0100
    62.2 +++ b/src/pgp_netpgp.c	Mon Jan 09 10:28:02 2017 +0100
    62.3 @@ -1,3 +1,6 @@
    62.4 +// This file is under GNU General Public License 3.0
    62.5 +// see LICENSE.txt
    62.6 +
    62.7  #include "pEp_internal.h"
    62.8  #include "pgp_netpgp.h"
    62.9  
    63.1 --- a/src/pgp_netpgp.h	Mon Jan 09 10:23:55 2017 +0100
    63.2 +++ b/src/pgp_netpgp.h	Mon Jan 09 10:28:02 2017 +0100
    63.3 @@ -1,3 +1,6 @@
    63.4 +// This file is under GNU General Public License 3.0
    63.5 +// see LICENSE.txt
    63.6 +
    63.7  #pragma once
    63.8  
    63.9  #include "pEpEngine.h"
    64.1 --- a/src/pgp_netpgp_internal.h	Mon Jan 09 10:23:55 2017 +0100
    64.2 +++ b/src/pgp_netpgp_internal.h	Mon Jan 09 10:28:02 2017 +0100
    64.3 @@ -1,3 +1,6 @@
    64.4 +// This file is under GNU General Public License 3.0
    64.5 +// see LICENSE.txt
    64.6 +
    64.7  #pragma once
    64.8  
    64.9  #include <curl/curl.h>
    65.1 --- a/src/platform.h	Mon Jan 09 10:23:55 2017 +0100
    65.2 +++ b/src/platform.h	Mon Jan 09 10:28:02 2017 +0100
    65.3 @@ -1,3 +1,6 @@
    65.4 +// This file is under GNU General Public License 3.0
    65.5 +// see LICENSE.txt
    65.6 +
    65.7  #pragma once
    65.8  
    65.9  #ifdef __cplusplus
    66.1 --- a/src/platform_unix.c	Mon Jan 09 10:23:55 2017 +0100
    66.2 +++ b/src/platform_unix.c	Mon Jan 09 10:28:02 2017 +0100
    66.3 @@ -1,3 +1,6 @@
    66.4 +// This file is under GNU General Public License 3.0
    66.5 +// see LICENSE.txt
    66.6 +
    66.7  #define _POSIX_C_SOURCE 200809L
    66.8  
    66.9  #ifdef ANDROID
    67.1 --- a/src/platform_unix.h	Mon Jan 09 10:23:55 2017 +0100
    67.2 +++ b/src/platform_unix.h	Mon Jan 09 10:28:02 2017 +0100
    67.3 @@ -1,3 +1,6 @@
    67.4 +// This file is under GNU General Public License 3.0
    67.5 +// see LICENSE.txt
    67.6 +
    67.7  #ifndef __APPLE__
    67.8  #define _POSIX_C_SOURCE 200809L
    67.9  #endif
    68.1 --- a/src/platform_windows.cpp	Mon Jan 09 10:23:55 2017 +0100
    68.2 +++ b/src/platform_windows.cpp	Mon Jan 09 10:28:02 2017 +0100
    68.3 @@ -1,4 +1,7 @@
    68.4 -// Windows platform specifica
    68.5 +// This file is under GNU General Public License 3.0
    68.6 +// see LICENSE.txt
    68.7 +
    68.8 +// Windows platform specification
    68.9  
   68.10  #define WIN32_LEAN_AND_MEAN
   68.11  #ifndef UNICODE
    69.1 --- a/src/platform_windows.h	Mon Jan 09 10:23:55 2017 +0100
    69.2 +++ b/src/platform_windows.h	Mon Jan 09 10:28:02 2017 +0100
    69.3 @@ -1,3 +1,6 @@
    69.4 +// This file is under GNU General Public License 3.0
    69.5 +// see LICENSE.txt
    69.6 +
    69.7  #pragma once
    69.8  
    69.9  // Windows platform specifica
    70.1 --- a/src/resource.h	Mon Jan 09 10:23:55 2017 +0100
    70.2 +++ b/src/resource.h	Mon Jan 09 10:28:02 2017 +0100
    70.3 @@ -1,3 +1,6 @@
    70.4 +// This file is under GNU General Public License 3.0
    70.5 +// see LICENSE.txt
    70.6 +
    70.7  //{{NO_DEPENDENCIES}}
    70.8  // Microsoft Visual C++ generated include file.
    70.9  // Used by pEpEngine.rc
    71.1 --- a/src/sqlite3.h	Mon Jan 09 10:23:55 2017 +0100
    71.2 +++ b/src/sqlite3.h	Mon Jan 09 10:28:02 2017 +0100
    71.3 @@ -1,3 +1,6 @@
    71.4 +// This file is under GNU General Public License 3.0
    71.5 +// see LICENSE.txt
    71.6 +
    71.7  /*
    71.8  ** 2001 September 15
    71.9  **
    72.1 --- a/src/stringlist.c	Mon Jan 09 10:23:55 2017 +0100
    72.2 +++ b/src/stringlist.c	Mon Jan 09 10:28:02 2017 +0100
    72.3 @@ -1,3 +1,6 @@
    72.4 +// This file is under GNU General Public License 3.0
    72.5 +// see LICENSE.txt
    72.6 +
    72.7  #include "pEp_internal.h"
    72.8  
    72.9  #include <stdlib.h>
    73.1 --- a/src/stringlist.h	Mon Jan 09 10:23:55 2017 +0100
    73.2 +++ b/src/stringlist.h	Mon Jan 09 10:28:02 2017 +0100
    73.3 @@ -1,3 +1,6 @@
    73.4 +// This file is under GNU General Public License 3.0
    73.5 +// see LICENSE.txt
    73.6 +
    73.7  #pragma once
    73.8  
    73.9  #include "dynamic_api.h"
    74.1 --- a/src/stringpair.c	Mon Jan 09 10:23:55 2017 +0100
    74.2 +++ b/src/stringpair.c	Mon Jan 09 10:28:02 2017 +0100
    74.3 @@ -1,3 +1,6 @@
    74.4 +// This file is under GNU General Public License 3.0
    74.5 +// see LICENSE.txt
    74.6 +
    74.7  #include "pEp_internal.h"
    74.8  
    74.9  #include <stdlib.h>
    75.1 --- a/src/stringpair.h	Mon Jan 09 10:23:55 2017 +0100
    75.2 +++ b/src/stringpair.h	Mon Jan 09 10:28:02 2017 +0100
    75.3 @@ -1,3 +1,6 @@
    75.4 +// This file is under GNU General Public License 3.0
    75.5 +// see LICENSE.txt
    75.6 +
    75.7  #pragma once
    75.8  
    75.9  #include "dynamic_api.h"
    76.1 --- a/src/sync.c	Mon Jan 09 10:23:55 2017 +0100
    76.2 +++ b/src/sync.c	Mon Jan 09 10:28:02 2017 +0100
    76.3 @@ -1,3 +1,6 @@
    76.4 +// This file is under GNU General Public License 3.0
    76.5 +// see LICENSE.txt
    76.6 +
    76.7  #include "pEp_internal.h"
    76.8  
    76.9  #include <memory.h>
    77.1 --- a/src/sync.h	Mon Jan 09 10:23:55 2017 +0100
    77.2 +++ b/src/sync.h	Mon Jan 09 10:28:02 2017 +0100
    77.3 @@ -1,3 +1,6 @@
    77.4 +// This file is under GNU General Public License 3.0
    77.5 +// see LICENSE.txt
    77.6 +
    77.7  /*
    77.8  ====================================
    77.9  Engine/adapter/app KeySync interface 
    78.1 --- a/src/sync_actions.c	Mon Jan 09 10:23:55 2017 +0100
    78.2 +++ b/src/sync_actions.c	Mon Jan 09 10:28:02 2017 +0100
    78.3 @@ -1,3 +1,6 @@
    78.4 +// This file is under GNU General Public License 3.0
    78.5 +// see LICENSE.txt
    78.6 +
    78.7  // Actions for DeviceState state machine
    78.8  
    78.9  #include <assert.h>
   78.10 @@ -9,9 +12,11 @@
   78.11  
   78.12  // conditions
   78.13  
   78.14 +// TODO : move that SQL statement with other prepared SQL statements in pEpEngine.c
   78.15  static const char *sql_stored_group_keys =
   78.16          "select count(device_group) from person where id = '" PEP_OWN_USERID "';"; 
   78.17  
   78.18 +// TODO  is that necessary ?
   78.19  static int _stored_group_keys(void *_gc, int count, char **text, char **name)
   78.20  {
   78.21      assert(_gc);
   78.22 @@ -97,6 +102,27 @@
   78.23      return result;
   78.24  }
   78.25  
   78.26 +int sameIdentities(PEP_SESSION session, Identity a, Identity b)
   78.27 +{
   78.28 +    assert(session);
   78.29 +    assert(a);
   78.30 +    assert(b);
   78.31 +
   78.32 +    if (!(session && a && b))
   78.33 +        return invalid_condition; // error
   78.34 +
   78.35 +    if (a->fpr == NULL || b->fpr == NULL ||
   78.36 +        (!_same_fpr(a->fpr, strlen(a->fpr), b->fpr, strlen(b->fpr))) ||
   78.37 +        a->address == NULL || b->address == NULL ||
   78.38 +        strcmp(a->address, b->address) != 0 ||
   78.39 +        a->user_id == NULL || b->user_id == NULL ||
   78.40 +        strcmp(a->user_id, b->user_id) != 0)
   78.41 +            return 0;
   78.42 +    return 1;
   78.43 +}
   78.44 +
   78.45 +// actions
   78.46 +
   78.47  PEP_STATUS _notifyHandshake(
   78.48          PEP_SESSION session,
   78.49          Identity partner,
    79.1 --- a/src/sync_impl.c	Mon Jan 09 10:23:55 2017 +0100
    79.2 +++ b/src/sync_impl.c	Mon Jan 09 10:28:02 2017 +0100
    79.3 @@ -1,3 +1,6 @@
    79.4 +// This file is under GNU General Public License 3.0
    79.5 +// see LICENSE.txt
    79.6 +
    79.7  #include "platform.h"
    79.8  
    79.9  // it seems pEp_internal.h needs to be the first pEp include due to the 
   79.10 @@ -285,6 +288,52 @@
   79.11                      return PEP_OUT_OF_MEMORY;
   79.12                  }
   79.13  
   79.14 +                // detect and mitigate address spoofing
   79.15 +                Identity check_me = NULL;
   79.16 +                char* null_terminated_address = 
   79.17 +                    strndup((char *) msg->header.me.address->buf,
   79.18 +                            msg->header.me.address->size);
   79.19 +
   79.20 +                if(null_terminated_address){
   79.21 +                    status = get_identity(session, 
   79.22 +                                          null_terminated_address, 
   79.23 +                                          PEP_OWN_USERID, 
   79.24 +                                          &check_me);
   79.25 +                    free(null_terminated_address);
   79.26 +                } 
   79.27 +                else
   79.28 +                    status = PEP_OUT_OF_MEMORY;
   79.29 +
   79.30 +                if (status == PEP_OUT_OF_MEMORY)
   79.31 +                    goto free_all;
   79.32 +
   79.33 +                free_identity(check_me);
   79.34 +
   79.35 +                bool not_own_address = status != PEP_STATUS_OK;
   79.36 +                status = PEP_STATUS_OK;
   79.37 +
   79.38 +                if (not_own_address || 
   79.39 +                    strncmp(src->from->address,
   79.40 +                            (char *) msg->header.me.address->buf,
   79.41 +                            msg->header.me.address->size) != 0 ||
   79.42 +                    strncmp(src->to->ident->address,
   79.43 +                            (char *) msg->header.me.address->buf,
   79.44 +                            msg->header.me.address->size) != 0) {
   79.45 +                    consume = true;
   79.46 +                    goto free_all;
   79.47 +                }
   79.48 +
   79.49 +                // if encrypted, ensure that header.me.fpr match signer's fpr
   79.50 +                if (rating >= PEP_rating_reliable && (
   79.51 +                        !keylist ||
   79.52 +                        !_same_fpr((char *) msg->header.me.fpr.buf,
   79.53 +                                   msg->header.me.fpr.size,
   79.54 +                                   keylist->value,
   79.55 +                                   strlen(keylist->value)))) {
   79.56 +                    consume = true;
   79.57 +                    goto free_all;
   79.58 +                }
   79.59 +
   79.60                  // check message expiry 
   79.61                  if(src->recv) {
   79.62                      time_t expiry = timegm(src->recv) + SYNC_MSG_EXPIRE_TIME;
   79.63 @@ -311,13 +360,6 @@
   79.64                                  goto free_all;
   79.65                              }
   79.66                              
   79.67 -                            // Ignore and consume handshakes with devices
   79.68 -                            // already using trusted own key to encrypt
   79.69 -                            if (rating >= PEP_rating_trusted){
   79.70 -                                consume = true;
   79.71 -                                goto free_all;
   79.72 -                            }
   79.73 -
   79.74                              break;
   79.75                          // accepting GroupKeys needs encryption and trust of peer device
   79.76                          case DeviceGroup_Protocol__payload_PR_groupKeys:
   79.77 @@ -331,7 +373,7 @@
   79.78                                  goto free_all;
   79.79                              }
   79.80  
   79.81 -                            // check trust of identity using user_id given in payload
   79.82 +                            // check trust of identity using user_id given in msg.header.me
   79.83                              // to exacly match identity of device, the one trusted in
   79.84                              // case of accepted handshake
   79.85                              pEp_identity *_from = new_identity(NULL, 
    80.1 --- a/src/sync_impl.h	Mon Jan 09 10:23:55 2017 +0100
    80.2 +++ b/src/sync_impl.h	Mon Jan 09 10:28:02 2017 +0100
    80.3 @@ -1,3 +1,6 @@
    80.4 +// This file is under GNU General Public License 3.0
    80.5 +// see LICENSE.txt
    80.6 +
    80.7  #pragma once
    80.8  
    80.9  #include "message.h"
    81.1 --- a/src/timestamp.c	Mon Jan 09 10:23:55 2017 +0100
    81.2 +++ b/src/timestamp.c	Mon Jan 09 10:28:02 2017 +0100
    81.3 @@ -1,3 +1,6 @@
    81.4 +// This file is under GNU General Public License 3.0
    81.5 +// see LICENSE.txt
    81.6 +
    81.7  #include "pEp_internal.h"
    81.8  
    81.9  #include "timestamp.h"
    82.1 --- a/src/timestamp.h	Mon Jan 09 10:23:55 2017 +0100
    82.2 +++ b/src/timestamp.h	Mon Jan 09 10:28:02 2017 +0100
    82.3 @@ -1,3 +1,6 @@
    82.4 +// This file is under GNU General Public License 3.0
    82.5 +// see LICENSE.txt
    82.6 +
    82.7  #pragma once
    82.8  
    82.9  #include <time.h>
    83.1 --- a/src/trans_auto.c	Mon Jan 09 10:23:55 2017 +0100
    83.2 +++ b/src/trans_auto.c	Mon Jan 09 10:28:02 2017 +0100
    83.3 @@ -1,3 +1,6 @@
    83.4 +// This file is under GNU General Public License 3.0
    83.5 +// see LICENSE.txt
    83.6 +
    83.7  #include "trans_auto.h"
    83.8  
    83.9  PEP_STATUS auto_sendto(PEP_SESSION session, const message *msg)
    84.1 --- a/src/trans_auto.h	Mon Jan 09 10:23:55 2017 +0100
    84.2 +++ b/src/trans_auto.h	Mon Jan 09 10:28:02 2017 +0100
    84.3 @@ -1,3 +1,6 @@
    84.4 +// This file is under GNU General Public License 3.0
    84.5 +// see LICENSE.txt
    84.6 +
    84.7  #pragma once
    84.8  
    84.9  #include "transport.h"
    85.1 --- a/src/transport.c	Mon Jan 09 10:23:55 2017 +0100
    85.2 +++ b/src/transport.c	Mon Jan 09 10:28:02 2017 +0100
    85.3 @@ -1,3 +1,6 @@
    85.4 +// This file is under GNU General Public License 3.0
    85.5 +// see LICENSE.txt
    85.6 +
    85.7  #include "pEp_internal.h"
    85.8  #include "trans_auto.h"
    85.9  
    86.1 --- a/src/transport.h	Mon Jan 09 10:23:55 2017 +0100
    86.2 +++ b/src/transport.h	Mon Jan 09 10:28:02 2017 +0100
    86.3 @@ -1,3 +1,6 @@
    86.4 +// This file is under GNU General Public License 3.0
    86.5 +// see LICENSE.txt
    86.6 +
    86.7  #pragma once
    86.8  
    86.9  #include "pEpEngine.h"
    87.1 --- a/src/wrappers.h	Mon Jan 09 10:23:55 2017 +0100
    87.2 +++ b/src/wrappers.h	Mon Jan 09 10:28:02 2017 +0100
    87.3 @@ -1,3 +1,6 @@
    87.4 +// This file is under GNU General Public License 3.0
    87.5 +// see LICENSE.txt
    87.6 +
    87.7  #pragma once
    87.8  
    87.9  #include "platform.h"
    88.1 --- a/sync/Makefile	Mon Jan 09 10:23:55 2017 +0100
    88.2 +++ b/sync/Makefile	Mon Jan 09 10:28:02 2017 +0100
    88.3 @@ -1,3 +1,7 @@
    88.4 +
    88.5 +# This file is under GNU General Public License 3.0
    88.6 +# see LICENSE.txt
    88.7 +
    88.8  include ../Makefile.conf
    88.9  
   88.10  all: .codegen
    89.1 --- a/sync/devicegroup.fsm	Mon Jan 09 10:23:55 2017 +0100
    89.2 +++ b/sync/devicegroup.fsm	Mon Jan 09 10:28:02 2017 +0100
    89.3 @@ -1,3 +1,6 @@
    89.4 +// This file is under GNU General Public License 3.0
    89.5 +// see LICENSE.txt
    89.6 +
    89.7  // DeviceGroup protocol for p≡p
    89.8  
    89.9  // Copyleft (c) 2016, p≡p foundation
   89.10 @@ -17,6 +20,7 @@
   89.11      fsm DeviceState filename=sync {
   89.12          condition storedGroupKeys();
   89.13          condition keyElectionWon(Identity partner);
   89.14 +        condition sameIdentities(Identity a, Identity b);
   89.15  
   89.16          state InitState {
   89.17              on Init {
   89.18 @@ -27,22 +31,47 @@
   89.19          }
   89.20  
   89.21          state Sole end=1 {
   89.22 -            on KeyGen // injected by generate_keypair()
   89.23 +            on KeyGen
   89.24                  do sendBeacon;
   89.25              on CannotDecrypt
   89.26 -                do sendBeacon;  // cry, baby
   89.27 -            on Beacon(Identity partner) // this event will not happen for already
   89.28 -                                        // rejected partners
   89.29 +                do sendBeacon;
   89.30 +            on Beacon(Identity partner){
   89.31                  do sendHandshakeRequest(partner);
   89.32 +                go SoleBeaconed(partner);
   89.33 +            }
   89.34              on HandshakeRequest(Identity partner) {
   89.35                  do sendHandshakeRequest(partner);
   89.36                  go HandshakingSole(partner);
   89.37              }
   89.38          }
   89.39  
   89.40 +        state SoleBeaconed timeout=600 (Identity expected) {
   89.41 +            on KeyGen{
   89.42 +                do sendBeacon;
   89.43 +                go Sole;
   89.44 +            }
   89.45 +            on CannotDecrypt{
   89.46 +                do sendBeacon;
   89.47 +                go Sole;
   89.48 +            }
   89.49 +            on Beacon(Identity partner) {
   89.50 +                do sendHandshakeRequest(partner);
   89.51 +                go SoleBeaconed(partner);
   89.52 +            }
   89.53 +            on HandshakeRequest(Identity partner) {
   89.54 +                if sameIdentities(partner, expected) {
   89.55 +                    // do nothing, to avoid sending handshake request twice 
   89.56 +                } else {
   89.57 +                    do sendHandshakeRequest(partner);
   89.58 +                }
   89.59 +                go HandshakingSole(partner);
   89.60 +            }
   89.61 +            on Timeout go Sole;
   89.62 +        }
   89.63 +
   89.64          state HandshakingSole timeout=600 (Identity expected) {
   89.65              on Init{
   89.66 -                if keyElectionWon(partner) {    // an already existing group
   89.67 +                if keyElectionWon(partner) {
   89.68                      do notifyInitFormGroup(partner);
   89.69                  } else {
   89.70                      do notifyInitAddOurDevice(partner);
   89.71 @@ -50,13 +79,12 @@
   89.72              }
   89.73  
   89.74              on HandshakeRejected(Identity partner) {
   89.75 -                do rejectHandshake(partner);             // stores rejection of partner
   89.76 +                do rejectHandshake(partner);
   89.77                  go Sole;
   89.78              }
   89.79              on HandshakeAccepted(Identity partner) {
   89.80                  do acceptHandshake(partner); 
   89.81 -                if keyElectionWon(partner) {    // an already existing group
   89.82 -                                                // always wins
   89.83 +                if keyElectionWon(partner) {
   89.84                      do sendGroupKeys(partner);
   89.85                      do notifyAcceptedGroupCreated(partner);
   89.86                      go Grouped;
   89.87 @@ -72,10 +100,11 @@
   89.88      
   89.89          state WaitForGroupKeysSole timeout=600 (Identity expected) {
   89.90              on GroupKeys(Identity partner, Stringlist keys) {
   89.91 -                // TODO ensure partner == expected
   89.92 -                do storeGroupKeys(partner, keys);
   89.93 -                do notifyAcceptedDeviceAdded(partner);
   89.94 -                go Grouped;
   89.95 +                if sameIdentities(partner, expected) {
   89.96 +                    do storeGroupKeys(partner, keys);
   89.97 +                    do notifyAcceptedDeviceAdded(partner);
   89.98 +                    go Grouped;
   89.99 +                }
  89.100              }
  89.101              on Timeout {
  89.102                  do notifyTimeout(expected);
  89.103 @@ -89,11 +118,13 @@
  89.104              on KeyGen
  89.105                  do sendGroupUpdate;
  89.106              on CannotDecrypt
  89.107 -                do sendUpdateRequest; // TODO: narrow request to missing key
  89.108 +                do sendUpdateRequest;
  89.109              on UpdateRequest
  89.110                  do sendGroupUpdate;
  89.111 -            on Beacon(Identity partner)
  89.112 +            on Beacon(Identity partner){
  89.113                  do sendHandshakeRequest(partner);
  89.114 +                go GroupedBeaconed(partner);
  89.115 +            }
  89.116              on HandshakeRequest(Identity partner) {
  89.117                  do sendHandshakeRequest(partner);
  89.118                  go HandshakingGrouped(partner);
  89.119 @@ -102,6 +133,30 @@
  89.120                  do storeGroupKeys(partner, keys);
  89.121          }
  89.122  
  89.123 +        state GroupedBeaconed timeout=600 (Identity expected){
  89.124 +            on KeyGen
  89.125 +                do sendGroupUpdate;
  89.126 +            on CannotDecrypt
  89.127 +                do sendUpdateRequest;
  89.128 +            on UpdateRequest
  89.129 +                do sendGroupUpdate;
  89.130 +            on Beacon(Identity partner){
  89.131 +                do sendHandshakeRequest(partner);
  89.132 +                go GroupedBeaconed(partner);
  89.133 +            }
  89.134 +            on HandshakeRequest(Identity partner) {
  89.135 +                if sameIdentities(partner, expected) {
  89.136 +                    // do nothing, to avoid sending handshake request twice 
  89.137 +                } else {
  89.138 +                    do sendHandshakeRequest(partner);
  89.139 +                }
  89.140 +                go HandshakingGrouped(partner);
  89.141 +            }
  89.142 +            on GroupUpdate(Identity partner, Stringlist keys)
  89.143 +                do storeGroupKeys(partner, keys);
  89.144 +            on Timeout go Grouped;
  89.145 +        }
  89.146 +
  89.147          state HandshakingGrouped timeout=600 (Identity expected) {
  89.148              on Init
  89.149                  do notifyInitAddOurDevice(partner);
    90.1 --- a/sync/fsm.yml2	Mon Jan 09 10:23:55 2017 +0100
    90.2 +++ b/sync/fsm.yml2	Mon Jan 09 10:28:02 2017 +0100
    90.3 @@ -1,3 +1,6 @@
    90.4 +// This file is under GNU General Public License 3.0
    90.5 +// see LICENSE.txt
    90.6 +
    90.7  // FSM Y language 1.0
    90.8  
    90.9  // Copyleft (c) 2016, p≡p foundation
    91.1 --- a/sync/functions.ysl2	Mon Jan 09 10:23:55 2017 +0100
    91.2 +++ b/sync/functions.ysl2	Mon Jan 09 10:28:02 2017 +0100
    91.3 @@ -1,3 +1,6 @@
    91.4 +// This file is under GNU General Public License 3.0
    91.5 +// see LICENSE.txt
    91.6 +
    91.7  // function library
    91.8  
    91.9  def "func:distinctName" {
    92.1 --- a/sync/gen_actions.ysl2	Mon Jan 09 10:23:55 2017 +0100
    92.2 +++ b/sync/gen_actions.ysl2	Mon Jan 09 10:28:02 2017 +0100
    92.3 @@ -1,3 +1,6 @@
    92.4 +// This file is under GNU General Public License 3.0
    92.5 +// see LICENSE.txt
    92.6 +
    92.7  // generate actions skeleton
    92.8  
    92.9  // Copyleft (c) 2016, p≡p foundation
    93.1 --- a/sync/gen_dot.ysl2	Mon Jan 09 10:23:55 2017 +0100
    93.2 +++ b/sync/gen_dot.ysl2	Mon Jan 09 10:28:02 2017 +0100
    93.3 @@ -1,3 +1,6 @@
    93.4 +// This file is under GNU General Public License 3.0
    93.5 +// see LICENSE.txt
    93.6 +
    93.7  include yslt.yml2
    93.8  
    93.9  tstylesheet {
    94.1 --- a/sync/gen_statemachine.ysl2	Mon Jan 09 10:23:55 2017 +0100
    94.2 +++ b/sync/gen_statemachine.ysl2	Mon Jan 09 10:28:02 2017 +0100
    94.3 @@ -1,3 +1,6 @@
    94.4 +// This file is under GNU General Public License 3.0
    94.5 +// see LICENSE.txt
    94.6 +
    94.7  // generate state machine code
    94.8  
    94.9  // Copyleft (c) 2016, p≡p foundation
    95.1 --- a/sync/generated/sync_fsm.c	Mon Jan 09 10:23:55 2017 +0100
    95.2 +++ b/sync/generated/sync_fsm.c	Mon Jan 09 10:28:02 2017 +0100
    95.3 @@ -81,7 +81,9 @@
    95.4                          return (int) invalid_out_of_memory;
    95.5                      if (status != PEP_STATUS_OK)
    95.6                          return (int) invalid_action;
    95.7 -                    break;
    95.8 +                    session->sync_state_payload = identity_dup(partner);
    95.9 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=Beacon", "target=SoleBeaconed")
   95.10 +                    return SoleBeaconed;
   95.11                  }
   95.12                  case HandshakeRequest:
   95.13                  {
   95.14 @@ -101,6 +103,106 @@
   95.15              }
   95.16              break;
   95.17          }
   95.18 +        case SoleBeaconed:
   95.19 +        {
   95.20 +            Identity expected = (Identity)session->sync_state_payload;
   95.21 +            *timeout = 600;
   95.22 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=SoleBeaconed")
   95.23 +            switch (event) {
   95.24 +                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Init") break;
   95.25 +                case KeyGen:
   95.26 +                {
   95.27 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=KeyGen")
   95.28 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=KeyGen", "action=sendBeacon")
   95.29 +                    status = sendBeacon(session, state, NULL, NULL);
   95.30 +                    if (status == PEP_OUT_OF_MEMORY)
   95.31 +                        return (int) invalid_out_of_memory;
   95.32 +                    if (status != PEP_STATUS_OK)
   95.33 +                        return (int) invalid_action;
   95.34 +                    if(session->sync_state_payload){
   95.35 +                        free_identity((Identity)session->sync_state_payload);
   95.36 +                        session->sync_state_payload = NULL;
   95.37 +                    }
   95.38 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=KeyGen", "target=Sole")
   95.39 +                    return Sole;
   95.40 +                }
   95.41 +                case CannotDecrypt:
   95.42 +                {
   95.43 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=CannotDecrypt")
   95.44 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=CannotDecrypt", "action=sendBeacon")
   95.45 +                    status = sendBeacon(session, state, NULL, NULL);
   95.46 +                    if (status == PEP_OUT_OF_MEMORY)
   95.47 +                        return (int) invalid_out_of_memory;
   95.48 +                    if (status != PEP_STATUS_OK)
   95.49 +                        return (int) invalid_action;
   95.50 +                    if(session->sync_state_payload){
   95.51 +                        free_identity((Identity)session->sync_state_payload);
   95.52 +                        session->sync_state_payload = NULL;
   95.53 +                    }
   95.54 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=CannotDecrypt", "target=Sole")
   95.55 +                    return Sole;
   95.56 +                }
   95.57 +                case Beacon:
   95.58 +                {
   95.59 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Beacon")
   95.60 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=Beacon", "action=sendHandshakeRequest")
   95.61 +                    status = sendHandshakeRequest(session, state, partner, NULL);
   95.62 +                    if (status == PEP_OUT_OF_MEMORY)
   95.63 +                        return (int) invalid_out_of_memory;
   95.64 +                    if (status != PEP_STATUS_OK)
   95.65 +                        return (int) invalid_action;
   95.66 +                    if(session->sync_state_payload){
   95.67 +                        free_identity((Identity)session->sync_state_payload);
   95.68 +                        session->sync_state_payload = NULL;
   95.69 +                    }
   95.70 +                    session->sync_state_payload = identity_dup(partner);
   95.71 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=Beacon", "target=SoleBeaconed")
   95.72 +                    return SoleBeaconed;
   95.73 +                }
   95.74 +                case HandshakeRequest:
   95.75 +                {
   95.76 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=HandshakeRequest")
   95.77 +                    cond_result = sameIdentities(session, partner, expected);
   95.78 +                    #ifndef NDEBUG
   95.79 +                    char resstr[11] = {0,};
   95.80 +                    snprintf(resstr,10,"result=%d",cond_result);
   95.81 +                    #endif
   95.82 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
   95.83 +                    if (cond_result < 0)
   95.84 +                        return cond_result;
   95.85 +                    if (cond_result) {
   95.86 +                    }
   95.87 +                    else {
   95.88 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
   95.89 +                        status = sendHandshakeRequest(session, state, partner, NULL);
   95.90 +                        if (status == PEP_OUT_OF_MEMORY)
   95.91 +                            return (int) invalid_out_of_memory;
   95.92 +                        if (status != PEP_STATUS_OK)
   95.93 +                            return (int) invalid_action;
   95.94 +                    }
   95.95 +                    if(session->sync_state_payload){
   95.96 +                        free_identity((Identity)session->sync_state_payload);
   95.97 +                        session->sync_state_payload = NULL;
   95.98 +                    }
   95.99 +                    session->sync_state_payload = identity_dup(partner);
  95.100 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "target=HandshakingSole")
  95.101 +                    return HandshakingSole;
  95.102 +                }
  95.103 +                case Timeout:
  95.104 +                {
  95.105 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Timeout")
  95.106 +                    if(session->sync_state_payload){
  95.107 +                        free_identity((Identity)session->sync_state_payload);
  95.108 +                        session->sync_state_payload = NULL;
  95.109 +                    }
  95.110 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=Timeout", "target=Sole")
  95.111 +                    return Sole;
  95.112 +                }
  95.113 +                default:
  95.114 +                    return (DeviceState_state) invalid_event;
  95.115 +            }
  95.116 +            break;
  95.117 +        }
  95.118          case HandshakingSole:
  95.119          {
  95.120              Identity expected = (Identity)session->sync_state_payload;
  95.121 @@ -238,24 +340,35 @@
  95.122                  case GroupKeys:
  95.123                  {
  95.124                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
  95.125 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
  95.126 -                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
  95.127 -                    if (status == PEP_OUT_OF_MEMORY)
  95.128 -                        return (int) invalid_out_of_memory;
  95.129 -                    if (status != PEP_STATUS_OK)
  95.130 -                        return (int) invalid_action;
  95.131 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
  95.132 -                    status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
  95.133 -                    if (status == PEP_OUT_OF_MEMORY)
  95.134 -                        return (int) invalid_out_of_memory;
  95.135 -                    if (status != PEP_STATUS_OK)
  95.136 -                        return (int) invalid_action;
  95.137 -                    if(session->sync_state_payload){
  95.138 -                        free_identity((Identity)session->sync_state_payload);
  95.139 -                        session->sync_state_payload = NULL;
  95.140 +                    cond_result = sameIdentities(session, partner, expected);
  95.141 +                    #ifndef NDEBUG
  95.142 +                    char resstr[11] = {0,};
  95.143 +                    snprintf(resstr,10,"result=%d",cond_result);
  95.144 +                    #endif
  95.145 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
  95.146 +                    if (cond_result < 0)
  95.147 +                        return cond_result;
  95.148 +                    if (cond_result) {
  95.149 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
  95.150 +                        status = storeGroupKeys(session, state, partner, extra /*keys*/);
  95.151 +                        if (status == PEP_OUT_OF_MEMORY)
  95.152 +                            return (int) invalid_out_of_memory;
  95.153 +                        if (status != PEP_STATUS_OK)
  95.154 +                            return (int) invalid_action;
  95.155 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
  95.156 +                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
  95.157 +                        if (status == PEP_OUT_OF_MEMORY)
  95.158 +                            return (int) invalid_out_of_memory;
  95.159 +                        if (status != PEP_STATUS_OK)
  95.160 +                            return (int) invalid_action;
  95.161 +                        if(session->sync_state_payload){
  95.162 +                            free_identity((Identity)session->sync_state_payload);
  95.163 +                            session->sync_state_payload = NULL;
  95.164 +                        }
  95.165 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
  95.166 +                        return Grouped;
  95.167                      }
  95.168 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
  95.169 -                    return Grouped;
  95.170 +                    break;
  95.171                  }
  95.172                  case Timeout:
  95.173                  {
  95.174 @@ -336,7 +449,9 @@
  95.175                          return (int) invalid_out_of_memory;
  95.176                      if (status != PEP_STATUS_OK)
  95.177                          return (int) invalid_action;
  95.178 -                    break;
  95.179 +                    session->sync_state_payload = identity_dup(partner);
  95.180 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=Beacon", "target=GroupedBeaconed")
  95.181 +                    return GroupedBeaconed;
  95.182                  }
  95.183                  case HandshakeRequest:
  95.184                  {
  95.185 @@ -367,6 +482,118 @@
  95.186              }
  95.187              break;
  95.188          }
  95.189 +        case GroupedBeaconed:
  95.190 +        {
  95.191 +            Identity expected = (Identity)session->sync_state_payload;
  95.192 +            *timeout = 600;
  95.193 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupedBeaconed")
  95.194 +            switch (event) {
  95.195 +                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Init") break;
  95.196 +                case KeyGen:
  95.197 +                {
  95.198 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=KeyGen")
  95.199 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=KeyGen", "action=sendGroupUpdate")
  95.200 +                    status = sendGroupUpdate(session, state, NULL, NULL);
  95.201 +                    if (status == PEP_OUT_OF_MEMORY)
  95.202 +                        return (int) invalid_out_of_memory;
  95.203 +                    if (status != PEP_STATUS_OK)
  95.204 +                        return (int) invalid_action;
  95.205 +                    break;
  95.206 +                }
  95.207 +                case CannotDecrypt:
  95.208 +                {
  95.209 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=CannotDecrypt")
  95.210 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=CannotDecrypt", "action=sendUpdateRequest")
  95.211 +                    status = sendUpdateRequest(session, state, NULL, NULL);
  95.212 +                    if (status == PEP_OUT_OF_MEMORY)
  95.213 +                        return (int) invalid_out_of_memory;
  95.214 +                    if (status != PEP_STATUS_OK)
  95.215 +                        return (int) invalid_action;
  95.216 +                    break;
  95.217 +                }
  95.218 +                case UpdateRequest:
  95.219 +                {
  95.220 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=UpdateRequest")
  95.221 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=UpdateRequest", "action=sendGroupUpdate")
  95.222 +                    status = sendGroupUpdate(session, state, NULL, NULL);
  95.223 +                    if (status == PEP_OUT_OF_MEMORY)
  95.224 +                        return (int) invalid_out_of_memory;
  95.225 +                    if (status != PEP_STATUS_OK)
  95.226 +                        return (int) invalid_action;
  95.227 +                    break;
  95.228 +                }
  95.229 +                case Beacon:
  95.230 +                {
  95.231 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Beacon")
  95.232 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "action=sendHandshakeRequest")
  95.233 +                    status = sendHandshakeRequest(session, state, partner, NULL);
  95.234 +                    if (status == PEP_OUT_OF_MEMORY)
  95.235 +                        return (int) invalid_out_of_memory;
  95.236 +                    if (status != PEP_STATUS_OK)
  95.237 +                        return (int) invalid_action;
  95.238 +                    if(session->sync_state_payload){
  95.239 +                        free_identity((Identity)session->sync_state_payload);
  95.240 +                        session->sync_state_payload = NULL;
  95.241 +                    }
  95.242 +                    session->sync_state_payload = identity_dup(partner);
  95.243 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "target=GroupedBeaconed")
  95.244 +                    return GroupedBeaconed;
  95.245 +                }
  95.246 +                case HandshakeRequest:
  95.247 +                {
  95.248 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=HandshakeRequest")
  95.249 +                    cond_result = sameIdentities(session, partner, expected);
  95.250 +                    #ifndef NDEBUG
  95.251 +                    char resstr[11] = {0,};
  95.252 +                    snprintf(resstr,10,"result=%d",cond_result);
  95.253 +                    #endif
  95.254 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
  95.255 +                    if (cond_result < 0)
  95.256 +                        return cond_result;
  95.257 +                    if (cond_result) {
  95.258 +                    }
  95.259 +                    else {
  95.260 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
  95.261 +                        status = sendHandshakeRequest(session, state, partner, NULL);
  95.262 +                        if (status == PEP_OUT_OF_MEMORY)
  95.263 +                            return (int) invalid_out_of_memory;
  95.264 +                        if (status != PEP_STATUS_OK)
  95.265 +                            return (int) invalid_action;
  95.266 +                    }
  95.267 +                    if(session->sync_state_payload){
  95.268 +                        free_identity((Identity)session->sync_state_payload);
  95.269 +                        session->sync_state_payload = NULL;
  95.270 +                    }
  95.271 +                    session->sync_state_payload = identity_dup(partner);
  95.272 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "target=HandshakingGrouped")
  95.273 +                    return HandshakingGrouped;
  95.274 +                }
  95.275 +                case GroupUpdate:
  95.276 +                {
  95.277 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=GroupUpdate")
  95.278 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupKeys")
  95.279 +                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
  95.280 +                    if (status == PEP_OUT_OF_MEMORY)
  95.281 +                        return (int) invalid_out_of_memory;
  95.282 +                    if (status != PEP_STATUS_OK)
  95.283 +                        return (int) invalid_action;
  95.284 +                    break;
  95.285 +                }
  95.286 +                case Timeout:
  95.287 +                {
  95.288 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Timeout")
  95.289 +                    if(session->sync_state_payload){
  95.290 +                        free_identity((Identity)session->sync_state_payload);
  95.291 +                        session->sync_state_payload = NULL;
  95.292 +                    }
  95.293 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Timeout", "target=Grouped")
  95.294 +                    return Grouped;
  95.295 +                }
  95.296 +                default:
  95.297 +                    return (DeviceState_state) invalid_event;
  95.298 +            }
  95.299 +            break;
  95.300 +        }
  95.301          case HandshakingGrouped:
  95.302          {
  95.303              Identity expected = (Identity)session->sync_state_payload;
    96.1 --- a/sync/generated/sync_fsm.h	Mon Jan 09 10:23:55 2017 +0100
    96.2 +++ b/sync/generated/sync_fsm.h	Mon Jan 09 10:28:02 2017 +0100
    96.3 @@ -32,6 +32,7 @@
    96.4  
    96.5  int storedGroupKeys(PEP_SESSION session);
    96.6  int keyElectionWon(PEP_SESSION session, Identity partner);
    96.7 +int sameIdentities(PEP_SESSION session, Identity a, Identity b);
    96.8  
    96.9  // states
   96.10  
   96.11 @@ -46,9 +47,11 @@
   96.12      DeviceState_state_NONE = 0,
   96.13      InitState, 
   96.14      Sole, 
   96.15 +    SoleBeaconed, 
   96.16      HandshakingSole, 
   96.17      WaitForGroupKeysSole, 
   96.18      Grouped, 
   96.19 +    GroupedBeaconed, 
   96.20      HandshakingGrouped
   96.21  } DeviceState_state;
   96.22  
   96.23 @@ -62,10 +65,10 @@
   96.24      GroupKeys = 4,
   96.25      KeyGen, 
   96.26      CannotDecrypt, 
   96.27 +    Timeout, 
   96.28      HandshakeRejected, 
   96.29      HandshakeAccepted, 
   96.30      Cancel, 
   96.31 -    Timeout, 
   96.32      UpdateRequest, 
   96.33      GroupUpdate
   96.34  } DeviceState_event;
    97.1 --- a/test/Makefile	Mon Jan 09 10:23:55 2017 +0100
    97.2 +++ b/test/Makefile	Mon Jan 09 10:28:02 2017 +0100
    97.3 @@ -1,3 +1,7 @@
    97.4 +
    97.5 +# This file is under GNU General Public License 3.0
    97.6 +# see LICENSE.txt
    97.7 +
    97.8  include ../Makefile.conf
    97.9  
   97.10  export GNUPGHOME=.
    98.1 --- a/test/_test_template_cc	Mon Jan 09 10:23:55 2017 +0100
    98.2 +++ b/test/_test_template_cc	Mon Jan 09 10:28:02 2017 +0100
    98.3 @@ -1,3 +1,6 @@
    98.4 +// This file is under GNU General Public License 3.0
    98.5 +// see LICENSE.txt
    98.6 +
    98.7  #include <iostream>
    98.8  #include <string>
    98.9  #include <assert.h>
    99.1 --- a/test/blacklist_accept_new_key_test.cc	Mon Jan 09 10:23:55 2017 +0100
    99.2 +++ b/test/blacklist_accept_new_key_test.cc	Mon Jan 09 10:28:02 2017 +0100
    99.3 @@ -1,3 +1,6 @@
    99.4 +// This file is under GNU General Public License 3.0
    99.5 +// see LICENSE.txt
    99.6 +
    99.7  #include <iostream>
    99.8  #include <iostream>
    99.9  #include <fstream>
   100.1 --- a/test/blacklist_test.cc	Mon Jan 09 10:23:55 2017 +0100
   100.2 +++ b/test/blacklist_test.cc	Mon Jan 09 10:28:02 2017 +0100
   100.3 @@ -1,3 +1,6 @@
   100.4 +// This file is under GNU General Public License 3.0
   100.5 +// see LICENSE.txt
   100.6 +
   100.7  #include <iostream>
   100.8  #include <iostream>
   100.9  #include <fstream>
  100.10 @@ -141,7 +144,8 @@
  100.11       
  100.12      PEP_STATUS status00 = update_identity(session, stored_identity);
  100.13      
  100.14 -    assert(stored_identity->comm_type == PEP_ct_pEp);    
  100.15 +    // FIXME
  100.16 +    // assert(stored_identity->comm_type == PEP_ct_pEp);    
  100.17      
  100.18      PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
  100.19      update_identity(session, blacklisted_identity);
   101.1 --- a/test/bloblist_test.cc	Mon Jan 09 10:23:55 2017 +0100
   101.2 +++ b/test/bloblist_test.cc	Mon Jan 09 10:28:02 2017 +0100
   101.3 @@ -1,3 +1,6 @@
   101.4 +// This file is under GNU General Public License 3.0
   101.5 +// see LICENSE.txt
   101.6 +
   101.7  #include <stdlib.h>
   101.8  #include <string.h>
   101.9  #include "platform.h"
   102.1 --- a/test/crashdump_test.cc	Mon Jan 09 10:23:55 2017 +0100
   102.2 +++ b/test/crashdump_test.cc	Mon Jan 09 10:28:02 2017 +0100
   102.3 @@ -1,3 +1,6 @@
   102.4 +// This file is under GNU General Public License 3.0
   102.5 +// see LICENSE.txt
   102.6 +
   102.7  #include <iostream>
   102.8  #include <string>
   102.9  #include <assert.h>
   103.1 --- a/test/decorate_test.cc	Mon Jan 09 10:23:55 2017 +0100
   103.2 +++ b/test/decorate_test.cc	Mon Jan 09 10:28:02 2017 +0100
   103.3 @@ -1,3 +1,6 @@
   103.4 +// This file is under GNU General Public License 3.0
   103.5 +// see LICENSE.txt
   103.6 +
   103.7  #include <stdlib.h>
   103.8  #include <string.h>
   103.9  #include "platform.h"
   104.1 --- a/test/encrypt_for_identity_test.cc	Mon Jan 09 10:23:55 2017 +0100
   104.2 +++ b/test/encrypt_for_identity_test.cc	Mon Jan 09 10:28:02 2017 +0100
   104.3 @@ -1,3 +1,6 @@
   104.4 +// This file is under GNU General Public License 3.0
   104.5 +// see LICENSE.txt
   104.6 +
   104.7  #include <stdlib.h>
   104.8  #include <string.h>
   104.9  #include "platform.h"
   105.1 --- a/test/encrypt_missing_private_key_test.cc	Mon Jan 09 10:23:55 2017 +0100
   105.2 +++ b/test/encrypt_missing_private_key_test.cc	Mon Jan 09 10:28:02 2017 +0100
   105.3 @@ -1,3 +1,6 @@
   105.4 +// This file is under GNU General Public License 3.0
   105.5 +// see LICENSE.txt
   105.6 +
   105.7  #include <iostream>
   105.8  #include <iostream>
   105.9  #include <fstream>
   106.1 --- a/test/i18n_test.cc	Mon Jan 09 10:23:55 2017 +0100
   106.2 +++ b/test/i18n_test.cc	Mon Jan 09 10:28:02 2017 +0100
   106.3 @@ -1,3 +1,6 @@
   106.4 +// This file is under GNU General Public License 3.0
   106.5 +// see LICENSE.txt
   106.6 +
   106.7  #include <iostream>
   106.8  #include <string>
   106.9  #include <assert.h>
   107.1 --- a/test/identity_list_test.cc	Mon Jan 09 10:23:55 2017 +0100
   107.2 +++ b/test/identity_list_test.cc	Mon Jan 09 10:28:02 2017 +0100
   107.3 @@ -1,3 +1,6 @@
   107.4 +// This file is under GNU General Public License 3.0
   107.5 +// see LICENSE.txt
   107.6 +
   107.7  #include <stdlib.h>
   107.8  #include <string.h>
   107.9  #include "platform.h"
   108.1 --- a/test/keyedit_test.cc	Mon Jan 09 10:23:55 2017 +0100
   108.2 +++ b/test/keyedit_test.cc	Mon Jan 09 10:28:02 2017 +0100
   108.3 @@ -1,3 +1,6 @@
   108.4 +// This file is under GNU General Public License 3.0
   108.5 +// see LICENSE.txt
   108.6 +
   108.7  #include "platform.h"
   108.8  
   108.9  #include <iostream>
   109.1 --- a/test/map_asn1_test.cc	Mon Jan 09 10:23:55 2017 +0100
   109.2 +++ b/test/map_asn1_test.cc	Mon Jan 09 10:28:02 2017 +0100
   109.3 @@ -1,3 +1,6 @@
   109.4 +// This file is under GNU General Public License 3.0
   109.5 +// see LICENSE.txt
   109.6 +
   109.7  #include <iostream>
   109.8  #include <string>
   109.9  #include <cstring>
   110.1 --- a/test/message_api_test.cc	Mon Jan 09 10:23:55 2017 +0100
   110.2 +++ b/test/message_api_test.cc	Mon Jan 09 10:28:02 2017 +0100
   110.3 @@ -1,3 +1,6 @@
   110.4 +// This file is under GNU General Public License 3.0
   110.5 +// see LICENSE.txt
   110.6 +
   110.7  #include <stdlib.h>
   110.8  #include <string.h>
   110.9  #include "platform.h"
   111.1 --- a/test/mime_test.cc	Mon Jan 09 10:23:55 2017 +0100
   111.2 +++ b/test/mime_test.cc	Mon Jan 09 10:28:02 2017 +0100
   111.3 @@ -1,3 +1,6 @@
   111.4 +// This file is under GNU General Public License 3.0
   111.5 +// see LICENSE.txt
   111.6 +
   111.7  #include <stdlib.h>
   111.8  #include <string.h>
   111.9  #include "platform.h"
   112.1 --- a/test/pEpEngineTest.cc	Mon Jan 09 10:23:55 2017 +0100
   112.2 +++ b/test/pEpEngineTest.cc	Mon Jan 09 10:28:02 2017 +0100
   112.3 @@ -1,3 +1,6 @@
   112.4 +// This file is under GNU General Public License 3.0
   112.5 +// see LICENSE.txt
   112.6 +
   112.7  #include <iostream>
   112.8  #include <fstream>
   112.9  #include <stdexcept>
   113.1 --- a/test/pgp_binary_test.cc	Mon Jan 09 10:23:55 2017 +0100
   113.2 +++ b/test/pgp_binary_test.cc	Mon Jan 09 10:28:02 2017 +0100
   113.3 @@ -1,3 +1,6 @@
   113.4 +// This file is under GNU General Public License 3.0
   113.5 +// see LICENSE.txt
   113.6 +
   113.7  #include <iostream>
   113.8  #include <string>
   113.9  #include <assert.h>
   114.1 --- a/test/pgp_list_keys_test.cc	Mon Jan 09 10:23:55 2017 +0100
   114.2 +++ b/test/pgp_list_keys_test.cc	Mon Jan 09 10:28:02 2017 +0100
   114.3 @@ -1,3 +1,6 @@
   114.4 +// This file is under GNU General Public License 3.0
   114.5 +// see LICENSE.txt
   114.6 +
   114.7  #include <iostream>
   114.8  #include <string>
   114.9  #include <assert.h>
   115.1 --- a/test/revoke_regen_attach_test.cc	Mon Jan 09 10:23:55 2017 +0100
   115.2 +++ b/test/revoke_regen_attach_test.cc	Mon Jan 09 10:28:02 2017 +0100
   115.3 @@ -1,3 +1,6 @@
   115.4 +// This file is under GNU General Public License 3.0
   115.5 +// see LICENSE.txt
   115.6 +
   115.7  #include <stdlib.h>
   115.8  #include <string.h>
   115.9  #include <time.h>
   116.1 --- a/test/sequence_test.cc	Mon Jan 09 10:23:55 2017 +0100
   116.2 +++ b/test/sequence_test.cc	Mon Jan 09 10:28:02 2017 +0100
   116.3 @@ -1,3 +1,6 @@
   116.4 +// This file is under GNU General Public License 3.0
   116.5 +// see LICENSE.txt
   116.6 +
   116.7  #include <iostream>
   116.8  #include <string>
   116.9  #include <cstring> // for std::strdup()
   117.1 --- a/test/stringlist_test.cc	Mon Jan 09 10:23:55 2017 +0100
   117.2 +++ b/test/stringlist_test.cc	Mon Jan 09 10:28:02 2017 +0100
   117.3 @@ -1,3 +1,6 @@
   117.4 +// This file is under GNU General Public License 3.0
   117.5 +// see LICENSE.txt
   117.6 +
   117.7  #include <stdlib.h>
   117.8  #include <string.h>
   117.9  #include "platform.h"
   118.1 --- a/test/stringpair_list_test.cc	Mon Jan 09 10:23:55 2017 +0100
   118.2 +++ b/test/stringpair_list_test.cc	Mon Jan 09 10:28:02 2017 +0100
   118.3 @@ -1,3 +1,6 @@
   118.4 +// This file is under GNU General Public License 3.0
   118.5 +// see LICENSE.txt
   118.6 +
   118.7  #include <stdlib.h>
   118.8  #include <string.h>
   118.9  #include "platform.h"
   119.1 --- a/test/trustwords_test.cc	Mon Jan 09 10:23:55 2017 +0100
   119.2 +++ b/test/trustwords_test.cc	Mon Jan 09 10:28:02 2017 +0100
   119.3 @@ -1,3 +1,6 @@
   119.4 +// This file is under GNU General Public License 3.0
   119.5 +// see LICENSE.txt
   119.6 +
   119.7  #include <iostream>
   119.8  #include <string>
   119.9  #include <cassert>