]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_cms/lib/CMSDecoder.cpp
Security-58286.70.7.tar.gz
[apple/security.git] / OSX / libsecurity_cms / lib / CMSDecoder.cpp
index dcb79035d9ea57aaa32b67ab183117b12dd6648e..bcf4e5d6c7df4c8c037d545152e4246db3a8c3e8 100644 (file)
@@ -66,7 +66,7 @@ struct _CMSDecoder {
        SecArenaPoolRef         arena;                          /* the decoder's arena */
        SecCmsDecoderRef        decoder;
        CFDataRef                       detachedContent;
-       CFTypeRef                       keychainOrArray;        /* from CMSDecoderSetSearchKeychain() */
+       CFTypeRef                       keychainOrArray;        /* unused */
        
        /*
         * The following are valid (and quiescent) after CMSDecoderFinalizeMessage().
@@ -383,24 +383,14 @@ OSStatus CMSDecoderCopyDetachedContent(
 }
 
 /*
- * Optionally specify a SecKeychainRef, or an array of them, containing
- * intermediate certs to be used in verifying a signed message's signer
- * certs. By default, the default keychain search list is used for this.
- * Specify an empty CFArrayRef to search *no* keychains for intermediate
- * certs.
- * IF this is called, it must be called before CMSDecoderCopySignerStatus().
+ * Beginning in 10.12, this function stopped affecting the behavior of the
+ * CMS Decoder. Its only use was in SecTrustSetKeychains which is a no-op.
+ * Please discontinue use.
  */
 OSStatus CMSDecoderSetSearchKeychain(
                                      CMSDecoderRef             cmsDecoder,
                                      CFTypeRef                 keychainOrArray)
 {
-       if(cmsDecoder == NULL) {
-               return errSecParam;
-       }
-       cmsDecoder->keychainOrArray = keychainOrArray;
-       if(keychainOrArray) {
-               CFRetain(keychainOrArray);
-       }
        return errSecSuccess;
 }
 
@@ -474,11 +464,7 @@ OSStatus CMSDecoderCopySignerStatus(
        SecTrustRef theTrust = NULL;
        OSStatus vfyRtn = SecCmsSignedDataVerifySignerInfo(cmsDecoder->signedData,
                                                        (int)signerIndex,
-                                                       /*
-                                                        * FIXME this cast should not be necessary, but libsecurity_smime
-                                                        * declares this argument as a SecKeychainRef
-                                                        */
-                                                       (SecKeychainRef)cmsDecoder->keychainOrArray,
+                                                       NULL,
                                                        policyOrArray,
                                                        &theTrust);
 
@@ -538,10 +524,6 @@ OSStatus CMSDecoderCopySignerStatus(
                        case kSecTrustResultDeny:
                                tpVfyStatus = CSSMERR_APPLETP_TRUST_SETTING_DENY;
                                break;
-                       case kSecTrustResultConfirm:
-                               dprintf("SecTrustEvaluate reported confirm\n");
-                               tpVfyStatus = CSSMERR_TP_NOT_TRUSTED;
-                               break;
                        default:
                        {
                                /* get low-level TP error */
@@ -1021,8 +1003,8 @@ OSStatus CMSDecoderCopySignerAppleCodesigningHashAgility(
     int numContentInfos = 0;
     CFDataRef returnedValue = NULL;
 
-    require(cmsDecoder && hashAgilityAttrValue, xit);
-    require_noerr(CMSDecoderGetCmsMessage(cmsDecoder, &cmsg), xit);
+    require(cmsDecoder && hashAgilityAttrValue, exit);
+    require_noerr(CMSDecoderGetCmsMessage(cmsDecoder, &cmsg), exit);
     numContentInfos = SecCmsMessageContentLevelCount(cmsg);
     for (int dex = 0; !signedData && dex < numContentInfos; dex++)
     {
@@ -1036,7 +1018,7 @@ OSStatus CMSDecoderCopySignerAppleCodesigningHashAgility(
                     break;
                 }
     }
-xit:
+exit:
     if (status == errSecSuccess && returnedValue) {
         *hashAgilityAttrValue = (CFDataRef) CFRetain(returnedValue);
     } else {
@@ -1044,3 +1026,49 @@ xit:
     }
     return status;
 }
+
+/*
+ * Obtain the Hash Agility V2 attribute value of signer 'signerIndex'
+ * of a CMS message, if present.
+ *
+ * Returns errSecParam if the CMS message was not signed or if signerIndex
+ * is greater than the number of signers of the message minus one.
+ *
+ * This cannot be called until after CMSDecoderFinalizeMessage() is called.
+ */
+OSStatus CMSDecoderCopySignerAppleCodesigningHashAgilityV2(
+    CMSDecoderRef        cmsDecoder,
+    size_t                signerIndex,            /* usually 0 */
+    CFDictionaryRef  CF_RETURNS_RETAINED *hashAgilityV2AttrValues)            /* RETURNED */
+{
+    OSStatus status = errSecParam;
+    SecCmsMessageRef cmsg;
+    SecCmsSignedDataRef signedData = NULL;
+    int numContentInfos = 0;
+    CFDictionaryRef returnedValue = NULL;
+
+    require(cmsDecoder && hashAgilityV2AttrValues, exit);
+    require_noerr(CMSDecoderGetCmsMessage(cmsDecoder, &cmsg), exit);
+    numContentInfos = SecCmsMessageContentLevelCount(cmsg);
+    for (int dex = 0; !signedData && dex < numContentInfos; dex++)
+    {
+        SecCmsContentInfoRef ci = SecCmsMessageContentLevel(cmsg, dex);
+        SECOidTag tag = SecCmsContentInfoGetContentTypeTag(ci);
+        if (tag == SEC_OID_PKCS7_SIGNED_DATA)
+            if ((signedData = (SecCmsSignedDataRef)SecCmsContentInfoGetContent(ci))) {
+                SecCmsSignerInfoRef signerInfo = SecCmsSignedDataGetSignerInfo(signedData, (int)signerIndex);
+                if (signerInfo)
+                {
+                    status = SecCmsSignerInfoGetAppleCodesigningHashAgilityV2(signerInfo, &returnedValue);
+                    break;
+                }
+            }
+    }
+exit:
+    if (status == errSecSuccess && returnedValue) {
+        *hashAgilityV2AttrValues = (CFDictionaryRef) CFRetain(returnedValue);
+    } else {
+        *hashAgilityV2AttrValues = NULL;
+    }
+    return status;
+}