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 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/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 */ diff --git a/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m index a2c701b0..0e57e7bd 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 @@ -462,15 +464,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]); @@ -689,31 +691,37 @@ XCTAssertEqual(color, PEPRatingReliable); } -- (void)testGetTrustwords +- (void)testGetTrustwordsFail { 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 - 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]; + // 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 diff --git a/build-mac/pEpObjCAdapterTests/PEPSessionTest.m b/build-mac/pEpObjCAdapterTests/PEPSessionTest.m index 52e4f372..101e57c1 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); @@ -277,42 +278,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] - 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] 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 5357e720..3955ba9b 100644 --- a/src/PEPInternalSession.m +++ b/src/PEPInternalSession.m @@ -638,17 +638,40 @@ 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) { - return get_trustwords(session, ident1, ident2, + 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 = updateIdentity(ident2); + if (PEP_STATUS_is_error(updateStatus)) { + return updateStatus; + } + + return get_trustwords(session, + ident1, + ident2, [[language precomposedStringWithCanonicalMapping] UTF8String], - trustwords.charPointerPointer, &sizeWritten, full); + trustwords.charPointerPointer, + &sizeWritten, + full); }]; free_identity(ident1); @@ -663,34 +686,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_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/PEPPassphraseUtil.m b/src/PEPPassphraseUtil.m index 30ae58aa..583ad16f 100644 --- a/src/PEPPassphraseUtil.m +++ b/src/PEPPassphraseUtil.m @@ -49,7 +49,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/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 diff --git a/src/PEPSessionProvider.m b/src/PEPSessionProvider.m index 0e82bb6b..48fd085b 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" @@ -30,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. 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");