Merge branch '1.1.260' into PEMA-42

master
Dirk Zimmermann 3 weeks ago
commit a883384d51
  1. 5
      Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPObjCAdapterConfigurationProtocol.h
  2. 32
      Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPObjCAdapterEchoConfigurationProtocol.h
  3. 26
      Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPObjCAdapterMediaKeysConfigurationProtocol.h
  4. 7
      Subprojects/PEPObjCAdapterProtocols/PublicHeaders/PEPSessionProtocol.h
  5. 4
      Subprojects/PEPObjCAdapterProtocols/build-mac/PEPObjCAdapterProtocols.xcodeproj/project.pbxproj
  6. 9
      Subprojects/PEPObjCTypes/PublicHeaders/PEPEngineTypes.h
  7. 18
      Subprojects/PEPObjCTypes/PublicHeaders/PEPMediaKeyPair+SecureCoding.h
  8. 26
      Subprojects/PEPObjCTypes/PublicHeaders/PEPMediaKeyPair.h
  9. 3
      Subprojects/PEPObjCTypes/PublicHeaders/PEPObjCTypes.h
  10. 22
      Subprojects/PEPObjCTypes/build-mac/PEPObjCTypes.xcodeproj/project.pbxproj
  11. 53
      Subprojects/PEPObjCTypes/build-mac/PEPObjCTypesTests/PEPMediaKeyPair+SecureCoding+Test.m
  12. 26
      Subprojects/PEPObjCTypes/src/NSObject/NSObject+Equality.h
  13. 44
      Subprojects/PEPObjCTypes/src/NSObject/NSObject+Equality.m
  14. 38
      Subprojects/PEPObjCTypes/src/PEPMediaKeyPair+SecureCoding.m
  15. 53
      Subprojects/PEPObjCTypes/src/PEPMediaKeyPair.m
  16. 21
      build-mac/pEpObjCAdapter.xcodeproj/project.pbxproj
  17. 100
      build-mac/pEpObjCAdapterTests/PEPInternalSessionTest.m
  18. 34
      build-mac/pEpObjCAdapterTests/PEPSessionTest.m
  19. 2
      build-mac/pEpObjCAdapterTests/TestUtils/XCTestCase+PEPSession.h
  20. 24
      build-mac/pEpObjCAdapterTests/TestUtils/XCTestCase+PEPSession.m
  21. 2
      src/Extensions/PEPInternalSession+PassphraseCache.m
  22. 89
      src/PEPInternalSession.h
  23. 65
      src/PEPInternalSession.m
  24. 14
      src/PEPObjCAdapter+Internal.h
  25. 43
      src/PEPObjCAdapter+ReadConfig.h
  26. 25
      src/PEPObjCAdapter+ReadEchoConfig.h
  27. 26
      src/PEPObjCAdapter+ReadMediaKeyConfig.h
  28. 40
      src/PEPObjCAdapter.m
  29. 2
      src/PEPPassphraseUtil.m
  30. 14
      src/PEPSession.m
  31. 35
      src/PEPSessionProvider.m
  32. 4
      src/PEPSync.m

@ -8,9 +8,12 @@
#import <Foundation/Foundation.h>
#import "PEPObjCAdapterEchoConfigurationProtocol.h"
#import "PEPObjCAdapterMediaKeysConfigurationProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@protocol PEPObjCAdapterConfigurationProtocol <NSObject>
@protocol PEPObjCAdapterConfigurationProtocol <PEPObjCAdapterEchoConfigurationProtocol, PEPObjCAdapterMediaKeysConfigurationProtocol>
/// Sets Engine config for unecryptedSubjectEnabled to the given value on all Sessions created by
/// this adapter.

@ -0,0 +1,32 @@
//
// PEPObjCAdapterEchoConfigurationProtocol.h
// PEPObjCAdapterProtocols
//
// Created by Dirk Zimmermann on 08.09.22.
//
#ifndef PEPObjCAdapterConfigurationProtocol_Echo_h
#define PEPObjCAdapterConfigurationProtocol_Echo_h
NS_ASSUME_NONNULL_BEGIN
/// Echo protocol configuration across all sessions, including existing ones.
///
/// @see https://dev.pep.foundation/Engine/Echo%20Protocol
@protocol PEPObjCAdapterEchoConfigurationProtocol <NSObject>
/// Enables or disable the use of the echo protocol.
///
/// The protocol is enabled by default.
+ (void)setEchoProtocolEnabled:(BOOL)enabled;
/// Enables or disables pings for the engine's `outgoing_message_rating_preview`.
///
/// Ping messages from outgoing_message_rating_preview are enabled by default.
+ (void)setEchoInOutgoingMessageRatingPreviewEnabled:(BOOL)enabled;
@end
NS_ASSUME_NONNULL_END
#endif /* PEPObjCAdapterConfigurationProtocol_Echo_h */

@ -0,0 +1,26 @@
//
// PEPObjCAdapterMediaKeysConfigurationProtocol.h
// PEPObjCAdapterProtocols
//
// Created by Dirk Zimmermann on 15.09.22.
//
#ifndef PEPObjCAdapterConfigurationProtocol_MediaKeys_h
#define PEPObjCAdapterConfigurationProtocol_MediaKeys_h
#import "PEPMediaKeyPair.h"
NS_ASSUME_NONNULL_BEGIN
/// Media keys configuration across all sessions, including existing ones.
///
/// @see https://dev.pep.foundation/Engine/Media%20keys
@protocol PEPObjCAdapterMediaKeysConfigurationProtocol <NSObject>
+ (void)configureMediaKeys:(NSArray<PEPMediaKeyPair *> *)mediaKeys;
@end
NS_ASSUME_NONNULL_END
#endif /* PEPObjCAdapterConfigurationProtocol_MediaKeys_h */

@ -10,6 +10,7 @@
#import "PEPTypes.h"
#import "PEPEngineTypes.h"
#import "PEPObjCTypes.h"
#import "PEPSessionProtocolTKA.h"
@class PEPLanguage;
@ -178,6 +179,10 @@ extern NSString *const _Nonnull PEPObjCAdapterErrorDomain;
- (void)keyResetAllOwnKeys:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
/// Wraps `sync_reinit` (sync_api.h).
- (void)syncReinit:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
// MARK: - Configuration
/// Add a passphrase for secret keys to the cache.
@ -213,7 +218,7 @@ extern NSString *const _Nonnull PEPObjCAdapterErrorDomain;
/// Wraps color_from_rating.
- (PEPColor)colorFromRating:(PEPRating)rating;
/// Wraps `disable_all_sync_channels` (`sync_api.h`).
/// Wraps `disable_all_sync_channels` (sync_api.h).
- (BOOL)disableAllSyncChannels:(NSError * _Nullable * _Nullable)error;
@end

