Browse Source

IOSAD-50 moves internal stuff to PEPInternalSession

IOSAD-50
buff 5 years ago
parent
commit
a0fff021e1
10 changed files with 531 additions and 536 deletions
  1. +0
    -2
      pEpObjCAdapter.xcodeproj/project.pbxproj
  2. +0
    -136
      pEpObjCAdapter/PEPInternalSession+Internal.h
  3. +124
    -0
      pEpObjCAdapter/PEPInternalSession.h
  4. +0
    -1
      pEpObjCAdapter/PEPInternalSession.m
  5. +0
    -2
      pEpObjCAdapter/PEPObjCAdapter+Internal.h
  6. +1
    -123
      pEpObjCAdapter/PEPObjCAdapter.h
  7. +0
    -263
      pEpObjCAdapter/PEPObjCAdapter.m
  8. +132
    -0
      pEpObjCAdapter/PEPSession.h
  9. +266
    -0
      pEpObjCAdapter/PEPSession.m
  10. +8
    -9
      pEpObjCAdapter/PEPSessionProvider.m

+ 0
- 2
pEpObjCAdapter.xcodeproj/project.pbxproj View File

@ -128,7 +128,6 @@
43209B301ECC2ACD007E7E2E /* PEPObjCAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPObjCAdapter.m; sourceTree = "<group>"; };
43209B311ECC2ACD007E7E2E /* PEPQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPQueue.h; sourceTree = "<group>"; };
43209B321ECC2ACD007E7E2E /* PEPQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPQueue.m; sourceTree = "<group>"; };
43209B331ECC2ACD007E7E2E /* PEPInternalSession+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPInternalSession+Internal.h"; sourceTree = "<group>"; };
43209B341ECC2ACD007E7E2E /* PEPInternalSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPInternalSession.h; sourceTree = "<group>"; };
43209B351ECC2ACD007E7E2E /* PEPInternalSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPInternalSession.m; sourceTree = "<group>"; };
432EF6091C58B77900B6782A /* 0xB623F674.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 0xB623F674.asc; sourceTree = "<group>"; };
@ -224,7 +223,6 @@
43209B301ECC2ACD007E7E2E /* PEPObjCAdapter.m */,
43209B311ECC2ACD007E7E2E /* PEPQueue.h */,
43209B321ECC2ACD007E7E2E /* PEPQueue.m */,
43209B331ECC2ACD007E7E2E /* PEPInternalSession+Internal.h */,
43209B341ECC2ACD007E7E2E /* PEPInternalSession.h */,
43209B351ECC2ACD007E7E2E /* PEPInternalSession.m */,
43D27DE41F5DA78700795687 /* NSDictionary+Extension.h */,


+ 0
- 136
pEpObjCAdapter/PEPInternalSession+Internal.h View File

@ -1,136 +0,0 @@
//
// PEPSession+Internal.h
// pEpiOSAdapter
//
// Created by Edouard Tisserant on 16.05.17.
// Copyright © 2017 pp. All rights reserved.
//
#ifndef PEPSession_internal_h
#define PEPSession_internal_h
#import "PEPObjCAdapter.h"
@interface PEPInternalSession ()
@property (nonatomic) PEP_SESSION _Nullable session;
- (id _Nullable)initInternal;
/** Decrypt a message */
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys;
/** Re-evaluate rating of decrypted message */
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src;
/** Encrypt a message */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Encrypt a message for the given identity, which is usually a mySelf identity */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Determine the status color of a message to be sent */
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg;
/** Determine the rating of an identity */
- (PEP_rating)identityRating:(nonnull PEPDict *)identity;
/** Get trustwords for a fingerprint */
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened;
/**
Supply an account used by our user himself. The identity is supplemented with the missing parts
An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
An identity can have the following fields (all other keys are ignored).
It is not necessary to supply all fields; missing fields are supplemented by pp engine.
@"username": real name or nick name (if pseudonymous) of identity
@"address": URI or SMTP address
@"user_id": persistent unique ID for identity
@"lang": preferred languageID for communication with this ID (default: @"en")
@"fpr": fingerprint of key to use for communication with this ID
@"comm_type": communication type code (usually not needed)
As an example:
User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
@"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address",
@"23", @"user_id", nil];
*/
- (void)mySelf:(nonnull PEPMutableDict *)identity;
/**
Supplement missing information for an arbitrary identity (used for communication partners).
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)updateIdentity:(nonnull PEPMutableDict *)identity;
/**
Mark a key as trusted with a person.
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity;
/**
if a key is not trusted by the user tell this using this message
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity;
/**
Use this to undo keyCompromized or trustPersonalKey
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity;
#pragma mark -- Internal API (testing etc.)
/** For testing purpose, manual key import */
- (void)importKey:(nonnull NSString *)keydata;
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment;
/**
Retrieves the log from the engine.
*/
- (nonnull NSString *)getLog;
/** Determine trustwords for two identities */
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full;
/** Determine trustwords between sender of a message and receiving identity */
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus;
/**
@returns The list of supported languages for trustwords.
*/
- (NSArray<PEPLanguage *> * _Nonnull)languageList;
/**
Directly invokes the engine's undo_last_mistrust() function
*/
- (PEP_STATUS)undoLastMistrust;
@end
#endif /* PEPSession_internal_h */

