merged in default

doxygen-key-id
commit 8e261315f9

@ -1,7 +1,7 @@
-- This file is under BSD License 2.0
-- Sync protocol for p≡p
-- Copyright (c) 2016, 2017 p≡p foundation
-- Copyright (c) 2016, 2010 p≡p foundation
-- Written by Volker Birk
@ -12,7 +12,7 @@ DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
BEGIN
EXPORTS Identity, IdentityList, TID, Hash, Version;
EXPORTS Identity, IdentityList, TID, Hash, Version, Rating;
ISO639-1 ::= PrintableString(FROM ("a".."z")) (SIZE(2))
Hex ::= PrintableString(FROM ("A".."F") | FROM ("0".."9"))
@ -36,5 +36,31 @@ Version ::= SEQUENCE {
minor INTEGER (0..255) DEFAULT 2
}
Rating ::= ENUMERATED {
-- no color
cannot-decrypt (1),
have-no-key (2),
unencrypted (3),
unreliable (5),
b0rken (-2),
-- yellow
reliable (6),
-- green
trusted (7),
trusted-and-anonymized (8),
fully-anonymous (9),
-- red
mistrust (-1),
under-attack (-3)
}
END

@ -142,6 +142,10 @@
15B0381422B2B823002D664C /* asn_SEQUENCE_OF.h in Headers */ = {isa = PBXBuildFile; fileRef = 15B037A922B2B822002D664C /* asn_SEQUENCE_OF.h */; };
15B75BE223FA9F9D00DAE976 /* SynchronizeGroupKeys.c in Sources */ = {isa = PBXBuildFile; fileRef = 15B75BDC23FA9F9D00DAE976 /* SynchronizeGroupKeys.c */; };
15B75BE323FA9F9D00DAE976 /* SynchronizeGroupKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = 15B75BE123FA9F9D00DAE976 /* SynchronizeGroupKeys.h */; };
15EB7B7B250794D9004C176D /* ReceiverRating.h in Headers */ = {isa = PBXBuildFile; fileRef = 15EB7B73250794D8004C176D /* ReceiverRating.h */; };
15EB7B7C250794D9004C176D /* Rating.h in Headers */ = {isa = PBXBuildFile; fileRef = 15EB7B78250794D8004C176D /* Rating.h */; };
15EB7B7D250794D9004C176D /* Rating.c in Sources */ = {isa = PBXBuildFile; fileRef = 15EB7B79250794D8004C176D /* Rating.c */; };
15EB7B7E250794D9004C176D /* ReceiverRating.c in Sources */ = {isa = PBXBuildFile; fileRef = 15EB7B7A250794D8004C176D /* ReceiverRating.c */; };
430BCC482015EE800077E998 /* pEp_string.h in Headers */ = {isa = PBXBuildFile; fileRef = 430BCC462015EE800077E998 /* pEp_string.h */; };
430BCC492015EE800077E998 /* pEp_string.c in Sources */ = {isa = PBXBuildFile; fileRef = 430BCC472015EE800077E998 /* pEp_string.c */; };
430D258B1C9ED75A00B94535 /* blacklist.c in Sources */ = {isa = PBXBuildFile; fileRef = 430D258A1C9ED75A00B94535 /* blacklist.c */; };
@ -396,6 +400,10 @@
15B037A922B2B822002D664C /* asn_SEQUENCE_OF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = asn_SEQUENCE_OF.h; path = ../asn.1/asn_SEQUENCE_OF.h; sourceTree = "<group>"; };
15B75BDC23FA9F9D00DAE976 /* SynchronizeGroupKeys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SynchronizeGroupKeys.c; path = ../asn.1/SynchronizeGroupKeys.c; sourceTree = "<group>"; };
15B75BE123FA9F9D00DAE976 /* SynchronizeGroupKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SynchronizeGroupKeys.h; path = ../asn.1/SynchronizeGroupKeys.h; sourceTree = "<group>"; };
15EB7B73250794D8004C176D /* ReceiverRating.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ReceiverRating.h; path = ../asn.1/ReceiverRating.h; sourceTree = "<group>"; };
15EB7B78250794D8004C176D /* Rating.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Rating.h; path = ../asn.1/Rating.h; sourceTree = "<group>"; };
15EB7B79250794D8004C176D /* Rating.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Rating.c; path = ../asn.1/Rating.c; sourceTree = "<group>"; };
15EB7B7A250794D8004C176D /* ReceiverRating.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ReceiverRating.c; path = ../asn.1/ReceiverRating.c; sourceTree = "<group>"; };
430BCC462015EE800077E998 /* pEp_string.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pEp_string.h; path = ../src/pEp_string.h; sourceTree = "<group>"; };
430BCC472015EE800077E998 /* pEp_string.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pEp_string.c; path = ../src/pEp_string.c; sourceTree = "<group>"; };
430D258A1C9ED75A00B94535 /* blacklist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blacklist.c; path = ../src/blacklist.c; sourceTree = "<group>"; };
@ -552,6 +560,10 @@
6406CE811CE382F400C14D77 /* asn.1 */ = {
isa = PBXGroup;
children = (
15EB7B79250794D8004C176D /* Rating.c */,
15EB7B78250794D8004C176D /* Rating.h */,
15EB7B7A250794D8004C176D /* ReceiverRating.c */,
15EB7B73250794D8004C176D /* ReceiverRating.h */,
15B75BDC23FA9F9D00DAE976 /* SynchronizeGroupKeys.c */,
15B75BE123FA9F9D00DAE976 /* SynchronizeGroupKeys.h */,
4378C79023D1AF1700D1AF3F /* ElectGroupKeyResetLeader.c */,
@ -828,7 +840,9 @@
15B0380F22B2B823002D664C /* Sync.h in Headers */,
43C3778E246A8C0300962D22 /* internal_format.h in Headers */,
15B0380422B2B822002D664C /* constr_SET_OF.h in Headers */,
15EB7B7C250794D9004C176D /* Rating.h in Headers */,
15B0381322B2B823002D664C /* asn_application.h in Headers */,
15EB7B7B250794D9004C176D /* ReceiverRating.h in Headers */,
15B0380322B2B822002D664C /* OwnKeysRequester.h in Headers */,
154918AB22B940200091B6D6 /* fsm_common.h in Headers */,
15147EF3237E9EA7003989FE /* GroupKeysAndClose.h in Headers */,
@ -1083,6 +1097,7 @@
15B037B522B2B822002D664C /* OCTET_STRING.c in Sources */,
64A826831B455D0800EECAF0 /* platform_unix.c in Sources */,
15B0380D22B2B822002D664C /* CommitReject.c in Sources */,
15EB7B7D250794D9004C176D /* Rating.c in Sources */,
15B0380B22B2B822002D664C /* NativeInteger.c in Sources */,
15147EF2237E9EA7003989FE /* GroupKeysAndClose.c in Sources */,
158FF95B23C49ED600CB1016 /* KeyReset.c in Sources */,
@ -1144,6 +1159,7 @@
430BCC492015EE800077E998 /* pEp_string.c in Sources */,
15B037EB22B2B822002D664C /* constr_SET_OF.c in Sources */,
15B037DD22B2B822002D664C /* Rollback.c in Sources */,
15EB7B7E250794D9004C176D /* ReceiverRating.c in Sources */,
158FF96123C49ED600CB1016 /* Distribution.c in Sources */,
43F73C0B2166282C00AB4524 /* openpgp_compat.c in Sources */,
15B037F422B2B822002D664C /* ber_decoder.c in Sources */,

@ -85,137 +85,10 @@
<None Include="..\generate_code.cmd" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\asn.1\asn_codecs_prim.c" />
<ClCompile Include="..\..\asn.1\asn_SEQUENCE_OF.c" />
<ClCompile Include="..\..\asn.1\asn_SET_OF.c" />
<ClCompile Include="..\..\asn.1\Beacon.c" />
<ClCompile Include="..\..\asn.1\ber_decoder.c" />
<ClCompile Include="..\..\asn.1\ber_tlv_length.c" />
<ClCompile Include="..\..\asn.1\ber_tlv_tag.c" />
<ClCompile Include="..\..\asn.1\BIT_STRING.c" />
<ClCompile Include="..\..\asn.1\BOOLEAN.c" />
<ClCompile Include="..\..\asn.1\Command.c" />
<ClCompile Include="..\..\asn.1\Commands.c" />
<ClCompile Include="..\..\asn.1\CommitAccept.c" />
<ClCompile Include="..\..\asn.1\CommitAcceptForGroup.c" />
<ClCompile Include="..\..\asn.1\CommitAcceptOfferer.c" />
<ClCompile Include="..\..\asn.1\CommitAcceptRequester.c" />
<ClCompile Include="..\..\asn.1\CommitReject.c" />
<ClCompile Include="..\..\asn.1\constraints.c" />
<ClCompile Include="..\..\asn.1\constr_CHOICE.c" />
<ClCompile Include="..\..\asn.1\constr_SEQUENCE.c" />
<ClCompile Include="..\..\asn.1\constr_SEQUENCE_OF.c" />
<ClCompile Include="..\..\asn.1\constr_SET_OF.c" />
<ClCompile Include="..\..\asn.1\constr_TYPE.c" />
<ClCompile Include="..\..\asn.1\der_encoder.c" />
<ClCompile Include="..\..\asn.1\Distribution.c" />
<ClCompile Include="..\..\asn.1\ElectGroupKeyResetLeader.c" />
<ClCompile Include="..\..\asn.1\GroupHandshake.c" />
<ClCompile Include="..\..\asn.1\GroupKeysAndClose.c" />
<ClCompile Include="..\..\asn.1\GroupKeysForNewMember.c" />
<ClCompile Include="..\..\asn.1\GroupKeysUpdate.c" />
<ClCompile Include="..\..\asn.1\GroupTrustThisKey.c" />
<ClCompile Include="..\..\asn.1\Hash.c" />
<ClCompile Include="..\..\asn.1\Hex.c" />
<ClCompile Include="..\..\asn.1\Identity.c" />
<ClCompile Include="..\..\asn.1\IdentityList.c" />
<ClCompile Include="..\..\asn.1\InitUnledGroupKeyReset.c" />
<ClCompile Include="..\..\asn.1\INTEGER.c" />
<ClCompile Include="..\..\asn.1\ISO639-1.c" />
<ClCompile Include="..\..\asn.1\KeyReset.c" />
<ClCompile Include="..\..\asn.1\KeySync.c" />
<ClCompile Include="..\..\asn.1\NativeEnumerated.c" />
<ClCompile Include="..\..\asn.1\NativeInteger.c" />
<ClCompile Include="..\..\asn.1\NegotiationOpen.c" />
<ClCompile Include="..\..\asn.1\NegotiationRequest.c" />
<ClCompile Include="..\..\asn.1\NegotiationRequestGrouped.c" />
<ClCompile Include="..\..\asn.1\OCTET_STRING.c" />
<ClCompile Include="..\..\asn.1\OwnKeysOfferer.c" />
<ClCompile Include="..\..\asn.1\OwnKeysRequester.c" />
<ClCompile Include="..\..\asn.1\pdu_collection.c" />
<ClCompile Include="..\..\asn.1\per_decoder.c" />
<ClCompile Include="..\..\asn.1\per_encoder.c" />
<ClCompile Include="..\..\asn.1\per_opentype.c" />
<ClCompile Include="..\..\asn.1\per_support.c" />
<ClCompile Include="..\..\asn.1\PrintableString.c" />
<ClCompile Include="..\..\asn.1\PString.c" />
<ClCompile Include="..\..\asn.1\Rollback.c" />
<ClCompile Include="..\..\asn.1\Sync.c" />
<ClCompile Include="..\..\asn.1\SynchronizeGroupKeys.c" />
<ClCompile Include="..\..\asn.1\TID.c" />
<ClCompile Include="..\..\asn.1\UTF8String.c" />
<ClCompile Include="..\..\asn.1\Version.c" />
<ClCompile Include="..\..\asn.1\xer_decoder.c" />
<ClCompile Include="..\..\asn.1\xer_encoder.c" />
<ClCompile Include="..\..\asn.1\xer_support.c" />
<ClCompile Include="..\..\asn.1\*.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\asn.1\asn_application.h" />
<ClInclude Include="..\..\asn.1\asn_codecs.h" />
<ClInclude Include="..\..\asn.1\asn_codecs_prim.h" />
<ClInclude Include="..\..\asn.1\asn_internal.h" />
<ClInclude Include="..\..\asn.1\asn_SEQUENCE_OF.h" />
<ClInclude Include="..\..\asn.1\asn_SET_OF.h" />
<ClInclude Include="..\..\asn.1\asn_system.h" />
<ClInclude Include="..\..\asn.1\Beacon.h" />
<ClInclude Include="..\..\asn.1\ber_decoder.h" />
<ClInclude Include="..\..\asn.1\ber_tlv_length.h" />
<ClInclude Include="..\..\asn.1\ber_tlv_tag.h" />
<ClInclude Include="..\..\asn.1\BIT_STRING.h" />
<ClInclude Include="..\..\asn.1\BOOLEAN.h" />
<ClInclude Include="..\..\asn.1\Command.h" />
<ClInclude Include="..\..\asn.1\Commands.h" />
<ClInclude Include="..\..\asn.1\CommitAccept.h" />
<ClInclude Include="..\..\asn.1\CommitAcceptForGroup.h" />
<ClInclude Include="..\..\asn.1\CommitAcceptOfferer.h" />
<ClInclude Include="..\..\asn.1\CommitAcceptRequester.h" />
<ClInclude Include="..\..\asn.1\CommitReject.h" />
<ClInclude Include="..\..\asn.1\constraints.h" />
<ClInclude Include="..\..\asn.1\constr_CHOICE.h" />
<ClInclude Include="..\..\asn.1\constr_SEQUENCE.h" />
<ClInclude Include="..\..\asn.1\constr_SEQUENCE_OF.h" />
<ClInclude Include="..\..\asn.1\constr_SET_OF.h" />
<ClInclude Include="..\..\asn.1\constr_TYPE.h" />
<ClInclude Include="..\..\asn.1\der_encoder.h" />
<ClInclude Include="..\..\asn.1\Distribution.h" />
<ClInclude Include="..\..\asn.1\ElectGroupKeyResetLeader.h" />
<ClInclude Include="..\..\asn.1\GroupHandshake.h" />
<ClInclude Include="..\..\asn.1\GroupKeysAndClose.h" />
<ClInclude Include="..\..\asn.1\GroupKeysForNewMember.h" />
<ClInclude Include="..\..\asn.1\GroupKeysUpdate.h" />
<ClInclude Include="..\..\asn.1\GroupTrustThisKey.h" />
<ClInclude Include="..\..\asn.1\Hash.h" />
<ClInclude Include="..\..\asn.1\Hex.h" />
<ClInclude Include="..\..\asn.1\Identity.h" />
<ClInclude Include="..\..\asn.1\IdentityList.h" />
<ClInclude Include="..\..\asn.1\InitUnledGroupKeyReset.h" />
<ClInclude Include="..\..\asn.1\INTEGER.h" />
<ClInclude Include="..\..\asn.1\ISO639-1.h" />
<ClInclude Include="..\..\asn.1\KeyReset.h" />
<ClInclude Include="..\..\asn.1\KeySync.h" />
<ClInclude Include="..\..\asn.1\NativeEnumerated.h" />
<ClInclude Include="..\..\asn.1\NativeInteger.h" />
<ClInclude Include="..\..\asn.1\NegotiationOpen.h" />
<ClInclude Include="..\..\asn.1\NegotiationRequest.h" />
<ClInclude Include="..\..\asn.1\NegotiationRequestGrouped.h" />
<ClInclude Include="..\..\asn.1\OCTET_STRING.h" />
<ClInclude Include="..\..\asn.1\OwnKeysOfferer.h" />
<ClInclude Include="..\..\asn.1\OwnKeysRequester.h" />
<ClInclude Include="..\..\asn.1\per_decoder.h" />
<ClInclude Include="..\..\asn.1\per_encoder.h" />
<ClInclude Include="..\..\asn.1\per_opentype.h" />
<ClInclude Include="..\..\asn.1\per_support.h" />
<ClInclude Include="..\..\asn.1\PrintableString.h" />
<ClInclude Include="..\..\asn.1\PString.h" />
<ClInclude Include="..\..\asn.1\Rollback.h" />
<ClInclude Include="..\..\asn.1\Sync.h" />
<ClInclude Include="..\..\asn.1\SynchronizeGroupKeys.h" />
<ClInclude Include="..\..\asn.1\TID.h" />
<ClInclude Include="..\..\asn.1\UTF8String.h" />
<ClInclude Include="..\..\asn.1\Version.h" />
<ClInclude Include="..\..\asn.1\xer_decoder.h" />
<ClInclude Include="..\..\asn.1\xer_encoder.h" />
<ClInclude Include="..\..\asn.1\xer_support.h" />
<ClInclude Include="..\..\asn.1\*.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />

@ -16,6 +16,7 @@
#include "base64.h"
#include "resource_id.h"
#include "internal_format.h"
#include "sync_codec.h"
#include <assert.h>
#include <string.h>
@ -245,7 +246,86 @@ void replace_opt_field(message *msg,
}
}
bool sync_message_attached(message *msg)
{
if (!(msg && msg->attachments))
return false;
for (bloblist_t *a = msg->attachments; a && a->value ; a = a->next) {
if (a->mime_type && strcasecmp(a->mime_type, "application/pEp.sync") == 0)
return true;
}
return false;
}
PEP_STATUS set_receiverRating(PEP_SESSION session, message *msg, PEP_rating rating)
{
if (!(session && msg && rating))
return PEP_ILLEGAL_VALUE;
if (!(msg->recv_by && msg->recv_by->fpr && msg->recv_by->fpr[0]))
return PEP_SYNC_NO_CHANNEL;
// don't add a second sync message
if (sync_message_attached(msg))
return PEP_STATUS_OK;
Sync_t *res = new_Sync_message(Sync_PR_keysync, KeySync_PR_receiverRating);
if (!res)
return PEP_OUT_OF_MEMORY;
res->choice.keysync.choice.receiverRating.rating = (Rating_t) rating;
char *payload;
size_t size;
PEP_STATUS status = encode_Sync_message(res, &payload, &size);
free_Sync_message(res);
if (status)
return status;
return base_decorate_message(session, msg, BASE_SYNC, payload, size, msg->recv_by->fpr);
}
PEP_STATUS get_receiverRating(PEP_SESSION session, message *msg, PEP_rating *rating)
{
if (!(session && msg && rating))
return PEP_ILLEGAL_VALUE;
*rating = PEP_rating_undefined;
size_t size;
const char *payload;
char *fpr;
PEP_STATUS status = base_extract_message(session, msg, BASE_SYNC, &size, &payload, &fpr);
if (status)
return status;
if (!fpr)
return PEP_SYNC_NO_CHANNEL;
bool own_key;
status = is_own_key(session, fpr, &own_key);
free(fpr);
if (!own_key)
return PEP_SYNC_NO_CHANNEL;
Sync_t *res;
status = decode_Sync_message(payload, size, &res);
if (status)
return status;
if (!(res->present == Sync_PR_keysync && res->choice.keysync.present == KeySync_PR_receiverRating)) {
free_Sync_message(res);
return PEP_SYNC_NO_CHANNEL;
}
*rating = res->choice.keysync.choice.receiverRating.rating;
replace_opt_field(msg, "X-EncStatus", rating_to_string(*rating), true);
return PEP_STATUS_OK;
}
void decorate_message(
PEP_SESSION session,
message *msg,
PEP_rating rating,
stringlist_t *keylist,
@ -258,8 +338,10 @@ void decorate_message(
if (add_version)
replace_opt_field(msg, "X-pEp-Version", PEP_VERSION, clobber);
if (rating != PEP_rating_undefined)
if (rating != PEP_rating_undefined) {
replace_opt_field(msg, "X-EncStatus", rating_to_string(rating), clobber);
set_receiverRating(session, msg, rating);
}
if (keylist) {
char *_keylist = keylist_to_string(keylist);
@ -2609,7 +2691,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
attach_own_key(session, src);
added_key_to_real_src = true;
}
decorate_message(src, PEP_rating_undefined, NULL, true, true);
decorate_message(session, src, PEP_rating_undefined, NULL, true, true);
return PEP_UNENCRYPTED;
}
else {
@ -2677,7 +2759,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
if (msg) {
decorate_message(msg, PEP_rating_undefined, NULL, true, true);
decorate_message(session, msg, PEP_rating_undefined, NULL, true, true);
if (_src->id) {
msg->id = strdup(_src->id);
assert(msg->id);
@ -3045,7 +3127,7 @@ DYNAMIC_API PEP_STATUS encrypt_message_for_self(
if (msg->id == NULL)
goto enomem;
}
decorate_message(msg, PEP_rating_undefined, NULL, true, true);
decorate_message(session, msg, PEP_rating_undefined, NULL, true, true);
}
*dst = msg;
@ -4606,8 +4688,15 @@ static PEP_STATUS _decrypt_message(
// Check for and deal with unencrypted messages
if (src->enc_format == PEP_enc_none) {
// if there is a valid receiverRating then return this rating else
// return unencrypted
*rating = PEP_rating_unencrypted;
PEP_rating _rating = PEP_rating_undefined;
status = get_receiverRating(session, src, &_rating);
if (status == PEP_STATUS_OK && _rating)
*rating = _rating;
else
*rating = PEP_rating_unencrypted;
// We remove these from the outermost source message
// if (keys_were_imported)
@ -4623,9 +4712,22 @@ static PEP_STATUS _decrypt_message(
return PEP_UNENCRYPTED;
}
// if there is an own identity defined via this message is coming in
// retrieve the details; in case there's no usuable own key make it
// functional
if (src->recv_by) {
status = myself(session, src->recv_by);
if (status) {
free_stringlist(_imported_key_list);
return status;
}
}
status = get_crypto_text(src, &ctext, &csize);
if (status != PEP_STATUS_OK)
if (status) {
free_stringlist(_imported_key_list);
return status;
}
/** Ok, we should be ready to decrypt. Try decrypt and verify first! **/
status = decrypt_and_verify(session, ctext, csize, dsig_text, dsig_size,
@ -5076,7 +5178,13 @@ static PEP_STATUS _decrypt_message(
dedup_stringlist(_keylist->next);
/* add pEp-related status flags to header */
decorate_message(msg, *rating, _keylist, false, true);
if (src->recv_by) {
free_identity(msg->recv_by);
msg->recv_by = identity_dup(src->recv_by);
if (!msg->recv_by)
goto enomem;
}
decorate_message(session, msg, *rating, _keylist, false, true);
// Maybe unnecessary
// if (keys_were_imported)

@ -28,7 +28,7 @@ extern "C" {
#define PEP_ENGINE_VERSION_MAJOR 2
#define PEP_ENGINE_VERSION_MINOR 1
#define PEP_ENGINE_VERSION_PATCH 0
#define PEP_ENGINE_VERSION_RC 29
#define PEP_ENGINE_VERSION_RC 35
#define PEP_OWN_USERID "pEp_own_userId"

@ -339,6 +339,7 @@ PEP_STATUS encrypt_only(
*
*/
void decorate_message(
PEP_SESSION session,
message *msg,
PEP_rating rating,
stringlist_t *keylist,

@ -296,7 +296,7 @@ template "field", mode=update_message {
const "state" > «yml:lcase(ancestor::protocol/@name)»_state.«yml:lcase(ancestor::fsm/@name)»
choose {
when "func:basicType()" // copyable
when "func:basicType() or @type='Rating'" // copyable
||
msg->choice.«yml:lcase(../../@name)».choice.«$message_name».«@name»
= session->«$state».«@name»;
@ -380,7 +380,7 @@ template "message", mode=update_state {
template "field", mode=update_state {
param "message_name";
choose {
when "func:basicType()" // copyable
when "func:basicType() or @type='Rating'" // copyable
||
session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name» = msg->choice.«yml:lcase(../../@name)»
.choice.«$message_name».«@name»;

@ -15,7 +15,7 @@ tstylesheet {
include ./functions.ysl2
function "pEp_imports"
| IMPORTS Version, Identity, IdentityList, TID, Hash FROM PEP;
| IMPORTS Version, Identity, IdentityList, TID, Hash, Rating FROM PEP;
function "header"
||

@ -585,7 +585,7 @@ tstylesheet {
goto the_end;
}
attach_own_key(session, _m);
decorate_message(_m, PEP_rating_undefined, NULL, true, true);
decorate_message(session, _m, PEP_rating_undefined, NULL, true, true);
m = _m;
break;
@ -1349,7 +1349,7 @@ tstylesheet {
case Init:
return "Init";
||
for "func:distinctName(state/event[not(@name='Init')])" {
for "func:distinctName(state/event[not(@name='Init')]|message)" {
|>> case «@name»:
|>>> return "«@name»";
}

@ -679,5 +679,14 @@ protocol Sync 1 {
message SynchronizeGroupKeys 21, ratelimit=60 {
}
// This could be part of TrustSync, but actually it does not matter.
// This message will not be sent by the Sync thread. It is used by
// decrypt_message() to mark a previously computed rating. It is only
// valid when signed with an own key.
message ReceiverRating 22, security=unencrypted {
field Rating rating;
}
}
}

@ -0,0 +1,154 @@
#include <stdlib.h>
#include <string>
#include <cstring>
#include "internal_format.h"
#include "test_util.h"
#include "TestConstants.h"
#include "Engine.h"
#include <gtest/gtest.h>
extern "C" {
PEP_STATUS set_receiverRating(PEP_SESSION session, message *msg, PEP_rating rating);
PEP_STATUS get_receiverRating(PEP_SESSION session, message *msg, PEP_rating *rating);
}
namespace {
//The fixture for ReceiverRatingTest
class ReceiverRatingTest : public ::testing::Test {
public:
Engine* engine;
PEP_SESSION session;
protected:
// You can remove any or all of the following functions if its body
// is empty.
ReceiverRatingTest() {
// You can do set-up work for each test here.
test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
}
~ReceiverRatingTest() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
// Leave this empty if there are no files to copy to the home directory path
std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
// Get a new test Engine.
engine = new Engine(test_path);
ASSERT_NE(engine, nullptr);
// Ok, let's initialize test directories etc.
engine->prep(NULL, NULL, NULL, init_files);
// Ok, try to start this bugger.
engine->start();
ASSERT_NE(engine->session, nullptr);
session = engine->session;
// Engine is up. Keep on truckin'
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
engine->shut_down();
delete engine;
engine = NULL;
session = NULL;
}
private:
const char* test_suite_name;
const char* test_name;
string test_path;
// Objects declared here can be used by all tests in the ReceiverRatingTest suite.
};
} // namespace
TEST_F(ReceiverRatingTest, check_internal_format) {
// a message from me, Alice, to myself
const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
PEP_STATUS status = read_file_and_import_key(session,
"test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
ASSERT_EQ(status , PEP_KEY_IMPORTED);
status = set_up_ident_from_scratch(session,
"test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
"pep.test.alice@pep-project.org", alice_fpr,
PEP_OWN_USERID, "Alice in Wonderland", NULL, true
);
ASSERT_EQ(status , PEP_STATUS_OK);
message* msg = new_message(PEP_dir_outgoing);
pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, NULL);
status = myself(session, alice);
ASSERT_EQ(status , PEP_STATUS_OK);
pEp_identity* alice2 = identity_dup(alice);
msg->to = new_identity_list(identity_dup(alice));
msg->from = identity_dup(alice);
msg->shortmsg = strdup("Yo Mama!");
msg->longmsg = strdup("Look at my hot new sender fpr field!");
// encrypt this message
message* enc_msg = NULL;
status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PEP, 0);
ASSERT_EQ(status , PEP_STATUS_OK);
// decrypt this message
message *dec_msg = NULL;
stringlist_t *keylist = NULL;
PEP_rating rating = PEP_rating_undefined;
PEP_decrypt_flags_t flags = 0;
enc_msg->recv_by = identity_dup(alice);
status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STREQ(msg->shortmsg, dec_msg->shortmsg);
ASSERT_STREQ(msg->longmsg, dec_msg->longmsg);
ASSERT_EQ(rating, PEP_rating_trusted_and_anonymized);
bloblist_t *as = dec_msg->attachments;
ASSERT_STREQ(as->mime_type, "application/pEp.sync");
// test if receiver rating can be evaluated
free_stringlist(keylist);
message *dec_msg2 = NULL;
dec_msg->recv_by = identity_dup(alice);
status = decrypt_message(session, dec_msg, &dec_msg2, &keylist, &rating, &flags);
ASSERT_EQ(status, PEP_UNENCRYPTED);
ASSERT_EQ(rating, PEP_rating_trusted_and_anonymized);
// this must be repeatable
free_stringlist(keylist);
dec_msg->recv_by = identity_dup(alice);
status = decrypt_message(session, dec_msg, &dec_msg2, &keylist, &rating, &flags);
ASSERT_EQ(status, PEP_UNENCRYPTED);
ASSERT_EQ(rating, PEP_rating_trusted_and_anonymized);
free_stringlist(keylist);
free_identity(alice);
free_message(msg);
free_message(enc_msg);
free_message(dec_msg);
free_message(dec_msg2);
}
Loading…
Cancel
Save