Re: Read a content file from a P7M

Discussion in 'Python' started by Emanuele Rocca, Mar 20, 2009.

  1. On 11/03/09 - 05:05, Luca wrote:
    > There is standard or sugested way in python to read the content of a P7M file?
    >
    > I don't need no feature like verify sign, or sign using a certificate.
    > I only need to extract the content file of the p7m (a doc, a pdf, ...)


    For PDF files you can just remove the P7M content before %PDF and after
    %%EOF.

    The following snippet converts /tmp/test.p7m into PDF, saving the
    resulting document into /tmp/test.pdf:

    import re
    from gzip import GzipFile

    contents = GzipFile('/tmp/test.p7m').read()

    contents_re = re.compile('%PDF-.*%%EOF', re.MULTILINE | re.DOTALL)
    contents = contents_re.search(contents).group()

    open('/tmp/test.pdf', 'w').write(contents)

    HTH.
    ciao,
    ema
     
    Emanuele Rocca, Mar 20, 2009
    #1
    1. Advertisements

  2. Emanuele Rocca wrote:
    > On 11/03/09 - 05:05, Luca wrote:
    >> There is standard or sugested way in python to read the content of a P7M file?
    >>
    >> I don't need no feature like verify sign, or sign using a certificate.
    >> I only need to extract the content file of the p7m (a doc, a pdf, ...)

    >
    > For PDF files you can just remove the P7M content before %PDF and after
    > %%EOF.


    If the .p7m is a S/MIME message then it might be encrypted. So you have
    to decrypt it. It could also be a opaque-signed S/MIME message. But
    still I'd use a decent S/MIME module to extract the stuff therein.

    Ciao, Michael.
     
    Michael Ströder, Mar 20, 2009
    #2
    1. Advertisements

  3. Emanuele Rocca

    jumpjack

    Joined:
    Oct 25, 2007
    Messages:
    2
    Likes Received:
    0
    Sorry for digging up such an old thread, but I googled for days with no luck.

    I have a filename.pdf.tsd file, which I'm said to contain a pdf signed with p7m but is corrupt, or no more compatible with the updated program used to create it.
    Acrobat can't read the file at all.
    PDF xChange reader can read the PDF contents but can't read the signatures.

    How coul I extract the signed pdf from the TSD file?

    I can't even find info on TSD file format, so I'm really in trouble to figure out how to handle it.
    Could I extract signature and timestamp data from the tsd file by manually looking at it with an hex viewer?
     
    jumpjack, Jul 16, 2012
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Smith
    Replies:
    0
    Views:
    662
    Alex Smith
    Jun 15, 2005
  2. Vittorio
    Replies:
    0
    Views:
    1,205
    Vittorio
    Jan 14, 2004
  3. hazz
    Replies:
    6
    Views:
    51,996
    SkyUCHC
    Jun 9, 2010
  4. Luca
    Replies:
    0
    Views:
    420
  5. Luca
    Replies:
    1
    Views:
    881
    Michael Ströder
    Mar 20, 2009
  6. Dieter
    Replies:
    0
    Views:
    273
    Dieter
    Jun 16, 2011
  7. Alex Dowad
    Replies:
    4
    Views:
    666
    Michel Demazure
    May 1, 2010
  8. Rafal\(sxat\)
    Replies:
    5
    Views:
    452
    David Mark
    May 26, 2009
Loading...