]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/Regressions/sc-25-soskeygen.c
Security-57337.50.23.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 static int kTestTestCount = (10*(4+10*4));
53
54
55 static SecKeyRef getTestKey(CFDataRef cfpassword, CFDataRef parameters, CFErrorRef *error) {
56 SecKeyRef user_privkey = SOSUserKeygen(cfpassword, parameters, error);
57 ok(user_privkey, "No key!");
58 ok(*error == NULL, "Error: (%@)", *error);
59 CFReleaseNull(*error);
60 return user_privkey;
61 }
62
63 static void tests(void) {
64 CFErrorRef error = NULL;
65 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
66
67 for(int j=0; j < 10; j++) {
68 CFDataRef parameters = SOSUserKeyCreateGenerateParameters(&error);
69 ok(parameters, "No parameters!");
70 ok(error == NULL, "Error: (%@)", error);
71 CFReleaseNull(error);
72
73 SecKeyRef baseline_privkey = getTestKey(cfpassword, parameters, &error);
74 if(baseline_privkey) {
75 SecKeyRef baseline_pubkey = SecKeyCreatePublicFromPrivate(baseline_privkey);
76
77 for(int i = 0; i < 10; i++) {
78 SecKeyRef user_privkey = getTestKey(cfpassword, parameters, &error);
79 SecKeyRef user_pubkey = SecKeyCreatePublicFromPrivate(user_privkey);
80 ok(CFEqualSafe(baseline_privkey, user_privkey), "Private Keys Don't Match");
81 ok(CFEqualSafe(baseline_pubkey, user_pubkey), "Public Keys Don't Match");
82 CFReleaseNull(error);
83 }
84 }
85 CFReleaseNull(parameters);
86 }
87 CFReleaseNull(cfpassword);
88 }
89
90 int sc_25_soskeygen(int argc, char *const *argv)
91 {
92 plan_tests(kTestTestCount);
93
94 tests();
95
96 return 0;
97 }