@@ -55,8 +55,8 @@ FILE_FORMAT file_format_cat = {
5555
5656/* Prototypes */
5757static CAT_CTX * cat_ctx_get (char * indata , uint32_t filesize );
58- static int cat_add_ms_ctl_object (PKCS7 * p7 );
59- static int cat_sign_ms_ctl_content (PKCS7 * p7 , PKCS7 * contents );
58+ static int cat_add_content_type (PKCS7 * p7 , PKCS7 * cursig );
59+ static int cat_sign_content (PKCS7 * p7 , PKCS7 * contents );
6060static int cat_list_content (PKCS7 * p7 );
6161static int cat_print_content_member_digest (ASN1_TYPE * content );
6262static int cat_print_content_member_name (ASN1_TYPE * content );
@@ -161,17 +161,17 @@ static PKCS7 *cat_pkcs7_signature_new(FILE_FORMAT_CTX *ctx, BIO *hash)
161161 fprintf (stderr , "Creating a new signature failed\n" );
162162 return NULL ; /* FAILED */
163163 }
164- if (!cat_add_ms_ctl_object ( p7 ) ) {
165- fprintf (stderr , "Adding MS_CTL_OBJID failed \n" );
164+ if (!ctx -> cat_ctx -> p7 || ! ctx -> cat_ctx -> p7 -> d . sign || ! ctx -> cat_ctx -> p7 -> d . sign -> contents ) {
165+ fprintf (stderr , "Failed to get content \n" );
166166 PKCS7_free (p7 );
167167 return NULL ; /* FAILED */
168168 }
169- if (!ctx -> cat_ctx -> p7 || ! ctx -> cat_ctx -> p7 -> d . sign || ! ctx -> cat_ctx -> p7 -> d . sign -> contents ) {
170- fprintf (stderr , "Failed to get content \n" );
169+ if (!cat_add_content_type ( p7 , ctx -> cat_ctx -> p7 ) ) {
170+ fprintf (stderr , "Adding content type failed \n" );
171171 PKCS7_free (p7 );
172172 return NULL ; /* FAILED */
173173 }
174- if (!cat_sign_ms_ctl_content (p7 , ctx -> cat_ctx -> p7 -> d .sign -> contents )) {
174+ if (!cat_sign_content (p7 , ctx -> cat_ctx -> p7 -> d .sign -> contents )) {
175175 fprintf (stderr , "Failed to set signed content\n" );
176176 PKCS7_free (p7 );
177177 return NULL ; /* FAILED */
@@ -251,23 +251,38 @@ static CAT_CTX *cat_ctx_get(char *indata, uint32_t filesize)
251251}
252252
253253/*
254- * Add "1.3.6.1.4.1.311.10.1" MS_CTL_OBJID signed attribute
254+ * Add a content type OID to the PKCS#7 signature structure.
255+ * The content type can be:
256+ * - "1.3.6.1.4.1.311.10.1" (MS_CTL_OBJID) for Certificate Trust Lists (CTL),
257+ * - "1.3.6.1.4.1.311.2.1.4" (SPC_INDIRECT_DATA_OBJID) for Authenticode data.
255258 * [in, out] p7: new PKCS#7 signature
259+ * [in] cursig: current PKCS#7 signature to determine content type
256260 * [returns] 0 on error or 1 on success
257261 */
258- static int cat_add_ms_ctl_object (PKCS7 * p7 )
262+ static int cat_add_content_type (PKCS7 * p7 , PKCS7 * cursig )
259263{
264+ const char * content_type ;
260265 STACK_OF (PKCS7_SIGNER_INFO ) * signer_info ;
261266 PKCS7_SIGNER_INFO * si ;
262267
268+ if (is_content_type (cursig , SPC_INDIRECT_DATA_OBJID )) {
269+ /* Authenticode content */
270+ content_type = SPC_INDIRECT_DATA_OBJID ;
271+ } else if (is_content_type (cursig , MS_CTL_OBJID )) {
272+ /* Certificate Trust List (CTL) */
273+ content_type = MS_CTL_OBJID ;
274+ } else {
275+ fprintf (stderr , "Unsupported content type\n" );
276+ return 0 ; /* FAILED */
277+ }
263278 signer_info = PKCS7_get_signer_info (p7 );
264279 if (!signer_info )
265280 return 0 ; /* FAILED */
266281 si = sk_PKCS7_SIGNER_INFO_value (signer_info , 0 );
267282 if (!si )
268283 return 0 ; /* FAILED */
269284 if (!PKCS7_add_signed_attribute (si , NID_pkcs9_contentType ,
270- V_ASN1_OBJECT , OBJ_txt2obj (MS_CTL_OBJID , 1 )))
285+ V_ASN1_OBJECT , OBJ_txt2obj (content_type , 1 )))
271286 return 0 ; /* FAILED */
272287 return 1 ; /* OK */
273288}
@@ -280,7 +295,7 @@ static int cat_add_ms_ctl_object(PKCS7 *p7)
280295 * [in] contents: Certificate Trust List (CTL)
281296 * [returns] 0 on error or 1 on success
282297 */
283- static int cat_sign_ms_ctl_content (PKCS7 * p7 , PKCS7 * contents )
298+ static int cat_sign_content (PKCS7 * p7 , PKCS7 * contents )
284299{
285300 u_char * content ;
286301 int seqhdrlen , content_length ;
0 commit comments