pull/62/head
David Lanzendörfer 2 years ago
commit a47996a60c

3
.gitignore vendored

@ -55,7 +55,10 @@ trustdb.gpg
.cache
__pycache__
*.pyc
test/gtest_parallel.py
test/python_tests/test?
test/python_tests/dummyhome?
test/python_tests/common
test/pEp_test_home
test/TestDriver
test/local

@ -25,3 +25,22 @@ debian10:tagged-build:
TAGGED_BUILD: "true"
rules:
- if: '$CI_COMMIT_TAG =~ /^Release_[0-9]+\.[0-9]+\.[0-9]+$/'
# CentOS
centos8:build:
extends: .make_in_docker
stage: build
variables:
CI_DISTRO_TARGET: "centos8"
rules:
- if: '$CI_COMMIT_TAG !~ /^Release_[0-9]+\.[0-9]+\.[0-9]+$/'
centos8:tagged-build:
extends: .make_in_docker
stage: build
variables:
CI_DISTRO_TARGET: "centos8"
TAGGED_BUILD: "true"
rules:
- if: '$CI_COMMIT_TAG =~ /^Release_[0-9]+\.[0-9]+\.[0-9]+$/'

@ -1,4 +1,4 @@
# 1st Party Dependencies
## Prefer git tags instead of SHA hashes when possible.
sequoia=365d00a08bec6a5a48d48a7c7893d78c27092b59
sequoia=openpgp/v1.3.0
yml2=2.7.0

@ -0,0 +1,18 @@
all: basic_api.h
YML2=$(wildcard *.yml2)
YSL2=$(wildcard *.ysl2)
%.xml: %.yml2
yml2proc -P $< -o $@
%.xsl: %.ysl2
yml2proc -DP $< -o $@
%.h: $(YML2) $(YSL2)
yml2proc -y gen_c_header.ysl2 pEp.yml2
.PHONY: clean
clean:
rm -f *.xml *.xsl *.h

