conversion from opaque pkcs7 p7m to detached smime
Asked Answered
M

1

6

Hi I couldn't find a way to convert an opaque pkcs#7(p7m) in a clear text deatached smime so that the signed content could be processed by regular mime libraries.

I'd like to take p7m file and convert it to an smime message keping a valid signature.

The steps should be:

  • extract signed content from p7m

  • extract cms structure from p7m

  • pack everything in a new smime structure with detached signature

Is this operation possible ?

I've searched through openssl manuals but I couldn't find a way to do it.

Meshed answered 19/9, 2011 at 19:34 Comment(0)
R
1

I was able to convert opaque-signed messages to a detached ones with the following code:

#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/pkcs7.h>

int main(int argc, char **argv)
{
    BIO *data = NULL, *bin = NULL, *bout = NULL;
    PKCS7 *p7, *p7b;

    OpenSSL_add_all_algorithms();

    bin = BIO_new_file("opaque.p7m", "rb");
    p7 = SMIME_read_PKCS7(bin, &data);
    p7b = PKCS7_dup(p7);

    data = PKCS7_dataInit(p7, NULL);

    PKCS7_set_detached(p7b, 1);

    bout = BIO_new_file("detached.p7m", "wb");
    SMIME_write_PKCS7(bout, p7b, data, PKCS7_BINARY | SMIME_DETACHED);
}

To test the program I generate the opaque.p7m with the following command:

$ openssl smime -sign -in foo.txt -signer my.crt -inkey my.key -nodetach -out opaque.p7m

To be terse, the code above has no checks. To accept different input formats, you can change SMIME_read_PKCS7 to PEM_read_bio_PKCS7 (PEM) or d2i_PKCS7_bio (DER).

Rhodie answered 4/12, 2013 at 15:39 Comment(1)
Does "attached" signature mean the same as "opaque" signature?Hob

© 2022 - 2024 — McMap. All rights reserved.