]> git.saurik.com Git - apple/security.git/blob - keychain/SecureObjectSync/Regressions/sc-31-peerinfo-simplefuzz.c
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / SecureObjectSync / Regressions / sc-31-peerinfo-simplefuzz.c
1 /*
2 * sc-31-peerinfo.c
3 *
4 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
5 *
6 */
7
8
9 #include <Security/SecBase.h>
10 #include <Security/SecItem.h>
11 #include <Security/SecKey.h>
12 #include <Security/SecKeyPriv.h>
13 #include "keychain/SecureObjectSync/SOSPeerInfoDER.h"
14
15 #include "keychain/SecureObjectSync/SOSCircle.h"
16 #include <Security/SecureObjectSync/SOSPeerInfo.h>
17 #include "keychain/SecureObjectSync/SOSPeerInfoCollections.h"
18 #include "keychain/SecureObjectSync/SOSInternal.h"
19 #include "keychain/SecureObjectSync/SOSUserKeygen.h"
20
21 #include <utilities/SecCFWrappers.h>
22
23 #include <CoreFoundation/CoreFoundation.h>
24
25 #include <stdlib.h>
26 #include <unistd.h>
27
28 #include "SOSCircle_regressions.h"
29
30 #include "SOSRegressionUtilities.h"
31 #if SOS_ENABLED
32
33 #if TARGET_OS_IPHONE
34 #include <MobileGestalt.h>
35 #endif
36
37 static unsigned long kTestCount = 2;
38 static unsigned long kTestFuzzerCount = 20000;
39
40 static void tests(void)
41 {
42 SecKeyRef signingKey = NULL;
43 SecKeyRef octagonSigningKey = NULL;
44 SecKeyRef octagonEncryptionKey = NULL;
45 SOSFullPeerInfoRef fpi = SOSCreateFullPeerInfoFromName(CFSTR("Test Peer"), &signingKey, &octagonSigningKey, &octagonEncryptionKey, NULL);
46 SOSPeerInfoRef pi = SOSFullPeerInfoGetPeerInfo(fpi);
47 unsigned long count;
48
49 ok(NULL != pi, "info creation");
50 size_t size = SOSPeerInfoGetDEREncodedSize(pi, NULL);
51
52 uint8_t buffer[size+100]; // make the buffer long enough to hold the DER + some room for the fuzzing
53
54 const uint8_t *buffer_p = SOSPeerInfoEncodeToDER(pi, NULL, buffer, buffer + sizeof(buffer));
55
56 ok(buffer_p != NULL, "encode");
57
58 size_t length = (buffer + sizeof(buffer)) - buffer_p;
59 // diag("size %lu length %lu\n", size, length);
60 uint8_t buffer2[length];
61 if(buffer_p == NULL) goto errOut;
62
63 for (count = 0; count < kTestFuzzerCount; count++) {
64 memcpy(buffer2, buffer_p, length);
65
66 const uint8_t *startp = buffer2;
67 size_t offset = arc4random_uniform((u_int32_t)length);
68 uint8_t value = arc4random() & 0xff;
69 // diag("Offset %lu value %d\n", offset, value);
70 buffer2[offset] = value;
71
72 SOSPeerInfoRef pi2 = SOSPeerInfoCreateFromDER(NULL, NULL, &startp, buffer2 + length);
73 CFReleaseNull(pi2);
74 ok(1, "fuzz");
75 }
76
77 errOut:
78 CFReleaseNull(signingKey);
79 CFReleaseNull(octagonSigningKey);
80 CFReleaseNull(octagonEncryptionKey);
81 CFReleaseNull(fpi);
82 }
83 #endif
84
85 int sc_31_peerinfo(int argc, char *const *argv)
86 {
87 #if SOS_ENABLED
88 plan_tests((int)(kTestCount + kTestFuzzerCount));
89 tests();
90 #else
91 plan_tests(0);
92 #endif
93 return 0;
94 }