2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 #include <Security/SecBase.h>
27 #include <Security/SecItem.h>
28 #include <Security/SecKey.h>
30 #include "keychain/SecureObjectSync/SOSAccount.h"
31 #include "keychain/SecureObjectSync/SOSCircle.h"
32 #include <Security/SecureObjectSync/SOSPeerInfo.h>
33 #include "keychain/SecureObjectSync/SOSInternal.h"
34 #include "keychain/SecureObjectSync/SOSKVSKeys.h"
35 #include <utilities/SecCFWrappers.h>
37 #include <CoreFoundation/CoreFoundation.h>
42 #include "SOSCircle_regressions.h"
44 #include "SOSRegressionUtilities.h"
49 static int kTestTestCount = 15;
50 static void tests(void)
52 SecKeyRef publicKey = NULL;
53 SecKeyRef octagonSigningPublicKey = NULL;
54 SecKeyRef octagonEncryptionPublicKey = NULL;
56 CFErrorRef error = NULL;
58 SOSCircleRef circle = SOSCircleCreate(NULL, CFSTR("Test Circle"), &error);
60 CFStringRef circle_key = SOSCircleKeyCreateWithCircle(circle, NULL);
62 CFStringRef circle_name = NULL;
63 ok(circle_key, "Circle key created");
64 is(SOSKVSKeyGetKeyType(circle_key), kCircleKey, "Is circle key");
65 is(SOSKVSKeyGetKeyTypeAndParse(circle_key, &circle_name, NULL, NULL, NULL, NULL, NULL), kCircleKey, "Is circle key, extract name");
66 ok(circle_name, "Circle name extracted");
67 ok(CFEqualSafe(circle_name, SOSCircleGetName(circle)), "Circle name matches '%@' '%@'", circle_name, SOSCircleGetName(circle));
68 CFReleaseNull(circle_name);
69 CFReleaseNull(circle_key);
71 SOSPeerInfoRef pi = SOSCreatePeerInfoFromName(CFSTR("Test Peer"), &publicKey, &octagonSigningPublicKey, &octagonEncryptionPublicKey, &error);
73 CFStringRef other_peer_id = CFSTR("OTHER PEER");
75 CFStringRef messageKey = SOSMessageKeyCreateWithCircleAndPeerNames(circle, SOSPeerInfoGetPeerID(pi), other_peer_id);
77 ok(messageKey, "Getting message key '%@'", messageKey);
79 CFStringRef message_circle_name = NULL;
80 CFStringRef message_from_peer_id = NULL;
81 CFStringRef message_to_peer_id = NULL;
82 CFStringRef message_ring = NULL;
83 CFStringRef message_peer_info = NULL;
84 CFStringRef message_backup = NULL;
86 is(SOSKVSKeyGetKeyType(messageKey), kMessageKey, "Is message key");
87 is(SOSKVSKeyGetKeyTypeAndParse(messageKey,
92 &message_from_peer_id,
93 &message_to_peer_id), kMessageKey, "Is message key, extract parts");
96 ok(CFEqualSafe(SOSCircleGetName(circle), message_circle_name), "circle key matches in message (%@ v %@)",SOSCircleGetName(circle), message_circle_name);
99 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi), message_from_peer_id), "from peer set correctly (%@ v %@)", SOSPeerInfoGetPeerID(pi), message_from_peer_id);
101 ok(CFEqualSafe(other_peer_id, message_to_peer_id), "to peer set correctly (%@ v %@)", other_peer_id, message_to_peer_id);
103 CFStringRef retirementKey = SOSRetirementKeyCreateWithCircleAndPeer(circle, SOSPeerInfoGetPeerID(pi));
104 CFStringRef retirement_circle_name = NULL;
105 CFStringRef retirement_peer_id = NULL;
107 is(SOSKVSKeyGetKeyType(retirementKey), kRetirementKey, "Is retirement key");
108 is(SOSKVSKeyGetKeyTypeAndParse(retirementKey,
109 &retirement_circle_name,
114 NULL), kRetirementKey, "Is retirement key, extract parts");
115 CFReleaseSafe(retirementKey);
116 ok(CFEqualSafe(SOSCircleGetName(circle), retirement_circle_name), "circle key matches in retirement (%@ v %@)",
117 SOSCircleGetName(circle), retirement_circle_name);
118 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi), retirement_peer_id), "retirement peer set correctly (%@ v %@)",
119 SOSPeerInfoGetPeerID(pi), retirement_peer_id);
121 CFReleaseNull(publicKey);
122 CFReleaseNull(octagonSigningPublicKey);
123 CFReleaseNull(octagonEncryptionPublicKey);
124 CFReleaseNull(circle);
125 CFReleaseNull(error);
127 CFReleaseNull(messageKey);
128 CFReleaseNull(message_circle_name);
129 CFReleaseNull(message_from_peer_id);
130 CFReleaseNull(message_to_peer_id);
131 CFReleaseNull(retirement_circle_name);
132 CFReleaseNull(retirement_peer_id);
137 int sc_20_keynames(int argc, char *const *argv)
140 plan_tests(kTestTestCount);