Wednesday, March 23, 2011

Decode/extract smime.p7m file contents (email with embedded files) with OpenSSL?

We have an old process (VBScript) that reads a common mailbox and processes certain emails into a database.

New regulations have all messages with attachments now being digitally signed.

The process now only extracts one file (smime.p7m). Using a GUI-based viewer, I can see the embedded files and extract them with no problem. However, what I really need is a command-line based extracter that will write out the embedded files (PDFs, DOCs, XLSs) - they're not encrypted, just signed. I tested this by using a laptop that had no certificates and simply opened the smime.p7m file with the aforementioned viewer.

It looks like OpenSSL will decode/extract this and someone managed to get a version compiled on Windows. However, a lot of trial and error testing of the executable has been frustrating because I can't find the right combination of flags to just say "open the smime.p7m file and write out all the embedded files you find". "openssl smime" always seems to want a "cert.pem" after all the options and I haven't got that.

What am I missing? Thanks in advance.

From stackoverflow
  • Looks like the only available option is to write a simple program using Chilkat's library. This option costs $149 or $289, depending on what kind of license, per developer, but at least it's royalty-free.

  • Did you try the "-noverify" option of openssl?

    For a signed-only message, you can use "openssl smime -verify -in -noverify -out /tmp/blob"

    Then you can use a RFC822-like parser to get the body and attachment(s) out of that "blob". That means that your parser has to be capable of encodings like quoted-printable and base64.

    David : Can't say that I did. Just trying to get OpenSSL working at all was a chore in this environment (military site) and I never really succeeded. In the end, writing a new program to do the work, utilizing the Chilkat libraries got the job done quickly. Thanks for the idea, though.
    dwery : I have tried and the suggested command line works nicely.

0 comments:

Post a Comment