Browse Source

Merge branch 'master' into IOS-217_IOS-2295

IOS-217_IOS-2295
Dirk Zimmermann 1 year ago
parent
commit
4eadeea7dd
10 changed files with 108 additions and 312 deletions
  1. +0
    -4
      PEPObjCAdapterTypes/PublicHeaders/PEPSessionProtocol.h
  2. +1
    -1
      pEpObjCAdapter.xcodeproj/project.pbxproj
  3. +20
    -0
      pEpObjCAdapter.xcodeproj/xcshareddata/xcschemes/PEPObjCAdapter_iOS.xcscheme
  4. +81
    -0
      pEpObjCAdapter.xcodeproj/xcshareddata/xcschemes/pEpObjCAdapterTests.xcscheme
  5. +0
    -11
      pEpObjCAdapter/PEPInternalSession.h
  6. +0
    -30
      pEpObjCAdapter/PEPInternalSession.m
  7. +6
    -5
      pEpObjCAdapter/PEPObjCAdapter.m
  8. +0
    -17
      pEpObjCAdapter/PEPSession.m
  9. +0
    -172
      pEpObjCTests/PEPInternalSessionTest.m
  10. +0
    -72
      pEpObjCTests/PEPSessionTest.m

+ 0
- 4
PEPObjCAdapterTypes/PublicHeaders/PEPSessionProtocol.h View File

@ -122,10 +122,6 @@ extern NSString *const _Nonnull PEPObjCAdapterErrorDomain;
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(void))successCallback;
- (void)queryKeySyncEnabledForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(BOOL enabled))successCallback;
- (void)importKey:(NSString *)keydata
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<PEPIdentity *> *identities))successCallback;


+ 1
- 1
pEpObjCAdapter.xcodeproj/project.pbxproj View File

@ -658,12 +658,12 @@
35FB0ABD1B57F99D00377032 /* Security.framework */,
35FB0ABB1B57F97E00377032 /* CFNetwork.framework */,
43209B251ECC2ACD007E7E2E /* pEpObjCAdapter */,
64415E181BE94FCB00F6CBB2 /* pEpObjCTests */,
15B10798257520B200D06C34 /* PEPObjCAdapterTypes */,
150E8FB325755B6900AE2198 /* PEPObjCAdapterTypes_macOS */,
1552D93C2576602D00A92F71 /* PEPObjCAdapter_macOS */,
1543DC67257943CE0041EFB5 /* PEPObjCAdapter_iOS */,
151606FE257A401000DD42E0 /* PEPObjCAdapterTypes_iOS */,
64415E181BE94FCB00F6CBB2 /* pEpObjCTests */,
4E81CD4A25C19DD4009F140D /* PEPObjCAdapterTypesTests_iOS */,
352988AB1AEF964100FA7E2E /* Products */,
43447C51221D448500B6323E /* Frameworks */,


+ 20
- 0
pEpObjCAdapter.xcodeproj/xcshareddata/xcschemes/PEPObjCAdapter_iOS.xcscheme View File

@ -112,6 +112,26 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64415E161BE94FCB00F6CBB2"
BuildableName = "pEpObjCAdapterTests.xctest"
BlueprintName = "pEpObjCAdapterTests"
ReferencedContainer = "container:pEpObjCAdapter.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4E81CD4825C19DD4009F140D"
BuildableName = "PEPObjCAdapterTypesTests_iOS.xctest"
BlueprintName = "PEPObjCAdapterTypesTests_iOS"
ReferencedContainer = "container:pEpObjCAdapter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction


+ 81
- 0
pEpObjCAdapter.xcodeproj/xcshareddata/xcschemes/pEpObjCAdapterTests.xcscheme View File

@ -5,6 +5,78 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19FF460E1B8B4D1400B43179"
BuildableName = "CocoaLumberjackSwift.framework"
BlueprintName = "CocoaLumberjackSwift"
ReferencedContainer = "container:../CocoaLumberjack/Lumberjack.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19FF46011B8B4CF400B43179"
BuildableName = "CocoaLumberjack.framework"
BlueprintName = "CocoaLumberjack"
ReferencedContainer = "container:../CocoaLumberjack/Lumberjack.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B7911EB321F7358500D7F66F"
BuildableName = "pEpIOSToolbox.framework"
BlueprintName = "pEpIOSToolbox"
ReferencedContainer = "container:../pep-toolbox/pEpIOSToolbox.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "151606FC257A401000DD42E0"
BuildableName = "libPEPObjCAdapterTypes_iOS.a"
BlueprintName = "PEPObjCAdapterTypes_iOS"
ReferencedContainer = "container:pEpObjCAdapter.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1543DC65257943CE0041EFB5"
BuildableName = "libPEPObjCAdapter_iOS.a"
BlueprintName = "PEPObjCAdapter_iOS"
ReferencedContainer = "container:pEpObjCAdapter.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
@ -41,6 +113,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1543DC65257943CE0041EFB5"
BuildableName = "libPEPObjCAdapter_iOS.a"
BlueprintName = "PEPObjCAdapter_iOS"
ReferencedContainer = "container:pEpObjCAdapter.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">


