]>
git.saurik.com Git - apple/security.git/blob - Security/sec/SOSCircle/Regressions/sc-30-peerinfo.c
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>
29 #include <Security/SecKeyPriv.h>
31 #include <SecureObjectSync/SOSCircle.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 "SOSCircle_regressions.h"
45 #include "SOSRegressionUtilities.h"
48 #include <MobileGestalt.h>
51 static int kTestTestCount
= 11;
52 static void tests(void)
54 SecKeyRef signingKey
= NULL
;
55 SOSFullPeerInfoRef fpi
= SOSCreateFullPeerInfoFromName(CFSTR("Test Peer"), &signingKey
, NULL
);
56 SOSPeerInfoRef pi
= SOSFullPeerInfoGetPeerInfo(fpi
);
59 ok(NULL
!= pi
, "info creation");
63 const uint8_t *buffer_p
= SOSPeerInfoEncodeToDER(pi
, NULL
, buffer
, buffer
+ sizeof(buffer
));
65 ok(buffer_p
!= NULL
, "encode");
67 SOSPeerInfoRef pi2
= SOSPeerInfoCreateFromDER(NULL
, NULL
, &buffer_p
, buffer
+ sizeof(buffer
));
71 skip("Decode failed", 1, ok(NULL
!= pi2
, "Decode"));
72 ok(CFEqual(pi
, pi2
), "Decode matches");
75 buffer_p
= SOSFullPeerInfoEncodeToDER(fpi
, NULL
, buffer
, buffer
+ sizeof(buffer
));
77 ok(buffer_p
!= NULL
, "Full peer encode");
79 SOSFullPeerInfoRef fpi2
= SOSFullPeerInfoCreateFromDER(kCFAllocatorDefault
, NULL
, &buffer_p
, buffer
+ sizeof(buffer
));
83 skip("Full Peer Decode failed", 1, ok(fpi2
, "Full peer inflated"));
85 ok(CFEqual(fpi
, fpi2
), "Full peer inflate matches");
89 // Application ticket time.
90 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
91 CFErrorRef error
= NULL
;
93 CFDataRef parameters
= SOSUserKeyCreateGenerateParameters(&error
);
94 ok(parameters
, "No parameters!");
95 ok(error
== NULL
, "Error: (%@)", error
);
98 SecKeyRef user_privkey
= SOSUserKeygen(cfpassword
, parameters
, &error
);
99 CFReleaseSafe(cfpassword
);
100 CFReleaseNull(parameters
);
101 SecKeyRef user_pubkey
= SecKeyCreatePublicFromPrivate(user_privkey
);
103 ok(SOSFullPeerInfoPromoteToApplication(fpi
, user_privkey
, &error
), "Promote to Application");
104 ok(SOSPeerInfoApplicationVerify(SOSFullPeerInfoGetPeerInfo(fpi
), user_pubkey
, &error
), "Promote to Application");
107 CFReleaseNull(user_privkey
);
108 CFReleaseNull(user_pubkey
);
110 CFReleaseNull(signingKey
);
117 int sc_30_peerinfo(int argc
, char *const *argv
)
119 plan_tests(kTestTestCount
);