@ -14,6 +14,8 @@
/* Begin PBXFileReference section */
43147DE527970BC600661780 /* PEPSessionProtocolTKA.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPSessionProtocolTKA.h; sourceTree = "<group>"; };
43147E0F27970DFE00661780 /* PEPTKADelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPTKADelegate.h; sourceTree = "<group>"; };
43DFAAB829265AE5009DABB9 /* PEPObjCAdapterMediaKeysConfigurationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapterMediaKeysConfigurationProtocol.h; sourceTree = "<group>"; };
43DFAAB929265AE5009DABB9 /* PEPObjCAdapterEchoConfigurationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapterEchoConfigurationProtocol.h; sourceTree = "<group>"; };
4E23E6CE2681B70400B8F4C2 /* libPEPObjCAdapterTypes_macOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libPEPObjCAdapterTypes_macOS.a; sourceTree = BUILT_PRODUCTS_DIR; };
4E23E6E62681C7CD00B8F4C2 /* libPEPObjCAdapterProtocols_macOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPEPObjCAdapterProtocols_macOS.a; sourceTree = BUILT_PRODUCTS_DIR; };
4E23E6E82681C7CD00B8F4C2 /* PEPObjCAdapterProtocols_macOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapterProtocols_macOS.h; sourceTree = "<group>"; };
@ -103,6 +105,8 @@
43147E0F27970DFE00661780 /* PEPTKADelegate.h */,
43147DE527970BC600661780 /* PEPSessionProtocolTKA.h */,
4EEB4CC22680DCAC00161040 /* PEPSessionProtocol.h */,
43DFAAB929265AE5009DABB9 /* PEPObjCAdapterEchoConfigurationProtocol.h */,
43DFAAB829265AE5009DABB9 /* PEPObjCAdapterMediaKeysConfigurationProtocol.h */,
);
name = PublicHeaders;
path = ../PublicHeaders;

