5 // Created by Richard Murphy on 6/1/15.
10 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
12 * @APPLE_LICENSE_HEADER_START@
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
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.
29 * @APPLE_LICENSE_HEADER_END@
34 #include <Security/SecBase.h>
35 #include <Security/SecItem.h>
36 #include <Security/SecKey.h>
37 #include <Security/SecKeyPriv.h>
39 #include <Security/SecureObjectSync/SOSInternal.h>
40 #include <Security/SecureObjectSync/SOSUserKeygen.h>
42 #include <utilities/SecCFWrappers.h>
44 #include <CoreFoundation/CoreFoundation.h>
48 #include "SOSCircle_regressions.h"
50 #include "SOSRegressionUtilities.h"
61 static int kTestTestCount
= (NKEYS
*(4+NPARMS
*4));
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
);
72 static void tests(void) {
73 CFErrorRef error
= NULL
;
74 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
76 for(int j
=0; j
< NPARMS
; j
++) {
77 CFDataRef parameters
= SOSUserKeyCreateGenerateParameters(&error
);
78 ok(parameters
, "No parameters!");
79 ok(error
== NULL
, "Error: (%@)", error
);
82 SecKeyRef baseline_privkey
= createTestKey(cfpassword
, parameters
, &error
);
83 if(baseline_privkey
) {
84 SecKeyRef baseline_pubkey
= SecKeyCreatePublicFromPrivate(baseline_privkey
);
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");
92 CFReleaseNull(user_privkey
);
93 CFReleaseNull(user_pubkey
);
95 CFReleaseNull(baseline_pubkey
);
97 CFReleaseNull(baseline_privkey
);
98 CFReleaseNull(parameters
);
100 CFReleaseNull(cfpassword
);
103 int sc_25_soskeygen(int argc
, char *const *argv
)
105 plan_tests(kTestTestCount
);