+ 124
- 0
pEpObjCAdapter/PEPInternalSession.h View File

@ -8,11 +8,135 @@
#import <Foundation/Foundation.h>
#import "PEPObjCAdapter.h" //BUFF: remove
/**
Represents a real pEp session (in contrat to PEPSession, which is a fake session to handle to the client).
Never expose this class to the user.
N threads <-> N sessions, with the constraint that a session is never used
in a pEpEngine call more than once at the same time.
*/
@interface PEPInternalSession : NSObject
@property (nonatomic) PEP_SESSION _Nullable session;
// We do not want the client to use a PEPSession. The client is supposed to use PEPObjCAdapter() only.
// Find everything in PEPSession+Internal.h
- (id _Nullable)initInternal;
/** Decrypt a message */
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys;
/** Re-evaluate rating of decrypted message */
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src;
/** Encrypt a message */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Encrypt a message for the given identity, which is usually a mySelf identity */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Determine the status color of a message to be sent */
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg;
/** Determine the rating of an identity */
- (PEP_rating)identityRating:(nonnull PEPDict *)identity;
/** Get trustwords for a fingerprint */
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened;
/**
Supply an account used by our user himself. The identity is supplemented with the missing parts
An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
An identity can have the following fields (all other keys are ignored).
It is not necessary to supply all fields; missing fields are supplemented by pp engine.
@"username": real name or nick name (if pseudonymous) of identity
@"address": URI or SMTP address
@"user_id": persistent unique ID for identity
@"lang": preferred languageID for communication with this ID (default: @"en")
@"fpr": fingerprint of key to use for communication with this ID
@"comm_type": communication type code (usually not needed)
As an example:
User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
@"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address",
@"23", @"user_id", nil];
*/
- (void)mySelf:(nonnull PEPMutableDict *)identity;
/**
Supplement missing information for an arbitrary identity (used for communication partners).
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)updateIdentity:(nonnull PEPMutableDict *)identity;
/**
Mark a key as trusted with a person.
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity;
/**
if a key is not trusted by the user tell this using this message
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity;
/**
Use this to undo keyCompromized or trustPersonalKey
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity;
#pragma mark -- Internal API (testing etc.)
/** For testing purpose, manual key import */
- (void)importKey:(nonnull NSString *)keydata;
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment;
/**
Retrieves the log from the engine.
*/
- (nonnull NSString *)getLog;
/** Determine trustwords for two identities */
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full;
/** Determine trustwords between sender of a message and receiving identity */
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus;
/**
@returns The list of supported languages for trustwords.
*/
- (NSArray<PEPLanguage *> * _Nonnull)languageList;
/**
Directly invokes the engine's undo_last_mistrust() function
*/
- (PEP_STATUS)undoLastMistrust;
@end

+ 0
- 1
pEpObjCAdapter/PEPInternalSession.m View File

@ -7,7 +7,6 @@
//
#import "PEPInternalSession.h"
#import "PEPInternalSession+Internal.h"
#import "PEPObjCAdapter.h"
#import "PEPObjCAdapter+Internal.h"
#import "PEPMessage.h"


+ 0
- 2
pEpObjCAdapter/PEPObjCAdapter+Internal.h View File