@ -0,0 +1,439 @@
// p≡p Basic API
// Copyleft (c) 2019, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Nana Karlstetter and Volker Birk
type ISO639_1 is string size=2 > a-z;
type hexcode is string > a-f0-9;
type hash doc="32bit Key ID to SHA512 in hexcode"
is hexcode min=16, max=128;
type hash_list doc="sequence of fingerprints of keys"
is list< hash >;
type TID doc="UUID version 4 variant 1"
is binary size=16;
type binary_ref is weak< binary >;
enum content_disposition {
item attachment 0;
item inline 1;
item other -1 doc="must be affirmatively set";
}
struct blob {
field function=free binary_ref value;
field size_t size;
field string mime_type;
field string filename;
field content_disposition disposition;
}
type blob_list is list< blob >;
type identity_list is list< identity >;
type string_list is list< string >;
type string_pair is pair< string, string >;
type string_pair_list is list< string_pair >;
type any_ref is weak< any >;
enum cipher_suite {
item default 0;
item cv25519 1;
item p256 2;
item p384 3;
item p521 4;
item rsa2k 5;
item rsa3k 6;
item rsa4k 7;
item rsa8k 8;
}
enum comm_type {
hex unknown 0;
doc > range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
hex no_encryption 0x01;
hex no_encrypted_channel 0x02;
hex key_not_found 0x03;
hex key_expired 0x04;
hex key_revoked 0x05;
hex key_b0rken 0x06;
hex key_expired_but_confirmed 0x07
doc="NOT with confirmed bit. Just retaining info here in case of renewal.";
hex my_key_not_included 0x09;
hex security_by_obscurity 0x0a;
hex b0rken_crypto 0x0b;
hex key_too_short 0x0c;
hex compromised 0x0e doc="known compromised connection";
hex mistrusted 0x0f doc="known mistrusted key";
doc > range 0x10 to 0x3f: unconfirmed encryption
hex unconfirmed_encryption 0x10 doc="generic";
hex OpenPGP_weak_unconfirmed 0x11 doc="RSA 1024 is weak";
hex to_be_checked 0x20 doc="generic";
hex SMIME_unconfirmed 0x21 doc="encrypted with S/MIME";
hex CMS_unconfirmed 0x22;
hex strong_but_unconfirmed 0x30 doc="generic";
hex OpenPGP_unconfirmed 0x38 doc="key at least 2048 bit RSA, EC, or anything useful";
hex OTR_unconfirmed 0x3a doc="encrypted with OTR";
doc > range 0x40 to 0x7f: unconfirmed encryption and anonymization
hex unconfirmed_enc_anon 0x40 doc="generic";
hex pEp_unconfirmed 0x7f doc="encrypted with pEp";
hex confirmed 0x80 doc="this bit decides if trust is confirmed";
doc > range 0x81 to 0x8f: reserved
doc > range 0x90 to 0xbf: confirmed encryption
hex confirmed_encryption 0x90 doc="generic";
hex OpenPGP_weak 0x91 doc="RSA 1024 is weak (unused)";
hex to_be_checked_confirmed 0xa0 doc="generic";
hex SMIME 0xa1;
hex CMS 0xa2;
hex strong_encryption 0xb0 doc="generic";
hex OpenPGP 0xb8 doc="key at least 2048 bit RSA or EC";
hex OTR 0xba;
doc > range 0xc0 to 0xff: confirmed encryption and anonymization
hex confirmed_enc_anon 0xc0 doc="generic";
hex pEp 0xff;
} // enum comm_type
struct identity {
field string address doc="SMTP address or URI. String with address UTF-8 encoded";
field hash fpr doc="fingerprint of key being used as ID. String with fingerprint UTF-8 encoded";
field string user_id doc="ID for person or system in case of M2M";
doc ||
user_id MIGHT be set to "pEp_own_userId" (use PEP_OWN_USERID preprocessor define)
if this is own user's identity. But it is not REQUIRED to be.
||
field string username doc="descriptive string. String with user name UTF-8 encoded";
field comm_type comm_type doc="type of communication with this ID";
field ISO639_1 lang[3] doc="ISO 639-1 ALPHA-2, last byte is 0";
field bool me doc="if this is the local user herself/himself";
field unsigned major_ver doc="highest version of pEp message received, if any";
field unsigned minor_ver doc="highest version of pEp message received, if any";
flags {
flag not_for_sync 0x0001
doc="don't use this identity for Sync";
flag list 0x0002
doc="identity of list of persons";
doc | the second octet flags are calculated
flag devicegroup 0x0100
doc="identity of a device group member";
}
} // struct Identity
protocol session {
callback messageToSend doc="a message needs to be delivered by application"
{
// parms
provide struct_message msg doc="message struct with message to send";
// exceptions
throws any doc="error status";
}
method config_passive_mode doc="enable passive mode"
{
// parms
use bool enable doc="flag if enabled or disabled";
}
method config_unencrypted_subject doc="disable subject encryption"
{
// parms
use bool enable doc="flag if enabled or disabled";
}
method config_use_only_own_private_keys doc="enable passive mode"
{
// parms
use bool enable doc="flag if enabled or disabled";
}
method config_service_log doc="log more for service purposes"
{
// parms
use bool enable doc="flag if enabled or disabled";
}
method config_cipher_suite doc="cipher suite being used when encrypting"
{
// parms
use suite cipher_suite doc="cipher suite to use";
// exceptions
throws cannot_config
doc="""
configuration failed; falling back to default. the default
ciphersuite for a crypt tech implementation is implementation
defined.
""";
}
method log_event
doc="""
log a user defined event defined by UTF-8 encoded strings into
management log.
"""
{
// parms
use string title doc="string with event name";
use string entity doc="string with name of entity which is logging";
use string description doc="string with long description for event or NULL if omitted";
use string comment doc="string with user defined comment or NULL if omitted";
}
method get_default own_userid doc="get the user_id of the own user"
{
// parms
create string userid
doc="""
own user id (if it exists). userid will be NULL if not found; otherwise,
returned string belongs to the caller.
""";
// exceptions
throws cannot_find_identity doc="no own_user found in the DB";
throws unknown_error
doc="""
results were returned, but no ID found (no reason this
should ever occur).
""";
}
method mark_as_compromised doc="mark key in trust db as compromised"
{
// parms
use hash fpr doc="fingerprint of key to mark";
}
method mark_as_compromized doc="deprecated to fix misspelling. Please move to mark_as_compromised"
method import_key doc="import key from data"
{
// parms
use string key_data doc="key data, i.e. ASCII armored OpenPGP key";
use size_t size doc="amount of data to handle";
create identity_list private_keys
doc="""
list of private keys that have been imported. private_keys can
be left NULL, it is then ignored.
""";
}
method export_key doc="export ascii armored key"
{
// parms
use hash fpr doc="key id or fingerprint of key";
create string key_data
doc="""
ASCII armored OpenPGP key. The key_data goes to the ownership of the
caller. The caller is responsible to free() it (on Windoze use pEp_free())
""";
return size_t size doc="amount of data to handle";
// exceptions
throws out_of_memory doc="out of memory";
throws key_not_found doc="key not found";
}
method export_secret_key doc="export secret key ascii armored"
{
// parms
use hash fpr doc="fingerprint of key, at least 16 hex digits";
create string key_data
doc="""
ASCII armored OpenPGP secret key. The key_data goes to the ownership of the
caller. The caller is responsible to free() it (on Windoze use pEp_free()).
beware of leaking secret key data - overwrite it in memory after use!
""";
return size_t size doc="amount of data to handle";
// exceptions
throws out_of_memory doc="out of memory";
throws key_not_found doc="key not found";
throws cannot_export_key doc="cannot export secret key (i.e. it's on an HKS)";
}
method export_secrect_key doc="deprecated misspelled function. Please replace with export_secret_key"
method get_crashdump_log doc="get the last log messages out"
{
// parms
use int maxlines doc="maximum number of lines (0 for default)";
create string logdata
doc="""
logdata as string in double quoted CSV format
column1 is title
column2 is entity
column3 is description
column4 is comment
""";
}
method get_languagelist doc="get the list of languages"
{
//parms
create string language
doc="""
languages as string in double quoted CSV format
column 1 is the ISO 639-1 language code
column 2 is the name of the language
""";
}
method get_phrase doc="get phrase in a dedicated language through i18n"
{
// parms
use string lang doc="string with ISO 639-1 language code";
use int phrase_id doc="id of phrase in i18n";
create string phrase doc="phrase as UTF-8 string";
}
method get_engine_version
doc="""
returns the current version of pEpEngine (this is different
from the pEp protocol version!).
"""
{
// parms doc="none"
// exceptions
throws any doc="string to the engine version string constant";
}
method is_pEp_user
doc="""
returns true if the USER corresponding to this identity has been listed
in the *person* table as a pEp user.
This *does not check comm_type*.
"""
{
// parms
use identity ident
doc="""
identity containing the user_id to check (this is the only part of
the struct we require to be set).
""";
return bool is_pEp
doc="""
boolean pointer - will return true or false by reference with respect
to whether or not user is a known pEp user
""";
// exceptions
throws illegal_value doc="if no user_id in input";
throws cannot_find_person doc="if user_id doesn't exist";
}
method per_user_directory doc="returns the directory for pEp management db"
{
// exceptions
throws any doc="path to actual per user directory or NULL on failure";
}
method per_machine_directory doc="returns the directory for pEp system db"
{
// exceptions
throws any doc="path to actual per user directory or NULL on failure";
}
}

