@ -24,6 +24,8 @@
# include "group.h"
# include "group_internal.h"
# include "status_to_string.h"
# include <assert.h>
# include <string.h>
# include <stdlib.h>
@ -108,6 +110,8 @@ static char * keylist_to_string(const stringlist_t *keylist)
static const char * rating_to_string ( PEP_rating rating )
{
switch ( rating ) {
case PEP_rating_undefined :
return " undefined " ;
case PEP_rating_cannot_decrypt :
return " cannot_decrypt " ;
case PEP_rating_have_no_key :
@ -131,7 +135,7 @@ static const char * rating_to_string(PEP_rating rating)
case PEP_rating_under_attack :
return " under_attack " ;
default :
return " undefined " ;
assert ( 0 ) ;
}
}
@ -404,6 +408,8 @@ void decorate_message(
replace_opt_field ( msg , " X-KeyList " , _keylist , clobber ) ;
free ( _keylist ) ;
}
msg - > rating = rating ;
}
/**
@ -2682,6 +2688,9 @@ DYNAMIC_API PEP_STATUS encrypt_message(
if ( src - > dir = = PEP_dir_incoming )
return PEP_ILLEGAL_VALUE ;
/ / Reset the message rating before doing anything . . .
src - > rating = PEP_rating_undefined ;
determine_encryption_format ( src ) ;
/ / TODO : change this for multi - encryption in message format 2.0
if ( src - > enc_format ! = PEP_enc_none )
@ -2944,7 +2953,16 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
if ( msg ) {
decorate_message ( session , msg , PEP_rating_undefined , NULL , true , true ) ;
/* Obtain the message rating... */
PEP_rating rating ;
status = sent_message_rating ( session , msg , & rating ) ;
if ( status = = PEP_OUT_OF_MEMORY )
goto enomem ;
else if ( status ! = PEP_STATUS_OK )
goto pEp_error ;
/* ...And store it into the message along with the other decorations. */
decorate_message ( session , msg , rating , NULL , true , true ) ;
if ( _src - > id ) {
msg - > id = strdup ( _src - > id ) ;
assert ( msg - > id ) ;
@ -4990,7 +5008,9 @@ static const char* process_key_claim(message* src,
/ / There are times when we don ' t want errors during calls to be fatal . Once any action is taken on that
/ / status , if we are going to continue processing and not bail from the message , the status needs to be reset
/ / to PEP_STATUS_OK , or , alternately , we need to be using a temp status variable .
/ /
/ / This internal function does * not * set the rating field of the message : that
/ / part of the job is within decrypt_message .
static PEP_STATUS _decrypt_message (
PEP_SESSION session ,
message * src ,
@ -6264,7 +6284,6 @@ DYNAMIC_API PEP_STATUS decrypt_message(
message * src ,
message * * dst ,
stringlist_t * * keylist ,
PEP_rating * rating ,
PEP_decrypt_flags_t * flags
)
{
@ -6272,24 +6291,32 @@ DYNAMIC_API PEP_STATUS decrypt_message(
assert ( src ) ;
assert ( dst ) ;
assert ( keylist ) ;
assert ( rating ) ;
assert ( flags ) ;
if ( ! ( session & & src & & dst & & keylist & & rating & & flags ) )
if ( ! ( session & & src & & dst & & keylist & & flags ) )
return PEP_ILLEGAL_VALUE ;
if ( ! ( * flags & PEP_decrypt_flag_untrusted_server ) )
* keylist = NULL ;
/ / Reset the message rating before doing anything . We will compute a new
/ / value , that _decrypt_message sets as an output parameter .
src - > rating = PEP_rating_undefined ;
PEP_rating rating = PEP_rating_undefined ;
stringlist_t * imported_key_fprs = NULL ;
uint64_t changed_key_bitvec = 0 ;
PEP_STATUS status = _decrypt_message ( session , src , dst , keylist ,
rating , flags , NULL ,
& rating , flags , NULL ,
& imported_key_fprs , & changed_key_bitvec ) ;
message * msg = * dst ? * dst : src ;
/* Set the rating field of the message. Notice that even in case of non-ok
result status the value of this field may be meaningful . */
msg - > rating = rating ;
/ / Ok , now we check to see if it was an administrative message . We do this by testing base_extract for success
/ / with protocol families .
if ( msg & & msg - > from ) {
@ -6303,10 +6330,10 @@ DYNAMIC_API PEP_STATUS decrypt_message(
tmp_status = base_extract_message ( session , msg , BASE_SYNC , & size , & data , & sender_fpr ) ;
if ( ! tmp_status & & size & & data ) {
if ( sender_fpr )
signal_Sync_message ( session , * rating , data , size , msg - > from , sender_fpr ) ;
signal_Sync_message ( session , rating , data , size , msg - > from , sender_fpr ) ;
/ / FIXME : this must be changed to sender_fpr
else if ( * keylist )
signal_Sync_message ( session , * rating , data , size , msg - > from , ( * keylist ) - > value ) ;
signal_Sync_message ( session , rating , data , size , msg - > from , ( * keylist ) - > value ) ;
}
}
if ( tmp_status ! = PEP_STATUS_OK ) {
@ -6324,7 +6351,7 @@ DYNAMIC_API PEP_STATUS decrypt_message(
PEP_STATUS tmpstatus = base_extract_message ( session , msg , BASE_DISTRIBUTION , & size , & data ,
& sender_fpr ) ;
if ( ! tmpstatus & & size & & data ) {
process_Distribution_message ( session , msg , * rating , data , size , sender_fpr ) ;
process_Distribution_message ( session , msg , rating , data , size , sender_fpr ) ;
}
}
}
@ -6352,7 +6379,7 @@ DYNAMIC_API PEP_STATUS decrypt_message(
/ / / / if ( ( ! event_sender_fpr ) & & * keylist )
/ / / / event_sender_fpr = ( * keylist ) - > value ;
/ / if ( event_sender_fpr )
/ / signal_Sync_message ( session , * rating , data , size , msg - > from , event_sender_fpr ) ;
/ / signal_Sync_message ( session , rating , data , size , msg - > from , event_sender_fpr ) ;
/ / }
/ / free ( sender_fpr ) ;
/ / }
@ -6480,6 +6507,16 @@ static void _max_comm_type_from_identity_list_preview(
}
}
DYNAMIC_API PEP_STATUS sent_message_rating (
PEP_SESSION session ,
message * msg ,
PEP_rating * rating
)
{
/ / FIXME : this is a stub . See ENGINE - 847.
return outgoing_message_rating ( session , msg , rating ) ;
}
DYNAMIC_API PEP_STATUS outgoing_message_rating (
PEP_SESSION session ,
message * msg ,
@ -6947,9 +6984,8 @@ DYNAMIC_API PEP_STATUS get_message_trustwords(
/ / Message is to be decrypted
message * dst = NULL ;
stringlist_t * _keylist = keylist ;
PEP_rating rating ;
PEP_decrypt_flags_t flags ;
status = decrypt_message ( session , msg , & dst , & _keylist , & rating , & flags ) ;
status = decrypt_message ( session , msg , & dst , & _keylist , & flags ) ;
if ( status ! = PEP_STATUS_OK ) {
free_message ( dst ) ;