title: How can I see what attributes are signed inside a PKCS 7 file?
body: <p>I have a <a href="https://en.wikipedia.org/wiki/PKCS_7" rel="nofollow noreferrer">PKCS 7</a> file, which contains signed data. It successfully verifies:</p>
  <pre class="lang-none prettyprint-override"><code>openssl smime -verify -in data.p7s -CAfile root-certificate.pem
  </code></pre>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code>Verification successful
  Signed data
  </code></pre>
  <p>But when I extract the signed part, I do not see that it is actually the same as what was signed. I mean the following steps:</p>
  <pre class="lang-none prettyprint-override"><code>openssl asn1parse -in data.p7s
  </code></pre>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code>...
     35:d=4  hl=2 l=   9 prim: OBJECT            :pkcs7-data
     46:d=4  hl=2 l=inf  cons: cont [ 0 ]
     48:d=5  hl=2 l=inf  cons: OCTET STRING
     50:d=6  hl=2 l=   5 prim: OCTET STRING      :(my data is here in plaintext)
  ...
  (then the signed block starts:)
   2861:d=6  hl=2 l=   9 prim: OBJECT            :rsaEncryption
   2872:d=6  hl=2 l=   0 prim: NULL
   2874:d=5  hl=4 l= 256 prim: OCTET STRING      [HEX DUMP]:&lt;signed data is here&gt;
  </code></pre>
  <p>I cut the <code>[HEX DUMP]</code> with the signed data:</p>
  <pre class="lang-none prettyprint-override"><code>dd if=data.p7s of=signed-part.bin bs=1 skip=2878 count=256
  </code></pre>
  <p>Decrypt it with the corresponding public key:</p>
  <pre class="lang-none prettyprint-override"><code>openssl rsautl -verify -in signed-part.bin -pubin -inkey root-public-key.pem -out verified-data.bin
  </code></pre>
  <p>And look inside the result:</p>
  <pre class="lang-none prettyprint-override"><code>openssl asn1parse -inform der -in verified-data.bin
  </code></pre>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code> 0:d=0  hl=2 l=  33 cons: SEQUENCE
   2:d=1  hl=2 l=   9 cons: SEQUENCE
   4:d=2  hl=2 l=   5 prim: OBJECT            :sha1
  11:d=2  hl=2 l=   0 prim: NULL
  13:d=1  hl=2 l=  20 prim: OCTET STRING      [HEX DUMP]:&lt;hash here&gt;
  </code></pre>
  <p>This <code>[HEX DUMP]</code> is <em>not</em> the <a href="https://en.wikipedia.org/wiki/SHA-1" rel="nofollow noreferrer">SHA-1</a> sum of my original data.</p>
  <p>I do not understand why the hash is different. Obviously, it's a hash of something different than my original data. Does the hash also cover any &quot;Authenticated attributes&quot;? If yes, how to see what exactly attributes have been hashed and signed?</p>