IOSAD-92 act on PEP_decrypt_flag_untrusted_server IOSAD-92
authorDirk Zimmermann <dirk@pep-project.org>
Tue, 24 Apr 2018 17:11:59 +0200
branchIOSAD-92
changeset 598893ee5ebcd43
parent 597 aa68b6d6a966
child 599 8db01039b24c
IOSAD-92 act on PEP_decrypt_flag_untrusted_server
pEpObjCAdapter/NSMutableDictionary+PEP.h
pEpObjCAdapter/NSMutableDictionary+PEP.m
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPMessage.m
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/NSMutableDictionary+PEP.h	Tue Apr 24 17:11:58 2018 +0200
     1.2 +++ b/pEpObjCAdapter/NSMutableDictionary+PEP.h	Tue Apr 24 17:11:59 2018 +0200
     1.3 @@ -10,6 +10,8 @@
     1.4  
     1.5  #import "message.h"
     1.6  
     1.7 +void replaceDictionaryContentsWithMessage(NSMutableDictionary *dict, message *message);
     1.8 +
     1.9  @interface NSMutableDictionary (PEP)
    1.10  
    1.11  /**
     2.1 --- a/pEpObjCAdapter/NSMutableDictionary+PEP.m	Tue Apr 24 17:11:58 2018 +0200
     2.2 +++ b/pEpObjCAdapter/NSMutableDictionary+PEP.m	Tue Apr 24 17:11:59 2018 +0200
     2.3 @@ -10,89 +10,94 @@
     2.4  
     2.5  #import "PEPMessageUtil.h"
     2.6  
     2.7 +void replaceDictionaryContentsWithMessage(NSMutableDictionary *dict, message *message)
     2.8 +{
     2.9 +    [dict removeAllObjects];
    2.10 +    
    2.11 +    [dict setValue:(message->dir == PEP_dir_outgoing) ? @YES : @NO forKey:kPepOutgoing];
    2.12 +    
    2.13 +    if (message->id) {
    2.14 +        [dict setValue:[NSString stringWithUTF8String:message->id] forKey:kPepID];
    2.15 +    }
    2.16 +    
    2.17 +    if (message->shortmsg) {
    2.18 +        [dict setValue:[NSString stringWithUTF8String:message->shortmsg] forKey:kPepShortMessage];
    2.19 +    }
    2.20 +    
    2.21 +    if (message->sent) {
    2.22 +        [dict setValue:[NSDate dateWithTimeIntervalSince1970:timegm(message->sent)]
    2.23 +                forKey:kPepSent];
    2.24 +    }
    2.25 +    
    2.26 +    if (message->recv) {
    2.27 +        [dict setValue:[NSDate dateWithTimeIntervalSince1970:mktime(message->recv)]
    2.28 +                forKey:kPepReceived];
    2.29 +    }
    2.30 +    
    2.31 +    if (message->from) {
    2.32 +        [dict setValue:PEP_identityFromStruct(message->from) forKey:kPepFrom];
    2.33 +    }
    2.34 +    
    2.35 +    if (message->to && message->to->ident) {
    2.36 +        [dict setValue:PEP_identityArrayFromList(message->to) forKey:kPepTo];
    2.37 +    }
    2.38 +    
    2.39 +    if (message->recv_by) {
    2.40 +        [dict setValue:PEP_identityFromStruct(message->recv_by) forKey:kPepReceivedBy];
    2.41 +    }
    2.42 +    
    2.43 +    if (message->cc && message->cc->ident) {
    2.44 +        [dict setValue:PEP_identityArrayFromList(message->cc) forKey:kPepCC];
    2.45 +    }
    2.46 +    
    2.47 +    if (message->bcc && message->bcc->ident) {
    2.48 +        [dict setValue:PEP_identityArrayFromList(message->bcc) forKey:kPepBCC];
    2.49 +    }
    2.50 +    
    2.51 +    if (message->reply_to && message->reply_to->ident) {
    2.52 +        [dict setValue:PEP_identityArrayFromList(message->reply_to) forKey:kPepReplyTo];
    2.53 +    }
    2.54 +    
    2.55 +    if (message->in_reply_to) {
    2.56 +        [dict setValue:PEP_arrayFromStringlist(message->in_reply_to) forKey:kPepInReplyTo];
    2.57 +    }
    2.58 +    
    2.59 +    if (message->references && message->references->value) {
    2.60 +        [dict setValue:PEP_arrayFromStringlist(message->references) forKey:kPepReferences];
    2.61 +    }
    2.62 +    
    2.63 +    if (message->keywords && message->keywords->value) {
    2.64 +        [dict setValue:PEP_arrayFromStringlist(message->keywords) forKey:kPepKeywords];
    2.65 +    }
    2.66 +    
    2.67 +    if (message->opt_fields) {
    2.68 +        [dict setValue:PEP_arrayFromStringPairlist(message->opt_fields) forKey:kPepOptFields];
    2.69 +    }
    2.70 +    
    2.71 +    if (message->longmsg_formatted) {
    2.72 +        [dict setValue:[NSString stringWithUTF8String:message->longmsg_formatted]
    2.73 +                forKey:kPepLongMessageFormatted];
    2.74 +    }
    2.75 +    
    2.76 +    if (message->longmsg) {
    2.77 +        [dict setValue:[NSString stringWithUTF8String:message->longmsg] forKey:kPepLongMessage];
    2.78 +    }
    2.79 +    
    2.80 +    if (message->attachments && message->attachments->value) {
    2.81 +        [dict setValue: PEP_arrayFromBloblist(message->attachments) forKey:kPepAttachments];
    2.82 +    }
    2.83 +    
    2.84 +    if (message->rawmsg_size > 0 && *message->rawmsg_ref) {
    2.85 +        NSData *data = [NSData dataWithBytes:message->rawmsg_ref length:message->rawmsg_size];
    2.86 +        dict[kPepRawMessage] = data;
    2.87 +    }
    2.88 +}
    2.89 +
    2.90  @implementation NSMutableDictionary (PEP)
    2.91  
    2.92  - (void)replaceWithMessage:(message *)message
    2.93  {
    2.94 -    [self removeAllObjects];
    2.95 -
    2.96 -    [self setObject:(message->dir == PEP_dir_outgoing) ? @YES : @NO forKey:kPepOutgoing];
    2.97 -
    2.98 -    if (message->id) {
    2.99 -        [self setObject:[NSString stringWithUTF8String:message->id] forKey:kPepID];
   2.100 -    }
   2.101 -
   2.102 -    if (message->shortmsg) {
   2.103 -        [self setObject:[NSString stringWithUTF8String:message->shortmsg] forKey:kPepShortMessage];
   2.104 -    }
   2.105 -
   2.106 -    if (message->sent) {
   2.107 -        [self setObject:[NSDate dateWithTimeIntervalSince1970:timegm(message->sent)]
   2.108 -                 forKey:kPepSent];
   2.109 -    }
   2.110 -
   2.111 -    if (message->recv) {
   2.112 -        [self setObject:[NSDate dateWithTimeIntervalSince1970:mktime(message->recv)]
   2.113 -                 forKey:kPepReceived];
   2.114 -    }
   2.115 -
   2.116 -    if (message->from) {
   2.117 -        [self setObject:PEP_identityFromStruct(message->from) forKey:kPepFrom];
   2.118 -    }
   2.119 -
   2.120 -    if (message->to && message->to->ident) {
   2.121 -        [self setObject:PEP_identityArrayFromList(message->to) forKey:kPepTo];
   2.122 -    }
   2.123 -
   2.124 -    if (message->recv_by) {
   2.125 -        [self setObject:PEP_identityFromStruct(message->recv_by) forKey:kPepReceivedBy];
   2.126 -    }
   2.127 -
   2.128 -    if (message->cc && message->cc->ident) {
   2.129 -        [self setObject:PEP_identityArrayFromList(message->cc) forKey:kPepCC];
   2.130 -    }
   2.131 -
   2.132 -    if (message->bcc && message->bcc->ident) {
   2.133 -        [self setObject:PEP_identityArrayFromList(message->bcc) forKey:kPepBCC];
   2.134 -    }
   2.135 -
   2.136 -    if (message->reply_to && message->reply_to->ident) {
   2.137 -        [self setObject:PEP_identityArrayFromList(message->reply_to) forKey:kPepReplyTo];
   2.138 -    }
   2.139 -
   2.140 -    if (message->in_reply_to) {
   2.141 -        [self setObject:PEP_arrayFromStringlist(message->in_reply_to) forKey:kPepInReplyTo];
   2.142 -    }
   2.143 -
   2.144 -    if (message->references && message->references->value) {
   2.145 -        [self setObject:PEP_arrayFromStringlist(message->references) forKey:kPepReferences];
   2.146 -    }
   2.147 -
   2.148 -    if (message->keywords && message->keywords->value) {
   2.149 -        [self setObject:PEP_arrayFromStringlist(message->keywords) forKey:kPepKeywords];
   2.150 -    }
   2.151 -
   2.152 -    if (message->opt_fields) {
   2.153 -        [self setObject:PEP_arrayFromStringPairlist(message->opt_fields) forKey:kPepOptFields];
   2.154 -    }
   2.155 -
   2.156 -    if (message->longmsg_formatted) {
   2.157 -        [self setObject:[NSString stringWithUTF8String:message->longmsg_formatted]
   2.158 -                 forKey:kPepLongMessageFormatted];
   2.159 -    }
   2.160 -
   2.161 -    if (message->longmsg) {
   2.162 -        [self setObject:[NSString stringWithUTF8String:message->longmsg] forKey:kPepLongMessage];
   2.163 -    }
   2.164 -
   2.165 -    if (message->attachments && message->attachments->value) {
   2.166 -        [self setObject: PEP_arrayFromBloblist(message->attachments) forKey:kPepAttachments];
   2.167 -    }
   2.168 -
   2.169 -    if (message->rawmsg_size > 0 && *message->rawmsg_ref) {
   2.170 -        NSData *data = [NSData dataWithBytes:message->rawmsg_ref length:message->rawmsg_size];
   2.171 -        self[kPepRawMessage] = data;
   2.172 -    }
   2.173 +    replaceDictionaryContentsWithMessage(self, message);
   2.174  }
   2.175  
   2.176  @end
     3.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Tue Apr 24 17:11:58 2018 +0200
     3.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Tue Apr 24 17:11:59 2018 +0200
     3.3 @@ -19,6 +19,7 @@
     3.4  #import "NSError+PEP.h"
     3.5  #import "PEPAutoPointer.h"
     3.6  #import "NSNumber+PEPRating.h"
     3.7 +#import "NSMutableDictionary+PEP.h"
     3.8  
     3.9  @implementation PEPInternalSession
    3.10  
    3.11 @@ -158,8 +159,13 @@
    3.12      }
    3.13  
    3.14      NSArray *keys_ = nil;
    3.15 -    if (_keys)
    3.16 +    if (_keys) {
    3.17          keys_ = PEP_arrayFromStringlist(_keys);
    3.18 +    }
    3.19 +
    3.20 +    if (theFlags & PEP_decrypt_flag_untrusted_server) {
    3.21 +        [messageDict replaceWithMessage:_src];
    3.22 +    }
    3.23  
    3.24      decryptMessageDictFree(_src, _dst, _keys);
    3.25  
     4.1 --- a/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 17:11:58 2018 +0200
     4.2 +++ b/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 17:11:59 2018 +0200
     4.3 @@ -10,6 +10,7 @@
     4.4  #import "PEPIdentity.h"
     4.5  
     4.6  #import "NSObject+Extension.h"
     4.7 +#import "NSMutableDictionary+PEP.h"
     4.8  
     4.9  @implementation PEPMessage
    4.10  
    4.11 @@ -139,6 +140,33 @@
    4.12      return (PEPMutableDict *) self;
    4.13  }
    4.14  
    4.15 +- (void)removeAllObjects
    4.16 +{
    4.17 +    self.messageID = nil;
    4.18 +    self.from = nil;
    4.19 +    self.to = nil;
    4.20 +    self.cc = nil;
    4.21 +    self.bcc = nil;
    4.22 +    self.shortMessage = nil;
    4.23 +    self.longMessage = nil;
    4.24 +    self.longMessageFormatted = nil;
    4.25 +    self.replyTo = nil;
    4.26 +    self.inReplyTo = nil;
    4.27 +    self.references = nil;
    4.28 +    self.sentDate = nil;
    4.29 +    self.receivedDate = nil;
    4.30 +    self.attachments = nil;
    4.31 +    self.optionalFields = nil;
    4.32 +    self.keywords = nil;
    4.33 +    self.receivedBy = nil;
    4.34 +    self.direction = PEP_dir_incoming; // basically, 0
    4.35 +}
    4.36 +
    4.37 +- (void)replaceWithMessage:(message *)message
    4.38 +{
    4.39 +    replaceDictionaryContentsWithMessage(self.mutableDictionary, message);
    4.40 +}
    4.41 +
    4.42  // MARK: - NSDictionary - Helpers
    4.43  
    4.44  - (NSArray<NSArray<NSString *> *> *)keyValuePairs
     5.1 --- a/pEpObjCTests/PEPSessionTest.m	Tue Apr 24 17:11:58 2018 +0200
     5.2 +++ b/pEpObjCTests/PEPSessionTest.m	Tue Apr 24 17:11:59 2018 +0200
     5.3 @@ -911,7 +911,7 @@
     5.4      XCTAssertEqual(rating, PEP_rating_unreliable);
     5.5  
     5.6      // Since we're requesting re-encryption, src should have been changed
     5.7 -    XCTAssertEqualObjects(msg, msgOriginal); // TODO
     5.8 +    XCTAssertNotEqualObjects(msg, msgOriginal);
     5.9  
    5.10      XCTAssertNotNil(pepDecryptedMail.longMessage);
    5.11  }