Skip to content

Commit 3a8e25e

Browse files
olszomalmtrojnar
authored andcommitted
Added support for multiple OID types in signer info attribute
1 parent 7d1b460 commit 3a8e25e

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

cat.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ FILE_FORMAT file_format_cat = {
5555

5656
/* Prototypes */
5757
static 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);
6060
static int cat_list_content(PKCS7 *p7);
6161
static int cat_print_content_member_digest(ASN1_TYPE *content);
6262
static 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;

helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ void print_hash(const char *descript1, const char *descript2, const u_char *mdbu
461461
}
462462

463463
/*
464-
* [in] p7: new PKCS#7 signature
464+
* [in] p7: PKCS#7 signature
465465
* [in] objid: Microsoft OID Authenticode
466466
* [returns] 0 on error or 1 on success
467467
*/

0 commit comments

Comments
 (0)