@ -0,0 +1,2 @@
version = "version 2.0"
copyleft = "Copyleft (c) 2019-2020, pEp foundation"

@ -0,0 +1,107 @@
// p≡p API header generator
// Copyleft (c) 2019-2020, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Volker Birk
include yslt.yml2
include ./config.yml2
tstylesheet {
include ./to_c.ysl2
include standardlib.ysl2
const "version" **version;
const "copyleft" **copyleft;
template "/package"
apply "package", 0;
template "package" document "{@name}_{@type}.h", "text" {
||
// «../@name» «$version»
// «@name»_«@type».h
// «$copyleft»
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <pEp/basic_types.h>
||
apply "doc|type|enum|struct", 0;
||
#ifdef __cplusplus
} // extern "C"
#endif
||
}
template "type" {
apply "@doc", 0;
| typedef «func:basetype(@name)» «@name»;
|
}
template "struct" {
||
typedef struct _«func:name()» {
||
apply "field|internal|doc";
apply "field[@function='free']", mode=free;
||
} «func:name()»;
||
}
template "field|internal" {
apply "@doc", 0;
| «func:c-type(@type)» «@name»;
}
template "field", mode=free
||
// free function for «@name»
void (*release_«@name»)(«func:c-type(@type)» «@name»);
||
template "enum" {
||
typedef enum _«func:name()» {
||
apply "item|doc";
||
} «func:name()»;
||
}
template "doc|@doc" {
> \n
for "str:split(., '\n')"
| // «.»
}
template "item" {
apply "@doc", 0;
choose {
when "@output='hex'"
| «func:name()»`if "text()" { " = 0x" value "yml:dec2hex(., 2)" }``if "position()!=last()" > ,`
otherwise
| «func:name()»`if "text()" { " = " value "." }``if "position()!=last()" > ,`
}
}
}