+ 0
- 11
pEpObjCAdapter/PEPInternalSession.h View File

@ -181,17 +181,6 @@
- (BOOL)disableSyncForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error;
/**
Queries the given own identity on whether it has key sync disabled or not.
@param identity The (own) identity to query.
@param error The usual cocoa error handling.
@return An NSNumber containing a boolean denoting whether key sync is enabled or not, or
nil on error. YES means that key sync is allowed for this identity, otherwise it's NO.
*/
- (NSNumber * _Nullable)queryKeySyncEnabledForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error;
#pragma mark -- Internal API (testing etc.)
/** For testing purpose, manual key import */


+ 0
- 30
pEpObjCAdapter/PEPInternalSession.m View File

@ -595,36 +595,6 @@ void decryptMessageFree(message *src, message *dst, stringlist_t *extraKeys)
return YES;
}
- (NSNumber * _Nullable)queryKeySyncEnabledForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
pEp_identity *ident = [identity toStruct];
if (!identity.isOwn) {
[NSError setError:error fromPEPStatus:PEPStatusIllegalValue];
return nil;
}
PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) {
return myself(session, ident);
}];
if ([NSError setError:error fromPEPStatus:status]) {
free_identity(ident);
return nil;
}
identity_flags_t flags = ident->flags;
free_identity(ident);
if (flags & PEP_idf_not_for_sync) {
return [NSNumber numberWithBool:NO];
} else {
return [NSNumber numberWithBool:YES];
}
}
- (NSArray<PEPIdentity *> * _Nullable)importKey:(NSString * _Nonnull)keydata
error:(NSError * _Nullable * _Nullable)error
{


+ 6
- 5
pEpObjCAdapter/PEPObjCAdapter.m View File

@ -17,7 +17,8 @@
#import "NSError+PEP.h"
#import "NSString+NormalizePassphrase.h"
#import "PEPInternalSession.h"
#import "PEPPassphraseCache.h"
#import "PEPPassphraseCache.h"
#import "Logger.h"
#import "keymanagement.h"
#import "mime.h"
@ -149,7 +150,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
{
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *containerUrl = [fm containerURLForSecurityApplicationGroupIdentifier:kAppGroupIdentifier];
NSLog(@"containerUrl '%@'", containerUrl);
LogInfo(@"containerUrl '%@'", containerUrl);
if (containerUrl == nil) {
// Will happen when running tests, so fall back.
@ -159,7 +160,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
}
if (containerUrl == nil) {
NSLog(@"ERROR: No app container, no application support directory.");
LogErrorAndCrash(@"No app container, no application support directory.");
}
NSURL *dirPath = [containerUrl URLByAppendingPathComponent:s_pEpHomeComponent];
@ -168,7 +169,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
NSError *theError = nil;
if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
attributes:nil error:&theError]) {
NSLog(@"ERROR: Could not create pEp home directory, directly writing to app container instead.");
LogErrorAndCrash(@"Could not create pEp home directory, directly writing to app container instead.");
}
return dirPath;
@ -232,7 +233,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
// Check if any error occurred during copying and display it.
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
LogInfo(@"%@", [error localizedDescription]);
}
}
#endif


+ 0
- 17
pEpObjCAdapter/PEPSession.m View File

@ -362,23 +362,6 @@ successCallback:(void (^)(PEPIdentity *identity))successCallback
});
}
- (void)queryKeySyncEnabledForIdentity:(PEPIdentity *)identity
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(BOOL enabled))successCallback
{
dispatch_async(queue, ^{
NSError *error = nil;
NSNumber *boolNum = [[PEPSessionProvider session]
queryKeySyncEnabledForIdentity:identity
error:&error];
if (boolNum != nil) {
successCallback(boolNum.boolValue);
} else {
errorCallback(error);
}
});
}
- (void)importKey:(NSString *)keydata
errorCallback:(void (^)(NSError *error))errorCallback
successCallback:(void (^)(NSArray<PEPIdentity *> *identities))successCallback


