]> git.saurik.com Git - apple/security.git/blame - OSX/libsecurity_ocspd/common/ocspdUtils.h
Security-58286.41.2.tar.gz
[apple/security.git] / OSX / libsecurity_ocspd / common / ocspdUtils.h
CommitLineData
b1ab9ed8 1/*
d8f41ccd 2 * Copyright (c) 2000,2002,2011,2014 Apple Inc. All Rights Reserved.
b1ab9ed8
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
949d2ff0 5 *
d8f41ccd
A
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.
949d2ff0 12 *
d8f41ccd
A
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
b1ab9ed8
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d8f41ccd
A
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.
949d2ff0 20 *
b1ab9ed8
A
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
949d2ff0 24/*
b1ab9ed8
A
25 * ocspUtils.h - common utilities for OCSPD
26 */
27#ifndef _OCSPD_UTILS_H_
28#define _OCSPD_UTILS_H_
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <CommonCrypto/CommonDigest.h>
35#include <Security/cssmtype.h>
949d2ff0 36#include <Security/SecAsn1Coder.h>
b1ab9ed8
A
37#include <CoreFoundation/CoreFoundation.h>
38
39/*
40 * Compare two CSSM_DATAs, return CSSM_TRUE if identical.
41 */
42CSSM_BOOL ocspdCompareCssmData(
43 const CSSM_DATA *data1,
44 const CSSM_DATA *data2);
45
46/*
949d2ff0
A
47 * Parse a GeneralizedTime string into a CFAbsoluteTime. Returns NULL_TIME on
48 * parse error. Fractional parts of a second are discarded.
b1ab9ed8 49 */
949d2ff0 50#define NULL_TIME 0.0
b1ab9ed8
A
51
52CFAbsoluteTime genTimeToCFAbsTime(
53 const CSSM_DATA *strData);
54
949d2ff0 55/*
b1ab9ed8
A
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
62void cfAbsTimeToGgenTime(
63 CFAbsoluteTime absTime,
64 char *genTime);
65
66#define OCSPD_MAX_DIGEST_LEN CC_SHA256_DIGEST_LENGTH
67
68void ocspdSha1(
69 const void *data,
70 CC_LONG len,
71 unsigned char *md); // allocd by caller, CC_SHA1_DIGEST_LENGTH bytes
72void ocspdMD5(
73 const void *data,
74 CC_LONG len,
75 unsigned char *md); // allocd by caller, CC_MD5_DIGEST_LENGTH bytes
76void ocspdMD4(
77 const void *data,
78 CC_LONG len,
79 unsigned char *md); // allocd by caller, CC_MD4_DIGEST_LENGTH bytes
80void 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 */
88unsigned ocspdArraySize(
89 const void **array);
90
949d2ff0
A
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 */
96CSSM_RETURN ocspdGetPublicKeyBytes(
97 SecAsn1CoderRef coder,
98 CSSM_KEY_PTR publicKey,
99 CSSM_DATA &publicKeyBytes); // filled out by this function
100
101
b1ab9ed8
A
102#define CFRELEASE(cf) \
103 if(cf != NULL) { \
104 CFRelease(cf); \
105 }
949d2ff0 106
b1ab9ed8
A
107#ifdef __cplusplus
108}
109#endif
110
111#endif /* _OCSPD_UTILS_H_ */