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>
13 #include <CommonCrypto/CommonRandomSPI.h>
15 @interface KCSRPTests : XCTestCase
19 @implementation KCSRPTests
23 // Put setup code here. This method is called before the invocation of each test method in the class.
27 // Put teardown code here. This method is called after the invocation of each test method in the class.
31 - (void) negotiateWithUser: (NSString*) user
32 digestInfo: (const struct ccdigest_info*) di
33 group: (ccsrp_const_gp_t) group
34 randomSource: (struct ccrng_state *) rng {
36 NSString* password = @"TryMeAs a ΓΌ password, sucka";
38 KCSRPClientContext * client = [[KCSRPClientContext alloc] initWithUser: user
42 XCTAssert([client getKey] == NULL, @"No key yet");
43 XCTAssert(![client isAuthenticated], @"Not yet authenticated");
45 XCTAssert(client, @"No KCSRPClientContext created");
47 KCSRPServerContext * server = [[KCSRPServerContext alloc] initWithUser:user
54 XCTAssert(server, @"No KCSRPServerContext created");
56 XCTAssert([server getKey] == NULL, @"No key yet");
60 NSData* A_data = [client copyStart:&error];
61 XCTAssert(A_data, @"copied start failed (%@)", error);
64 XCTAssert([client getKey] == NULL, @"Shouldn't have key");
65 XCTAssert(![client isAuthenticated], @"Not yet authenticated");
67 NSData* B_data = [server copyChallengeFor:A_data error: &error];
68 XCTAssert(B_data, @"Copied challenge for start failed (%@)", error);
71 XCTAssert([server getKey] != NULL, @"Should have key");
72 XCTAssert(![server isAuthenticated], @"Not yet authenticated");
74 NSData* M_data = [client copyResposeToChallenge:B_data
78 XCTAssert(M_data, @"Copied responseToChallenge failed (%@)", error);
81 XCTAssert([client getKey] != NULL, @"Don't have key");
82 XCTAssert(![client isAuthenticated], @"Not yet authenticated");
84 NSData* HAMK_data = [server copyConfirmationFor:M_data error:&error];
85 XCTAssert(HAMK_data, @"Copied confirmation failed (%@)", error);
88 XCTAssert([server getKey] != NULL, @"Don't have key");
89 XCTAssert([server isAuthenticated], @"Not yet authenticated");
91 bool verified = [client verifyConfirmation:HAMK_data error:&error];
92 XCTAssert(verified, @"Verification failed (%@)", error);
95 XCTAssert([client getKey] != NULL, @"Don't have key");
96 XCTAssert([client isAuthenticated], @"Should be authenticated");
101 - (void)testNegotiation {
102 [self negotiateWithUser: @"TestUser"
103 digestInfo: ccsha256_di()
104 group: ccsrp_gp_rfc5054_3072()
105 randomSource: ccDRBGGetRngState()];