+ 0
- 172
pEpObjCTests/PEPInternalSessionTest.m View File

@ -1120,90 +1120,6 @@
[self shutdownSync];
}
/// ENGINE-684
- (void)testMyselfWithQueryKeySyncEnabledForIdentity
{
PEPInternalSession *session = [PEPSessionProvider session];
PEPIdentity *identMeEnabled = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i-enabled@pep-project.org"
userID:@"me-myself-and-i-enabled"
userName:@"pEp Me Enabled"
isOwn:YES];
PEPIdentity *identMeDisabled = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i-disabled@pep-project.org"
userID:@"me-myself-and-i-disabled"
userName:@"pEp Me Disabled"
isOwn:YES];
for (PEPIdentity *ident in @[identMeEnabled, identMeDisabled]) {
BOOL expectEnabled = ident == identMeEnabled ? YES : NO;
if (!expectEnabled) {
ident.flags |= PEPIdentityFlagsNotForSync;
}
NSError *error = nil;
XCTAssertTrue([session mySelf:ident error:&error]);
XCTAssertNil(error);
if (!expectEnabled) {
XCTAssertTrue([session disableSyncForIdentity:ident error:&error]);
XCTAssertNil(error);
}
NSNumber *enabledNum = [session queryKeySyncEnabledForIdentity:ident error:&error];
XCTAssertNotNil(enabledNum);
XCTAssertNil(error);
XCTAssertEqual([enabledNum boolValue], expectEnabled);
}
}
- (void)testDisableAllSyncChannels
{
PEPInternalSession *session = [PEPSessionProvider session];
PEPIdentity *ident1 = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i-1@pep-project.org"
userID:@"me-myself-and-i-1"
userName:@"me-myself-and-i-1"
isOwn:YES];
PEPIdentity *ident2 = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i-2@pep-project.org"
userID:@"me-myself-and-i-2"
userName:@"me-myself-and-i-2"
isOwn:YES];
for (PEPIdentity *ident in @[ident1, ident2]) {
NSError *error = nil;
XCTAssertTrue([session mySelf:ident error:&error]);
XCTAssertNil(error);
NSNumber *enabledNum = [session queryKeySyncEnabledForIdentity:ident error:&error];
XCTAssertNotNil(enabledNum);
XCTAssertNil(error);
XCTAssertEqual([enabledNum boolValue], YES);
}
NSError *error = nil;
XCTAssertTrue([session disableAllSyncChannels:&error]);
XCTAssertNil(error);
for (PEPIdentity *ident in @[ident1, ident2]) {
NSError *error = nil;
NSNumber *enabledNum = [session queryKeySyncEnabledForIdentity:ident error:&error];
XCTAssertNotNil(enabledNum);
XCTAssertNil(error);
XCTAssertEqual([enabledNum boolValue], NO);
}
}
#pragma mark - key_reset_user
- (void)testKeyResetIdentityOnOwnKeyIsIllegal
@ -1280,94 +1196,6 @@
error = nil;
XCTAssertFalse([session disableSyncForIdentity:notMe error:&error]);
XCTAssertNotNil(error);
error = nil;
XCTAssertNil([session queryKeySyncEnabledForIdentity:notMe error:&error]);
XCTAssertNotNil(error);
}
- (void)testEnableDisableSyncOnOwnIdentityWithQuery
{
PEPInternalSession *session = [PEPSessionProvider session];
PEPIdentity *identMe1 = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i@pep-project.org"
userID:@"me-myself-and-i"
userName:@"pEp Me"
isOwn:YES];
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe1 error:&error]);
XCTAssertNil(error);
error = nil;
PEPIdentity *identMe2 = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i2@pep-project.org"
userID:@"me-myself-and-i2"
userName:@"pEp Me2"
isOwn:YES];
XCTAssertTrue([session mySelf:identMe2 error:&error]);
XCTAssertNil(error);
XCTAssertNotEqualObjects(identMe1.fingerPrint, identMe2.fingerPrint);
for (int i = 0; i < 10; ++i) {
error = nil;
BOOL enable = i % 2 == 0; // enable keysync on even numbers (roughly)
if (enable) {
XCTAssertTrue([session enableSyncForIdentity:identMe1 error:&error]);
XCTAssertTrue([session enableSyncForIdentity:identMe2 error:&error]);
} else {
XCTAssertTrue([session disableSyncForIdentity:identMe1 error:&error]);
XCTAssertTrue([session disableSyncForIdentity:identMe2 error:&error]);
}
XCTAssertNil(error);
NSNumber *keySyncState1 = [session queryKeySyncEnabledForIdentity:identMe1 error:&error];
NSNumber *keySyncState2 = [session queryKeySyncEnabledForIdentity:identMe2 error:&error];
XCTAssertNil(error);
XCTAssertNotNil(keySyncState1);
XCTAssertNotNil(keySyncState2);
if (enable) {
XCTAssertTrue([keySyncState1 boolValue]);
} else {
XCTAssertFalse([keySyncState1 boolValue]);
}
XCTAssertEqualObjects(keySyncState1, keySyncState2);
}
}
/**
ENGINE-604, just in case.
*/
- (void)testQueryKeySyncOnOwnIdentityInALoop
{
PEPInternalSession *session = [PEPSessionProvider session];
PEPIdentity *identMe = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i@pep-project.org"
userID:@"me-myself-and-i"
userName:@"pEp Me"
isOwn:YES];
NSError *error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
for (NSNumber *numBool in @[@YES, @NO]) {
error = nil;
if ([numBool boolValue]) {
XCTAssertTrue([session enableSyncForIdentity:identMe error:&error]);
} else {
XCTAssertTrue([session disableSyncForIdentity:identMe error:&error]);
}
XCTAssertNil(error);
for (int i = 0; i < 10; ++i) {
NSNumber *numQuery = [session queryKeySyncEnabledForIdentity:identMe error:&error];
XCTAssertNotNil(numQuery);
XCTAssertEqualObjects(numBool, numQuery);
XCTAssertNil(error);
}
}
}
#pragma mark - Basic Passphrases