@ -0,0 +1,226 @@
// p≡p Keymanagement API version 0.1
// Copyleft (c) 2019, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Nana Karlstetter and Volker Birk
protocol session {
method update_identity doc="update identity information"
{
// parms
lend identity identity
doc="""
identity information of communication partner
(identity->fpr is OUT ONLY), and at least
.address must be set.
If .username is set, it will be used to set or patch
the username record for this identity.
at least identity->address must be a non-empty UTF-8 string as input
update_identity() never writes flags; use set_identity_flags() for
writing
this function NEVER reads the incoming fpr, only writes to it.
this function will fail if called on an identity which, with its input
values, *explicitly* indicates it is an own identity (i.e. .me is set
to true on input, or a user_id is given AND it is a known own user_id).
however, it can RETURN an own identity if this is not indicated a
priori, and in fact will do so with prejudice when not faced with a
matching default (i.e. it is forced to search by address only).
if the identity is known to be an own identity (or the caller wishes
to make it one), call myself() on the identity instead.
FIXME: is this next point accurate?
if this function returns PEP_ct_unknown or PEP_ct_key_expired in
identity->comm_type, the caller must insert the identity into the
asynchronous management implementation, so retrieve_next_identity()
will return this identity later
END FIXME
""";
// exceptions
throws illegal_value
doc="""
if called with illegal inputs, including an identity
with .me set or with an own user_id specified in the
*input* (see caveats)
""";
throws key_unsuitable
doc="""
if a default key was found for this identity, no
other acceptable keys were found; if this is returned,
the reason for rejecting the first default key found
may be found in the comm_type
""";
}
method myself doc="ensures that an own identity is complete"
{
// parms
lend identity ident
doc="""
identity of local user
both .address and .user_id must be set.
if .fpr is set, an attempt will be made to make
that the default key for this identity after key validation
if .fpr is not set, key retrieval is performed.
If .username is set, it will be used to set or patch
the username record for this identity.
If an fpr was entered and is not a valid key, the reason for failure
is immediately returned in the status and, possibly, identity->comm_type
If a default own user_id exists in the database, an alias will
be created for the default for the input user_id. The ENGINE'S default
user_id is always returned in the .user_id field
myself() NEVER elects keys from the keyring; it will only choose keys
which have been set up explicitly via myself(), or which were imported
during a first time DB setup from an OpenPGP keyring (compatibility only)
this function generates a keypair on demand; because it's synchronous
it can need a decent amount of time to return
if you need to do this asynchronous, you need to return an identity
with retrieve_next_identity() where identity.me is true.
""";
}
method key_mistrusted doc="mark key as being compromised"
{
//parms
use identity ident
doc="""
person and key which was compromised
ident is INPUT ONLY. If you want updated trust on the identity, you'll have
to call update_identity or myself respectively after this.
N.B. If you are calling this on a key that is the identity or user default,
it will be removed as the default key for ANY identity and user for which
it is the default. Please keep in mind that the undo in undo_last_mistrust
will only undo the current identity's / it's user's default, not any
other identities which may be impacted (this will not affect most use
cases)
""";
}
method trust_personal_key doc="mark a key as trusted for a user"
{
// parms
use identity ident
doc="""
person and key to trust in - this must not be an own_identity in which
the .me flag is set or the user_id is an own user_id. The fields user_id,
address and fpr must be supplied own identities will result in a return
of illegal_value.
For non-own users, this will 1) set the trust bit on its comm type in the DB,
2) set this key as the identity default if the current identity default
is not trusted, and 3) set this key as the user default if the current user
default is not trusted.
""";
}
method trust_own_key
doc="""
mark a key as trusted for self, generally used when we need to trust
a public key associated with outselves for issues like manual key import.
"""
{
// parms
use identity ident
doc="""
own ident containing fpr to trust.
If this is a public key only, keep in mind that if the private part of the
keypair is later added, it will not undergo separate trust evaluation. This
is fine - even desired - as long as the semantics of this function are
understood as both trusting the key and verifying it as an own key. This will
NEVER cause replacement of or setting of a default *alone*. However, if a
private key is ever associated with this fpr, please keep in mind that trusting
it here makes it an eligible key for selection for encryption later. So use
this function on purpose with an understanding of what you're doing!
""";
}
method key_reset_trust
doc="""
reset trust bit or explicitly mistrusted status for an identity and its
accompanying key/user_id pair.
"""
{
// parms
use ientity ident
doc="""
identity for person and key whose trust status is to be reset.
Ident is INPUT ONLY. If you want updated trust on the identity, you'll have
to call update_identity or myself respectively after this.
N.B. If you are calling this on a key that is the identity or user default,
it will be removed as the default key for the identity and user (but is still
available for key election, it is just not the cached default anymore).
""";
}
method own_key_is_listed doc="returns true id key is listed as own key"
{
// parms
use hash fpr doc="fingerprint of key to test";
return bool listed doc="flags if key is own";
}
method own_identities_retrieve doc="retrieve all own identities"
{
// parms
create identity_list own_identities
doc="""
list of own identities.
The ownership of the copy of own_identities goes to the caller.
""";
}
method own_keys_retrieve doc="retrieve all flagged keypair fingerprints/private keypair fingerprints"
{
// parms
create hashlist keylist
doc="""
list of fingerprints. This function does not return keys without
a private key part.
""";
}
method set_own_key doc="mark a key as own key"
{
// parms
lend identity me
doc="""
own identity this key is used for. The key has to be in the key ring already.
me->address, me->user_id and me->username must be set to valid data.
myself is called by set_own_key without key generation.
me->flags are ignored
me->address must not be an alias
me->fpr will be ignored and replaced by fpr, but caller MUST surrender ownership of the
me->fpr reference, because it may be freed and replaced within the myself call. caller
owns me->fpr memory again upon return.
""";
use hash fpr doc="fingerprint of the key to mark as own key";
}
}

@ -0,0 +1,45 @@
/**
* <!-- encrypt_message() -->
*
* @brief Encrypt message in memory
*
* @param[in] session session handle
* @param[in,out] src message to encrypt - usually in-only, but can be
* in-out for unencrypted messages; in that case,
* we may attach the key and decorate the message
* @param[in] extra extra keys for encryption
* @param[out] dst pointer to new encrypted message or NULL if no
* encryption could take place
* @param[in] enc_format The desired format this message should be encrypted with
* @param[in] flags flags to set special encryption features
*
* @retval PEP_STATUS_OK on success
* @retval PEP_KEY_HAS_AMBIG_NAME at least one of the receipient keys has
* an ambiguous name
* @retval PEP_UNENCRYPTED on demand or no recipients with usable
* key, is left unencrypted, and key is
* attached to it
* @retval PEP_ILLEGAL_VALUE illegal parameter values
* @retval PEP_OUT_OF_MEMORY out of memory
* @retval any other value on error
*
* @warning the ownership of src remains with the caller
* the ownership of dst goes to the caller
*
* enc_format PEP_enc_inline_EA:
* internal format of the encrypted attachments is changing, see
* https://dev.pep.foundation/Engine/ElevatedAttachments
*
* Only use this for transports without support for attachments
* when attached data must be sent inline
*
*/
DYNAMIC_API PEP_STATUS encrypt_message(
PEP_SESSION session,
message *src,
stringlist_t *extra,
message **dst,
PEP_enc_format enc_format,
PEP_encrypt_flags_t flags
);

