]> git.saurik.com Git - apple/security.git/blame_incremental - OSX/libsecurity_smime/lib/SecCMS.h
Security-58286.1.32.tar.gz
[apple/security.git] / OSX / libsecurity_smime / lib / SecCMS.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 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#ifndef libsecurity_smime_SecCMS_h
26#define libsecurity_smime_SecCMS_h
27
28#include <CoreFoundation/CoreFoundation.h>
29#include <Security/SecBase.h>
30#include <Security/SecTrust.h>
31
32extern const void * kSecCMSSignDigest;
33extern const void * kSecCMSSignDetached;
34extern const void * kSecCMSSignHashAlgorithm;
35extern const void * kSecCMSCertChainMode;
36extern const void * kSecCMSAdditionalCerts;
37extern const void * kSecCMSSignedAttributes;
38extern const void * kSecCMSSignDate;
39extern const void * kSecCMSAllCerts;
40extern const void * kSecCMSHashAgility;
41
42extern const void * kSecCMSHashingAlgorithmSHA1;
43extern const void * kSecCMSHashingAlgorithmSHA256;
44extern const void * kSecCMSHashingAlgorithmSHA384;
45extern const void * kSecCMSHashingAlgorithmSHA512;
46
47extern const void * kSecCMSBulkEncryptionAlgorithm;
48extern const void * kSecCMSEncryptionAlgorithmDESCBC;
49extern const void * kSecCMSEncryptionAlgorithmAESCBC;
50
51/* Return an array of certificates contained in message, if message is of the
52 type SignedData and has no signers, return NULL otherwise. Not that if
53 the message is properly formed but has no certificates an empty array will
54 be returned.
55 Designed to match the sec submodule implementation available for iOS
56 */
57CFArrayRef SecCMSCertificatesOnlyMessageCopyCertificates(CFDataRef message);
58
59/* Create a degenerate PKCS#7 containing a cert or a CFArray of certs. */
60CFDataRef SecCMSCreateCertificatesOnlyMessage(CFTypeRef cert_or_array_thereof);
61CFDataRef SecCMSCreateCertificatesOnlyMessageIAP(SecCertificateRef cert);
62
63/*!
64 @function SecCMSVerifyCopyDataAndAttributes
65 @abstract verify a signed data cms blob.
66 @param message the cms message to be parsed
67 @param detached_contents to pass detached contents (optional)
68 @param policy specifies policy or array thereof should be used (optional).
69 if none is passed the blob will **not** be verified and only
70 the attached contents will be returned.
71 @param trustref (output/optional) if specified, the trust chain built during
72 verification will not be evaluated but returned to the caller to do so.
73 @param attached_contents (output/optional) return a copy of the attached
74 contents.
75 @param signed_attributes (output/optional) return a copy of the signed
76 attributes as a CFDictionary from oids (CFData) to values
77 (CFArray of CFData).
78 @result A result code. See "Security Error Codes" (SecBase.h).
79 errSecDecode not a CMS message we can parse,
80 errSecAuthFailed bad signature, or untrusted signer if caller doesn't
81 ask for trustref,
82 errSecParam garbage in, garbage out.
83 */
84OSStatus SecCMSVerifyCopyDataAndAttributes(CFDataRef message, CFDataRef detached_contents,
85 CFTypeRef policy, SecTrustRef *trustref,
86 CFDataRef *attached_contents, CFDictionaryRef *signed_attributes);
87
88/*!
89 @function SecCMSVerify
90 @abstract same as SecCMSVerifyCopyDataAndAttributes, for binary compatibility.
91 */
92OSStatus SecCMSVerify(CFDataRef message, CFDataRef detached_contents,
93 CFTypeRef policy, SecTrustRef *trustref, CFDataRef *attached_contents);
94
95OSStatus SecCMSVerifySignedData(CFDataRef message, CFDataRef detached_contents,
96 CFTypeRef policy, SecTrustRef *trustref, CFArrayRef additional_certificates,
97 CFDataRef *attached_contents, CFDictionaryRef *message_attributes);
98
99/*!
100 @function SecCMSSignDataAndAttributes
101 @abstract create a signed data cms blob.
102 @param identity signer
103 @param data message to be signed
104 @param detached sign detached or not
105 @param signed_data (output) return signed message.
106 @param signed_attributes (input/optional) signed attributes to insert
107 as a CFDictionary from oids (CFData) to value (CFData).
108 @result A result code. See "Security Error Codes" (SecBase.h).
109 errSecParam garbage in, garbage out.
110 */
111OSStatus SecCMSSignDataAndAttributes(SecIdentityRef identity, CFDataRef data,
112 bool detached, CFMutableDataRef signed_data, CFDictionaryRef signed_attributes);
113
114/*!
115 @function SecCMSSignDigestAndAttributes
116 @abstract create a detached signed data cms blob for a SHA-1 hash.
117 @param identity signer
118 @param digest SHA-1 digest of message to be signed
119 @param signed_data (output) return signed message.
120 @param signed_attributes (input/optional) signed attributes to insert
121 as a CFDictionary from oids (CFData) to value (CFData).
122 @result A result code. See "Security Error Codes" (SecBase.h).
123 errSecParam garbage in, garbage out.
124 */
125OSStatus SecCMSSignDigestAndAttributes(SecIdentityRef identity, CFDataRef digest,
126 CFMutableDataRef signed_data, CFDictionaryRef signed_attributes);
127
128/*!
129 @function SecCMSCreateSignedData
130 @abstract create a signed data cms blob.
131 @param identity signer
132 @param data SHA-1 digest or message to be signed
133 @param parameters (input/optional) specify algorithm, detached, digest
134 @param signed_attributes (input/optional) signed attributes to insert
135 as a CFDictionary from oids (CFData) to value (CFData).
136 @param signed_data (output) return signed message.
137 @result A result code. See "Security Error Codes" (SecBase.h).
138 errSecParam garbage in, garbage out.
139 */
140OSStatus SecCMSCreateSignedData(SecIdentityRef identity, CFDataRef data,
141 CFDictionaryRef parameters, CFDictionaryRef signed_attributes,
142 CFMutableDataRef signed_data);
143
144/*!
145 @function SecCMSCreateEnvelopedData
146 @abstract create a enveloped cms blob for recipients
147 @param recipient_or_cfarray_thereof SecCertificateRef for each recipient
148 @param params CFDictionaryRef with encryption parameters
149 @param data Data to be encrypted
150 @param enveloped_data (output) return enveloped message.
151 @result A result code. See "Security Error Codes" (SecBase.h).
152 errSecParam garbage in, garbage out.
153 */
154OSStatus SecCMSCreateEnvelopedData(CFTypeRef recipient_or_cfarray_thereof,
155 CFDictionaryRef params, CFDataRef data, CFMutableDataRef enveloped_data);
156
157
158/*!
159 @function SecCMSDecryptEnvelopedData
160 @abstract open an enveloped cms blob. expects recipients identity in keychain.
161 @param message Eveloped message
162 @param data (output) return decrypted message.
163 @param recipient (output/optional) return addressed recipient
164 @result A result code. See "Security Error Codes" (SecBase.h).
165 errSecParam garbage in, garbage out.
166 */
167OSStatus SecCMSDecryptEnvelopedData(CFDataRef message,
168 CFMutableDataRef data, SecCertificateRef *recipient);
169
170#endif