2 // KeychainCircleTests.m
7 #import <XCTest/XCTest.h>
9 #import "KCSRPContext.h"
10 #include <corecrypto/ccrng.h>
11 #include <corecrypto/ccsha2.h>
12 #include <corecrypto/ccdh_gp.h>
14 @interface KCSRPTests : XCTestCase
18 @implementation KCSRPTests
22 // Put setup code here. This method is called before the invocation of each test method in the class.
26 // Put teardown code here. This method is called after the invocation of each test method in the class.
30 - (void) negotiateWithUser: (NSString*) user
31 digestInfo: (const struct ccdigest_info*) di
32 group: (ccsrp_const_gp_t) group
33 randomSource: (struct ccrng_state *) rng {
35 NSString* password = @"TryMeAs a ΓΌ password, sucka";
37 KCSRPClientContext * client = [[KCSRPClientContext alloc] initWithUser: user
41 XCTAssert([client getKey] == NULL, @"No key yet");
42 XCTAssert(![client isAuthenticated], @"Not yet authenticated");
44 XCTAssert(client, @"No KCSRPClientContext created");
46 KCSRPServerContext * server = [[KCSRPServerContext alloc] initWithUser:user
53 XCTAssert(server, @"No KCSRPServerContext created");
55 XCTAssert([server getKey] == NULL, @"No key yet");
59 NSData* A_data = [client copyStart:&error];
60 XCTAssert(A_data, @"copied start failed (%@)", error);
63 XCTAssert([client getKey] == NULL, @"Shouldn't have key");
64 XCTAssert(![client isAuthenticated], @"Not yet authenticated");
66 NSData* B_data = [server copyChallengeFor:A_data error: &error];
67 XCTAssert(B_data, @"Copied challenge for start failed (%@)", error);
70 XCTAssert([server getKey] != NULL, @"Should have key");
71 XCTAssert(![server isAuthenticated], @"Not yet authenticated");
73 NSData* M_data = [client copyResposeToChallenge:B_data
77 XCTAssert(M_data, @"Copied responseToChallenge failed (%@)", error);
80 XCTAssert([client getKey] != NULL, @"Don't have key");
81 XCTAssert(![client isAuthenticated], @"Not yet authenticated");
83 NSData* HAMK_data = [server copyConfirmationFor:M_data error:&error];
84 XCTAssert(HAMK_data, @"Copied confirmation failed (%@)", error);
87 XCTAssert([server getKey] != NULL, @"Don't have key");
88 XCTAssert([server isAuthenticated], @"Not yet authenticated");
90 bool verified = [client verifyConfirmation:HAMK_data error:&error];
91 XCTAssert(verified, @"Verification failed (%@)", error);
94 XCTAssert([client getKey] != NULL, @"Don't have key");
95 XCTAssert([client isAuthenticated], @"Should be authenticated");
100 - (void)testNegotiation {
101 [self negotiateWithUser: @"TestUser"
102 digestInfo: ccsha256_di()
103 group: ccsrp_gp_rfc5054_3072()
104 randomSource: ccrng(NULL)];