@ -0,0 +1,569 @@
// p≡p Message API
// Copyleft (c) 2019-2020, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Volker Birk and Nana Karlstetter
enum text_format {
hex plain 0;
hex html 1;
hex other 0xff;
}
enum direction {
item incoming 0;
item outgoing 1;
}
enum enc_format {
item none 0 doc='message is not encrypted';
item pieces 1 doc='inline PGP + PGP extensions';
item S_MIME 2 doc='RFC5751';
item PGP_MIME 3 doc='RFC3156';
item PEP 4 doc='pEp encryption format';
item PGP_MIME_Outlook1 5 doc='Message B0rken by Outlook type 1';
}
enum rating {
item undefined 0 doc="no rating available";
doc "no color";
item cannot_decrypt 1;
item have_no_key 2;
item unencrypted 3;
// 4 is reserved
item unreliable 5;
doc "yellow";
item reliable 6;
doc "green";
item trusted 7;
item trusted_and_anonymized 8;
item fully_anonymous 9;
doc "red";
item mistrust -1;
item b0rken -2;
item under_attack -3;
}
enum color {
item no_color 0;
item yellow 1;
item green 2;
item red -1;
}
struct message {
field direction dir;
field string id doc='string of message ID';
field string shortmsg doc='string of short message';
field string longmsg doc='string of long message (plain)';
field string longmsg_formatted doc='string of long message (formatted)';
field blob_list attachments doc='blobs with attachements';
field binary_ref rawmsg_ref doc='reference to raw message data';
field size_t rawmsg_size doc='size of raw message data';
field timestamp sent doc='when the message is sent';
field timestamp recv doc='when the message is received';
field identity from doc='whom the message is from';
field identity_list to doc='whom the message is to';
field identity recv_by doc='via which identity the message is received';
field identity_list cc doc='whom a CC is being sent';
field identity_list bcc doc='whom a BCC is being sent';
field identity_list reply_to doc='where a reply should go to';
field string_list in_reply_to doc='list of strings with MessageIDs of refering messages';
field any_ref refering_msg_ref doc='reference to refering message';
field string_list references doc='list of strings with references';
field string_list refered_by doc='list of references to messages being refered';
field string_list keywords doc='list of strings with keywords';
field string comments doc='string with comments';
field string_pair_list opt_fields doc='optional fields';
field enc_format format doc='format of encrypted data';
new (msg_direction dir);
}
protocol session {
method encrypt_message
doc="""
encrypt message in memory. enc_format PEP_enc_inline_EA:
internal format of the encrypted attachments is changing, see
https://dev.pep.foundation/Engine/ElevatedAttachments
Only use this for transports without support for attachments
when attached data must be sent inline
"""
{
// parms
lend message src
doc="""
message to encrypt - usually in-only, but can be in-out for
unencrypted messages; in that case, we may attach the key and
decorate the message
""";
use hash_list extra doc="extra keys for encryption";
create message dst
doc="""
pointer to new encrypted message or #NV if no encryption could
take place
""";
use enc_format format doc="The desired format this message should be encrypted with";
// flags
flags {
flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
flag force_encryption 0x1;
flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
flag force_no_attached_key 0x4;
flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
flag key_reset_only 0x20
doc="""This flag is used to let internal functions know that an encryption call is being
used as part of a reencryption operation
""";
flag encrypt_reencrypt 0x40;
}
// exceptions
throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
throws unencrypted
doc="""
on demand or no recipients with usable key, is left unencrypted,
and key is attached to it
""";
}
method encrypt_message_and_add_priv_key
doc="""
encrypt message in memory, adding an encrypted private key (encrypted separately
and sent within the inner message)
"""
{
// parms
use message src doc="message to encrypt";
create message dst
doc="pointer to new encrypted message or empty if no encryption could take place";
use hash to_fpr
doc="fingerprint of the recipient key to which the private key should be encrypted";
use enc_format format doc="encrypted format";
// flags
flags {
flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
flag force_encryption 0x1;
flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
flag force_no_attached_key 0x4;
flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
flag key_reset_only 0x20;
}
// exceptions
throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
throws unencrypted
doc="""
on demand or no recipients with usable key, is left unencrypted,
and key is attached to it
""";
}
method encrypt_message_for_self
doc="""
encrypt message in memory for user's identity only,
ignoring recipients and other identities from the message
"""
{
// parms
use identity target_id
doc="""
self identity this message should be encrypted for. Message is NOT encrypted for
identities other than the target_id (and then, only if the target_id refers to self!).
""";
use message src doc="message to encrypt";
use hash_list extra doc="extra keys for encryption";
create message dst doc="pointer to new encrypted message or empty on failure";
use enc_format format doc="encrypted format";
// flags
flags {
flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
flag force_encryption 0x1;
flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
flag force_no_attached_key 0x4;
flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
flag key_reset_only 0x20;
}
doc | (FIXME: The exceptions may not be correct or complete)
throws key_not_found doc="at least one of the receipient keys could not be found";
throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
throws get_key_failed doc="cannot retrieve key";
}
method decrypt_message doc="decrypt message in memory"
{
// parms
lend message src
doc="""
message to decrypt.
The ownership of src remains with the caller - however, the contents
might be modified (strings freed and allocated anew or set to empty,
etc) intentionally; when this happens, decrypt_flag_src_modified is set.
""";
create message dst doc="pointer to new decrypted message or empty on failure";
lend hash_list keylist
doc="""
in: stringlist with additional keyids for reencryption if needed
(will be freed and replaced with output keylist)
out: stringlist with keyids used for signing and encryption. first
first key is signer, additional keys are the ones it was encrypted
to. Only signer and whichever of the user's keys was used are reliable.
The ownership of keylist goes to the caller.
If src is unencrypted this function returns unencrypted and sets dst to empty.
""";
return rating msg_rating doc="rating for the message";
// flags
flags {
flag decrypt_flag_own_private_key 0x1
doc="""
private key was imported for one of our addresses (NOT trusted
or set to be used - handshake/trust is required for that)
""";
flag decrypt_flag_consume 0x2 doc='used by sync';
flag decrypt_flag_ignore 0x4 doc='used by sync';
flag decrypt_flag_src_modified 0x8
doc="""
indicates that the src object has been modified. At the moment,
this is always as a direct result of the behaviour driven
by the input flags. This flag is the ONLY value that should be
relied upon to see if such changes have taken place.
""";
flag decrypt_flag_untrusted_server 0x100
doc="""
input flag. Used to signal that decrypt function should engage in behaviour
specified for when the server storing the source is untrusted.
""";
flag decrypt_flag_dont_trigger_sync 0x200;
}
// exceptions
throws decrypted doc="if message decrypted but not verified";
throws cannot_reencrypt
doc="""
if message was decrypted (and possibly verified) but a reencryption
operation is expected by the caller and failed.
""";
throws unencrypted
doc="""
if src is unencrypted this function returns unencrypted and sets
dst to empty.
""";
throws any doc="all error status values allowed";
}
method own_message_private_key_details
doc="""
details on own key in own message. Note: In order to obtain details about key
to be possibly imported as a replacement of key currently used as own identity,
application passes message that have been previously flagged by decrypt_message()
as own message containing own key to this function.
"""
{
// parms
use message msg
doc="""
message to decrypt. msg MUST be encrypted so that this function
can check own signature.
""";
create identity ident doc="identity containing uid, address and fpr of key";
// exceptions
throws any doc="error status";
}
method outgoing_message_rating doc="get rating for an outgoing message"
{
// parms
use message msg
doc="""
message to get the rating for. From must point to a valid pEp_identity.
Dir must be dir_outgoing.
""";
return rating msg_rating doc="rating for the message";
// exceptions
throws any doc="error status";
}
method outgoing_message_rating_preview doc="get rating preview"
{
// parms
use message msg
doc="""
message to get the rating for. From must point to a valid pEp_identity.
Dir must be dir_outgoing.
""";
return rating msg_rating doc="rating preview for the message";
// exceptions
throws any doc="error status";
}
method identity_rating doc="get rating for a single identity"
{
// parms
use identity ident doc="identity to get the rating for";
return rating identity_rating doc="rating for the identity";
// exceptions
throws any doc="error status";
}
method get_trustwords doc="get full trustwords string for a *pair* of identities"
{
// parms
use identity id1 doc="identity of first party in communication - fpr can't be empty";
use identity id2 doc="identity of second party in communication - fpr can't be empty";
use ISO639_1 lang doc="string with ISO 639-1 language code";
create string words
doc="""
string with all trustwords, separated
by a blank each. Empty if language is not supported or trustword
wordlist is damaged or unavailable.
The word pointer goes to the ownership of the caller.
The caller is responsible to free() it (on Windoze use pEp_free())
""";
use bool full
doc="""
if true, generate ALL trustwords for these identities.
else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
subset in next version)
""";
// exceptions
throws out_of_memory doc="out of memory";
throws trustword_not_found doc="at least one trustword not found";
}
method get_message_trustwords doc="get full trustwords string for message sender and reciever identities"
{
// parms
use message msg doc="message to get sender identity from";
use hash_list keylist doc="empty if message to be decrypted, keylist returned by decrypt_message() otherwise.";
use identity received_by doc="identity for account receiving message can't be empty";
use ISO639_1 lang doc="string with ISO 639-1 language code";
create string words
doc="""
string with all trustwords, separated by a blank each.
Empty if language is not supported or trustword wordlist is damaged or unavailable.
""";
use bool full
doc="""
if true, generate ALL trustwords for these identities.
else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
subset in next version)
""";
// exceptions
throws out_of_memory doc="out of memory";
throws trustword_not_found doc="at least one trustword not found";
throws like decrypt_message doc="error status of decrypt_message() if decryption fails";
}
method get_trustwords_for_fprs doc="get full trustwords string for a pair of fingerprints"
{
// parms
use string fpr1 doc="fingerprint 1";
use string fpr2 doc="fingerprint 2";
use ISO639_1 lang doc="string with ISO 639-1 language code";
create string words
doc="""
pointer to string with all trustwords UTF-8 encoded, separated by a blank each.
NULL if language is not supported or trustword wordlist is damaged or unavailable.
The caller is responsible to free() it (on Windoze use pEp_free()).
""";
return size_t wsize doc="length of full trustwords string";
use bool full
doc="""
if true, generate ALL trustwords for these identities. Else, generate a fixed-size
subset. (TODO: fixed-minimum-entropy subset in next version)
""";
// exceptions
throws out_of_memory doc="out of memory";
throws trustword_not_found doc="at least one trustword not found";
}
method re_evaluate_message_rating doc="re-evaluate already decrypted message rating"
{
// parms
use message msg doc="message to get the rating for. msg->from must point to a valid pEp_identity";
use hash_list x_keylist doc="decrypted message recipients keys fpr";
use rating x_enc_status doc="original rating for the decrypted message";
return rating msg_rating doc="rating for the message";
// exceptions
throws illegal_value
doc="""
if decrypted message doesn't contain X-EncStatus optional field and
x_enc_status is pEp_rating_udefined or if decrypted message doesn't
contain X-Keylist optional field and x_keylist is empty.
""";
throws out_of_memory doc="if not enough memory could be allocated";
}
method get_key_rating_for_user doc="get the rating of a certain key for a certain user"
{
// parms
use string user_id doc="string with user ID";
use string fpr doc="string with fingerprint";
return rating key_rating doc="rating of key for this user";
// exceptions
throws record_not_found doc="if no trust record for user_id and fpr can be found";
}
method rating_from_comm_type doc="get the rating for a comm type"
{
// parms
use comm_type ct doc="the comm type to deliver the rating for";
// exceptions
throws any doc="rating value for comm type ct";
}
}
func color_from_rating doc="calculate color from rating"
{
// parms
use color_from_rating rating doc="color representing that rating";
// return value
return color rating_color doc="color representing that rating";
}
func get_binary_path doc="retrieve path of cryptotech binary if available"
{
//parms
use cryptotech tech doc="cryptotech to get the binary for";
use string path
doc="""
path to cryptotech binary or empty if not available. **path is owned by
the library, do not change it!
""";
}