@ -13,7 +13,6 @@
#import "PEPQueue.h"
#import "PEPInternalSession.h"
#import "PEPInternalSession+Internal.h"
@interface PEPObjCAdapter ()
@ -32,7 +31,6 @@
+ (void)bindSession:(PEPInternalSession*)session;
+ (void)unbindSession:(PEPInternalSession*)session;
@end
#endif /* PEPIOSAdapter_Internal_h */

+ 1
- 123
pEpObjCAdapter/PEPObjCAdapter.h View File

@ -8,7 +8,7 @@
#import <Foundation/Foundation.h>
#import "PEPMessage.h"
#import "PEPSession.h"
#include "sync_app.h"
@class PEPLanguage;
@ -23,14 +23,8 @@
- (PEP_STATUS)fastPolling:(bool)isfast;
@end
typedef NSDictionary<NSString *, id> PEPDict;
typedef NSMutableDictionary<NSString *, id> PEPMutableDict;
typedef NSArray<NSString *> PEPStringList;
@interface PEPObjCAdapter : NSObject
+ (void)cleanup;
/**
The HOME URL, where all pEp related files will be stored.
*/
@ -61,120 +55,4 @@ typedef NSArray<NSString *> PEPStringList;
*/
+ (void)stopSync;
#pragma mark - PEPSession Public Methods
/** Decrypt a message */
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys;
/** Re-evaluate rating of decrypted message */
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src;
/** Encrypt a message */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Encrypt a message for the given identity, which is usually a mySelf identity */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Determine the status color of a message to be sent */
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg;
/** Determine the rating of an identity */
- (PEP_rating)identityRating:(nonnull PEPDict *)identity;
/** Get trustwords for a fingerprint */
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened;
/**
Supply an account used by our user himself. The identity is supplemented with the missing parts
An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
An identity can have the following fields (all other keys are ignored).
It is not necessary to supply all fields; missing fields are supplemented by pp engine.
@"username": real name or nick name (if pseudonymous) of identity
@"address": URI or SMTP address
@"user_id": persistent unique ID for identity
@"lang": preferred languageID for communication with this ID (default: @"en")
@"fpr": fingerprint of key to use for communication with this ID
@"comm_type": communication type code (usually not needed)
As an example:
User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
@"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address",
@"23", @"user_id", nil];
*/
- (void)mySelf:(nonnull PEPMutableDict *)identity;
/**
Supplement missing information for an arbitrary identity (used for communication partners).
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)updateIdentity:(nonnull PEPMutableDict *)identity;
/**
Mark a key as trusted with a person.
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity;
/**
if a key is not trusted by the user tell this using this message
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity;
/**
Use this to undo keyCompromized or trustPersonalKey
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity;
#pragma mark -- Internal API (testing etc.)
/** For testing purpose, manual key import */
- (void)importKey:(nonnull NSString *)keydata;
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment;
/**
Retrieves the log from the engine.
*/
- (nonnull NSString *)getLog;
/** Determine trustwords for two identities */
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full;
/** Determine trustwords between sender of a message and receiving identity */
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus;
/**
@returns The list of supported languages for trustwords.
*/
- (NSArray<PEPLanguage *> * _Nonnull)languageList;
/**
Directly invokes the engine's undo_last_mistrust() function
*/
- (PEP_STATUS)undoLastMistrust;
@end

+ 0
- 263
pEpObjCAdapter/PEPObjCAdapter.m View File

