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 <SecureObjectSync/SOSCircle.h>
31 #include <SecureObjectSync/SOSCloudCircle.h>
32 #include <SecureObjectSync/SOSPeerInfo.h>
33 #include <SecureObjectSync/SOSInternal.h>
34 #include <SecureObjectSync/SOSUserKeygen.h>
36 #include <utilities/SecCFWrappers.h>
38 #include <CoreFoundation/CoreFoundation.h>
43 #include <securityd/SOSCloudCircleServer.h>
45 #include "SOSCircle_regressions.h"
47 #include "SOSRegressionUtilities.h"
49 static int kTestTestCount
= 18;
50 static void tests(void)
52 SOSCircleRef circle
= SOSCircleCreate(NULL
, CFSTR("TEST DOMAIN"), NULL
);
54 ok(NULL
!= circle
, "Circle creation");
56 ok(0 == SOSCircleCountPeers(circle
), "Zero peers");
58 //SecKeyRef publicKey = NULL;
59 SecKeyRef dev_a_key
= NULL
;
60 SecKeyRef dev_b_key
= NULL
;
61 CFErrorRef error
= NULL
;
62 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
64 ok(cfpassword
, "no password");
66 CFDataRef parameters
= SOSUserKeyCreateGenerateParameters(&error
);
67 ok(parameters
, "No parameters!");
68 ok(error
== NULL
, "Error: (%@)", error
);
71 SecKeyRef user_privkey
= SOSUserKeygen(cfpassword
, parameters
, &error
);
72 CFReleaseNull(parameters
);
74 SOSFullPeerInfoRef peer_a_full_info
= SOSCreateFullPeerInfoFromName(CFSTR("Peer A"), &dev_a_key
, NULL
);
76 SOSFullPeerInfoRef peer_b_full_info
= SOSCreateFullPeerInfoFromName(CFSTR("Peer B"), &dev_b_key
, NULL
);
78 ok(SOSCircleRequestAdmission(circle
, user_privkey
, peer_a_full_info
, NULL
));
79 ok(SOSCircleRequestAdmission(circle
, user_privkey
, peer_a_full_info
, NULL
));
80 ok(SOSCircleRequestAdmission(circle
, user_privkey
, peer_a_full_info
, NULL
));
82 ok(SOSCircleAcceptRequest(circle
, user_privkey
, peer_a_full_info
, SOSFullPeerInfoGetPeerInfo(peer_a_full_info
), NULL
));
84 ok(!SOSCircleRequestAdmission(circle
, user_privkey
, peer_a_full_info
, NULL
));
85 ok(SOSCircleRequestAdmission(circle
, user_privkey
, peer_b_full_info
, NULL
));
87 ok(SOSCircleCountPeers(circle
) == 1, "Peer count");
89 size_t size
= SOSCircleGetDEREncodedSize(circle
, &error
);
91 uint8_t* start
= SOSCircleEncodeToDER(circle
, &error
, buffer
, buffer
+ sizeof(buffer
));
93 ok(start
, "successful encoding");
94 ok(start
== buffer
, "Used whole buffer");
96 const uint8_t *der
= buffer
;
97 SOSCircleRef inflated
= SOSCircleCreateFromDER(NULL
, &error
, &der
, buffer
+ sizeof(buffer
));
99 ok(inflated
, "inflated");
100 ok(CFEqualSafe(inflated
, circle
), "Compares");
103 ok(SOSCircleRemovePeer(circle
, user_privkey
, peer_a_full_info
, SOSFullPeerInfoGetPeerInfo(peer_a_full_info
), NULL
));
104 ok(SOSCircleCountPeers(circle
) == 0, "Peer count");
106 CFReleaseNull(dev_a_key
);
107 CFReleaseNull(cfpassword
);
110 int sc_40_circle(int argc
, char *const *argv
)
112 plan_tests(kTestTestCount
);