]> git.saurik.com Git - apple/security.git/blob - OSX/utilities/src/SecSCTUtils.c
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / utilities / src / SecSCTUtils.c
1 //
2 // SecSCTUtils.c
3 // utilities
4 /*
5 * Copyright (c) 2015 Apple Inc. All Rights Reserved.
6 *
7 * @APPLE_LICENSE_HEADER_START@
8 *
9 * This file contains Original Code and/or Modifications of Original Code
10 * as defined in and that are subject to the Apple Public Source License
11 * Version 2.0 (the 'License'). You may not use this file except in
12 * compliance with the License. Please obtain a copy of the License at
13 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * file.
15 *
16 * The Original Code and all software distributed under the License are
17 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
18 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
19 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
21 * Please see the License for the specific language governing rights and
22 * limitations under the License.
23 *
24 * @APPLE_LICENSE_HEADER_END@
25 */
26
27 #include <AssertMacros.h>
28 #include <utilities/SecCFWrappers.h>
29 #include "SecSCTUtils.h"
30
31 static size_t SSLDecodeSize(const uint8_t *p)
32 {
33 return (p[0]<<8 | p[1]);
34 }
35
36 CFArrayRef SecCreateSignedCertificateTimestampsArrayFromSerializedSCTList(const uint8_t *p, size_t listLen)
37 {
38 size_t encodedListLen;
39 CFMutableArrayRef sctArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
40 require_quiet(sctArray, out);
41
42 require(listLen > 2 , out);
43 encodedListLen = SSLDecodeSize(p); p+=2; listLen-=2;
44
45 require(encodedListLen==listLen, out);
46
47 while (listLen > 0)
48 {
49 size_t itemLen;
50 require(listLen >= 2, out);
51 itemLen = SSLDecodeSize(p); p += 2; listLen-=2;
52 require(itemLen <= listLen, out);
53 CFDataRef sctData = CFDataCreate(kCFAllocatorDefault, p, itemLen);
54 p += itemLen; listLen -= itemLen;
55 require(sctData, out);
56 CFArrayAppendValue(sctArray, sctData);
57 CFReleaseSafe(sctData);
58 }
59
60 return sctArray;
61
62 out:
63 CFReleaseSafe(sctArray);
64 return NULL;
65 }