@ -110,11 +110,6 @@ static NSLock *s_initLock;
@implementation PEPObjCAdapter
+ (void)cleanup
{
[PEPSessionProvider cleanup];
}
+ (void)initialize
{
s_homeURL = [self createApplicationDirectory];
@ -454,262 +449,4 @@ static id <PEPSyncDelegate> syncDelegate = nil;
}
#pragma mark - PEPSession Public Methods - non static
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys
{
return [PEPObjCAdapter decryptMessageDict:src dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys];
}
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
{
return [PEPObjCAdapter reEvaluateMessageRating:src];
}
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst
{
return [PEPObjCAdapter encryptMessageDict:src extra:keys dest:dst];
}
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst
{
return [PEPObjCAdapter encryptMessageDict:src identity:identity dest:dst];
}
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
{
return [PEPObjCAdapter outgoingMessageColor:msg];
}
- (PEP_rating)identityRating:(nonnull PEPDict *)identity
{
return [PEPObjCAdapter identityRating:identity];
}
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened
{
return [PEPObjCAdapter trustwords:fpr forLanguage:languageID shortened:shortened];
}
- (void)mySelf:(nonnull PEPMutableDict *)identity
{
[PEPObjCAdapter mySelf:identity];
}
- (void)updateIdentity:(nonnull PEPMutableDict *)identity
{
[PEPObjCAdapter updateIdentity:identity];
}
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
{
[PEPObjCAdapter trustPersonalKey:identity];
}
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity
{
[PEPObjCAdapter keyMistrusted:identity];
}
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity
{
[PEPObjCAdapter keyResetTrust:identity];
}
#pragma mark Internal API (testing etc.)
- (void)importKey:(nonnull NSString *)keydata
{
[PEPObjCAdapter importKey:keydata];
}
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment
{
[PEPObjCAdapter logTitle:title entity:entity description:description comment:comment];
}
- (nonnull NSString *)getLog
{
return [PEPObjCAdapter getLog];
}
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full
{
return [PEPObjCAdapter getTrustwordsIdentity1:identity1
identity2:identity2
language:language
full:full];
}
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
{
return [PEPObjCAdapter getTrustwordsMessageDict:messageDict
receiverDict:receiverDict
keysArray:keysArray
language:language
full:full
resultingStatus:resultingStatus];
}
- (NSArray<PEPLanguage *> * _Nonnull)languageList
{
return [PEPObjCAdapter languageList];
}
- (PEP_STATUS)undoLastMistrust
{
return [PEPObjCAdapter undoLastMistrust];
}
#pragma mark - PEPSession Public Methods - static
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session decryptMessageDict:src dest:dst keys:keys];
}
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session reEvaluateMessageRating:src];
}
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session encryptMessageDict:src extra:keys dest:dst];
}
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session encryptMessageDict:src identity:identity dest:dst];
}
+ (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session outgoingMessageColor:msg];
}
+ (PEP_rating)identityRating:(nonnull PEPDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session identityRating:identity];
}
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session trustwords:fpr forLanguage:languageID shortened:shortened];
}
+ (void)mySelf:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session mySelf:identity];
}
+ (void)updateIdentity:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session updateIdentity:identity];
}
+ (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session trustPersonalKey:identity];
}
+ (void)keyMistrusted:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session keyMistrusted:identity];
}
+ (void)keyResetTrust:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session keyResetTrust:identity];
}
#pragma mark Internal API (testing etc.)
+ (void)importKey:(nonnull NSString *)keydata
{
PEPInternalSession *session = [PEPSessionProvider session];
[session importKey:keydata];
}
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment
{
PEPInternalSession *session = [PEPSessionProvider session];
[session logTitle:title entity:entity description:description comment:comment];
}
+ (nonnull NSString *)getLog
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session getLog];
}
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
}
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session getTrustwordsMessageDict:messageDict receiverDict:receiverDict keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
}
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session languageList];
}
+ (PEP_STATUS)undoLastMistrust
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session undoLastMistrust];
}
@end

+ 132
- 0
pEpObjCAdapter/PEPSession.h View File