@ -0,0 +1,71 @@
// p≡p API Y language
// Copyleft (c) 2019-2020, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Volker Birk and Nana Karlstetter
decl package @name;
decl api @name (type=api) alias package;
decl type @name;
decl extends @type;
decl enum @name;
decl item @name;
decl struct @name;
decl field @type @name; // optional: function=free for a free function
decl internal < field >; // internal field, p≡p engine only
decl hex is item (output=hex);
decl flag @name;
decl protocol @name;
decl method @name;
decl construct, new is construct;
// readonly in parm, ownership remains with caller
decl use @type @name (mode=use) alias parm;
// inout parm, ownership remains with caller
decl supply @type @name (mode=supply) alias parm;
// factory delivers this, ownership goes to caller
decl create @type @name (mode=create) alias parm;
// in parm, ownership goes to callee
decl provide @type @name (mode=provide) alias parm;
// out parm, ownership goes to callee
decl return @type @name (mode=return) alias parm;
decl throws @except;
decl caveat(mode=caveat) alias doc;
// base types
// string text
// p≡p engine uses UTF-8 strings which are NFC normalized.
// Cf. https //dev.pep.foundation/Engine/Basic%20Concepts%20of%20the%20pEp%20Engine
// binary binary data
// int signed integer number
// unsigned unsigned integer number
// size_t size in memory
// bool true or false
// timestamp point of time
// any any type
// collections
// list one or more elements, which have a sequence
// set one or more elements, which do not have a sequence
// pair two elements in sequence
package pEp {
api transport include ./transport_api.yml2
api message include ./message_api.yml2
api keymanagement include ./keymanagement_api.yml2
api basic include ./basic_api.yml2
}

