4 * Created by Mitch Adler on 1/25/121.
5 * Copyright 2012 Apple Inc. All rights reserved.
10 #include <Security/SecBase.h>
11 #include <Security/SecItem.h>
12 #include <Security/SecKey.h>
14 #include <SecureObjectSync/SOSAccount.h>
15 #include <SecureObjectSync/SOSCircle.h>
16 #include <SecureObjectSync/SOSPeerInfo.h>
17 #include <SecureObjectSync/SOSInternal.h>
19 #include <utilities/SecCFWrappers.h>
21 #include <CoreFoundation/CoreFoundation.h>
26 #include "SOSCircle_regressions.h"
28 #include "SOSRegressionUtilities.h"
31 static int kTestTestCount
= 15;
32 static void tests(void)
34 SecKeyRef publicKey
= NULL
;
35 SecKeyRef signingKey
= NULL
;
36 GenerateECPair(256, &publicKey
, &signingKey
);
38 CFErrorRef error
= NULL
;
39 SOSCircleRef circle
= SOSCircleCreate(NULL
, CFSTR("Test Circle"), &error
);
41 CFStringRef circle_key
= SOSCircleKeyCreateWithCircle(circle
, NULL
);
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
));
50 CFReleaseSafe(circle_key
);
52 SOSPeerInfoRef pi
= SOSCreatePeerInfoFromName(CFSTR("Test Peer"), &publicKey
, &error
);
54 CFStringRef other_peer_id
= CFSTR("OTHER PEER");
56 CFStringRef messageKey
= SOSMessageKeyCreateWithCircleAndPeerNames(circle
, SOSPeerInfoGetPeerID(pi
), other_peer_id
);
58 ok(messageKey
, "Getting message key '%@'", messageKey
);
60 CFStringRef message_circle_name
= NULL
;
61 CFStringRef message_from_peer_id
= NULL
;
62 CFStringRef message_to_peer_id
= NULL
;
64 is(SOSKVSKeyGetKeyType(messageKey
), kMessageKey
, "Is message key");
65 is(SOSKVSKeyGetKeyTypeAndParse(messageKey
,
67 &message_from_peer_id
,
68 &message_to_peer_id
), kMessageKey
, "Is message key, extract parts");
71 ok(CFEqualSafe(SOSCircleGetName(circle
), message_circle_name
), "circle key matches in message (%@ v %@)",SOSCircleGetName(circle
), message_circle_name
);
74 ok(CFEqualSafe(SOSPeerInfoGetPeerID(pi
), message_from_peer_id
), "from peer set correctly (%@ v %@)", SOSPeerInfoGetPeerID(pi
), message_from_peer_id
);
76 ok(CFEqualSafe(other_peer_id
, message_to_peer_id
), "to peer set correctly (%@ v %@)", other_peer_id
, message_to_peer_id
);
78 CFStringRef retirementKey
= SOSRetirementKeyCreateWithCircleAndPeer(circle
, SOSPeerInfoGetPeerID(pi
));
79 CFStringRef retirement_circle_name
= NULL
;
80 CFStringRef retirement_peer_id
= NULL
;
82 is(SOSKVSKeyGetKeyType(retirementKey
), kRetirementKey
, "Is retirement key");
83 is(SOSKVSKeyGetKeyTypeAndParse(retirementKey
,
84 &retirement_circle_name
,
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
);
93 CFReleaseNull(publicKey
);
94 CFReleaseNull(signingKey
);
95 CFReleaseNull(circle
);
98 CFReleaseNull(messageKey
);
99 CFReleaseNull(message_circle_name
);
100 CFReleaseNull(message_from_peer_id
);
101 CFReleaseNull(message_to_peer_id
);
104 int sc_20_keynames(int argc
, char *const *argv
)
106 plan_tests(kTestTestCount
);