@ -29,7 +29,7 @@ typedef NS_CLOSED_ENUM(NSUInteger, PEPTransportID) {
typedef NS_CLOSED_ENUM(int, PEPDecryptFlags) {
PEPDecryptFlagsNone = 0x0, // not actually defined in the engine
PEPDecryptFlagsOwnPrivateKey = 0x1, // PEP_decrypt_flag_own_private_key
PEPDecryptFlagsConsume = 0x2, //PEP_decrypt_flag_consume
PEPDecryptFlagsConsume = 0x2, // PEP_decrypt_flag_consume
PEPDecryptFlagsIgnore = 0x4, // PEP_decrypt_flag_ignore
PEPDecryptFlagsSourceModified = 0x8, // PEP_decrypt_flag_src_modified
PEPDecryptFlagsUntrustedServer = 0x100, // PEP_decrypt_flag_untrusted_server
@ -42,6 +42,7 @@ typedef NS_CLOSED_ENUM(int, PEPEncFormat) {
PEPEncFormatSMIME, // PEP_enc_S_MIME
PEPEncFormatPGPMIME, // PEP_enc_PGP_MIME
PEPEncFormatPEP, // PEP_enc_PEP
PEPEncFormatMediaKey = PEPEncFormatPEP, // media_key_enc_format
PEPEncFormatPGPMIMEOutlook1 // PEP_enc_PGP_MIME_Outlook1
};
@ -51,6 +52,7 @@ typedef NS_CLOSED_ENUM(int, PEPRating) {
PEPRatingHaveNoKey = 2, // PEP_rating_have_no_key
PEPRatingUnencrypted = 3, // PEP_rating_unencrypted
PEPRatingUnreliable = 5, // PEP_rating_unreliable
PEPRatingMediaKeyMessage = PEPRatingUnreliable, // media_key_message_rating
PEPRatingReliable = 6, // PEP_rating_reliable
PEPRatingTrusted = 7, // PEP_rating_trusted
PEPRatingTrustedAndAnonymized = 8, // PEP_rating_trusted_and_anonymized
@ -188,9 +190,11 @@ typedef NS_CLOSED_ENUM(int, PEPSyncHandshakeSignal) {
PEPSyncHandshakeSignalAcceptedDeviceAdded = 6, // SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED
PEPSyncHandshakeSignalAcceptedGroupCreated = 7, // SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
PEPSyncHandshakeSignalAcceptedDeviceAccepted = 8, // SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED
PEPSyncHandshakeSignalOutgoingRatingChange = 64, // SYNC_NOTIFY_OUTGOING_RATING_CHANGE
PEPSyncHandshakeSignalStart = 126, // SYNC_NOTIFY_START
PEPSyncHandshakeSignalStop = 127, // SYNC_NOTIFY_STOP
PEPSyncHandshakeSignalPassphraseRequired = 128, // SYNC_PASSPHRASE_REQUIRED
@ -224,6 +228,7 @@ typedef NS_CLOSED_ENUM(int, PEPCommType) {
PEPCommTypeMistrusted = 0x0f, // PEP_ct_mistrusted
PEPCommTypeUnconfirmedEncryption = 0x10, // PEP_ct_unconfirmed_encryption
PEPCommTypeMediaKey = PEPCommTypeUnconfirmedEncryption, // PEP_comm_type media_key_comm_type
PEPCommTypeOpenPGPWeakUnconfirmed = 0x11, // PEP_ct_OpenPGP_weak_unconfirmed
PEPCommTypeToBeChecked = 0x20, // PEP_ct_to_be_checked

@ -0,0 +1,18 @@
//
// PEPMediaKeyPair+SecureCoding.h
// PEPObjCTypes
//
// Created by Dirk Zimmermann on 06.09.22.
//
#import <Foundation/Foundation.h>
#import "PEPMediaKeyPair.h"
NS_ASSUME_NONNULL_BEGIN
@interface PEPMediaKeyPair (SecureCoding) <NSSecureCoding>
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,26 @@
//
// PEPMediaKeyPair.h
// PEPObjCTypes
//
// Created by Dirk Zimmermann on 06.09.22.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// Models the input to the engine's `config_media_keys`.
/// @see https://dev.pep.foundation/Engine/Media%20keys
@interface PEPMediaKeyPair : NSObject
/// The media key pattern.
@property (nonatomic, readonly) NSString *pattern;
/// The fingerprint for this media key entry.
@property (nonatomic, readonly) NSString *fingerprint;
- (instancetype)initWithPattern:(NSString *)pattern fingerprint:(NSString *)fingerprint;
@end
NS_ASSUME_NONNULL_END

@ -16,6 +16,9 @@
#import "PEPErrors.h"
#import "PEPTransportConfig.h"
#import "PEPMediaKeyPair.h"
#import "PEPMediaKeyPair+SecureCoding.h"
@interface PEPObjCTypes : NSObject
@end

@ -20,6 +20,11 @@
439F4C43275632E2005F278E /* PEPLanguage+SecureCodingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E5758CC26833F920084F02D /* PEPLanguage+SecureCodingTest.m */; };
439F4C44275632E6005F278E /* PEPMessage+SecureCodingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E5758CD26833F920084F02D /* PEPMessage+SecureCodingTest.m */; };
43D44C842685BEB400638D1C /* pEpObjCTypesModuleMap.modulemap in CopyFiles */ = {isa = PBXBuildFile; fileRef = 43D44C832685BE4300638D1C /* pEpObjCTypesModuleMap.modulemap */; platformFilter = ios; };
43DFAABD29265B41009DABB9 /* PEPMediaKeyPair+SecureCoding+Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DFAABC29265B41009DABB9 /* PEPMediaKeyPair+SecureCoding+Test.m */; };
43DFAAC029265B76009DABB9 /* PEPMediaKeyPair.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DFAABE29265B76009DABB9 /* PEPMediaKeyPair.m */; };
43DFAAC129265B76009DABB9 /* PEPMediaKeyPair+SecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DFAABF29265B76009DABB9 /* PEPMediaKeyPair+SecureCoding.m */; };
43DFAAD329265FEE009DABB9 /* PEPMediaKeyPair.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DFAABE29265B76009DABB9 /* PEPMediaKeyPair.m */; };
43DFAAD429265FF5009DABB9 /* PEPMediaKeyPair+SecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DFAABF29265B76009DABB9 /* PEPMediaKeyPair+SecureCoding.m */; };
4E57585D268329170084F02D /* PEPObjCTypes_macOS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E57585C268329170084F02D /* PEPObjCTypes_macOS.m */; };
4E575869268329A20084F02D /* PEPObjCTypes_iOS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E575868268329A20084F02D /* PEPObjCTypes_iOS.m */; platformFilter = ios; };
4E57586A268329A20084F02D /* PEPObjCTypes_iOS.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4E575867268329A20084F02D /* PEPObjCTypes_iOS.h */; platformFilter = ios; };
@ -92,6 +97,11 @@
15BD319B2742A1B500B1B1F5 /* PEPErrors.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPErrors.m; sourceTree = "<group>"; };
439F4C36275632B2005F278E /* PEPObjCTypesTests_macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PEPObjCTypesTests_macOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
43D44C832685BE4300638D1C /* pEpObjCTypesModuleMap.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = pEpObjCTypesModuleMap.modulemap; sourceTree = "<group>"; };
43DFAABA29265B17009DABB9 /* PEPMediaKeyPair.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPMediaKeyPair.h; sourceTree = "<group>"; };
43DFAABB29265B17009DABB9 /* PEPMediaKeyPair+SecureCoding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPMediaKeyPair+SecureCoding.h"; sourceTree = "<group>"; };
43DFAABC29265B41009DABB9 /* PEPMediaKeyPair+SecureCoding+Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PEPMediaKeyPair+SecureCoding+Test.m"; sourceTree = "<group>"; };
43DFAABE29265B76009DABB9 /* PEPMediaKeyPair.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPMediaKeyPair.m; sourceTree = "<group>"; };
43DFAABF29265B76009DABB9 /* PEPMediaKeyPair+SecureCoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PEPMediaKeyPair+SecureCoding.m"; sourceTree = "<group>"; };
4E575841268328CD0084F02D /* PEPObjCTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCTypes.h; sourceTree = "<group>"; };
4E575858268329170084F02D /* libPEPObjCTypes_macOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPEPObjCTypes_macOS.a; sourceTree = BUILT_PRODUCTS_DIR; };
4E57585A268329170084F02D /* PEPObjCTypes_macOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCTypes_macOS.h; sourceTree = "<group>"; };
@ -220,13 +230,15 @@
4E57587326832F2F0084F02D /* src */ = {
isa = PBXGroup;
children = (
15BD2F9E27342A3500B1B1F5 /* PEPEqualableTools */,
1598067926CFE9CF00593C9D /* PEPTransportConfig.m */,
4E57587826832F2F0084F02D /* PEPAttachment.m */,
4E57587526832F2F0084F02D /* PEPIdentity.m */,
4E57587B26832F2F0084F02D /* PEPLanguage.m */,
4E57587D26832F2F0084F02D /* PEPMessage.m */,
15BD319B2742A1B500B1B1F5 /* PEPErrors.m */,
15BD2F9E27342A3500B1B1F5 /* PEPEqualableTools */,
43DFAABE29265B76009DABB9 /* PEPMediaKeyPair.m */,
43DFAABF29265B76009DABB9 /* PEPMediaKeyPair+SecureCoding.m */,
);
path = src;
sourceTree = "<group>";
@ -243,6 +255,8 @@
4E57588426832F2F0084F02D /* PEPAttachment.h */,
4E57588626832F2F0084F02D /* PEPIdentity.h */,
15BD319A2742A1B500B1B1F5 /* PEPErrors.h */,
43DFAABA29265B17009DABB9 /* PEPMediaKeyPair.h */,
43DFAABB29265B17009DABB9 /* PEPMediaKeyPair+SecureCoding.h */,
);
path = PublicHeaders;
sourceTree = "<group>";
@ -263,6 +277,7 @@
4E5758CB26833F920084F02D /* PEPIdentity+SecureCodingTest.m */,
4E5758CC26833F920084F02D /* PEPLanguage+SecureCodingTest.m */,
4E5758CD26833F920084F02D /* PEPMessage+SecureCodingTest.m */,
43DFAABC29265B41009DABB9 /* PEPMediaKeyPair+SecureCoding+Test.m */,
4E5758C326833D140084F02D /* Info.plist */,
);
path = PEPObjCTypesTests;
@ -510,10 +525,13 @@
4E57589626832F2F0084F02D /* PEPLanguage.m in Sources */,
4E57589026832F2F0084F02D /* PEPAttachment.m in Sources */,
4E57588B26832F2F0084F02D /* PEPIdentity.m in Sources */,
43DFAAC129265B76009DABB9 /* PEPMediaKeyPair+SecureCoding.m in Sources */,
1598067C26CFE9CF00593C9D /* PEPTransportConfig.m in Sources */,
4E57585D268329170084F02D /* PEPObjCTypes_macOS.m in Sources */,
43DFAAC029265B76009DABB9 /* PEPMediaKeyPair.m in Sources */,
4E57589A26832F2F0084F02D /* PEPMessage.m in Sources */,
15BD2F9C27342A2400B1B1F5 /* PEPEqualableTools.m in Sources */,
43DFAABD29265B41009DABB9 /* PEPMediaKeyPair+SecureCoding+Test.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -522,12 +540,14 @@
buildActionMask = 2147483647;
files = (
15BD319F2742A1B500B1B1F5 /* PEPErrors.m in Sources */,
43DFAAD429265FF5009DABB9 /* PEPMediaKeyPair+SecureCoding.m in Sources */,
4E57589726832F2F0084F02D /* PEPLanguage.m in Sources */,
4E57589126832F2F0084F02D /* PEPAttachment.m in Sources */,
4E57588C26832F2F0084F02D /* PEPIdentity.m in Sources */,
1598067D26CFE9CF00593C9D /* PEPTransportConfig.m in Sources */,
4E575869268329A20084F02D /* PEPObjCTypes_iOS.m in Sources */,
4E57589B26832F2F0084F02D /* PEPMessage.m in Sources */,
43DFAAD329265FEE009DABB9 /* PEPMediaKeyPair.m in Sources */,
15BD2F9D27342A2400B1B1F5 /* PEPEqualableTools.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

@ -0,0 +1,53 @@
//
// PEPMediaKeyPair+SecureCoding+Test.m
// PEPObjCTypesTests_iOS
//
// Created by Dirk Zimmermann on 06.09.22.
//
#import <XCTest/XCTest.h>
#import "PEPMediaKeyPair+SecureCoding.h"
@interface PEPMediaKeyPair_SecureCoding_Test : XCTestCase
@end
@implementation PEPMediaKeyPair_SecureCoding_Test
- (void)testBasicArchiveUnarchive
{
NSString * const pattern = @"thePattern";
NSString * const fingerprint = @"theFingerprint";
PEPMediaKeyPair *mediaKeyPair1 = [[PEPMediaKeyPair alloc] initWithPattern:pattern
fingerprint:fingerprint];
XCTAssertTrue([mediaKeyPair1 conformsToProtocol:@protocol(NSSecureCoding)]);
PEPMediaKeyPair *mediaKeyPair2 = [self archiveAndUnarchiveMediaKeyPair:mediaKeyPair1];
XCTAssertEqualObjects(mediaKeyPair1, mediaKeyPair2);
XCTAssertEqualObjects(mediaKeyPair1.pattern, mediaKeyPair2.pattern);
XCTAssertEqualObjects(mediaKeyPair1.fingerprint, mediaKeyPair2.fingerprint);
}
// MARK: - Helper
- (PEPMediaKeyPair *)archiveAndUnarchiveMediaKeyPair:(PEPMediaKeyPair *)mediaKeyPair
{
NSError *error;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mediaKeyPair
requiringSecureCoding:YES
error:&error];
XCTAssertNotNil(data);
PEPMediaKeyPair *unarchivedMediaKeyPair = [NSKeyedUnarchiver
unarchivedObjectOfClass:[PEPMediaKeyPair class]
fromData:data
error:&error];
XCTAssertNotNil(unarchivedMediaKeyPair);
return unarchivedMediaKeyPair;
}
@end

@ -0,0 +1,26 @@
//
// NSObject+Equality.h
// pEpObjCAdapter
//
// Created by Dirk Zimmermann on 24.04.18.
// Copyright © 2018 p≡p. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (Equality)
/**
Invokes `[value1 isEqual:value2]` between all value pairs retrieved
from `self` and `other`, based on the list of keys.
@Note `nil` is considered equal to `nil`, in contrast to [NSObject isEqual:].
*/
- (BOOL)isEqualToObject:(NSObject * _Nonnull)other
basedOnKeys:(NSArray<NSString *> * _Nonnull)keys;
/**
Calculates a hash based on the given `keys`.
*/
- (NSUInteger)hashBasedOnKeys:(NSArray<NSString *> * _Nonnull)keys;
@end