@ -0,0 +1,105 @@
// p≡p API C data types mapping
// Copyleft (c) 2019, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Volker Birk
template "*", mode=name {
param "abbr", "false()";
if ".!=/*" {
apply "..", 0, mode=name;
if "@name!='basic' and @name != string(../@name)"
> _
}
if "@name!='basic' and @name != string(../@name)"
> «@name»
}
function "name" {
param "abbr", "false()";
apply ".", mode=name with "abbr", "$abbr";
}
def "func:name" {
param "abbr", "false()";
result call "name" with "abbr", "$abbr";
}
def "func:basetype" {
param "type";
const "definition", "//type[@name=$type]";
choose {
when "$definition/extends"
result "func:c-type($definition/extends/@type)";
otherwise
result "func:c-type($type)";
}
}
def "func:c-type" {
param "dsltype";
choose {
// base types
when "$dsltype = 'string'"
result > char *
when "$dsltype = 'binary'"
result > char *
when "$dsltype = 'int'"
result > int
when "$dsltype = 'unsigned'"
result > unsigned int
when "$dsltype = 'size_t'"
result > size_t
when "$dsltype = 'bool'"
result > bool
when "$dsltype = 'timestamp'"
result > timestamp
when "$dsltype = 'any'"
result > void *
// basic type definitions
when "/package/package[@name='basic']/type[@name=$dsltype]"
result > «$dsltype»
when "/package/package[@name='basic']/struct[@name=$dsltype]"
result > pEp_«$dsltype»
when "/package/package[@name='basic']/enum[@name=$dsltype]"
result > pEp_«$dsltype»
// definitions in local module
when "../../type[@name=$dsltype]"
for "../../type[@name=$dsltype]"
result > «$dsltype»
when "../../struct[@name=$dsltype]"
for "../../struct[@name=$dsltype]"
result > «func:name()»
when "../../enum[@name=$dsltype]"
for "../../enum[@name=$dsltype]"
result > «func:name()»
// definitions in other module
when "/package/package/type[@name=$dsltype]"
for "/package/package/type[@name=$dsltype]" {
warning value "concat('WARNING: type ', $dsltype, ' found in non-local module')";
result > «$dsltype»
}
when "/package/package/struct[@name=$dsltype]"
for "/package/package/struct[@name=$dsltype]" {
warning value "concat('WARNING: type ', $dsltype, ' found in non-local module')";
result > «func:name()»
}
when "/package/package/enum[@name=$dsltype]"
for "/package/package/enum[@name=$dsltype]" {
warning value "concat('WARNING: type ', $dsltype, ' found in non-local module')";
result > «func:name()»
}
// other
otherwise
error value "concat('type “', $dsltype, '” not found')";
}
}

