]> git.saurik.com Git - apple/security.git/blob - sec/SOSCircle/Regressions/sc-20-keynames.c
Security-55471.tar.gz
[apple/security.git] / sec / SOSCircle / Regressions / sc-20-keynames.c
1 /*
2 * sc-20-keynames.c
3 *
4 * Created by Mitch Adler on 1/25/121.
5 * Copyright 2012 Apple Inc. All rights reserved.
6 *
7 */
8
9
10 #include <Security/SecBase.h>
11 #include <Security/SecItem.h>
12 #include <Security/SecKey.h>
13
14 #include <SecureObjectSync/SOSAccount.h>
15 #include <SecureObjectSync/SOSCircle.h>
16 #include <SecureObjectSync/SOSPeerInfo.h>
17 #include <SecureObjectSync/SOSInternal.h>
18
19 #include <utilities/SecCFWrappers.h>
20
21 #include <CoreFoundation/CoreFoundation.h>
22
23 #include <stdlib.h>
24 #include <unistd.h>
25
26 #include "SOSCircle_regressions.h"
27
28 #include "SOSRegressionUtilities.h"
29
30
31 static int kTestTestCount = 15;
32 static void tests(void)
33 {
34 SecKeyRef publicKey = NULL;
35 SecKeyRef signingKey = NULL;
36 GenerateECPair(256, &publicKey, &signingKey);
37
38 CFErrorRef error = NULL;
39 SOSCircleRef circle = SOSCircleCreate(NULL, CFSTR("Test Circle"), &error);
40
41 CFStringRef circle_key = SOSCircleKeyCreateWithCircle(circle, NULL);
42
43 CFStringRef circle_name = NULL;
44 ok(circle_key, "Circle key created");
45 is(SOSKVSKeyGetKeyType(circle_key), kCircleKey, "Is circle key");
46 is(SOSKVSKeyGetKeyTypeAndParse(circle_key, &circle_name, NULL, NULL), kCircleKey, "Is circle key, extract name");
47 ok(circle_name, "Circle name extracted");
48 ok(CFEqualSafe(circle_name, SOSCircleGetName(circle)), "Circle name matches '%@' '%@'", circle_name, SOSCircleGetName(circle));
49
50 CFReleaseSafe(circle_key);
51
52 SOSPeerInfoRef pi = SOSCreatePeerInfoFromName(CFSTR("Test Peer"), &publicKey, &error);
53
54 CFStringRef other_peer_id = CFSTR("OTHER PEER");
55
56 CFStringRef messageKey = SOSMessageKeyCreateWithCircleAndPeerNames(circle, SOSPeerInfoGetPeerID(pi), other_peer_id);
57
58 ok(messageKey, "Getting message key '%@'", messageKey);
59
60 CFStringRef message_circle_name = NULL;
61 CFStringRef message_from_peer_id = NULL;
62 CFStringRef message_to_peer_id = NULL;
63
64 is(SOSKVSKeyGetKeyType(messageKey), kMessageKey, "Is message key");
65 is(SOSKVSKeyGetKeyTypeAndParse(messageKey,
66 &message_circle_name,
67 &message_from_peer_id,
68 &message_to_peer_id), kMessageKey, "Is message key, extract parts");
69
70
71 ok(CFEqualSafe(SOSCircleGetName(circle), message_circle_name), "circle key matches in message (%@ v %@)",SOSCircleGetName(circle), message_circle_name);
72
73
74 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi), message_from_peer_id), "from peer set correctly (%@ v %@)", SOSPeerInfoGetPeerID(pi), message_from_peer_id);
75
76 ok(CFEqualSafe(other_peer_id, message_to_peer_id), "to peer set correctly (%@ v %@)", other_peer_id, message_to_peer_id);
77
78 CFStringRef retirementKey = SOSRetirementKeyCreateWithCircleAndPeer(circle, SOSPeerInfoGetPeerID(pi));
79 CFStringRef retirement_circle_name = NULL;
80 CFStringRef retirement_peer_id = NULL;
81
82 is(SOSKVSKeyGetKeyType(retirementKey), kRetirementKey, "Is retirement key");
83 is(SOSKVSKeyGetKeyTypeAndParse(retirementKey,
84 &retirement_circle_name,
85 &retirement_peer_id,
86 NULL), kRetirementKey, "Is retirement key, extract parts");
87 CFReleaseSafe(retirementKey);
88 ok(CFEqualSafe(SOSCircleGetName(circle), retirement_circle_name), "circle key matches in retirement (%@ v %@)",
89 SOSCircleGetName(circle), retirement_circle_name);
90 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi), retirement_peer_id), "retirement peer set correctly (%@ v %@)",
91 SOSPeerInfoGetPeerID(pi), retirement_peer_id);
92
93 CFReleaseNull(publicKey);
94 CFReleaseNull(signingKey);
95 CFReleaseNull(circle);
96 CFReleaseNull(error);
97 CFReleaseNull(pi);
98 CFReleaseNull(messageKey);
99 CFReleaseNull(message_circle_name);
100 CFReleaseNull(message_from_peer_id);
101 CFReleaseNull(message_to_peer_id);
102 }
103
104 int sc_20_keynames(int argc, char *const *argv)
105 {
106 plan_tests(kTestTestCount);
107
108 tests();
109
110 return 0;
111 }