+ 0
- 72
pEpObjCTests/PEPSessionTest.m View File

@ -274,13 +274,6 @@
XCTAssertTrue([self disableSyncForIdentity:identMe error:&error]);
}
XCTAssertNil(error);
for (int i = 0; i < 10; ++i) {
NSNumber *numQuery = [self queryKeySyncEnabledForIdentity:identMe error:&error];
XCTAssertNotNil(numQuery);
XCTAssertEqualObjects(numBool, numQuery);
XCTAssertNil(error);
}
}
}
@ -380,48 +373,6 @@
XCTAssertNotEqual(fprOriginal, fprAfterReset);
}
- (void)testDisableAllSyncChannels
{
PEPIdentity *ident1 = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i-1@pep-project.org"
userID:@"me-myself-and-i-1"
userName:@"me-myself-and-i-1"
isOwn:YES];
PEPIdentity *ident2 = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i-2@pep-project.org"
userID:@"me-myself-and-i-2"
userName:@"me-myself-and-i-2"
isOwn:YES];
for (PEPIdentity *ident in @[ident1, ident2]) {
NSError *error = nil;
NSNumber *enabledNum = [self queryKeySyncEnabledForIdentity:ident error:&error];
XCTAssertNotNil(enabledNum);
XCTAssertNil(error);
XCTAssertEqual([enabledNum boolValue], YES);
}
PEPSession *asyncSession = [PEPSession new];
NSError *error = nil;
XCTAssertTrue([asyncSession disableAllSyncChannels:&error]);
XCTAssertNil(error);
for (PEPIdentity *ident in @[ident1, ident2]) {
NSError *error = nil;
XCTAssertTrue([self mySelf:ident error:&error]);
XCTAssertNil(error);
NSNumber *enabledNum = [self queryKeySyncEnabledForIdentity:ident error:&error];
XCTAssertNotNil(enabledNum);
XCTAssertNil(error);
XCTAssertEqual([enabledNum boolValue], NO);
}
}
#pragma mark - Helpers
- (PEPMessage *)mailWrittenToMySelf
@ -845,29 +796,6 @@
return result;
}
- (NSNumber * _Nullable)queryKeySyncEnabledForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{
PEPSession *asyncSession = [PEPSession new];
XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
__block NSNumber *result = nil;
__block NSError *theError = nil;
[asyncSession queryKeySyncEnabledForIdentity:identity
errorCallback:^(NSError * _Nonnull error) {
result = nil;
theError = error;
[exp fulfill];
} successCallback:^(BOOL enabled) {
result = [NSNumber numberWithBool:enabled];
[exp fulfill];
}];
[self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
if (error) {
*error = theError;
}
return result;
}
- (BOOL)disableSyncForIdentity:(PEPIdentity * _Nonnull)identity
error:(NSError * _Nullable * _Nullable)error
{


Loading…
Cancel
Save