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