@ -0,0 +1,44 @@
//
// NSObject+Equality.m
// pEpObjCAdapter
//
// Created by Dirk Zimmermann on 24.04.18.
// Copyright © 2018 pp. All rights reserved.
//
#import "NSObject+Equality.h"
@implementation NSObject (Extension)
- (BOOL)isEqualToObject:(NSObject * _Nonnull)other
basedOnKeys:(NSArray<NSString *> * _Nonnull)keys
{
for (NSString *theKey in keys) {
NSObject *objSelf = [self valueForKey:theKey];
NSObject *objOther = [other valueForKey:theKey];
if (objSelf == nil && objOther == nil) {
// considered equal, continue
} else if (![objSelf isEqual:objOther]) {
// NSValue, NSArray, NSString all have correctly implemented isEqual, so this works
return NO;
}
}
return YES;
}
- (NSUInteger)hashBasedOnKeys:(NSArray<NSString *> * _Nonnull)keys
{
NSUInteger prime = 31;
NSUInteger result = 1;
for (NSString *theKey in keys) {
NSObject *objSelf = [self valueForKey:theKey];
result = prime * result + objSelf.hash;
}
return result;
}
@end

@ -0,0 +1,38 @@
//
// PEPMediaKeyPair+SecureCoding.m
// PEPObjCTypes
//
// Created by Dirk Zimmermann on 06.09.22.
//
#import "PEPMediaKeyPair+SecureCoding.h"
static NSString * const kPattern = @"pattern";
static NSString * const kFingerprint = @"fingerprint";
@implementation PEPMediaKeyPair (SecureCoding)
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder
{
NSString *pattern = [coder decodeObjectOfClass:[NSString class] forKey:kPattern];
NSString *fingerprint = [coder decodeObjectOfClass:[NSString class] forKey:kFingerprint];
if (pattern == nil || fingerprint == nil) {
return nil;
}
return [[PEPMediaKeyPair alloc] initWithPattern:pattern fingerprint:fingerprint];
}
- (void)encodeWithCoder:(nonnull NSCoder *)coder
{
[coder encodeObject:self.pattern forKey:kPattern];
[coder encodeObject:self.fingerprint forKey:kFingerprint];
}
@end

