mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			76 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			76 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Matlab
		
	
| 
								 
											10 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								//  Copyright (c) 2017 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#import <XCTest/XCTest.h>
							 | 
						||
| 
								 | 
							
								#import <25519/Curve25519.h>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								#import "OWSUnitTestEnvironment.h"
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								#import "SecurityUtils.h"
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								#import "OWSIdentityManager.h"
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								#import "OWSRecipientIdentity.h"
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								#import "TSStorageManager.h"
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								#import "TextSecureKitEnv.h"
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								@interface TSStorageIdentityKeyStoreTests : XCTestCase
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@end
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@implementation TSStorageIdentityKeyStoreTests
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								- (void)setUp {
							 | 
						||
| 
								 | 
							
								    [super setUp];
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								    
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								    [[TSStorageManager sharedManager] purgeCollection:@"TSStorageManagerTrustedKeysCollection"];
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								    [OWSRecipientIdentity removeAllObjectsInCollection];
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								- (void)tearDown {
							 | 
						||
| 
								 | 
							
								    // Put teardown code here. This method is called after the invocation of each test method in the class.
							 | 
						||
| 
								 | 
							
								    [super tearDown];
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								- (void)testNewEmptyKey {
							 | 
						||
| 
								 | 
							
								    NSData *newKey = [SecurityUtils generateRandomBytes:32];
							 | 
						||
| 
								 | 
							
								    NSString *recipientId = @"test@gmail.com";
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
							 | 
						||
| 
								 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								- (void)testAlreadyRegisteredKey {
							 | 
						||
| 
								 | 
							
								    NSData *newKey = [SecurityUtils generateRandomBytes:32];
							 | 
						||
| 
								 | 
							
								    NSString *recipientId = @"test@gmail.com";
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    [[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								    
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
							 | 
						||
| 
								 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								- (void)testChangedKey
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								    NSData *originalKey = [SecurityUtils generateRandomBytes:32];
							 | 
						||
| 
								 | 
							
								    NSString *recipientId = @"test@protonmail.com";
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    [[OWSIdentityManager sharedManager] saveRemoteIdentity:originalKey recipientId:recipientId];
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								    
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
							 | 
						||
| 
								 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								    
							 | 
						||
| 
								 | 
							
								    NSData *otherKey = [SecurityUtils generateRandomBytes:32];
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
							 | 
						||
| 
								 | 
							
								    XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								- (void)testIdentityKey {
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    [[OWSIdentityManager sharedManager] generateNewIdentityKey];
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								    
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    XCTAssert([[[OWSIdentityManager sharedManager] identityKeyPair].publicKey length] == 32);
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@end
							 |