2 * Copyright (c) 2004-2018 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 @header SecCmsSignerInfo.h
27 @availability 10.4 and later
28 @abstract Interfaces of the CMS implementation.
29 @discussion The functions here implement functions for encoding
30 and decoding Cryptographic Message Syntax (CMS) objects
31 as described in rfc3369.
34 #ifndef _SECURITY_SECCMSSIGNERINFO_H_
35 #define _SECURITY_SECCMSSIGNERINFO_H_ 1
37 #include <Security/SecCmsBase.h>
39 #include <Security/SecTrust.h>
40 #include <CoreFoundation/CFDate.h>
45 extern SecCmsSignerInfoRef
46 SecCmsSignerInfoCreate(SecCmsMessageRef cmsg
, SecIdentityRef identity
, SECOidTag digestalgtag
)
47 API_AVAILABLE(macos(10.4)) API_UNAVAILABLE(iosmac
);
51 extern SecCmsSignerInfoRef
52 SecCmsSignerInfoCreate(SecCmsSignedDataRef sigd
, SecIdentityRef identity
, SECOidTag digestalgtag
)
53 API_AVAILABLE(ios(2.0), tvos(2.0), watchos(1.0)) API_UNAVAILABLE(iosmac
);
54 #endif // !TARGET_OS_OSX
57 #pragma clang diagnostic push
58 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
59 extern SecCmsSignerInfoRef
60 SecCmsSignerInfoCreateWithSubjKeyID(SecCmsMessageRef cmsg
, CSSM_DATA_PTR subjKeyID
, SecPublicKeyRef pubKey
, SecPrivateKeyRef signingKey
, SECOidTag digestalgtag
)
61 API_AVAILABLE(macos(10.4)) API_UNAVAILABLE(iosmac
);
62 #pragma clang diagnostic pop
63 #else // !TARGET_OS_OSX
64 extern SecCmsSignerInfoRef
65 SecCmsSignerInfoCreateWithSubjKeyID(SecCmsSignedDataRef sigd
, const SecAsn1Item
*subjKeyID
, SecPublicKeyRef pubKey
, SecPrivateKeyRef signingKey
, SECOidTag digestalgtag
)
66 API_AVAILABLE(ios(2.0), tvos(2.0), watchos(1.0)) API_UNAVAILABLE(iosmac
);
67 #endif // !TARGET_OS_OSX
72 @abstract Destroy a SignerInfo data structure.
75 SecCmsSignerInfoDestroy(SecCmsSignerInfoRef si
)
76 API_AVAILABLE(macos(10.4)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
82 extern SecCmsVerificationStatus
83 SecCmsSignerInfoGetVerificationStatus(SecCmsSignerInfoRef signerinfo
);
89 SecCmsSignerInfoGetDigestAlg(SecCmsSignerInfoRef signerinfo
);
95 SecCmsSignerInfoGetDigestAlgTag(SecCmsSignerInfoRef signerinfo
);
101 SecCmsSignerInfoGetCertList(SecCmsSignerInfoRef signerinfo
);
105 @abstract Return the signing time, in UTCTime format, of a CMS signerInfo.
106 @param sinfo SignerInfo data for this signer.
107 @discussion Returns a pointer to XXXX (what?)
108 @result A return value of NULL is an error.
111 SecCmsSignerInfoGetSigningTime(SecCmsSignerInfoRef sinfo
, CFAbsoluteTime
*stime
);
115 @abstract Return the data in the signed Codesigning Hash Agility attribute.
116 @param sinfo SignerInfo data for this signer, pointer to a CFDataRef for attribute value
117 @discussion Returns a CFDataRef containing the value of the attribute
118 @result A return value of SECFailure is an error.
121 SecCmsSignerInfoGetAppleCodesigningHashAgility(SecCmsSignerInfoRef sinfo
, CFDataRef
*sdata
);
125 @abstract Return the data in the signed Codesigning Hash Agility V2 attribute.
126 @param sinfo SignerInfo data for this signer, pointer to a CFDictionaryRef for attribute values
127 @discussion Returns a CFDictionaryRef containing the values of the attribute. V2 encodes the
128 hash agility values using DER.
129 @result A return value of SECFailure is an error.
132 SecCmsSignerInfoGetAppleCodesigningHashAgilityV2(SecCmsSignerInfoRef sinfo
, CFDictionaryRef
*sdict
);
135 @function SecCmsSignerInfoGetAppleExpirationTime
136 @abstract Return the expriation time, in CFAbsoluteTime, of a CMS signerInfo.
137 @param sinfo SignerInfo data for this signer.
138 @discussion Returns a CFAbsoluteTime
139 @result A return value of SECFailure is an error.
142 SecCmsSignerInfoGetAppleExpirationTime(SecCmsSignerInfoRef sinfo
, CFAbsoluteTime
*etime
);
146 @abstract Return the signing cert of a CMS signerInfo.
147 @discussion The certs in the enclosing SignedData must have been imported already.
149 extern SecCertificateRef
150 SecCmsSignerInfoGetSigningCertificate(SecCmsSignerInfoRef signerinfo
, SecKeychainRef keychainOrArray
);
154 @abstract Return the common name of the signer.
155 @param sinfo SignerInfo data for this signer.
156 @discussion Returns a CFStringRef containing the common name of the signer.
157 @result A return value of NULL is an error.
159 extern CF_RETURNS_RETAINED CFStringRef
160 SecCmsSignerInfoGetSignerCommonName(SecCmsSignerInfoRef sinfo
);
164 @abstract Return the email address of the signer
165 @param sinfo SignerInfo data for this signer.
166 @discussion Returns a CFStringRef containing the name of the signer.
167 @result A return value of NULL is an error.
169 extern CF_RETURNS_RETAINED CFStringRef
170 SecCmsSignerInfoGetSignerEmailAddress(SecCmsSignerInfoRef sinfo
);
174 @abstract Add the signing time to the authenticated (i.e. signed) attributes of "signerinfo".
175 @discussion This is expected to be included in outgoing signed
176 messages for email (S/MIME) but is likely useful in other situations.
178 This should only be added once; a second call will do nothing.
180 XXX This will probably just shove the current time into "signerinfo"
181 but it will not actually get signed until the entire item is
182 processed for encoding. Is this (expected to be small) delay okay?
185 SecCmsSignerInfoAddSigningTime(SecCmsSignerInfoRef signerinfo
, CFAbsoluteTime t
);
189 @abstract Add a SMIMECapabilities attribute to the authenticated (i.e. signed) attributes of "signerinfo".
190 @discussion This is expected to be included in outgoing signed messages for email (S/MIME).
193 SecCmsSignerInfoAddSMIMECaps(SecCmsSignerInfoRef signerinfo
);
197 @abstract Add a SMIMEEncryptionKeyPreferences attribute to the authenticated (i.e. signed) attributes of "signerinfo".
198 @discussion This is expected to be included in outgoing signed messages for email (S/MIME).
201 SecCmsSignerInfoAddSMIMEEncKeyPrefs(SecCmsSignerInfoRef signerinfo
, SecCertificateRef cert
, SecKeychainRef keychainOrArray
);
205 @abstract Add a SMIMEEncryptionKeyPreferences attribute to the authenticated (i.e. signed) attributes of "signerinfo", using the OID prefered by Microsoft.
206 @discussion This is expected to be included in outgoing signed messages for email (S/MIME), if compatibility with Microsoft mail clients is wanted.
209 SecCmsSignerInfoAddMSSMIMEEncKeyPrefs(SecCmsSignerInfoRef signerinfo
, SecCertificateRef cert
, SecKeychainRef keychainOrArray
);
213 @abstract Countersign a signerinfo.
216 SecCmsSignerInfoAddCounterSignature(SecCmsSignerInfoRef signerinfo
,
217 SECOidTag digestalg
, SecIdentityRef identity
);
221 @abstract Add the Apple Codesigning Hash Agility attribute to the authenticated (i.e. signed) attributes of "signerinfo".
222 @discussion This is expected to be included in outgoing Apple code signatures.
225 SecCmsSignerInfoAddAppleCodesigningHashAgility(SecCmsSignerInfoRef signerinfo
, CFDataRef attrValue
);
229 @abstract Add the Apple Codesigning Hash Agility V2 attribute to the authenticated (i.e. signed) attributes of "signerinfo".
230 @discussion This is expected to be included in outgoing Apple code signatures. V2 encodes the hash agility values using DER.
231 The dictionary should have CFNumberRef keys, corresponding to SECOidTags for digest algorithms, and CFDataRef values,
232 corresponding to the digest value for that digest algorithm.
235 SecCmsSignerInfoAddAppleCodesigningHashAgilityV2(SecCmsSignerInfoRef signerinfo
, CFDictionaryRef attrValues
);
238 @function SecCmsSignerInfoAddAppleExpirationTime
239 @abstract Add the expiration time to the authenticated (i.e. signed) attributes of "signerinfo".
240 @discussion This is expected to be included in outgoing signed messages for Asset Receipts but is likely
241 useful in other situations. This should only be added once; a second call will do nothing.
242 @result A result of SECFailure indicates an error adding the attribute.
245 SecCmsSignerInfoAddAppleExpirationTime(SecCmsSignerInfoRef signerinfo
, CFAbsoluteTime t
);
249 @abstract The following needs to be done in the S/MIME layer code after signature of a signerinfo has been verified.
250 @param signerinfo The SecCmsSignerInfo object for which we verified the signature.
251 @result The preferred encryption certificate of the user who signed this message will be added to the users default Keychain and it will be marked as the preferred certificate to use when sending that person messages from now on.
254 SecCmsSignerInfoSaveSMIMEProfile(SecCmsSignerInfoRef signerinfo
);
258 @abstract Set cert chain inclusion mode for this signer.
261 SecCmsSignerInfoIncludeCerts(SecCmsSignerInfoRef signerinfo
, SecCmsCertChainMode cm
, SECCertUsage usage
);
263 /*! @functiongroup CMS misc utility functions */
266 Convert a SecCmsVerificationStatus to a human readable string.
269 SecCmsUtilVerificationStatusToString(SecCmsVerificationStatus vs
);
272 * Preference domain and key for the Microsoft ECDSA compatibility flag.
273 * Default if not present is TRUE, meaning we generate ECDSA-signed messages
274 * which are compatible with Microsoft Entourage. FALSE means we adhere to
275 * the spec (RFC 3278 section 2.1.1).
277 #define kMSCompatibilityDomain "com.apple.security.smime"
278 #define kMSCompatibilityMode CFSTR("MSCompatibilityMode")
281 @function SecCmsSignerInfoCopyCertFromEncryptionKeyPreference
282 @abstract Copy the certificate specified in the encryption key preference.
283 @param signerinfo The SecCmsSignerInfo object for which we verified the signature.
284 @result The preferred encryption certificate of the user who signed this message, if found.
285 @discussion This function should be called after the signer info has been verified.
287 SecCertificateRef
SecCmsSignerInfoCopyCertFromEncryptionKeyPreference(SecCmsSignerInfoRef signerinfo
);
290 /* MARK: Timestamping support */
293 SecCmsSignerInfoVerifyUnAuthAttrs(SecCmsSignerInfoRef signerinfo
)
294 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
297 SecCmsSignerInfoVerifyUnAuthAttrsWithPolicy(SecCmsSignerInfoRef signerinfo
,CFTypeRef timeStampPolicy
)
298 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
300 #pragma clang diagnostic push
301 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
303 SecCmsSignerInfoGetEncDigest(SecCmsSignerInfoRef signerinfo
)
304 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
305 #pragma clang diagnostic pop
308 SecCmsSignerInfoGetTimestampCertList(SecCmsSignerInfoRef signerinfo
)
309 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
311 extern SecCertificateRef
312 SecCmsSignerInfoGetTimestampSigningCert(SecCmsSignerInfoRef signerinfo
)
313 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
317 @abstract Return the timestamp time, in UTCTime format, of a CMS signerInfo.
318 @param sinfo SignerInfo data for this signer.
319 @discussion Returns a pointer to XXXX (what?)
320 @result A return value of NULL is an error.
323 SecCmsSignerInfoGetTimestampTime(SecCmsSignerInfoRef sinfo
, CFAbsoluteTime
*stime
)
324 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
328 @abstract Return the timestamp time, in UTCTime format, of a CMS signerInfo.
329 @param sinfo SignerInfo data for this signer, timeStampPolicy the policy to verify the timestamp signer
330 @discussion Returns a pointer to XXXX (what?)
331 @result A return value of NULL is an error.
334 SecCmsSignerInfoGetTimestampTimeWithPolicy(SecCmsSignerInfoRef sinfo
, CFTypeRef timeStampPolicy
, CFAbsoluteTime
*stime
)
335 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
339 @abstract Create a timestamp unsigned attribute with a TimeStampToken.
341 #pragma clang diagnostic push
342 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
344 SecCmsSignerInfoAddTimeStamp(SecCmsSignerInfoRef signerinfo
, CSSM_DATA
*tstoken
)
345 API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios
, watchos
, tvos
, bridgeos
, iosmac
);
346 #pragma clang diagnostic pop
347 #endif // TARGET_OS_OSX
351 #endif /* _SECURITY_SECCMSSIGNERINFO_H_ */