@ -8,6 +8,138 @@
#import <Foundation/Foundation.h>
#import "PEPMessage.h"
typedef NSDictionary<NSString *, id> PEPDict;
typedef NSMutableDictionary<NSString *, id> PEPMutableDict;
typedef NSArray<NSString *> PEPStringList;
@class PEPLanguage;
/**
Fake session to handle to the client.
Assures all calls are handled on the correct internal session for the thread it is called on.
You can instatntiate and use this session how often and wherever you want. Also over multiple threads.
Note: You must call `cleanup()` once before your process gets terminated to be able to gracefully shutdown.
*/
@interface PEPSession : NSObject
- (void)cleanup;
/** Decrypt a message */
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys;
/** Re-evaluate rating of decrypted message */
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src;
/** Encrypt a message */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Encrypt a message for the given identity, which is usually a mySelf identity */
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst;
/** Determine the status color of a message to be sent */
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg;
/** Determine the rating of an identity */
- (PEP_rating)identityRating:(nonnull PEPDict *)identity;
/** Get trustwords for a fingerprint */
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened;
/**
Supply an account used by our user himself. The identity is supplemented with the missing parts
An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
An identity can have the following fields (all other keys are ignored).
It is not necessary to supply all fields; missing fields are supplemented by pp engine.
@"username": real name or nick name (if pseudonymous) of identity
@"address": URI or SMTP address
@"user_id": persistent unique ID for identity
@"lang": preferred languageID for communication with this ID (default: @"en")
@"fpr": fingerprint of key to use for communication with this ID
@"comm_type": communication type code (usually not needed)
As an example:
User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
@"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address",
@"23", @"user_id", nil];
*/
- (void)mySelf:(nonnull PEPMutableDict *)identity;
/**
Supplement missing information for an arbitrary identity (used for communication partners).
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)updateIdentity:(nonnull PEPMutableDict *)identity;
/**
Mark a key as trusted with a person.
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity;
/**
if a key is not trusted by the user tell this using this message
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity;
/**
Use this to undo keyCompromized or trustPersonalKey
See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
*/
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity;
#pragma mark -- Internal API (testing etc.)
/** For testing purpose, manual key import */
- (void)importKey:(nonnull NSString *)keydata;
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment;
/**
Retrieves the log from the engine.
*/
- (nonnull NSString *)getLog;
/** Determine trustwords for two identities */
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full;
/** Determine trustwords between sender of a message and receiving identity */
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus;
/**
@returns The list of supported languages for trustwords.
*/
- (NSArray<PEPLanguage *> * _Nonnull)languageList;
/**
Directly invokes the engine's undo_last_mistrust() function
*/
- (PEP_STATUS)undoLastMistrust;
@end

+ 266
- 0
pEpObjCAdapter/PEPSession.m View File

@ -8,6 +8,272 @@
#import "PEPSession.h"
#import "PEPInternalSession.h"
#import "PEPSessionProvider.h"
@implementation PEPSession
#pragma mark - Public API
- (void)cleanup
{
[PEPSessionProvider cleanup];
}
- (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys
{
return [PEPSession decryptMessageDict:src dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys];
}
- (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
{
return [PEPSession reEvaluateMessageRating:src];
}
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst
{
return [PEPSession encryptMessageDict:src extra:keys dest:dst];
}
- (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst
{
return [PEPSession encryptMessageDict:src identity:identity dest:dst];
}
- (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
{
return [PEPSession outgoingMessageColor:msg];
}
- (PEP_rating)identityRating:(nonnull PEPDict *)identity
{
return [PEPSession identityRating:identity];
}
- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened
{
return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
}
- (void)mySelf:(nonnull PEPMutableDict *)identity
{
[PEPSession mySelf:identity];
}
- (void)updateIdentity:(nonnull PEPMutableDict *)identity
{
[PEPSession updateIdentity:identity];
}
- (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
{
[PEPSession trustPersonalKey:identity];
}
- (void)keyMistrusted:(nonnull PEPMutableDict *)identity
{
[PEPSession keyMistrusted:identity];
}
- (void)keyResetTrust:(nonnull PEPMutableDict *)identity
{
[PEPSession keyResetTrust:identity];
}
#pragma mark Internal API (testing etc.)
- (void)importKey:(nonnull NSString *)keydata
{
[PEPSession importKey:keydata];
}
- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment
{
[PEPSession logTitle:title entity:entity description:description comment:comment];
}
- (nonnull NSString *)getLog
{
return [PEPSession getLog];
}
- (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full
{
return [PEPSession getTrustwordsIdentity1:identity1
identity2:identity2
language:language
full:full];
}
- (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
{
return [PEPSession getTrustwordsMessageDict:messageDict
receiverDict:receiverDict
keysArray:keysArray
language:language
full:full
resultingStatus:resultingStatus];
}
- (NSArray<PEPLanguage *> * _Nonnull)languageList
{
return [PEPSession languageList];
}
- (PEP_STATUS)undoLastMistrust
{
return [PEPSession undoLastMistrust];
}
#pragma mark - Static
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
keys:(PEPStringList * _Nullable * _Nullable)keys
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session decryptMessageDict:src dest:dst keys:keys];
}
+ (PEP_rating)reEvaluateMessageRating:(nonnull PEPDict *)src
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session reEvaluateMessageRating:src];
}
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
extra:(nullable PEPStringList *)keys
dest:(PEPDict * _Nullable * _Nullable)dst
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session encryptMessageDict:src extra:keys dest:dst];
}
+ (PEP_STATUS)encryptMessageDict:(nonnull PEPDict *)src
identity:(nonnull PEPDict *)identity
dest:(PEPDict * _Nullable * _Nullable)dst
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session encryptMessageDict:src identity:identity dest:dst];
}
+ (PEP_rating)outgoingMessageColor:(nonnull PEPDict *)msg
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session outgoingMessageColor:msg];
}
+ (PEP_rating)identityRating:(nonnull PEPDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session identityRating:identity];
}
+ (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
shortened:(BOOL)shortened
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session trustwords:fpr forLanguage:languageID shortened:shortened];
}
+ (void)mySelf:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session mySelf:identity];
}
+ (void)updateIdentity:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session updateIdentity:identity];
}
+ (void)trustPersonalKey:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session trustPersonalKey:identity];
}
+ (void)keyMistrusted:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session keyMistrusted:identity];
}
+ (void)keyResetTrust:(nonnull PEPMutableDict *)identity
{
PEPInternalSession *session = [PEPSessionProvider session];
[session keyResetTrust:identity];
}
#pragma mark Internal API (testing etc.)
+ (void)importKey:(nonnull NSString *)keydata
{
PEPInternalSession *session = [PEPSessionProvider session];
[session importKey:keydata];
}
+ (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
description:(nullable NSString *)description comment:(nullable NSString *)comment
{
PEPInternalSession *session = [PEPSessionProvider session];
[session logTitle:title entity:entity description:description comment:comment];
}
+ (nonnull NSString *)getLog
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session getLog];
}
+ (nullable NSString *)getTrustwordsIdentity1:(nonnull PEPDict *)identity1
identity2:(nonnull PEPDict *)identity2
language:(nullable NSString *)language
full:(BOOL)full
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session getTrustwordsIdentity1:identity1 identity2:identity2 language:language full:full];
}
+ (nullable NSString *)getTrustwordsMessageDict:(nonnull PEPDict *)messageDict
receiverDict:(nonnull PEPDict *)receiverDict
keysArray:(PEPStringList * _Nullable)keysArray
language:(nullable NSString *)language
full:(BOOL)full
resultingStatus:(PEP_STATUS * _Nullable)resultingStatus
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session getTrustwordsMessageDict:messageDict receiverDict:receiverDict keysArray:keysArray language:language full:full resultingStatus:resultingStatus];
}
+ (NSArray<PEPLanguage *> * _Nonnull)languageList
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session languageList];
}
+ (PEP_STATUS)undoLastMistrust
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session undoLastMistrust];
}
@end

