IOSAD-72 trustPersonalKey
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 15 Mar 2018 08:04:34 +0100
changeset 5348cca11a32204
parent 533 79edad305d94
child 535 9ef279e6880d
IOSAD-72 trustPersonalKey
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 15 08:04:33 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 15 08:04:34 2018 +0100
     1.3 @@ -487,17 +487,24 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -- (void)trustPersonalKey:(PEPIdentity *)identity
     1.8 +- (BOOL)trustPersonalKey:(nonnull PEPIdentity *)identity
     1.9 +                   error:(NSError * _Nullable * _Nullable)error
    1.10  {
    1.11      pEp_identity *ident = PEP_identityToStruct(identity);
    1.12  
    1.13      [self lockWrite];
    1.14 -    trust_personal_key(_session, ident);
    1.15 +    PEP_STATUS status = trust_personal_key(_session, ident);
    1.16      [self unlockWrite];
    1.17  
    1.18 +    if ([NSError setError:error fromPEPStatus:status]) {
    1.19 +        free_identity(ident);
    1.20 +        return NO;
    1.21 +    }
    1.22 +
    1.23      [identity reset];
    1.24      [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
    1.25      free_identity(ident);
    1.26 +    return YES;
    1.27  }
    1.28  
    1.29  - (void)keyResetTrust:(PEPIdentity *)identity
     2.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Mar 15 08:04:33 2018 +0100
     2.2 +++ b/pEpObjCAdapter/PEPSession.m	Thu Mar 15 08:04:34 2018 +0100
     2.3 @@ -167,10 +167,11 @@
     2.4      return [session updateIdentity:identity error:error];
     2.5  }
     2.6  
     2.7 -- (void)trustPersonalKey:(nonnull PEPIdentity *)identity
     2.8 +- (BOOL)trustPersonalKey:(nonnull PEPIdentity *)identity
     2.9 +                   error:(NSError * _Nullable * _Nullable)error
    2.10  {
    2.11      PEPInternalSession *session = [PEPSessionProvider session];
    2.12 -    [session trustPersonalKey:identity];
    2.13 +    return [session trustPersonalKey:identity error:error];
    2.14  }
    2.15  
    2.16  - (void)keyMistrusted:(nonnull PEPIdentity *)identity
     3.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 15 08:04:33 2018 +0100
     3.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 15 08:04:34 2018 +0100
     3.3 @@ -141,7 +141,8 @@
     3.4   Mark a key as trusted with a person.
     3.5   See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
     3.6   */
     3.7 -- (void)trustPersonalKey:(nonnull PEPIdentity *)identity;
     3.8 +- (BOOL)trustPersonalKey:(nonnull PEPIdentity *)identity
     3.9 +                   error:(NSError * _Nullable * _Nullable)error;
    3.10  
    3.11  /**
    3.12   if a key is not trusted by the user tell this using this message
     4.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:33 2018 +0100
     4.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:34 2018 +0100
     4.3 @@ -239,7 +239,8 @@
     4.4      XCTAssertNotNil(alice);
     4.5      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
     4.6  
     4.7 -    [session trustPersonalKey:alice];
     4.8 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
     4.9 +    XCTAssertNil(error);
    4.10      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.11  
    4.12      [session keyResetTrust:alice];
    4.13 @@ -253,7 +254,8 @@
    4.14      // After ENGINE-371 has been fixed, this should be just PEP_rating_reliable
    4.15      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.16  
    4.17 -    [session trustPersonalKey:alice];
    4.18 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
    4.19 +    XCTAssertNil(error);
    4.20      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.21  
    4.22      [session keyResetTrust:alice];
    4.23 @@ -286,7 +288,8 @@
    4.24      XCTAssertNotNil(alice);
    4.25      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
    4.26  
    4.27 -    [session trustPersonalKey:alice];
    4.28 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
    4.29 +    XCTAssertNil(error);
    4.30      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.31  
    4.32      [session keyResetTrust:alice];
    4.33 @@ -297,14 +300,16 @@
    4.34  
    4.35      [session undoLastMistrust];
    4.36  
    4.37 -    [session trustPersonalKey:alice];
    4.38 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
    4.39 +    XCTAssertNil(error);
    4.40      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.41  
    4.42      [session keyResetTrust:alice];
    4.43      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
    4.44  
    4.45      // This line provoked the crash
    4.46 -    [session trustPersonalKey:alice];
    4.47 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
    4.48 +    XCTAssertNil(error);
    4.49  }
    4.50  
    4.51  /**
    4.52 @@ -358,7 +363,8 @@
    4.53      dispatch_group_async(backgroundGroup,
    4.54                           dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), encryptingBlock);
    4.55  
    4.56 -    [session trustPersonalKey:alice];
    4.57 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
    4.58 +    XCTAssertNil(error);
    4.59      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.60  
    4.61      [session keyResetTrust:alice];
    4.62 @@ -372,7 +378,8 @@
    4.63      // After ENGINE-371 has been fixed, this should be just PEP_rating_reliable
    4.64      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.65  
    4.66 -    [session trustPersonalKey:alice];
    4.67 +    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
    4.68 +    XCTAssertNil(error);
    4.69      XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
    4.70  
    4.71      [session keyResetTrust:alice];
    4.72 @@ -448,7 +455,8 @@
    4.73      XCTAssertEqual(rating, PEP_rating_reliable);
    4.74  
    4.75      // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
    4.76 -    [session trustPersonalKey:identBob];
    4.77 +    XCTAssertTrue([session trustPersonalKey:identBob error:&error]);
    4.78 +    XCTAssertNil(error);
    4.79  
    4.80      // This time it should be green
    4.81      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    4.82 @@ -490,7 +498,8 @@
    4.83      XCTAssertEqual([self ratingForIdentity:identBob session:session], PEP_rating_trusted);
    4.84  
    4.85      // Trust again
    4.86 -    [session trustPersonalKey:identBob];
    4.87 +    XCTAssertTrue([session trustPersonalKey:identBob error:&error]);
    4.88 +    XCTAssertNil(error);
    4.89  
    4.90      // Back to green
    4.91      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
    4.92 @@ -580,7 +589,8 @@
    4.93      XCTAssertEqual(rating, PEP_rating_reliable);
    4.94  
    4.95      // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
    4.96 -    [session trustPersonalKey:identBob];
    4.97 +    XCTAssertTrue([session trustPersonalKey:identBob error:&error]);
    4.98 +    XCTAssertNil(error);
    4.99  
   4.100      // This time it should be green
   4.101      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   4.102 @@ -610,7 +620,8 @@
   4.103      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   4.104      XCTAssertEqual(rating, PEP_rating_reliable);
   4.105  
   4.106 -    [session trustPersonalKey:identJohn];
   4.107 +    XCTAssertTrue([session trustPersonalKey:identJohn error:&error]);
   4.108 +    XCTAssertNil(error);
   4.109  
   4.110      // This time it should be green
   4.111      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   4.112 @@ -1012,7 +1023,8 @@
   4.113                                 isOwn:NO
   4.114                                 fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   4.115  
   4.116 -    [session trustPersonalKey:identAlice];
   4.117 +    XCTAssertFalse([session trustPersonalKey:identAlice error:&error]);
   4.118 +    XCTAssertNotNil(error);
   4.119  }
   4.120  
   4.121  /**