From 206414e55543e34ece06337132767f1887f569d7 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Fri, 7 Oct 2016 15:19:16 +0200 Subject: pkcs7: print the eContent type in output functions if it does not match the defaults --- lib/x509/pkcs7-output.c | 12 ++++++++++++ lib/x509/pkcs7.c | 9 +++------ lib/x509/pkcs7_int.h | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/x509/pkcs7-output.c b/lib/x509/pkcs7-output.c index 79fc5e0113..b3da94d905 100644 --- a/lib/x509/pkcs7-output.c +++ b/lib/x509/pkcs7-output.c @@ -27,6 +27,7 @@ #include #include "errors.h" #include +#include #include #define addf _gnutls_buffer_append_printf @@ -177,9 +178,20 @@ int gnutls_pkcs7_print(gnutls_pkcs7_t pkcs7, int count, ret, i; gnutls_pkcs7_signature_info_st info; gnutls_buffer_st str; + const char *oid; _gnutls_buffer_init(&str); + /* For backwards compatibility with structures using the default OID, + * we don't print the eContent Type explicitly */ + oid = gnutls_pkcs7_get_embedded_data_oid(pkcs7); + if (oid) { + if (strcmp(oid, DATA_OID) != 0 + && strcmp(oid, DIGESTED_DATA_OID) != 0) { + addf(&str, "eContent Type: %s\n", oid); + } + } + for (i = 0;; i++) { if (i == 0) addf(&str, "Signers:\n"); diff --git a/lib/x509/pkcs7.c b/lib/x509/pkcs7.c index 0d57afa4e7..0ff6efdc4a 100644 --- a/lib/x509/pkcs7.c +++ b/lib/x509/pkcs7.c @@ -32,13 +32,10 @@ #include "errors.h" #include #include +#include #include #include -#define SIGNED_DATA_OID "1.2.840.113549.1.7.2" -#define PLAIN_DATA_OID "1.2.840.113549.1.7.1" -#define DIGESTED_DATA_OID "1.2.840.113549.1.7.5" - #define ATTR_MESSAGE_DIGEST "1.2.840.113549.1.9.4" #define ATTR_SIGNING_TIME "1.2.840.113549.1.9.5" #define ATTR_CONTENT_TYPE "1.2.840.113549.1.9.3" @@ -104,7 +101,7 @@ static int _decode_pkcs7_signed_data(gnutls_pkcs7_t pkcs7) goto cleanup; } - if (strcmp(pkcs7->encap_data_oid, PLAIN_DATA_OID) != 0 + if (strcmp(pkcs7->encap_data_oid, DATA_OID) != 0 && strcmp(pkcs7->encap_data_oid, DIGESTED_DATA_OID) != 0) { _gnutls_debug_log ("Unknown PKCS#7 Encapsulated Content OID '%s'; treating as raw data\n", @@ -2155,7 +2152,7 @@ int gnutls_pkcs7_sign(gnutls_pkcs7_t pkcs7, result = asn1_write_value(pkcs7->signed_data, - "encapContentInfo.eContentType", PLAIN_DATA_OID, + "encapContentInfo.eContentType", DATA_OID, 0); if (result != ASN1_SUCCESS) { ret = _gnutls_asn2err(result); diff --git a/lib/x509/pkcs7_int.h b/lib/x509/pkcs7_int.h index 57e72b96e5..b0f7e456e1 100644 --- a/lib/x509/pkcs7_int.h +++ b/lib/x509/pkcs7_int.h @@ -31,6 +31,9 @@ #define DATA_OID "1.2.840.113549.1.7.1" #define ENC_DATA_OID "1.2.840.113549.1.7.6" +#define SIGNED_DATA_OID "1.2.840.113549.1.7.2" +#define DIGESTED_DATA_OID "1.2.840.113549.1.7.5" + typedef enum schema_id { PBES2_GENERIC=1, /* when the algorithm is unknown, temporal use when reading only */ -- cgit v1.2.1