+ 8
- 9
pEpObjCAdapter/PEPSessionProvider.m View File

@ -9,7 +9,6 @@
#import "PEPSessionProvider.h"
#import "PEPInternalSession.h"
#import "PEPInternalSession+Internal.h"
#import "PEPCopyableThread.h"
@implementation PEPSessionProvider
@ -22,7 +21,7 @@ static NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *s_sessionFor
+ (PEPInternalSession * _Nonnull)session
{
[[self sessionForThreadLock] lock];
PEPCopyableThread *currentThread = [[PEPCopyableThread alloc] initWithThread:[NSThread currentThread]];
NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *dict = [self sessionForThreadDict];
PEPInternalSession *session = dict[currentThread];
@ -30,24 +29,24 @@ static NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *s_sessionFor
session = [[PEPInternalSession alloc] initInternal];
dict[currentThread] = session;
}
[self nullifySesssionOfFinishedThreads];
[self nullifySessionsOfFinishedThreads];
[[self sessionForThreadLock] unlock];
return session;
}
+ (void)cleanup
{
[[self sessionForThreadLock] lock];
NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *dict = [self sessionForThreadDict];
for (PEPCopyableThread *thread in dict.allKeys) {
[thread cancel];
[self nullifySessionForThread:thread];
}
[dict removeAllObjects];
[[self sessionForThreadLock] unlock];
}
@ -73,7 +72,7 @@ static NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *s_sessionFor
#pragma mark -
+ (void)nullifySesssionOfFinishedThreads
+ (void)nullifySessionsOfFinishedThreads
{
NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *dict = [self sessionForThreadDict];
for (PEPCopyableThread *thread in dict.allKeys) {
@ -90,7 +89,7 @@ static NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *s_sessionFor
[self performSelector:@selector(nullifySession:)
onThread:thread.thread
withObject:session
waitUntilDone:YES];
waitUntilDone:NO];
dict[thread] = nil;
}


Loading…
Cancel
Save