@ -0,0 +1,53 @@
//
// PEPMediaKeyPair.m
// PEPObjCTypes
//
// Created by Dirk Zimmermann on 06.09.22.
//
#import "PEPMediaKeyPair.h"
@implementation PEPMediaKeyPair
- (instancetype)initWithPattern:(NSString *)pattern fingerprint:(NSString *)fingerprint
{
self = [super init];
if (self) {
_pattern = pattern;
_fingerprint = fingerprint;
}
return self;
}
// MARK: - Equality
- (BOOL)isEqualToPEPMediaKeyPair:(PEPMediaKeyPair * _Nonnull)mediaKeyPair
{
return [self.pattern isEqualToString:mediaKeyPair.pattern] &&
[self.fingerprint isEqualToString:mediaKeyPair.fingerprint];
}
- (NSUInteger)hash
{
NSUInteger prime = 31;
NSUInteger result = 1;
result = prime * result + self.pattern.hash;
result = prime * result + self.fingerprint.hash;
return result;
}
- (BOOL)isEqual:(id)object
{
if (object == self) {
return YES;
}
if (!object || ![object isKindOfClass:[self class]]) {
return NO;
}
return [self isEqualToPEPMediaKeyPair:object];
}
@end

@ -402,6 +402,13 @@
remoteGlobalIDString = 43B2ACC02923AF7700D8C6F8;
remoteInfo = PEPObjCAdapter_iOS;
};
43DFAACF29265BD2009DABB9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 43927FC6275A1E08008E80C2 /* PEPObjCTypeUtils.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 43312024292553A200DFD28C;
remoteInfo = PEPObjCTypeUtilsTests_iOS;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
@ -506,6 +513,9 @@
43B2ACFE2923D06E00D8C6F8 /* pEpIOSToolbox.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = pEpIOSToolbox.xcodeproj; path = "../../pep-toolbox/pEpIOSToolbox.xcodeproj"; sourceTree = "<group>"; };
43D2D5EE2632B0FA00088BDC /* XCTestCase+PEPSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCTestCase+PEPSession.h"; sourceTree = "<group>"; };
43D2D5F02632B0FA00088BDC /* XCTestCase+PEPSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCTestCase+PEPSession.m"; sourceTree = "<group>"; };
43DFAAC229265BD2009DABB9 /* PEPObjCAdapter+ReadEchoConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPObjCAdapter+ReadEchoConfig.h"; sourceTree = "<group>"; };
43DFAAD129265BD2009DABB9 /* PEPObjCAdapter+ReadMediaKeyConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPObjCAdapter+ReadMediaKeyConfig.h"; sourceTree = "<group>"; };
43DFAAD229265BD2009DABB9 /* PEPObjCAdapter+ReadConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPObjCAdapter+ReadConfig.h"; sourceTree = "<group>"; };
43E02A1C1C71F65B008F05E9 /* A3FC7F0A_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = A3FC7F0A_sec.asc; sourceTree = "<group>"; };
43E02A1D1C71F65B008F05E9 /* A3FC7F0A.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = A3FC7F0A.asc; sourceTree = "<group>"; };
43E1A7AB252B421D00307A7D /* Logger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = "<group>"; };
@ -747,6 +757,9 @@
43E1A7AB252B421D00307A7D /* Logger.h */,
15C3089326E8B8550013F39F /* Logger.m */,
43B2ACF12923C52000D8C6F8 /* Platform.h */,
43DFAAD229265BD2009DABB9 /* PEPObjCAdapter+ReadConfig.h */,
43DFAAC229265BD2009DABB9 /* PEPObjCAdapter+ReadEchoConfig.h */,
43DFAAD129265BD2009DABB9 /* PEPObjCAdapter+ReadMediaKeyConfig.h */,
);
name = src;
path = ../src;
@ -783,6 +796,7 @@
43927FD5275A1E09008E80C2 /* libPEPObjCTypeUtils_macOS.a */,
43927FD7275A1E09008E80C2 /* libPEPObjCTypeUtils_iOS.a */,
43927FD9275A1E09008E80C2 /* PEPObjCTypeUtilsTests_macOS.xctest */,
43DFAAD029265BD2009DABB9 /* PEPObjCTypeUtilsTests_iOS.xctest */,
);
name = Products;
sourceTree = "<group>";
@ -1167,6 +1181,13 @@
remoteRef = 43B2AD0B2923D06E00D8C6F8 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
43DFAAD029265BD2009DABB9 /* PEPObjCTypeUtilsTests_iOS.xctest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = PEPObjCTypeUtilsTests_iOS.xctest;
remoteRef = 43DFAACF29265BD2009DABB9 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */

