]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/Regressions/sc-20-keynames.c
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / Regressions / sc-20-keynames.c
1 /*
2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26 #include <Security/SecBase.h>
27 #include <Security/SecItem.h>
28 #include <Security/SecKey.h>
29
30 #include <Security/SecureObjectSync/SOSAccount.h>
31 #include <Security/SecureObjectSync/SOSCircle.h>
32 #include <Security/SecureObjectSync/SOSPeerInfo.h>
33 #include <Security/SecureObjectSync/SOSInternal.h>
34 #include <Security/SecureObjectSync/SOSKVSKeys.h>
35 #include <utilities/SecCFWrappers.h>
36
37 #include <CoreFoundation/CoreFoundation.h>
38
39 #include <stdlib.h>
40 #include <unistd.h>
41
42 #include "SOSCircle_regressions.h"
43
44 #include "SOSRegressionUtilities.h"
45
46
47 static int kTestTestCount = 15;
48 static void tests(void)
49 {
50 SecKeyRef publicKey = NULL;
51
52 CFErrorRef error = NULL;
53
54 SOSCircleRef circle = SOSCircleCreate(NULL, CFSTR("Test Circle"), &error);
55
56 CFStringRef circle_key = SOSCircleKeyCreateWithCircle(circle, NULL);
57
58 CFStringRef circle_name = NULL;
59 ok(circle_key, "Circle key created");
60 is(SOSKVSKeyGetKeyType(circle_key), kCircleKey, "Is circle key");
61 is(SOSKVSKeyGetKeyTypeAndParse(circle_key, &circle_name, NULL, NULL, NULL, NULL, NULL), kCircleKey, "Is circle key, extract name");
62 ok(circle_name, "Circle name extracted");
63 ok(CFEqualSafe(circle_name, SOSCircleGetName(circle)), "Circle name matches '%@' '%@'", circle_name, SOSCircleGetName(circle));
64 CFReleaseNull(circle_name);
65 CFReleaseNull(circle_key);
66
67 SOSPeerInfoRef pi = SOSCreatePeerInfoFromName(CFSTR("Test Peer"), &publicKey, &error);
68
69 CFStringRef other_peer_id = CFSTR("OTHER PEER");
70
71 CFStringRef messageKey = SOSMessageKeyCreateWithCircleAndPeerNames(circle, SOSPeerInfoGetPeerID(pi), other_peer_id);
72
73 ok(messageKey, "Getting message key '%@'", messageKey);
74
75 CFStringRef message_circle_name = NULL;
76 CFStringRef message_from_peer_id = NULL;
77 CFStringRef message_to_peer_id = NULL;
78 CFStringRef message_ring = NULL;
79 CFStringRef message_peer_info = NULL;
80 CFStringRef message_backup = NULL;
81
82 is(SOSKVSKeyGetKeyType(messageKey), kMessageKey, "Is message key");
83 is(SOSKVSKeyGetKeyTypeAndParse(messageKey,
84 &message_circle_name,
85 &message_peer_info,
86 &message_ring,
87 &message_backup,
88 &message_from_peer_id,
89 &message_to_peer_id), kMessageKey, "Is message key, extract parts");
90
91
92 ok(CFEqualSafe(SOSCircleGetName(circle), message_circle_name), "circle key matches in message (%@ v %@)",SOSCircleGetName(circle), message_circle_name);
93
94
95 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi), message_from_peer_id), "from peer set correctly (%@ v %@)", SOSPeerInfoGetPeerID(pi), message_from_peer_id);
96
97 ok(CFEqualSafe(other_peer_id, message_to_peer_id), "to peer set correctly (%@ v %@)", other_peer_id, message_to_peer_id);
98
99 CFStringRef retirementKey = SOSRetirementKeyCreateWithCircleAndPeer(circle, SOSPeerInfoGetPeerID(pi));
100 CFStringRef retirement_circle_name = NULL;
101 CFStringRef retirement_peer_id = NULL;
102
103 is(SOSKVSKeyGetKeyType(retirementKey), kRetirementKey, "Is retirement key");
104 is(SOSKVSKeyGetKeyTypeAndParse(retirementKey,
105 &retirement_circle_name,
106 NULL,
107 NULL,
108 NULL,
109 &retirement_peer_id,
110 NULL), kRetirementKey, "Is retirement key, extract parts");
111 CFReleaseSafe(retirementKey);
112 ok(CFEqualSafe(SOSCircleGetName(circle), retirement_circle_name), "circle key matches in retirement (%@ v %@)",
113 SOSCircleGetName(circle), retirement_circle_name);
114 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi), retirement_peer_id), "retirement peer set correctly (%@ v %@)",
115 SOSPeerInfoGetPeerID(pi), retirement_peer_id);
116
117 CFReleaseNull(publicKey);
118 CFReleaseNull(circle);
119 CFReleaseNull(error);
120 CFReleaseNull(pi);
121 CFReleaseNull(messageKey);
122 CFReleaseNull(message_circle_name);
123 CFReleaseNull(message_from_peer_id);
124 CFReleaseNull(message_to_peer_id);
125 CFReleaseNull(retirement_circle_name);
126 CFReleaseNull(retirement_peer_id);
127
128 }
129
130 int sc_20_keynames(int argc, char *const *argv)
131 {
132 plan_tests(kTestTestCount);
133
134 tests();
135
136 return 0;
137 }