]>
Commit | Line | Data |
---|---|---|
427c49bc A |
1 | /* |
2 | * sc-30-peerinfo.c | |
3 | * | |
4 | * Created by Mitch Adler on 1/25/121. | |
5 | * Copyright 2012 Apple Inc. All rights reserved. | |
6 | * | |
7 | */ | |
8 | ||
9 | ||
10 | #include <Security/SecBase.h> | |
11 | #include <Security/SecItem.h> | |
12 | #include <Security/SecKey.h> | |
13 | #include <Security/SecKeyPriv.h> | |
14 | ||
15 | #include <SecureObjectSync/SOSCircle.h> | |
16 | #include <SecureObjectSync/SOSPeerInfo.h> | |
17 | #include <SecureObjectSync/SOSInternal.h> | |
18 | #include <SecureObjectSync/SOSUserKeygen.h> | |
19 | ||
20 | #include <utilities/SecCFWrappers.h> | |
21 | ||
22 | #include <CoreFoundation/CoreFoundation.h> | |
23 | ||
24 | #include <stdlib.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #include "SOSCircle_regressions.h" | |
28 | ||
29 | #include "SOSRegressionUtilities.h" | |
30 | ||
31 | #if TARGET_OS_IPHONE | |
32 | #include <MobileGestalt.h> | |
33 | #endif | |
34 | ||
35 | static int kTestTestCount = 11; | |
36 | static void tests(void) | |
37 | { | |
38 | SecKeyRef signingKey = NULL; | |
39 | SOSFullPeerInfoRef fpi = SOSCreateFullPeerInfoFromName(CFSTR("Test Peer"), &signingKey, NULL); | |
40 | SOSPeerInfoRef pi = SOSFullPeerInfoGetPeerInfo(fpi); | |
41 | CFRetainSafe(pi); | |
42 | ||
43 | ok(NULL != pi, "info creation"); | |
44 | ||
45 | uint8_t buffer[4096]; | |
46 | ||
47 | const uint8_t *buffer_p = SOSPeerInfoEncodeToDER(pi, NULL, buffer, buffer + sizeof(buffer)); | |
48 | ||
49 | ok(buffer_p != NULL, "encode"); | |
50 | ||
51 | SOSPeerInfoRef pi2 = SOSPeerInfoCreateFromDER(NULL, NULL, &buffer_p, buffer + sizeof(buffer)); | |
52 | ||
53 | SKIP: | |
54 | { | |
55 | skip("Decode failed", 1, ok(NULL != pi2, "Decode")); | |
56 | ok(CFEqual(pi, pi2), "Decode matches"); | |
57 | } | |
58 | ||
59 | buffer_p = SOSFullPeerInfoEncodeToDER(fpi, NULL, buffer, buffer + sizeof(buffer)); | |
60 | ||
61 | ok(buffer_p != NULL, "Full peer encode"); | |
62 | ||
63 | SOSFullPeerInfoRef fpi2 = SOSFullPeerInfoCreateFromDER(kCFAllocatorDefault, NULL, &buffer_p, buffer + sizeof(buffer)); | |
64 | ||
65 | SKIP: | |
66 | { | |
67 | skip("Full Peer Decode failed", 1, ok(fpi2, "Full peer inflated")); | |
68 | ||
69 | ok(CFEqual(fpi, fpi2), "Full peer inflate matches"); | |
70 | } | |
71 | ||
72 | ||
73 | // Application ticket time. | |
74 | CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10); | |
75 | CFErrorRef error = NULL; | |
76 | ||
77 | CFDataRef parameters = SOSUserKeyCreateGenerateParameters(&error); | |
78 | ok(parameters, "No parameters!"); | |
79 | ok(error == NULL, "Error: (%@)", error); | |
80 | CFReleaseNull(error); | |
81 | ||
82 | SecKeyRef user_privkey = SOSUserKeygen(cfpassword, parameters, &error); | |
83 | CFReleaseSafe(cfpassword); | |
84 | CFReleaseNull(parameters); | |
85 | SecKeyRef user_pubkey = SecKeyCreatePublicFromPrivate(user_privkey); | |
86 | ||
87 | ok(SOSFullPeerInfoPromoteToApplication(fpi, user_privkey, &error), "Promote to Application"); | |
88 | ok(SOSPeerInfoApplicationVerify(SOSFullPeerInfoGetPeerInfo(fpi), user_pubkey, &error), "Promote to Application"); | |
89 | ||
90 | ||
91 | CFReleaseNull(user_privkey); | |
92 | CFReleaseNull(user_pubkey); | |
93 | ||
94 | CFReleaseNull(signingKey); | |
95 | CFReleaseNull(pi); | |
96 | CFReleaseNull(pi2); | |
97 | CFReleaseNull(fpi); | |
98 | CFReleaseNull(fpi2); | |
99 | } | |
100 | ||
101 | int sc_30_peerinfo(int argc, char *const *argv) | |
102 | { | |
103 | plan_tests(kTestTestCount); | |
104 | ||
105 | tests(); | |
106 | ||
107 | return 0; | |
108 | } |