@ -91,7 +91,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
XCTAssertNotEqual(identMe.commType, PEPCommTypeUnknown);
@ -111,7 +110,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
XCTAssertNotEqual(identMe.commType, PEPCommTypeUnknown);
@ -405,7 +403,21 @@
XCTAssertNotNil(numRating);
XCTAssertNil(error);
// key_reset_trust makes the key not being elected anymore
// key_reset_trust makes the key not being elected anymore?
// mistrust Bob
XCTAssertTrue([session keyMistrusted:identBob error:&error]);
XCTAssertNil(error);
identBob.fingerPrint = nil;
XCTAssertTrue([session updateIdentity:identBob error:&error]);
XCTAssertNil(error);
XCTAssertNil(identBob.fingerPrint);
// Gray == PEPRatingUnencrypted
numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
XCTAssertNotNil(numRating);
XCTAssertNil(error);
XCTAssertEqual(numRating.pEpRating, PEPRatingUnencrypted);
}
@ -761,7 +773,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
// PEP_CANNOT_FIND_PERSON == 902
@ -795,7 +806,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
// The fingerprint is definitely wrong, we don't have a key
@ -825,7 +835,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
PEPIdentity *identAlice = [self
@ -872,7 +881,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
NSString *fprAlice = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
@ -1100,6 +1108,57 @@
[self shutdownSync];
}
#pragma mark - Sync/sync_reinit
- (void)testSyncReinitWithoutSyncLoop
{
PEPInternalSession *session = [PEPSessionProvider session];
NSError *error = nil;
[session syncReinit:&error];
XCTAssertNotNil(error);
XCTAssertEqual(error.code, PEPStatusStatemachineError);
}
/// @Note This test only proves that `sync_reinit` can be called without errors.
/// There was no observable change to verify, e.g., there was no message sent out.
- (void)testSyncReinit
{
XCTAssertEqual(self.sendMessageDelegate.messages.count, 0);
XCTAssertNil(self.sendMessageDelegate.lastMessage);
PEPIdentity *identMe = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i@pep-project.org"
userID:@"me-myself-and-i"
userName:@"pEp Me"
isOwn:YES];
PEPInternalSession *session = [PEPSessionProvider session];
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
[self startSync];
XCTKVOExpectation *expHaveMessage = [[XCTKVOExpectation alloc]
initWithKeyPath:@"lastMessage"
object:self.sendMessageDelegate];
[self waitForExpectations:@[expHaveMessage] timeout:PEPTestInternalSyncTimeout];
XCTAssertNotNil(self.sendMessageDelegate.lastMessage);
XCTAssertEqual(self.sendMessageDelegate.messages.count, 1);
self.sendMessageDelegate.lastMessage = nil;
error = nil;
[session syncReinit:&error];
XCTAssertNil(error);
[self shutdownSync];
}
#pragma mark - key_reset_user
- (void)testKeyResetIdentityOnOwnKeyIsIllegal
@ -1455,6 +1514,28 @@
XCTAssertTrue(mock.passphraseRequiredWasCalled);
}
#pragma mark - Media Key / Echo Protocol
- (void)testConfigureMediaKeys
{
// These echo settings don't interfere at all with the tests,
// but may be used to prove (via debugger) that the config works.
// See [PEPSessionProvider configureEchoProtocolOnSession:]
[PEPObjCAdapter setEchoProtocolEnabled:NO];
[PEPObjCAdapter setEchoInOutgoingMessageRatingPreviewEnabled:NO];
NSArray *mediaKeys = @[
[[PEPMediaKeyPair alloc] initWithPattern:@"*@example.com"
fingerprint:@"97B69752A72FC5036971F5C83AC51FA45F01DA6C"]
];
PEPInternalSession *session = [PEPSessionProvider session];
NSError *error = nil;
[session configureMediaKeys:mediaKeys error:&error];
XCTAssertNil(error);
}
#pragma mark - Helpers
- (void)setupEncryptWithImportedKeySession:(PEPInternalSession **)session
@ -1503,6 +1584,7 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
[self startSync];
@ -1510,8 +1592,6 @@
initWithKeyPath:@"lastMessage"
object:self.sendMessageDelegate];
XCTAssertNotNil(identMe.fingerPrint);
[self waitForExpectations:@[expHaveMessage] timeout:PEPTestInternalSyncTimeout];
XCTAssertNotNil(self.sendMessageDelegate.lastMessage);
@ -1558,7 +1638,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
PEPIdentity *identAlice = [[PEPIdentity alloc]
@ -1795,7 +1874,6 @@
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identMe.fingerPrint);
PEPMessage *msg = [PEPMessage new];

@ -379,6 +379,40 @@
XCTAssertNotEqual(fprOriginal, fprAfterReset);
}
#pragma mark - Sync/sync_reinit
- (void)testSyncReinitWithoutSyncLoop
{
NSError *error = nil;
[self syncReinit:&error];
XCTAssertNotNil(error);
XCTAssertEqual(error.code, PEPStatusStatemachineError);
}
#pragma mark - Media Key / Echo Protocol
- (void)testConfigureMediaKeys
{
NSArray *mediaKeys = @[
[[PEPMediaKeyPair alloc] initWithPattern:@"*@example.com"
fingerprint:@"97B69752A72FC5036971F5C83AC51FA45F01DA6C"]
];
[PEPObjCAdapter configureMediaKeys:mediaKeys];
NSString *fprAlice = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
// Note: This should lead to an updateIdentity, which in turn leads to checking
// the media keys.
[self
checkImportingKeyFilePath:@"6FF00E97_sec.asc"
address:@"pep.test.alice@pep-project.org"
userID:@"alice_user_id"
fingerPrint:fprAlice];
[PEPObjCAdapter configureMediaKeys:mediaKeys];
}
#pragma mark - Helpers
- (PEPMessage *)mailWrittenToMySelf

@ -76,6 +76,8 @@ NS_ASSUME_NONNULL_BEGIN
fingerprint:(NSString * _Nullable)fingerprint
error:(NSError * _Nullable * _Nullable)error;
- (BOOL)syncReinit:(NSError * _Nullable *)error;
@end
NS_ASSUME_NONNULL_END

@ -422,4 +422,28 @@
return result;
}
- (BOOL)syncReinit:(NSError * _Nullable *)error
{
PEPSession *asyncSession = [PEPSession new];
__block NSError *outerError = nil;
XCTestExpectation *expSyncReinit = [self expectationWithDescription:@"expSyncReinit"];
[asyncSession syncReinit:^(NSError * _Nonnull innerError) {
outerError = innerError;
[expSyncReinit fulfill];
} successCallback:^{
[expSyncReinit fulfill];
}];
[self waitForExpectations:@[expSyncReinit] timeout:PEPTestInternalSyncTimeout];
if (outerError) {
*error = outerError;
return NO;
}
return YES;
}
@end

