]> git.saurik.com Git - apple/security.git/blob - OSX/include/security_ocspd/ocspdUtils.h
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / include / security_ocspd / ocspdUtils.h
1 /*
2 * Copyright (c) 2000,2002,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * ocspUtils.h - common utilities for OCSPD
26 */
27 #ifndef _OCSPD_UTILS_H_
28 #define _OCSPD_UTILS_H_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <CommonCrypto/CommonDigest.h>
35 #include <Security/cssmtype.h>
36 #include <Security/SecAsn1Coder.h>
37 #include <CoreFoundation/CoreFoundation.h>
38
39 /*
40 * Compare two CSSM_DATAs, return CSSM_TRUE if identical.
41 */
42 CSSM_BOOL ocspdCompareCssmData(
43 const CSSM_DATA *data1,
44 const CSSM_DATA *data2);
45
46 /*
47 * Parse a GeneralizedTime string into a CFAbsoluteTime. Returns NULL_TIME on
48 * parse error. Fractional parts of a second are discarded.
49 */
50 #define NULL_TIME 0.0
51
52 CFAbsoluteTime genTimeToCFAbsTime(
53 const CSSM_DATA *strData);
54
55 /*
56 * Convert CFAbsoluteTime to generalized time string, GMT format (4 digit year,
57 * trailing 'Z'). Caller allocated the output which is GENERAL_TIME_STRLEN bytes plus
58 * a NULL.
59 */
60 #define GENERAL_TIME_STRLEN 15 /* NOT including trailing NULL */
61
62 void cfAbsTimeToGgenTime(
63 CFAbsoluteTime absTime,
64 char *genTime);
65
66 #define OCSPD_MAX_DIGEST_LEN CC_SHA256_DIGEST_LENGTH
67
68 void ocspdSha1(
69 const void *data,
70 CC_LONG len,
71 unsigned char *md); // allocd by caller, CC_SHA1_DIGEST_LENGTH bytes
72 void ocspdMD5(
73 const void *data,
74 CC_LONG len,
75 unsigned char *md); // allocd by caller, CC_MD5_DIGEST_LENGTH bytes
76 void ocspdMD4(
77 const void *data,
78 CC_LONG len,
79 unsigned char *md); // allocd by caller, CC_MD4_DIGEST_LENGTH bytes
80 void ocspdSHA256(
81 const void *data,
82 CC_LONG len,
83 unsigned char *md); // allocd by caller, CC_SHA256_DIGEST_LENGTH bytes
84
85 /*
86 * How many items in a NULL-terminated array of pointers?
87 */
88 unsigned ocspdArraySize(
89 const void **array);
90
91 /*
92 * Fill out a CSSM_DATA with the subset of public key bytes from the given
93 * CSSM_KEY_PTR which should be hashed to produce the issuerKeyHash field
94 * of a CertID in an OCSP request.
95 */
96 CSSM_RETURN ocspdGetPublicKeyBytes(
97 SecAsn1CoderRef coder,
98 CSSM_KEY_PTR publicKey,
99 CSSM_DATA &publicKeyBytes); // filled out by this function
100
101
102 #define CFRELEASE(cf) \
103 if(cf != NULL) { \
104 CFRelease(cf); \
105 }
106
107 #ifdef __cplusplus
108 }
109 #endif
110
111 #endif /* _OCSPD_UTILS_H_ */