Get hash and hash algorithm of a signed PDF #46
-
Describe the solution you'd like Describe alternatives you've considered |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
Just found out:
Please ignore this issue. |
Beta Was this translation helpful? Give feedback.
-
Hi Frederico, There are a number of different aspects to your question, so allow me to break it down a little further. First, if you're the one calling pyHanko to sign PDFs: you can actually control the digest function used via the The Aaaaand just as I was about to suggest using |
Beta Was this translation helpful? Give feedback.
-
Hey Matthias! Thanks for the quick reply. Actually, I need the hash of the content being signed... so I guess |
Beta Was this translation helpful? Give feedback.
-
Aha, I see. That creates multiple tricky chicken-or-egg problems, actually, although the particulars will depend on how the signing service you're using actually operates. First, there's an architectural issue that you have to be aware of: if the certificate is not known when pyHanko starts the signing process, you can't use any of the high-level APIs. In your situation, given the degree of control that your workflow seems to require, you're pretty much forced to use this lower-level API. The other issue is more fundamental, and not really related to pyHanko as such: does the signing service you're using supply complete CMS (AKA PKCS#7) signature containers, or just raw signature values? Here's why that matters:
Out of curiosity, can you point me towards the documentation for that certificate extension and/or protocol you're using? Assuming it's public information, of course. |
Beta Was this translation helpful? Give feedback.
-
Yep, that's the case. I send a
I don't follow. But as you said, probably I don't have to worry about it.
Reading the (awesome) documentation, I came across this interrupted signing functionality right at the beginning. Apparently, that's what I need, or am I missing something?
Unfortunately, it is not public, and I cannot share much information about it, sorry. |
Beta Was this translation helpful? Give feedback.
-
Alright, that at least eliminates the worst case scenario, which is good. Passing in the document digest should do the trick, then.
I'd love to answer "yes" here, but I'm afraid you will have to use The low-level
Ah, that's unfortunate. You'll have to make do with this abstract explanation then, I suppose :). That said, other people have successfully used |
Beta Was this translation helpful? Give feedback.
-
I got it working with |
Beta Was this translation helpful? Give feedback.
-
Since this discussion seems to be resolved, I'll close the issue now. :) |
Beta Was this translation helpful? Give feedback.
-
Dear Matthias, Only now have I realized that the lower level API seems to produce a strange error regarding the timestamp. I have tried it with a third-party timestamper and a local, but both produce the same issue: the PDF is timestamped a day in the past. Perhaps I am doing something stupidly wrong. Here is the minimal code to reproduce the issue. Thank you. |
Beta Was this translation helpful? Give feedback.
-
Ah, good catch! This isn't a signing API problem; it appears to be a bug in I'll open a new issue for this one, since it's unrelated to your original question. |
Beta Was this translation helpful? Give feedback.
Hi Frederico,
There are a number of different aspects to your question, so allow me to break it down a little further.
First, if you're the one calling pyHanko to sign PDFs: you can actually control the digest function used via the
PdfSignatureMetadata
object you pass intosign_pdf
. Unless the document has seed values on its signature fields, that setting will be respected. Seed values are rarely used in the wild these days, so chances are you won't ever have to worry about those.The
sign_pdf
function is pretty much the most high-level API pyHanko exposes, so getting access to the internals from there will indeed be difficult. You could get access to all the information you want by hooki…