4 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
9 #include <Security/SecBase.h>
10 #include <Security/SecItem.h>
11 #include <Security/SecKey.h>
12 #include <Security/SecKeyPriv.h>
13 #include <SOSPeerInfoDER.h>
15 #include <Security/SecureObjectSync/SOSCircle.h>
16 #include <Security/SecureObjectSync/SOSPeerInfo.h>
17 #include <Security/SecureObjectSync/SOSPeerInfoCollections.h>
18 #include <Security/SecureObjectSync/SOSInternal.h>
19 #include <Security/SecureObjectSync/SOSUserKeygen.h>
21 #include <utilities/SecCFWrappers.h>
23 #include <CoreFoundation/CoreFoundation.h>
28 #include "SOSCircle_regressions.h"
30 #include "SOSRegressionUtilities.h"
33 #include <MobileGestalt.h>
36 static unsigned long kTestCount
= 2;
37 static unsigned long kTestFuzzerCount
= 20000;
39 static void tests(void)
41 SecKeyRef signingKey
= NULL
;
42 SecKeyRef octagonSigningKey
= NULL
;
43 SecKeyRef octagonEncryptionKey
= NULL
;
44 SOSFullPeerInfoRef fpi
= SOSCreateFullPeerInfoFromName(CFSTR("Test Peer"), &signingKey
, &octagonSigningKey
, &octagonEncryptionKey
, NULL
);
45 SOSPeerInfoRef pi
= SOSFullPeerInfoGetPeerInfo(fpi
);
48 ok(NULL
!= pi
, "info creation");
49 size_t size
= SOSPeerInfoGetDEREncodedSize(pi
, NULL
);
51 uint8_t buffer
[size
+100]; // make the buffer long enough to hold the DER + some room for the fuzzing
53 const uint8_t *buffer_p
= SOSPeerInfoEncodeToDER(pi
, NULL
, buffer
, buffer
+ sizeof(buffer
));
55 ok(buffer_p
!= NULL
, "encode");
57 size_t length
= (buffer
+ sizeof(buffer
)) - buffer_p
;
58 // diag("size %lu length %lu\n", size, length);
59 uint8_t buffer2
[length
];
60 if(buffer_p
== NULL
) goto errOut
;
62 for (count
= 0; count
< kTestFuzzerCount
; count
++) {
63 memcpy(buffer2
, buffer_p
, length
);
65 const uint8_t *startp
= buffer2
;
66 size_t offset
= arc4random_uniform((u_int32_t
)length
);
67 uint8_t value
= arc4random() & 0xff;
68 // diag("Offset %lu value %d\n", offset, value);
69 buffer2
[offset
] = value
;
71 SOSPeerInfoRef pi2
= SOSPeerInfoCreateFromDER(NULL
, NULL
, &startp
, buffer2
+ length
);
77 CFReleaseNull(signingKey
);
78 CFReleaseNull(octagonSigningKey
);
79 CFReleaseNull(octagonEncryptionKey
);
83 int sc_31_peerinfo(int argc
, char *const *argv
)
85 plan_tests((int)(kTestCount
+ kTestFuzzerCount
));