]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/Regressions/sc-25-soskeygen.c
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / Regressions / sc-25-soskeygen.c
1 //
2 // sc-25-soskeygen.c
3 // sec
4 //
5 // Created by Richard Murphy on 6/1/15.
6 //
7 //
8
9 /*
10 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
11 *
12 * @APPLE_LICENSE_HEADER_START@
13 *
14 * This file contains Original Code and/or Modifications of Original Code
15 * as defined in and that are subject to the Apple Public Source License
16 * Version 2.0 (the 'License'). You may not use this file except in
17 * compliance with the License. Please obtain a copy of the License at
18 * http://www.opensource.apple.com/apsl/ and read it before using this
19 * file.
20 *
21 * The Original Code and all software distributed under the License are
22 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
23 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
24 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
26 * Please see the License for the specific language governing rights and
27 * limitations under the License.
28 *
29 * @APPLE_LICENSE_HEADER_END@
30 */
31
32
33
34 #include <Security/SecBase.h>
35 #include <Security/SecItem.h>
36 #include <Security/SecKey.h>
37 #include <Security/SecKeyPriv.h>
38
39 #include <Security/SecureObjectSync/SOSInternal.h>
40 #include <Security/SecureObjectSync/SOSUserKeygen.h>
41
42 #include <utilities/SecCFWrappers.h>
43
44 #include <CoreFoundation/CoreFoundation.h>
45
46 #include <stdlib.h>
47 #include <unistd.h>
48 #include "SOSCircle_regressions.h"
49
50 #include "SOSRegressionUtilities.h"
51
52
53 #if TARGET_OS_WATCH
54 #define NPARMS 3
55 #define NKEYS 3
56 #else
57 #define NPARMS 10
58 #define NKEYS 10
59 #endif
60
61 static int kTestTestCount = (NKEYS*(4+NPARMS*4));
62
63
64 static SecKeyRef createTestKey(CFDataRef cfpassword, CFDataRef parameters, CFErrorRef *error) {
65 SecKeyRef user_privkey = SOSUserKeygen(cfpassword, parameters, error);
66 ok(user_privkey, "No key!");
67 ok(*error == NULL, "Error: (%@)", *error);
68 CFReleaseNull(*error);
69 return user_privkey;
70 }
71
72 static void tests(void) {
73 CFErrorRef error = NULL;
74 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
75
76 for(int j=0; j < NPARMS; j++) {
77 CFDataRef parameters = SOSUserKeyCreateGenerateParameters(&error);
78 ok(parameters, "No parameters!");
79 ok(error == NULL, "Error: (%@)", error);
80 CFReleaseNull(error);
81
82 SecKeyRef baseline_privkey = createTestKey(cfpassword, parameters, &error);
83 if(baseline_privkey) {
84 SecKeyRef baseline_pubkey = SecKeyCreatePublicFromPrivate(baseline_privkey);
85
86 for(int i = 0; i < NKEYS; i++) {
87 SecKeyRef user_privkey = createTestKey(cfpassword, parameters, &error);
88 SecKeyRef user_pubkey = SecKeyCreatePublicFromPrivate(user_privkey);
89 ok(CFEqualSafe(baseline_privkey, user_privkey), "Private Keys Don't Match");
90 ok(CFEqualSafe(baseline_pubkey, user_pubkey), "Public Keys Don't Match");
91 CFReleaseNull(error);
92 CFReleaseNull(user_privkey);
93 CFReleaseNull(user_pubkey);
94 }
95 CFReleaseNull(baseline_pubkey);
96 }
97 CFReleaseNull(baseline_privkey);
98 CFReleaseNull(parameters);
99 }
100 CFReleaseNull(cfpassword);
101 }
102
103 int sc_25_soskeygen(int argc, char *const *argv)
104 {
105 plan_tests(kTestTestCount);
106
107 tests();
108
109 return 0;
110 }