@ -11,7 +11,7 @@
#import "pEpEngine.h"
#import "PEPPassphraseCache.h"
#import "PEPObjCAdapter+Internal.h"
#import "PEPObjCAdapter+ReadConfig.h"
#import "NSString+NormalizePassphrase.h"
#import "PEPPassphraseUtil.h"

@ -19,6 +19,9 @@
@class PEPIdentity;
@class PEPMessage;
@class PEPPassphraseCache;
@class PEPMediaKeyPair;
NS_ASSUME_NONNULL_BEGIN
/**
Represents a real pEp session (in contrast to PEPSession, which is a fake session to handle to the client).
@ -43,19 +46,19 @@
- (void)configUnEncryptedSubjectEnabled:(BOOL)enabled;
/// Get the (global) passphrase cache, convenience method.
- (PEPPassphraseCache * _Nonnull)passphraseCache;
- (PEPPassphraseCache *)passphraseCache;
/** Decrypt a message */
- (PEPMessage * _Nullable)decryptMessage:(PEPMessage * _Nonnull)message
- (PEPMessage * _Nullable)decryptMessage:(PEPMessage *)message
flags:(PEPDecryptFlags * _Nullable)flags
extraKeys:(PEPStringList * _Nullable * _Nullable)extraKeys
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error;
/** Re-evaluate rating of decrypted message */
- (BOOL)reEvaluateMessage:(PEPMessage * _Nonnull)message
- (BOOL)reEvaluateMessage:(PEPMessage *)message
xKeyList:(PEPStringList *_Nullable)xKeyList
rating:(PEPRating * _Nonnull)rating
rating:(PEPRating *)rating
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error;
@ -63,39 +66,39 @@
Encrypt a message, indicating the encoding format
@note The resulting message dict could be the input one.
*/
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage *)message
extraKeys:(PEPStringList * _Nullable)extraKeys
encFormat:(PEPEncFormat)encFormat
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error;
/** Encrypt a message with default encryption format (PEP_enc_PEP) */
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage *)message
extraKeys:(PEPStringList * _Nullable)extraKeys
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error;
/** Encrypt a message for the given own identity */
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
forSelf:(PEPIdentity * _Nonnull)ownIdentity
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage *)message
forSelf:(PEPIdentity *)ownIdentity
extraKeys:(PEPStringList * _Nullable)extraKeys
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error;
/** Encrypt a message to the given recipient FPR, attaching the private key */
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
toFpr:(NSString * _Nonnull)toFpr
- (PEPMessage * _Nullable)encryptMessage:(PEPMessage *)message
toFpr:(NSString *)toFpr
encFormat:(PEPEncFormat)encFormat
flags:(PEPDecryptFlags)flags
status:(PEPStatus * _Nullable)status
error:(NSError * _Nullable * _Nullable)error;
/** Determine the status color of a message to be sent */
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
- (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage *)theMessage
error:(NSError * _Nullable * _Nullable)error;
/** Determine the preview status color of a message to be sent */
- (NSNumber * _Nullable)outgoingRatingPreviewForMessage:(PEPMessage * _Nonnull)theMessage
- (NSNumber * _Nullable)outgoingRatingPreviewForMessage:(PEPMessage *)theMessage
error:(NSError * _Nullable * _Nullable)error;
/**
@ -103,12 +106,12 @@
The rating is the rating a _message_ would have, if it is sent to this (and only this) identity.
It is *not* a rating of the identity. In fact, there is no rating for identities.
*/
- (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity * _Nonnull)identity
- (NSNumber * _Nullable)ratingForIdentity:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/** Get trustwords for a fingerprint */
- (NSArray<NSString *> * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
languageID:(NSString * _Nonnull)languageID
- (NSArray<NSString *> * _Nullable)trustwordsForFingerprint:(NSString *)fingerprint
languageID:(NSString *)languageID
shortened:(BOOL)shortened
error:(NSError * _Nullable * _Nullable)error;
@ -121,7 +124,7 @@
/// @param identity The identity to mark as own.
///
/// @param error Standard cocoa error handling.
- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
- (BOOL)mySelf:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/// Calls the engine's update_identity on the given identity.
@ -135,25 +138,25 @@
/// @param identity The identity for which to call update_identity.
///
/// @param error Standart cocoa error handling.
- (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
- (BOOL)updateIdentity:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
Mark a key as trusted with a person.
*/
- (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
- (BOOL)trustPersonalKey:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
if a key is not trusted by the user tell this using this message
*/
- (BOOL)keyMistrusted:(PEPIdentity * _Nonnull)identity
- (BOOL)keyMistrusted:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
Use this to undo keyCompromized or trustPersonalKey
*/
- (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
- (BOOL)keyResetTrust:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
@ -165,7 +168,7 @@
@param error The usual cocoa error handling.
@return The usual cocoa error handling.
*/
- (BOOL)enableSyncForIdentity:(PEPIdentity * _Nonnull)identity
- (BOOL)enableSyncForIdentity:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
@ -177,13 +180,13 @@
@param error The usual cocoa error handling.
@return The usual cocoa error handling.
*/
- (BOOL)disableSyncForIdentity:(PEPIdentity * _Nonnull)identity
- (BOOL)disableSyncForIdentity:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
#pragma mark -- Internal API (testing etc.)
/** For testing purpose, manual key import */
- (NSArray<PEPIdentity *> * _Nullable)importKey:(NSString * _Nonnull)keydata
- (NSArray<PEPIdentity *> * _Nullable)importKey:(NSString *)keydata
error:(NSError * _Nullable * _Nullable)error;
/**
@ -192,15 +195,15 @@
- (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error;
/** Determine trustwords for two identities */
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
identity2:(PEPIdentity * _Nonnull)identity2
- (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity *)identity1
identity2:(PEPIdentity *)identity2
language:(NSString * _Nullable)language
full:(BOOL)full
error:(NSError * _Nullable * _Nullable)error;
/** Determine trustwords for two fprs */
- (NSString * _Nullable)getTrustwordsFpr1:(NSString * _Nonnull)fpr1
fpr2:(NSString * _Nonnull)fpr2
- (NSString * _Nullable)getTrustwordsFpr1:(NSString *)fpr1
fpr2:(NSString *)fpr2
language:(NSString * _Nullable)language
full:(BOOL)full
error:(NSError * _Nullable * _Nullable)error;
@ -213,25 +216,25 @@
/**
Can convert a string like "cannot_decrypt" into its equivalent PEPRating_cannot_decrypt.
*/
- (PEPRating)ratingFromString:(NSString * _Nonnull)string;
- (PEPRating)ratingFromString:(NSString *)string;
/**
Can convert a pEp rating like PEPRating_cannot_decrypt
into its equivalent string "cannot_decrypt" .
*/
- (NSString * _Nonnull)stringFromRating:(PEPRating)rating;
- (NSString *)stringFromRating:(PEPRating)rating;
/**
Is the given identity really a pEp user?
If the engine indicates an error, or the identity is not a pEp user, returns false.
*/
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
- (NSNumber * _Nullable)isPEPUser:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
When (manually) importing (secret) keys, associate them with the given own identity.
*/
- (BOOL)setOwnKey:(PEPIdentity * _Nonnull)identity fingerprint:(NSString * _Nonnull)fingerprint
- (BOOL)setOwnKey:(PEPIdentity *)identity fingerprint:(NSString *)fingerprint
error:(NSError * _Nullable * _Nullable)error;
/**
@ -244,7 +247,7 @@
Wraps set_identity_flags.
*/
- (BOOL)setFlags:(PEPIdentityFlags)flags
forIdentity:(PEPIdentity * _Nonnull)identity
forIdentity:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
@ -268,7 +271,7 @@
/**
Wraps trust_own_key.
*/
- (BOOL)trustOwnKeyIdentity:(PEPIdentity * _Nonnull)identity
- (BOOL)trustOwnKeyIdentity:(PEPIdentity *)identity
error:(NSError * _Nullable * _Nullable)error;
/**
@ -279,7 +282,7 @@
/**
Wraps key_reset_user.
*/
- (BOOL)keyReset:(PEPIdentity * _Nonnull)identity
- (BOOL)keyReset:(PEPIdentity *)identity
fingerprint:(NSString * _Nullable)fingerprint
error:(NSError * _Nullable * _Nullable)error;
@ -316,10 +319,26 @@
/// with a domain of PEPObjCAdapterErrorDomain.
/// @Throws PEPAdapterErrorPassphraseTooLong (with a domain of PEPObjCAdapterErrorDomain)
/// or PEPStatusOutOfMemory (with PEPObjCAdapterEngineStatusErrorDomain)
- (BOOL)configurePassphrase:(NSString * _Nonnull)passphrase
- (BOOL)configurePassphrase:(NSString *)passphrase
error:(NSError * _Nullable * _Nullable)error;
/// Wraps `disable_all_sync_channels` (`sync_api.h`).
- (BOOL)disableAllSyncChannels:(NSError * _Nullable * _Nullable)error;
/// Wraps `sync_reinit` (sync_api.h).
- (BOOL)syncReinit:(NSError * _Nullable * _Nullable)error;
#pragma mark - Media Key / Echo Protocol
/// Wraps `config_media_keys`.
/// @Note The media keys can be nil, which should make the session not use any media keys.
- (BOOL)configureMediaKeys:(NSArray<PEPMediaKeyPair *> * _Nullable)mediaKeys
error:(NSError * _Nullable * _Nullable)error;
- (void)configureEchoProtocolEnabled:(BOOL)enabled;
- (void)configureEchoInOutgoingMessageRatingPreviewEnabled:(BOOL)enabled;
@end
NS_ASSUME_NONNULL_END

@ -12,7 +12,7 @@
#import "PEPConstants.h"
#import "PEPObjCAdapter.h"
#import "PEPObjCAdapter+Internal.h"
#import "PEPObjCAdapter+ReadConfig.h"
#import "PEPLanguage.h"
#import "PEPCSVScanner.h"
#import "NSArray+Take.h"
@ -31,8 +31,10 @@
#import "PEPIdentity+PEPConvert.h"
#import "NSArray+PEPConvert.h"
#import "NSArray+PEPIdentityList.h"
#import "PEPMediaKeyPair.h"
#import "key_reset.h"
#import "media_key.h"
@implementation PEPInternalSession
@ -985,4 +987,65 @@ static NSDictionary *stringToRating;
}
}
- (BOOL)syncReinit:(NSError * _Nullable * _Nullable)error
{
PEPStatus theStatus = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) {
return sync_reinit(self.session);
}];
if ([PEPStatusNSErrorUtil setError:error fromPEPStatus:theStatus]) {
return NO;
} else {
return YES;
}
}
#pragma mark - Media Key / Echo Protocol
stringpair_list_t *stringListFromMediaKeys(NSArray<PEPMediaKeyPair *> *mediaKeys)
{
stringpair_list_t *engineList = NULL;
stringpair_list_t *engineListStart = NULL;
for (PEPMediaKeyPair *pair in mediaKeys) {
stringpair_t *engineStringPair = new_stringpair([pair.pattern UTF8String],
[pair.fingerprint UTF8String]);
engineList = stringpair_list_add(engineList, engineStringPair);
if (engineListStart == NULL) {
engineListStart = engineList;
}
}
return engineListStart;
}
- (BOOL)configureMediaKeys:(NSArray<PEPMediaKeyPair *> *)mediaKeys
error:(NSError * _Nullable * _Nullable)error
{
if (error) {
*error = nil;
}
PEPStatus theStatus = (PEPStatus) config_media_keys(self.session,
stringListFromMediaKeys(mediaKeys));
if ([PEPStatusNSErrorUtil setError:error fromPEPStatus:theStatus]) {
return NO;
}
return YES;
}
- (void)configureEchoProtocolEnabled:(BOOL)enabled
{
config_enable_echo_protocol(self.session, enabled);
}
- (void)configureEchoInOutgoingMessageRatingPreviewEnabled:(BOOL)enabled
{
config_enable_echo_in_outgoing_message_rating_preview(self.session, enabled);
}
@end

@ -1,21 +1,21 @@
//
// PEPIOSAdapter+Internal.h
// PEPIOSAdapter+ReadConfig.h
// pEpiOSAdapter
//
// Created by Edouard Tisserant on 11/11/15.
// Copyright © 2015 p≡p. All rights reserved.
//
#ifndef PEPIOSAdapter_Internal_h
#define PEPIOSAdapter_Internal_h
#ifndef PEPIOSAdapter_ReadConfig_h
#define PEPIOSAdapter_ReadConfig_h