From 203d191879bfda702cd0194d331b8b912f77ac09 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Thu, 9 Feb 2023 13:37:12 +0100 Subject: [PATCH 01/29] E3-3 TMP Use get_xor_trustwords_for_fprs --- src/PEPInternalSession.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index 5357e720..51e1248e 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -676,10 +676,10 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) __block size_t sizeWritten = 0; PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) { - return get_trustwords_for_fprs(session, _fpr1, _fpr2, - [[language precomposedStringWithCanonicalMapping] - UTF8String], - trustwords.charPointerPointer, &sizeWritten, full); + return get_xor_trustwords_for_fprs(session, _fpr1, _fpr2, + [[language precomposedStringWithCanonicalMapping] + UTF8String], + trustwords.charPointerPointer, &sizeWritten, full); }]; NSString *result = nil; From 6dc49fcff9f37d615268dd0605d4ff3eda676036 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Thu, 9 Feb 2023 15:30:24 +0100 Subject: [PATCH 02/29] E3-3 Adapt 2.x style enums --- .../PublicHeaders/PEPEngineTypes.h | 80 ++++++++++++------- 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/Subprojects/PEPObjCTypes/PublicHeaders/PEPEngineTypes.h b/Subprojects/PEPObjCTypes/PublicHeaders/PEPEngineTypes.h index b9c814e9..eaef4e76 100644 --- a/Subprojects/PEPObjCTypes/PublicHeaders/PEPEngineTypes.h +++ b/Subprojects/PEPObjCTypes/PublicHeaders/PEPEngineTypes.h @@ -45,6 +45,7 @@ typedef NS_CLOSED_ENUM(int, PEPSyncHandshakeSignal) { PEPSyncHandshakeSignalStart = 126, // SYNC_NOTIFY_START PEPSyncHandshakeSignalStop = 127, // SYNC_NOTIFY_STOP PEPSyncHandshakeSignalPassphraseRequired = 128, // SYNC_PASSPHRASE_REQUIRED + PEPSyncHandshakeSignalGroupInvitation = 192, // SYNC_NOTIFY_GROUP_INVITATION PEPSyncHandshakeSignalSole = 254, // SYNC_NOTIFY_SOLE PEPSyncHandshakeSignalInGroup = 255, // SYNC_NOTIFY_IN_GROUP }; @@ -52,7 +53,7 @@ typedef NS_CLOSED_ENUM(int, PEPSyncHandshakeSignal) { typedef NS_CLOSED_ENUM(int, PEPContentDisposition) { PEPContentDispositionAttachment = 0, // PEP_CONTENT_DISP_ATTACHMENT PEPContentDispositionInline = 1, // PEP_CONTENT_DISP_INLINE - PEPContentDispositionOther = -1, // PEP_CONTENT_DISP_OTHER + PEPContentDispositionOther, // PEP_CONTENT_DISP_OTHER }; typedef NS_CLOSED_ENUM(int, PEPMsgDirection) { @@ -83,28 +84,6 @@ typedef NS_CLOSED_ENUM(int, PEPColor) { PEPColorRed = -1, // PEP_color_red }; -typedef NS_CLOSED_ENUM(int, PEPRating) { - PEPRatingUndefined = 0, // PEP_rating_undefined - PEPRatingCannotDecrypt = 1, // PEP_rating_cannot_decrypt - PEPRatingHaveNoKey = 2, // PEP_rating_have_no_key - PEPRatingUnencrypted = 3, // PEP_rating_unencrypted - PEPRatingUnreliable = 5, // PEP_rating_unreliable - PEPRatingB0rken = -2, // PEP_rating_b0rken - PEPRatingReliable = 6, // PEP_rating_reliable - - // Keep the rating definition for the app, even though media keys - // are not actively used. - // Engine Release_2.1.64, media_key.c: - // `const PEP_rating media_key_message_rating = PEP_rating_unreliable` - PEPRatingMediaKeyProtected = 6, - - PEPRatingTrusted = 7, // PEP_rating_trusted - PEPRatingTrustedAndAnonymized = 8, // PEP_rating_trusted_and_anonymized - PEPRatingFullyAnonymous = 9, // PEP_rating_fully_anonymous - PEPRatingMistrust = -1, // PEP_rating_mistrust - PEPRatingUnderAttack = -3, // PEP_rating_under_attack -}; - typedef NS_CLOSED_ENUM(int, PEPMessageWrapType) { PEPMessageWrapTypeUnwrapped, // PEP_message_unwrapped PEPMessageWrapTypeDefault, // PEP_message_default @@ -127,6 +106,9 @@ typedef NS_CLOSED_ENUM(int, PEPIdentityFlags) { PEPIdentityFlagsNotForSync = 0x0001, // PEP_idf_not_for_sync PEPIdentityFlagsList = 0x0002, // PEP_idf_list PEPIdentityFlagsDeviceGroup = 0x0100, // PEP_idf_devicegroup + PEPIdentityFlagsOrgIdent = 0x0200, // PEP_idf_org_ident + PEPIdentityFlagsGroupIdent = 0x0400, // PEP_idf_group_ident + PEPIdentityFlagsTransportMandatory = 0x0800, // PEP_idf_transport_mandatory }; typedef NS_CLOSED_ENUM(int, PEPCommType) { @@ -180,13 +162,31 @@ typedef NS_CLOSED_ENUM(int, PEPCipherSuite) { PEPCipherSuiteRsa8k = 8, // PEP_CIPHER_SUITE_RSA8K }; +typedef NS_CLOSED_ENUM(int, PEPRating) { + PEPRatingUndefined = 0, // PEP_rating_undefined + PEPRatingCannotDecrypt = 1, // PEP_rating_cannot_decrypt + PEPRatingHaveNoKey = 2, // PEP_rating_have_no_key + PEPRatingUnencrypted = 3, // PEP_rating_unencrypted + PEPRatingUnreliable = 4, // PEP_rating_unreliable + PEPRatingMediaKeyProtected = 5, // PEP_rating_media_key_protected + PEPRatingB0rken = -2, // PEP_rating_b0rken + PEPRatingReliable = 6, // PEP_rating_reliable + PEPRatingTrusted = 7, // PEP_rating_trusted + PEPRatingTrustedAndAnonymized = 8, // PEP_rating_trusted_and_anonymized + PEPRatingFullyAnonymous = 9, // PEP_rating_fully_anonymous + PEPRatingMistrust = -1, // PEP_rating_mistrust + PEPRatingUnderAttack = -3, // PEP_rating_under_attack +}; + typedef NS_CLOSED_ENUM(int, PEPEncFormat) { PEPEncFormatNone = 0, // PEP_enc_none PEPEncFormatPieces = 1, // PEP_enc_pieces PEPEncFormatInline = 1, // PEP_enc_inline - PEPEncFormatSMime, // PEP_enc_S_MIME - PEPEncFormatPGPMime, // PEP_enc_PGP_MIME - PEPEncFormatPEP, // PEP_enc_PEP + PEPEncFormatSMime = 2, // PEP_enc_S_MIME + PEPEncFormatPGPMime = 3, // PEP_enc_PGP_MIME + PEPEncFormatPEPMessageV1 = 3, // PEP_enc_PEP_message_v1 + PEPEncFormatPEP = 4, // PEP_enc_PEP + PEPEncFormatPEPMessageV2 = 4, // PEP_enc_PEP_message_v2 PEPEncFormatPGPMimeOutlook1, // PEP_enc_PGP_MIME_Outlook1 PEPEncFormatInlineEA, // PEP_enc_inline_EA PEPEncFormatAuto = 255, // PEP_enc_auto @@ -223,11 +223,12 @@ typedef NS_CLOSED_ENUM(int, PEPStatus) { PEPStatusCannotSetPGPKeyPair = 0x0382, // PEP_CANNOT_SET_PGP_KEYPAIR PEPStatusCannotSetIdentity = 0x0383, // PEP_CANNOT_SET_IDENTITY PEPStatusCannotSetTrust = 0x0384, // PEP_CANNOT_SET_TRUST - PEPStatusKeyBlacklisted = 0x0385, // PEP_KEY_BLACKLISTED + PEPStatusKeyBlacklisted, // PEP_KEY_BLACKLISTED PEPStatusCannotFindPerson = 0x0386, // PEP_CANNOT_FIND_PERSON - PEPStatusCannotSetPEPVersion = 0X0387, // PEP_CANNOT_SET_PEP_VERSION + PEPStatusCannotSetPEPProtocolVersion = 0X0387, // PEP_CANNOT_SET_PEP_PROTOCOL_VERSION PEPStatusCannotFindAlias = 0x0391, // PEP_CANNOT_FIND_ALIAS PEPStatusCannotSetAlias = 0x0392, // PEP_CANNOT_SET_ALIAS + PEPStatusNoOwnUseridFound = 0x0393, // PEP_NO_OWN_USERID_FOUND PEPStatusUnencrypted = 0x0400, // PEP_UNENCRYPTED PEPStatusVerified = 0x0401, // PEP_VERIFIED PEPStatusDecrypted = 0x0402, // PEP_DECRYPTED @@ -268,18 +269,39 @@ typedef NS_CLOSED_ENUM(int, PEPStatus) { PEPStatusPassphraseRequired = 0x0a00, // PEP_PASSPHRASE_REQUIRED PEPStatusWrongPassphrase = 0x0a01, // PEP_WRONG_PASSPHRASE PEPStatusPassphraseForNewKeysRequired = 0x0a02, // PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED + PEPStatusCannotCreateGroup = 0x0b00, // PEP_CANNOT_CREATE_GROUP + PEPStatusCannotFindGroupEntry = 0x0b01, // PEP_CANNOT_FIND_GROUP_ENTRY + PEPStatusGroupExists = 0x0b02, // PEP_GROUP_EXISTS + PEPStatusGroupNotFound = 0x0b03, // PEP_GROUP_NOT_FOUND + PEPStatusCannotEnableGroup = 0x0b04, // PEP_CANNOT_ENABLE_GROUP + PEPStatusCannotDisableGroup = 0x0b05, // PEP_CANNOT_DISABLE_GROUP + PEPStatusCannotAddGroupMember = 0x0b06, // PEP_CANNOT_ADD_GROUP_MEMBER + PEPStatusCannotDeactivateGroupMember = 0x0b07, // PEP_CANNOT_DEACTIVATE_GROUP_MEMBER + PEPStatusNoMembershipStatusFound = 0x0b08, // PEP_NO_MEMBERSHIP_STATUS_FOUND + PEPStatusCannotLeaveGroup = 0x0b09, // PEP_CANNOT_LEAVE_GROUP + PEPStatusCannotJoinGroup = 0x0b0a, // PEP_CANNOT_JOIN_GROUP + PEPStatusCannotRetrieveMembershipInfo = 0x0b0b, // PEP_CANNOT_RETRIEVE_MEMBERSHIP_INFO PEPStatusDistributionIllegalMessage = 0x1002, // PEP_DISTRIBUTION_ILLEGAL_MESSAGE + PEPStatusStorageIllegalMessage = 0x1102, // PEP_STORAGE_ILLEGAL_MESSAGE + PEPStatusPepmessageIllegalMessage = 0x1202, // PEP_PEPMESSAGE_ILLEGAL_MESSAGE + PEPStatusTransportCannotInit = 0x2000, // PEP_TRANSPORT_CANNOT_INIT + PEPStatusTransportCannotInitSend = 0x2001, // PEP_TRANSPORT_CANNOT_INIT_SEND + PEPStatusTransportCannotInitRecv = 0x2002, // PEP_TRANSPORT_CANNOT_INIT_RECV + PEPStatusTransportDown = 0x2003, // PEP_TRANSPORT_DOWN + PEPStatusTransportError = 0x20ff, // PEP_TRANSPORT_ERROR PEPStatusCommitFailed = 0xff01, // PEP_COMMIT_FAILED PEPStatusMessageConsume = 0xff02, // PEP_MESSAGE_CONSUME PEPStatusMessageIgnore = 0xff03, // PEP_MESSAGE_IGNORE PEPStatusCannotConfig = 0xff04, // PEP_CANNOT_CONFIG + PEPStatusUnboundEnvironmentVariable = -8, // PEP_UNBOUND_ENVIRONMENT_VARIABLE + PEPStatusPathSyntaxError = -7, // PEP_PATH_SYNTAX_ERROR PEPStatusRecordNotFound = -6, // PEP_RECORD_NOT_FOUND PEPStatusCannotCreateTempFile = -5, // PEP_CANNOT_CREATE_TEMP_FILE PEPStatusIllegalValue = -4, // PEP_ILLEGAL_VALUE PEPStatusBufferTooSmall = -3, // PEP_BUFFER_TOO_SMALL PEPStatusOutOfMemory = -2, // PEP_OUT_OF_MEMORY PEPStatusUnknownError = -1, // PEP_UNKNOWN_ERROR - PEPStatusVersionMismatch = -7, // PEP_VERSION_MISMATCH + PEPStatusVersionMismatch = -9, // PEP_VERSION_MISMATCH }; #endif /* PEPEngineTypes_h */ From c73e378beffde9b8cf920219ea0b7cadbbb4b8d4 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Thu, 9 Feb 2023 16:00:33 +0100 Subject: [PATCH 03/29] E3-3 Adapt ratings used in the test to 3.2 reality --- build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m | 8 ++++---- build-mac/pEpObjCAdapterTests/PEPSessionTest.m | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index a2c701b0..10e24b5d 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -263,7 +263,7 @@ XCTAssertTrue([session keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingHaveNoKey); } /// This was once crashing, for historical details, see ENGINE-384. @@ -299,7 +299,7 @@ XCTAssertTrue([session keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingHaveNoKey); } - (void)testOutgoingColors @@ -466,11 +466,11 @@ numRating = [self testOutgoingRatingForMessage:msg session:session error:&error]; XCTAssertNotNil(numRating); XCTAssertNil(error); - XCTAssertEqual(numRating.pEpRating, PEPRatingUnencrypted); + XCTAssertEqual(numRating.pEpRating, PEPRatingReliable); // Rating is also already reliable, since setIdentity has been called already rating = [self ratingForIdentity:identBob session:session]; - XCTAssertEqual(rating, PEPRatingHaveNoKey); + XCTAssertEqual(rating, PEPRatingReliable); // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity XCTAssertTrue([session trustPersonalKey:identBob error:&error]); diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 52e4f372..8c567114 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -247,7 +247,7 @@ XCTAssertTrue([self keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable); + XCTAssertEqual([self ratingForIdentity:alice], PEPRatingHaveNoKey); XCTAssertTrue([self keyMistrusted:alice error:&error]); XCTAssertNil(error); From a8ec1f94bc85af0663dd3a216c497911d68ca33d Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Thu, 9 Feb 2023 16:10:06 +0100 Subject: [PATCH 04/29] Revert "E3-3 Adapt ratings used in the test to 3.2 reality" This reverts commit c73e378beffde9b8cf920219ea0b7cadbbb4b8d4. --- build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m | 8 ++++---- build-mac/pEpObjCAdapterTests/PEPSessionTest.m | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index 10e24b5d..a2c701b0 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -263,7 +263,7 @@ XCTAssertTrue([session keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingHaveNoKey); + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); } /// This was once crashing, for historical details, see ENGINE-384. @@ -299,7 +299,7 @@ XCTAssertTrue([session keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingHaveNoKey); + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); } - (void)testOutgoingColors @@ -466,11 +466,11 @@ numRating = [self testOutgoingRatingForMessage:msg session:session error:&error]; XCTAssertNotNil(numRating); XCTAssertNil(error); - XCTAssertEqual(numRating.pEpRating, PEPRatingReliable); + XCTAssertEqual(numRating.pEpRating, PEPRatingUnencrypted); // Rating is also already reliable, since setIdentity has been called already rating = [self ratingForIdentity:identBob session:session]; - XCTAssertEqual(rating, PEPRatingReliable); + XCTAssertEqual(rating, PEPRatingHaveNoKey); // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity XCTAssertTrue([session trustPersonalKey:identBob error:&error]); diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 8c567114..52e4f372 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -247,7 +247,7 @@ XCTAssertTrue([self keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice], PEPRatingHaveNoKey); + XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable); XCTAssertTrue([self keyMistrusted:alice error:&error]); XCTAssertNil(error); From 7e9d2e4fedde3a3e50e1b1b86d96398d90c08bc8 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 08:14:22 +0100 Subject: [PATCH 05/29] E3-3 Adapt to minor API change (removal of an unused parameter) --- src/PEPSync.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PEPSync.m b/src/PEPSync.m index 47f0ab84..ccee0739 100644 --- a/src/PEPSync.m +++ b/src/PEPSync.m @@ -262,7 +262,7 @@ static __weak PEPSync *s_pEpSync; s_notifyHandshake, s_retrieve_next_sync_event); if (status == PEP_STATUS_OK) { - status = do_sync_protocol(self.syncLoopSession.session, nil); + status = do_sync_protocol(self.syncLoopSession.session); if (status != PEP_STATUS_OK) { LogError(@"do_sync_protocol returned PEP_STATUS %d", status); LogInfo(@"sync loop is NOT running"); From 01e6892d94b26bbbe9069d94e8214048d2ce1a33 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 09:02:25 +0100 Subject: [PATCH 06/29] E3-3 Remove the log test --- build-mac/pEpObjCAdapterTests/PEPSessionTest.m | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 52e4f372..b02010f0 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -277,17 +277,6 @@ } } -- (void)testGetLogWithError -{ - NSError *error = nil; - NSString *log = [self getLogWithError:&error]; - - XCTAssertGreaterThan(log.length, 0); - - XCTAssertNotNil(log); - XCTAssertNil(error); -} - - (void)testGetTrustwords { PEPIdentity *partner1Orig = [[PEPIdentity alloc] From dfaa61884d767844a6b66967aa5b31b64f1ec456 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 09:07:47 +0100 Subject: [PATCH 07/29] E3-3 Remove the trustwords method that can't be supported anymore --- .../PublicHeaders/PEPSessionProtocol.h | 7 ----- src/PEPInternalSession.h | 7 ----- src/PEPInternalSession.m | 28 ------------------- src/PEPSession.m | 22 --------------- 4 files changed, 64 deletions(-) diff --git a/Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPSessionProtocol.h b/Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPSessionProtocol.h index 98817db0..e809a4ad 100644 --- a/Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPSessionProtocol.h +++ b/Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPSessionProtocol.h @@ -130,13 +130,6 @@ extern NSString *const _Nonnull PEPObjCAdapterErrorDomain; errorCallback:(void (^)(NSError *error))errorCallback successCallback:(void (^)(NSString *trustwords))successCallback; -- (void)getTrustwordsFpr1:(NSString *)fpr1 - fpr2:(NSString *)fpr2 - language:(NSString *_Nullable)language - full:(BOOL)full - errorCallback:(void (^)(NSError *error))errorCallback - successCallback:(void (^)(NSString *trustwords))successCallback; - - (void)languageList:(void (^)(NSError *error))errorCallback successCallback:(void (^)(NSArray *languages))successCallback; diff --git a/src/PEPInternalSession.h b/src/PEPInternalSession.h index 80200d31..eec60477 100644 --- a/src/PEPInternalSession.h +++ b/src/PEPInternalSession.h @@ -195,13 +195,6 @@ NS_ASSUME_NONNULL_BEGIN full:(BOOL)full error:(NSError * _Nullable * _Nullable)error; -/** Determine trustwords for two fprs */ -- (NSString * _Nullable)getTrustwordsFpr1:(NSString *)fpr1 - fpr2:(NSString *)fpr2 - language:(NSString * _Nullable)language - full:(BOOL)full - error:(NSError * _Nullable * _Nullable)error; - /** @returns The list of supported languages for trustwords. */ diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index 51e1248e..9f5b676b 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -663,34 +663,6 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) return result; } -- (NSString * _Nullable)getTrustwordsFpr1:(NSString * _Nonnull)fpr1 - fpr2:(NSString * _Nonnull)fpr2 - language:(NSString * _Nullable)language - full:(BOOL)full - error:(NSError * _Nullable * _Nullable)error -{ - const char *_fpr1 = [fpr1 UTF8String]; // fprs are NFC normalized anyway - const char *_fpr2 = [fpr2 UTF8String]; - - PEPAutoPointer *trustwords = [PEPAutoPointer new]; - __block size_t sizeWritten = 0; - - PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) { - return get_xor_trustwords_for_fprs(session, _fpr1, _fpr2, - [[language precomposedStringWithCanonicalMapping] - UTF8String], - trustwords.charPointerPointer, &sizeWritten, full); - }]; - - NSString *result = nil; - - if (![PEPStatusNSErrorUtil setError:error fromPEPStatus:status]) { - result = [NSString stringWithUTF8String:trustwords.charPointer]; - } - - return result; -} - - (NSArray * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error { PEPAutoPointer *chLangs = [PEPAutoPointer new]; diff --git a/src/PEPSession.m b/src/PEPSession.m index c471a7ff..c0c38cd0 100644 --- a/src/PEPSession.m +++ b/src/PEPSession.m @@ -411,28 +411,6 @@ successCallback:(void (^)(NSString *log))successCallback }); } -- (void)getTrustwordsFpr1:(NSString *)fpr1 - fpr2:(NSString *)fpr2 - language:(NSString * _Nullable)language - full:(BOOL)full - errorCallback:(void (^)(NSError *error))errorCallback - successCallback:(void (^)(NSString *trustwords))successCallback -{ - dispatch_async(queue, ^{ - NSError *error = nil; - NSString *trustwords = [[PEPSessionProvider session] getTrustwordsFpr1:fpr1 - fpr2:fpr2 - language:language - full:full - error:&error]; - if (trustwords) { - successCallback(trustwords); - } else { - errorCallback(error); - } - }); -} - - (void)languageList:(void (^)(NSError *error))errorCallback successCallback:(void (^)(NSArray *languages))successCallback From 5cbec3bbd6d6b0f0d7bfa476e61cfab39df94f83 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 09:10:57 +0100 Subject: [PATCH 08/29] E3-3 Coding guidelines --- .../PEPInternalSessionTest.m | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index a2c701b0..e3af4f85 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -694,24 +694,34 @@ PEPInternalSession *session = [PEPSessionProvider session]; PEPIdentity *partner1Orig = [[PEPIdentity alloc] - initWithAddress:@"partner1@dontcare.me" userID:@"partner1" + initWithAddress:@"partner1@dontcare.me" + userID:@"partner1" userName:@"partner1" - isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; + isOwn:NO + fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; PEPIdentity *meOrig = [[PEPIdentity alloc] - initWithAddress:@"me@dontcare.me" userID:@"me" + initWithAddress:@"me@dontcare.me" + userID:@"me" userName:@"me" - isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; + isOwn:NO + fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; NSError *error = nil; - NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig - language:@"en" full:YES error:&error]; + NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig + identity2:partner1Orig + language:@"en" + full:YES + error:&error]; XCTAssertNil(error); XCTAssertEqualObjects(trustwordsFull, @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); - NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig - language:@"ZZ" full:YES error:&error]; + NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig + identity2:partner1Orig + language:@"ZZ" + full:YES + error:&error]; XCTAssertNotNil(error); XCTAssertNil(trustwordsUndefined); } From a97f370204d7d6db0d123861c048a589b25c9bbb Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 10:00:40 +0100 Subject: [PATCH 09/29] E3-3 Use update_identity just before getting trustwords --- src/PEPInternalSession.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index 9f5b676b..f035e0cd 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -638,13 +638,23 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) full:(BOOL)full error:(NSError * _Nullable * _Nullable)error { - pEp_identity *ident1 = [identity1 toStruct]; - pEp_identity *ident2 = [identity2 toStruct]; + __block pEp_identity *ident1 = [identity1 toStruct]; + __block pEp_identity *ident2 = [identity2 toStruct]; PEPAutoPointer *trustwords = [PEPAutoPointer new]; __block size_t sizeWritten = 0; PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) { + PEP_STATUS updateStatus = update_identity(session, ident1); + if (PEP_STATUS_is_error(updateStatus)) { + return updateStatus; + } + + updateStatus = update_identity(session, ident2); + if (PEP_STATUS_is_error(updateStatus)) { + return updateStatus; + } + return get_trustwords(session, ident1, ident2, [[language precomposedStringWithCanonicalMapping] UTF8String], From 02f1702d61bddd62dd04566717820df8ea75569c Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 11:00:21 +0100 Subject: [PATCH 10/29] E3-3 An array of identities? --- src/PEPInternalSession.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index f035e0cd..6bcfd0f4 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -640,19 +640,19 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) { __block pEp_identity *ident1 = [identity1 toStruct]; __block pEp_identity *ident2 = [identity2 toStruct]; + NSArray *identities = @[[NSValue valueWithPointer:ident1], [NSValue valueWithPointer:ident2]]; PEPAutoPointer *trustwords = [PEPAutoPointer new]; __block size_t sizeWritten = 0; PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) { - PEP_STATUS updateStatus = update_identity(session, ident1); - if (PEP_STATUS_is_error(updateStatus)) { - return updateStatus; - } + for (NSValue *valueIdentity in identities) { + pEp_identity *ident = [valueIdentity pointerValue]; - updateStatus = update_identity(session, ident2); - if (PEP_STATUS_is_error(updateStatus)) { - return updateStatus; + PEP_STATUS updateStatus = update_identity(session, ident); + if (PEP_STATUS_is_error(updateStatus)) { + return updateStatus; + } } return get_trustwords(session, ident1, ident2, From 8d021198f0a1489fec2f2d522707cdf822b4431d Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 11:00:39 +0100 Subject: [PATCH 11/29] Revert "E3-3 An array of identities?" This reverts commit 02f1702d61bddd62dd04566717820df8ea75569c. --- src/PEPInternalSession.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index 6bcfd0f4..f035e0cd 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -640,19 +640,19 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) { __block pEp_identity *ident1 = [identity1 toStruct]; __block pEp_identity *ident2 = [identity2 toStruct]; - NSArray *identities = @[[NSValue valueWithPointer:ident1], [NSValue valueWithPointer:ident2]]; PEPAutoPointer *trustwords = [PEPAutoPointer new]; __block size_t sizeWritten = 0; PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) { - for (NSValue *valueIdentity in identities) { - pEp_identity *ident = [valueIdentity pointerValue]; + PEP_STATUS updateStatus = update_identity(session, ident1); + if (PEP_STATUS_is_error(updateStatus)) { + return updateStatus; + } - PEP_STATUS updateStatus = update_identity(session, ident); - if (PEP_STATUS_is_error(updateStatus)) { - return updateStatus; - } + updateStatus = update_identity(session, ident2); + if (PEP_STATUS_is_error(updateStatus)) { + return updateStatus; } return get_trustwords(session, ident1, ident2, From 836256db41d967e2e787e765817e434d99530016 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 12:17:29 +0100 Subject: [PATCH 12/29] E3-3 Note TODO for notifyHandshake with NULL identities --- src/PEPSync.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PEPSync.m b/src/PEPSync.m index ccee0739..3ab7ed9e 100644 --- a/src/PEPSync.m +++ b/src/PEPSync.m @@ -398,6 +398,8 @@ static __weak PEPSync *s_pEpSync; PEPIdentity *partnerIdentity = partner != nil ? [PEPIdentity fromStruct:partner] : nil; free_identity(partner); + // TODO: Do NULL `pEp_identity` make even remotely sense? + return (PEP_STATUS) [self.notifyHandshakeDelegate notifyHandshake:NULL me:meIdentity From 307ece724eaefaaacdf51bc7104e94641adfe412 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 12:34:44 +0100 Subject: [PATCH 13/29] Revert "E3-3 Note TODO for notifyHandshake with NULL identities" This reverts commit 836256db41d967e2e787e765817e434d99530016. --- src/PEPSync.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PEPSync.m b/src/PEPSync.m index 3ab7ed9e..ccee0739 100644 --- a/src/PEPSync.m +++ b/src/PEPSync.m @@ -398,8 +398,6 @@ static __weak PEPSync *s_pEpSync; PEPIdentity *partnerIdentity = partner != nil ? [PEPIdentity fromStruct:partner] : nil; free_identity(partner); - // TODO: Do NULL `pEp_identity` make even remotely sense? - return (PEP_STATUS) [self.notifyHandshakeDelegate notifyHandshake:NULL me:meIdentity From 6ff22085f3003d11d044bb1d1de88ad953a1074f Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 10 Feb 2023 15:22:12 +0100 Subject: [PATCH 14/29] E3-3 Logic for myself vs update_identity --- src/PEPInternalSession.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index f035e0cd..040115b9 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -645,12 +645,21 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) __block size_t sizeWritten = 0; PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) { - PEP_STATUS updateStatus = update_identity(session, ident1); + PEP_STATUS (^updateIdentity)(pEp_identity *identity) = + ^(pEp_identity *identity) { + if (identity->me) { + return myself(session, identity); + } else { + return update_identity(session, identity); + } + }; + + PEP_STATUS updateStatus = updateIdentity(ident1); if (PEP_STATUS_is_error(updateStatus)) { return updateStatus; } - updateStatus = update_identity(session, ident2); + updateStatus = updateIdentity(ident2); if (PEP_STATUS_is_error(updateStatus)) { return updateStatus; } From 68ca55149657bc978fe0aeddab0468a8518737b3 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 09:28:58 +0100 Subject: [PATCH 15/29] E3-3 Fix some readme parts --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 514d107f..2542dc0a 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Install Xcode (if not installed already) ### Apple ID -You need to have an Apple ID (connected to pEp team account) configured in Xcode . Ask `#service`, if you want to be added to the team account. +You need to have an Apple ID (connected to pEp team account) configured in Xcode . Ask `#service`, if you want to be added to the team account. ## Build Dependencies ``` @@ -65,7 +65,7 @@ git clone https://gitea.pep.foundation/pep.foundation/pEpObjCAdapter.git ## Build for iOS -### iOS Only: Copy System DB +### iOS Only: Copy System DB The `system.db` from the pEpEngine repository must be copied in the bundle that uses the pEpObjCAdapter.a static lib. The ObjCAdapter copies it at runtime in the desired directory. @@ -73,13 +73,13 @@ Backround: Has been introduces to use Apple Shared App Directory of the client A ### Using Xcode UI -`open pEpObjCAdapter/pEpObjCAdapter.xcworkspace/` +`open build-mac/pEpObjCAdapter.xcodeproj/` Build scheme "pEpObjCAdapter_iOS". ### Using terminal -`xcodebuild -workspace "pEpObjCAdapter.xcworkspace" -scheme "PEPObjCAdapter_iOS" -configuration RELEASE` +`xcodebuild -workspace "build-mac/pEpObjCAdapter.xcodeproj/" -scheme "PEPObjCAdapter_iOS" -configuration RELEASE` (or DEBUG) @@ -113,6 +113,6 @@ Build scheme "PEPObjCAdapter_macOS". You can find the build artefacts in the `pEpMacOSAdapter/build` folder -# HowToBuild pEpObjCAdapter for Linux +# How to build pEpObjCAdapter for Linux -See pEpObjCAdapter/pEpObjCAdapter/build-linux/README.md \ No newline at end of file +See pEpObjCAdapter/pEpObjCAdapter/build-linux/README.md From ce50e715542590e8c1b6797ef27bb38e59b920a9 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 09:48:50 +0100 Subject: [PATCH 16/29] E3-3 Fix testOutgoingBccColors --- build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index e3af4f85..c00e2985 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -462,15 +462,15 @@ XCTAssertTrue([session updateIdentity:identBob error:&error]); XCTAssertNil(error); - // setIdentity has already been called by the import, so reliable + // `setIdentity` has already been called by the import, so message rating should be reliable. numRating = [self testOutgoingRatingForMessage:msg session:session error:&error]; XCTAssertNotNil(numRating); XCTAssertNil(error); - XCTAssertEqual(numRating.pEpRating, PEPRatingUnencrypted); + XCTAssertEqual(numRating.pEpRating, PEPRatingReliable); - // Rating is also already reliable, since setIdentity has been called already + // Identity rating is also already reliable, since setIdentity has been called already. rating = [self ratingForIdentity:identBob session:session]; - XCTAssertEqual(rating, PEPRatingHaveNoKey); + XCTAssertEqual(rating, PEPRatingReliable); // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity XCTAssertTrue([session trustPersonalKey:identBob error:&error]); From 93398788bfb61b524fa0977bbbd6833b9c3b43ec Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 09:51:41 +0100 Subject: [PATCH 17/29] E3-3 Adapt two tests to current reality * testIdentityRatingTrustResetMistrustUndo * testIdentityRatingCrash Both cases are in clarification: https://gitea.pep.foundation/pEp.foundation/pEpEngine/issues/127 --- build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index c00e2985..63612cd3 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -263,7 +263,8 @@ XCTAssertTrue([session keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); + // https://gitea.pep.foundation/pEp.foundation/pEpEngine/issues/127 + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingHaveNoKey); } /// This was once crashing, for historical details, see ENGINE-384. @@ -299,7 +300,8 @@ XCTAssertTrue([session keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); + // https://gitea.pep.foundation/pEp.foundation/pEpEngine/issues/127 + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingHaveNoKey); } - (void)testOutgoingColors From ddc7818fb96165c36d680fb07a7123d6dd9c8ea5 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 10:05:08 +0100 Subject: [PATCH 18/29] E3-3 Adapt test to current reality * testIdentityRatingTrustResetMistrustUndo Clarification: https://gitea.pep.foundation/pEp.foundation/pEpEngine/issues/127 --- build-mac/pEpObjCAdapterTests/PEPSessionTest.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index b02010f0..0ee47c7c 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -247,7 +247,8 @@ XCTAssertTrue([self keyResetTrust:alice error:&error]); XCTAssertNil(error); - XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable); + // https://gitea.pep.foundation/pEp.foundation/pEpEngine/issues/127 + XCTAssertEqual([self ratingForIdentity:alice], PEPRatingHaveNoKey); XCTAssertTrue([self keyMistrusted:alice error:&error]); XCTAssertNil(error); From 2261200b0d3354ab0197a4f6a48df10d50bd30be Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 11:16:41 +0100 Subject: [PATCH 19/29] E3-3 Try to get testGetTrustwords running with pre-defined keys --- .../PEPInternalSessionTest.m | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index 63612cd3..a37ee8cf 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -695,23 +695,27 @@ { PEPInternalSession *session = [PEPSessionProvider session]; - PEPIdentity *partner1Orig = [[PEPIdentity alloc] - initWithAddress:@"partner1@dontcare.me" - userID:@"partner1" - userName:@"partner1" - isOwn:NO - fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; + PEPIdentity *me = [self + checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc" + address:@"pep.test.alice@pep-project.org" + userID:@"Alice_User_ID" + fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97" + session:session]; + XCTAssertEqual([self ratingForIdentity:me session:session], PEPRatingTrustedAndAnonymized); - PEPIdentity *meOrig = [[PEPIdentity alloc] - initWithAddress:@"me@dontcare.me" - userID:@"me" - userName:@"me" - isOwn:NO - fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; + PEPIdentity *alice = [self + checkImportingKeyFilePath:@"6FF00E97_sec.asc" + address:@"pep.test.alice@pep-project.org" + userID:@"This Is Alice" + fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97" + session: session]; + XCTAssertNotNil(alice); + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); NSError *error = nil; - NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig - identity2:partner1Orig + + NSString *trustwordsFull = [session getTrustwordsIdentity1:me + identity2:alice language:@"en" full:YES error:&error]; @@ -719,8 +723,8 @@ XCTAssertEqualObjects(trustwordsFull, @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); - NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig - identity2:partner1Orig + NSString *trustwordsUndefined = [session getTrustwordsIdentity1:me + identity2:alice language:@"ZZ" full:YES error:&error]; From 3f1fdf4d70e5f9260192ac2130491dd06d966592 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 11:30:07 +0100 Subject: [PATCH 20/29] E3-3 Can't easily test trustwords anymore --- .../PEPInternalSessionTest.m | 41 ------------------- .../pEpObjCAdapterTests/PEPSessionTest.m | 25 ----------- 2 files changed, 66 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index a37ee8cf..8e5862b2 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -691,47 +691,6 @@ XCTAssertEqual(color, PEPRatingReliable); } -- (void)testGetTrustwords -{ - PEPInternalSession *session = [PEPSessionProvider session]; - - PEPIdentity *me = [self - checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc" - address:@"pep.test.alice@pep-project.org" - userID:@"Alice_User_ID" - fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97" - session:session]; - XCTAssertEqual([self ratingForIdentity:me session:session], PEPRatingTrustedAndAnonymized); - - PEPIdentity *alice = [self - checkImportingKeyFilePath:@"6FF00E97_sec.asc" - address:@"pep.test.alice@pep-project.org" - userID:@"This Is Alice" - fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97" - session: session]; - XCTAssertNotNil(alice); - XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); - - NSError *error = nil; - - NSString *trustwordsFull = [session getTrustwordsIdentity1:me - identity2:alice - language:@"en" - full:YES - error:&error]; - XCTAssertNil(error); - XCTAssertEqualObjects(trustwordsFull, - @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); - - NSString *trustwordsUndefined = [session getTrustwordsIdentity1:me - identity2:alice - language:@"ZZ" - full:YES - error:&error]; - XCTAssertNotNil(error); - XCTAssertNil(trustwordsUndefined); -} - - (void)testStringToRating { PEPInternalSession *session = [PEPSessionProvider session]; diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 0ee47c7c..101e57c1 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -278,31 +278,6 @@ } } -- (void)testGetTrustwords -{ - PEPIdentity *partner1Orig = [[PEPIdentity alloc] - initWithAddress:@"partner1@dontcare.me" userID:@"partner1" - userName:@"partner1" - isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; - - PEPIdentity *meOrig = [[PEPIdentity alloc] - initWithAddress:@"me@dontcare.me" userID:@"me" - userName:@"me" - isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; - - NSError *error = nil; - NSString *trustwordsFull = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig - language:@"en" full:YES error:&error]; - XCTAssertNil(error); - XCTAssertEqualObjects(trustwordsFull, - @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); - - NSString *trustwordsUndefined = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig - language:@"ZZ" full:YES error:&error]; - XCTAssertNotNil(error); - XCTAssertNil(trustwordsUndefined); -} - - (void)testGenKey { PEPIdentity *identMe = [[PEPIdentity alloc] From 8aefbe416eaa8190875828e6e6ca9d127cf203fc Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 11:30:15 +0100 Subject: [PATCH 21/29] Revert "E3-3 Can't easily test trustwords anymore" This reverts commit 3f1fdf4d70e5f9260192ac2130491dd06d966592. --- .../PEPInternalSessionTest.m | 41 +++++++++++++++++++ .../pEpObjCAdapterTests/PEPSessionTest.m | 25 +++++++++++ 2 files changed, 66 insertions(+) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index 8e5862b2..a37ee8cf 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -691,6 +691,47 @@ XCTAssertEqual(color, PEPRatingReliable); } +- (void)testGetTrustwords +{ + PEPInternalSession *session = [PEPSessionProvider session]; + + PEPIdentity *me = [self + checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc" + address:@"pep.test.alice@pep-project.org" + userID:@"Alice_User_ID" + fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97" + session:session]; + XCTAssertEqual([self ratingForIdentity:me session:session], PEPRatingTrustedAndAnonymized); + + PEPIdentity *alice = [self + checkImportingKeyFilePath:@"6FF00E97_sec.asc" + address:@"pep.test.alice@pep-project.org" + userID:@"This Is Alice" + fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97" + session: session]; + XCTAssertNotNil(alice); + XCTAssertEqual([self ratingForIdentity:alice session:session], PEPRatingReliable); + + NSError *error = nil; + + NSString *trustwordsFull = [session getTrustwordsIdentity1:me + identity2:alice + language:@"en" + full:YES + error:&error]; + XCTAssertNil(error); + XCTAssertEqualObjects(trustwordsFull, + @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); + + NSString *trustwordsUndefined = [session getTrustwordsIdentity1:me + identity2:alice + language:@"ZZ" + full:YES + error:&error]; + XCTAssertNotNil(error); + XCTAssertNil(trustwordsUndefined); +} + - (void)testStringToRating { PEPInternalSession *session = [PEPSessionProvider session]; diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 101e57c1..0ee47c7c 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -278,6 +278,31 @@ } } +- (void)testGetTrustwords +{ + PEPIdentity *partner1Orig = [[PEPIdentity alloc] + initWithAddress:@"partner1@dontcare.me" userID:@"partner1" + userName:@"partner1" + isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; + + PEPIdentity *meOrig = [[PEPIdentity alloc] + initWithAddress:@"me@dontcare.me" userID:@"me" + userName:@"me" + isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; + + NSError *error = nil; + NSString *trustwordsFull = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig + language:@"en" full:YES error:&error]; + XCTAssertNil(error); + XCTAssertEqualObjects(trustwordsFull, + @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); + + NSString *trustwordsUndefined = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig + language:@"ZZ" full:YES error:&error]; + XCTAssertNotNil(error); + XCTAssertNil(trustwordsUndefined); +} + - (void)testGenKey { PEPIdentity *identMe = [[PEPIdentity alloc] From 0c12bfb8b340b14a12c2d06c173f58d530568cd8 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 11:37:34 +0100 Subject: [PATCH 22/29] E3-3 Keep the internal session (failing) trustwords test --- .../PEPInternalSessionTest.m | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index a37ee8cf..0e57e7bd 100644 --- a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m @@ -691,7 +691,7 @@ XCTAssertEqual(color, PEPRatingReliable); } -- (void)testGetTrustwords +- (void)testGetTrustwordsFail { PEPInternalSession *session = [PEPSessionProvider session]; @@ -714,22 +714,14 @@ NSError *error = nil; - NSString *trustwordsFull = [session getTrustwordsIdentity1:me - identity2:alice - language:@"en" - full:YES - error:&error]; - XCTAssertNil(error); - XCTAssertEqualObjects(trustwordsFull, - @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); - - NSString *trustwordsUndefined = [session getTrustwordsIdentity1:me - identity2:alice - language:@"ZZ" - full:YES - error:&error]; + // Expected fail with 3.2, because the partner will be counted as PGP user. + XCTAssertNil([session getTrustwordsIdentity1:me + identity2:alice + language:@"en" + full:YES + error:&error]); XCTAssertNotNil(error); - XCTAssertNil(trustwordsUndefined); + XCTAssertEqual(error.code, PEPStatusTrustwordNotFound); } - (void)testStringToRating From 0c1ac747a1eba44beecc8a498ff3287105c024e5 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Mon, 13 Feb 2023 11:39:57 +0100 Subject: [PATCH 23/29] E3-3 Remove the outer session trustwords test --- .../pEpObjCAdapterTests/PEPSessionTest.m | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 0ee47c7c..101e57c1 100644 --- a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m +++ b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m @@ -278,31 +278,6 @@ } } -- (void)testGetTrustwords -{ - PEPIdentity *partner1Orig = [[PEPIdentity alloc] - initWithAddress:@"partner1@dontcare.me" userID:@"partner1" - userName:@"partner1" - isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; - - PEPIdentity *meOrig = [[PEPIdentity alloc] - initWithAddress:@"me@dontcare.me" userID:@"me" - userName:@"me" - isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; - - NSError *error = nil; - NSString *trustwordsFull = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig - language:@"en" full:YES error:&error]; - XCTAssertNil(error); - XCTAssertEqualObjects(trustwordsFull, - @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); - - NSString *trustwordsUndefined = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig - language:@"ZZ" full:YES error:&error]; - XCTAssertNotNil(error); - XCTAssertNil(trustwordsUndefined); -} - - (void)testGenKey { PEPIdentity *identMe = [[PEPIdentity alloc] From 050048baf81a653414c9534c375d608bdb4bfce5 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Thu, 16 Feb 2023 17:11:23 +0100 Subject: [PATCH 24/29] E3-3 Log engine call threads --- src/PEPPassphraseUtil.m | 5 ++++- src/PEPSessionProvider.m | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/PEPPassphraseUtil.m b/src/PEPPassphraseUtil.m index 30ae58aa..afe994e0 100644 --- a/src/PEPPassphraseUtil.m +++ b/src/PEPPassphraseUtil.m @@ -42,6 +42,8 @@ // The passphrase worked, so reset its timeout [[PEPPassphraseCache sharedInstance] resetTimeoutForPassphrase:passphrase]; + NSLog(@"*** %@ status: %d", [[NSThread currentThread] name], lastStatus); + return (PEPStatus) lastStatus; } } @@ -49,7 +51,8 @@ // If execution lands here, it means we ran out of passwords to set while // receiving password-related error codes. return [self tryPassphraseProviderSession:session - lastStatus:lastStatus block:block]; + lastStatus:lastStatus + block:block]; } #pragma mark - Private diff --git a/src/PEPSessionProvider.m b/src/PEPSessionProvider.m index 0e82bb6b..ecf44cc3 100644 --- a/src/PEPSessionProvider.m +++ b/src/PEPSessionProvider.m @@ -6,6 +6,8 @@ // Copyright © 2017 p≡p. All rights reserved. // +#include + #import "PEPSessionProvider.h" #import "PEPObjCAdapter+ReadConfig.h" @@ -56,6 +58,29 @@ static PEPInternalSession *s_sessionForMainThread = nil; [[self sessionForThreadLock] unlock]; + pthread_t thread = pthread_self(); + uint64_t thread_id; + int success = pthread_threadid_np(thread, &thread_id); + assert(success == 0); + + NSString *label = @"posix"; + NSString *threadIdString = [NSString stringWithFormat:@"%@ %llu", label, thread_id]; + + NSString *threadName = [[NSThread currentThread] name]; + if (!threadName) { + threadName = @""; + } + if ([threadName isEqualToString:@""]) { + [[NSThread currentThread] setName:threadIdString]; + } else { + if (![threadName containsString:label]) { + NSString *combinedThreadName = [NSString stringWithFormat:@"%@ (%@)", + threadName, + threadIdString]; + [[NSThread currentThread] setName:combinedThreadName]; + } + } + return newOrExistingSession; } From fb5a76e2ff7a8f72734270051353fa556f385838 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 17 Feb 2023 10:40:52 +0100 Subject: [PATCH 25/29] E3-3 Also logging the calling --- src/PEPPassphraseUtil.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PEPPassphraseUtil.m b/src/PEPPassphraseUtil.m index afe994e0..d52500c2 100644 --- a/src/PEPPassphraseUtil.m +++ b/src/PEPPassphraseUtil.m @@ -36,6 +36,8 @@ return (PEPStatus) status; } + NSLog(@"*** %@ calling ...", [[NSThread currentThread] name]); + lastStatus = block(session); if (lastStatus != PEP_PASSPHRASE_REQUIRED && lastStatus != PEP_WRONG_PASSPHRASE) { From 5c77a34966b4262dc32c28663c74037a37e90515 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Wed, 22 Feb 2023 13:25:59 +0100 Subject: [PATCH 26/29] E3-3 Roll back the thread logging --- src/PEPPassphraseUtil.m | 4 ---- src/PEPSessionProvider.m | 49 +++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/PEPPassphraseUtil.m b/src/PEPPassphraseUtil.m index d52500c2..583ad16f 100644 --- a/src/PEPPassphraseUtil.m +++ b/src/PEPPassphraseUtil.m @@ -36,16 +36,12 @@ return (PEPStatus) status; } - NSLog(@"*** %@ calling ...", [[NSThread currentThread] name]); - lastStatus = block(session); if (lastStatus != PEP_PASSPHRASE_REQUIRED && lastStatus != PEP_WRONG_PASSPHRASE) { // The passphrase worked, so reset its timeout [[PEPPassphraseCache sharedInstance] resetTimeoutForPassphrase:passphrase]; - NSLog(@"*** %@ status: %d", [[NSThread currentThread] name], lastStatus); - return (PEPStatus) lastStatus; } } diff --git a/src/PEPSessionProvider.m b/src/PEPSessionProvider.m index ecf44cc3..48fd085b 100644 --- a/src/PEPSessionProvider.m +++ b/src/PEPSessionProvider.m @@ -32,6 +32,32 @@ static PEPInternalSession *s_sessionForMainThread = nil; #pragma mark - Public API +void annotatedThreadname(void) +{ + pthread_t thread = pthread_self(); + uint64_t thread_id; + int success = pthread_threadid_np(thread, &thread_id); + assert(success == 0); + + NSString *label = @"posix"; + NSString *threadIdString = [NSString stringWithFormat:@"%@ %llu", label, thread_id]; + + NSString *threadName = [[NSThread currentThread] name]; + if (!threadName) { + threadName = @""; + } + if ([threadName isEqualToString:@""]) { + [[NSThread currentThread] setName:threadIdString]; + } else { + if (![threadName containsString:label]) { + NSString *combinedThreadName = [NSString stringWithFormat:@"%@ (%@)", + threadName, + threadIdString]; + [[NSThread currentThread] setName:combinedThreadName]; + } + } +} + + (PEPInternalSession * _Nonnull)session { // Assure a session for the main thread exists and is kept alive before anyother session is created. @@ -58,29 +84,6 @@ static PEPInternalSession *s_sessionForMainThread = nil; [[self sessionForThreadLock] unlock]; - pthread_t thread = pthread_self(); - uint64_t thread_id; - int success = pthread_threadid_np(thread, &thread_id); - assert(success == 0); - - NSString *label = @"posix"; - NSString *threadIdString = [NSString stringWithFormat:@"%@ %llu", label, thread_id]; - - NSString *threadName = [[NSThread currentThread] name]; - if (!threadName) { - threadName = @""; - } - if ([threadName isEqualToString:@""]) { - [[NSThread currentThread] setName:threadIdString]; - } else { - if (![threadName containsString:label]) { - NSString *combinedThreadName = [NSString stringWithFormat:@"%@ (%@)", - threadName, - threadIdString]; - [[NSThread currentThread] setName:combinedThreadName]; - } - } - return newOrExistingSession; } From 634eddec75a5f2291e922ad75604bd1a3978202b Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 24 Feb 2023 13:37:31 +0100 Subject: [PATCH 27/29] E3-3 Format --- src/PEPInternalSession.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PEPInternalSession.m b/src/PEPInternalSession.m index 040115b9..3955ba9b 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -664,10 +664,14 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys) return updateStatus; } - return get_trustwords(session, ident1, ident2, + return get_trustwords(session, + ident1, + ident2, [[language precomposedStringWithCanonicalMapping] UTF8String], - trustwords.charPointerPointer, &sizeWritten, full); + trustwords.charPointerPointer, + &sizeWritten, + full); }]; free_identity(ident1); From 116a49965f86909572a5902b010d7af842bbf88f Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 24 Feb 2023 14:05:26 +0100 Subject: [PATCH 28/29] E3-3 Debug SYNC_NOTIFY_INIT_FORM_GROUP --- src/PEPSync.m | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/PEPSync.m b/src/PEPSync.m index ccee0739..dd36f50f 100644 --- a/src/PEPSync.m +++ b/src/PEPSync.m @@ -14,6 +14,7 @@ #import "PEPSync_Internal.h" #import "message_api.h" +#import "pEpEngine.h" #import "PEPSendMessageDelegate.h" #import "PEPNotifyHandshakeDelegate.h" @@ -387,10 +388,42 @@ static __weak PEPSync *s_pEpSync; return 0; } +- (void)checkTrustwordsSession:(PEP_SESSION)session + ident1:(pEp_identity *)ident1 + ident2:(pEp_identity *)ident2 +{ + PEP_STATUS statusMyself = myself(session, ident2); + NSAssert(statusMyself == PEP_STATUS_OK, @"check status of update_identity"); + + PEP_STATUS statusUpdate = update_identity(session, ident2); + NSAssert(statusUpdate == PEP_STATUS_OK, @"check status of update_identity"); + + char *trustwords; + size_t sizeWritten; + + PEP_STATUS status = get_trustwords(session, + ident1, + ident2, + "en", + &trustwords, + &sizeWritten, + YES); + NSAssert(status == PEP_STATUS_OK, @"check status of get_trustwords"); + if (status == PEP_STATUS_OK) { + NSLog(@"*** trustwords %s", trustwords); + } +} + - (PEP_STATUS)notifyHandshake:(pEp_identity *)me partner:(pEp_identity *)partner signal:(sync_handshake_signal)signal { + if (signal == SYNC_NOTIFY_INIT_FORM_GROUP) { + [self checkTrustwordsSession:self.syncLoopSession.session + ident1:me + ident2:partner]; + } + if (self.notifyHandshakeDelegate) { PEPIdentity *meIdentity = [PEPIdentity fromStruct:me]; free_identity(me); From 317a09e96ddc234feec6bb0d794aa82ccd1e3557 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Fri, 24 Feb 2023 14:27:01 +0100 Subject: [PATCH 29/29] Revert "E3-3 Debug SYNC_NOTIFY_INIT_FORM_GROUP" This reverts commit 116a49965f86909572a5902b010d7af842bbf88f. --- src/PEPSync.m | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/PEPSync.m b/src/PEPSync.m index dd36f50f..ccee0739 100644 --- a/src/PEPSync.m +++ b/src/PEPSync.m @@ -14,7 +14,6 @@ #import "PEPSync_Internal.h" #import "message_api.h" -#import "pEpEngine.h" #import "PEPSendMessageDelegate.h" #import "PEPNotifyHandshakeDelegate.h" @@ -388,42 +387,10 @@ static __weak PEPSync *s_pEpSync; return 0; } -- (void)checkTrustwordsSession:(PEP_SESSION)session - ident1:(pEp_identity *)ident1 - ident2:(pEp_identity *)ident2 -{ - PEP_STATUS statusMyself = myself(session, ident2); - NSAssert(statusMyself == PEP_STATUS_OK, @"check status of update_identity"); - - PEP_STATUS statusUpdate = update_identity(session, ident2); - NSAssert(statusUpdate == PEP_STATUS_OK, @"check status of update_identity"); - - char *trustwords; - size_t sizeWritten; - - PEP_STATUS status = get_trustwords(session, - ident1, - ident2, - "en", - &trustwords, - &sizeWritten, - YES); - NSAssert(status == PEP_STATUS_OK, @"check status of get_trustwords"); - if (status == PEP_STATUS_OK) { - NSLog(@"*** trustwords %s", trustwords); - } -} - - (PEP_STATUS)notifyHandshake:(pEp_identity *)me partner:(pEp_identity *)partner signal:(sync_handshake_signal)signal { - if (signal == SYNC_NOTIFY_INIT_FORM_GROUP) { - [self checkTrustwordsSession:self.syncLoopSession.session - ident1:me - ident2:partner]; - } - if (self.notifyHandshakeDelegate) { PEPIdentity *meIdentity = [PEPIdentity fromStruct:me]; free_identity(me);