@ -0,0 +1,9 @@
// p≡p Transport API
// Copyleft (c) 2019, p≡p foundation
// this file is under GNU General Public License 3.0
// see LICENSE.txt
// written by Volker Birk

@ -7,6 +7,15 @@ ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
CPPFLAGS+=$(CPPFLAGS_GENERATED)
ASN1C_INC+= -I.
ASN1C_OPTIONS = -fincludes-quoted -fcompound-names -pdu=auto
DISTRIBUTION = distribution keyreset managedgroup exploration
SYNC = sync keysync trustsync groupsync
STORAGE = storage messagestorage
DISTRIBUTION_FILES = $(addsuffix .asn1, $(DISTRIBUTION))
SYNC_FILES = $(addsuffix .asn1, $(SYNC))
STORAGE_FILES = $(addsuffix .asn1, $(STORAGE))
.PHONY: all clean install uninstall
@ -19,23 +28,24 @@ libasn1.a: $(ALL_OBJECTS)
%.o: %.c %.h
$(CC) $(CFLAGS) $(CPPFLAGS) $(OPTIMIZE) $(ASN1C_INC) -c $< -o $@
Sync.c: sync.asn1 keysync.asn1 trustsync.asn1 groupsync.asn1 pEp.asn1 distribution.asn1
$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keysync.asn1 trustsync.asn1 groupsync.asn1 distribution.asn1 keyreset.asn1 managedgroup.asn1 exploration.asn1 $<
Sync.c: $(SYNC_FILES) $(DISTRIBUTION_FILES) pEp.asn1
$(ASN1C) -gen-PER $(ASN1C_OPTIONS) $+
rm -f converter-sample.c
touch Sync.c
Distribution.c: distribution.asn1 keyreset.asn1 managedgroup.asn1 exploration.asn1 pEp.asn1
$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keyreset.asn1 managedgroup.asn1 exploration.asn1 $<
Distribution.c: $(DISTRIBUTION_FILES) pEp.asn1
$(ASN1C) -gen-PER $(ASN1C_OPTIONS) $+
rm -f converter-sample.c
touch Distribution.c
Storage.c: storage.asn1 messagestorage.asn1 pEp.asn1
$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 messagestorage.asn1 $<
Storage.c: $(STORAGE_FILES) pEp.asn1
$(ASN1C) -gen-PER $(ASN1C_OPTIONS) $+
rm -f converter-sample.c
touch Storage.c
clean:
rm -f *.a *.o *.c *.h *.sample sync.asn1 keysync.asn1 trustsync.asn1 groupsync.asn1 distribution.asn1 keyreset.asn1 managedgroup.asn1 exploration.asn1 storage.asn1 messagestorage.asn1
rm -f *.a *.o *.c *.h *.sample \
$(SYNC_FILES) $(DISTRIBUTION_FILES) $(STORAGE_FILES)
install:
@ -43,3 +53,8 @@ uninstall:
tags: $(wildcard *.c) $(wildcard *.h)
ctags --sort=yes *.c *.h
# ensure generated files are here - useful after "make clean"
$(SYNC_FILES) $(DISTRIBUTION_FILES) $(STORAGE_FILES):
rm -f ../codegen/.copy
$(MAKE) -C ../codegen .copy

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1500C9AE264BE75F001FD417 /* sqlite3.c in Sources */ = {isa = PBXBuildFile; fileRef = 151672CE262F38D900E99CE5 /* sqlite3.c */; };
151672D0262F38D900E99CE5 /* sqlite3.c in Sources */ = {isa = PBXBuildFile; fileRef = 151672CE262F38D900E99CE5 /* sqlite3.c */; };
151672D1262F38D900E99CE5 /* sqlite3.h in Headers */ = {isa = PBXBuildFile; fileRef = 151672CF262F38D900E99CE5 /* sqlite3.h */; };
151672D4262F38E500E99CE5 /* sqlite3.h in Headers */ = {isa = PBXBuildFile; fileRef = 151672CF262F38D900E99CE5 /* sqlite3.h */; };
@ -247,7 +248,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "CUSTOM_BUILD_DIR=\"${PROJECT_DIR}/build\"\nCUSTOM_INCLUDE_DIR=\"${CUSTOM_BUILD_DIR}/include\"\nmkdir -p ${CUSTOM_INCLUDE_DIR}\ncp -R \"${TARGET_BUILD_DIR}\"/usr/local/include/sqlite3.h ${CUSTOM_INCLUDE_DIR}\ncp \"${TARGET_BUILD_DIR}/libPEPSQLITE3_macOS.a\" ${CUSTOM_BUILD_DIR}\n";
shellScript = "CUSTOM_BUILD_DIR=\"${PROJECT_DIR}/build\"\nCUSTOM_INCLUDE_DIR=\"${CUSTOM_BUILD_DIR}/include\"\nmkdir -p ${CUSTOM_INCLUDE_DIR}\ncp \"${PROJECT_DIR}\"/../../../../sqlite/sqlite3.h ${CUSTOM_INCLUDE_DIR}\ncp \"${TARGET_BUILD_DIR}/libPEPSQLITE3_macOS.a\" ${CUSTOM_BUILD_DIR}\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
@ -267,6 +268,7 @@
buildActionMask = 2147483647;
files = (
15A32658261205E7009D07EB /* PEPSQLITE3_macOS.m in Sources */,
1500C9AE264BE75F001FD417 /* sqlite3.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;