title: Programmatically compute "SHA-256-Digest-Manifest-Main-Attributes" in jar file?
body: <p>Because of using HSM hardware we need to sign a jar file w/o actually using Jarsigner. It's all pretty obvious, to the exception of the SHA256 digest of the manifest's main attributes, the attribute "SHA-256-Digest-Manifest-Main-Attributes" in the .SF file.</p>
  
  <p>The main attributes are defined in the <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Manifest-Overview" rel="nofollow noreferrer">manifest specification</a>.</p>
  
  <p>However, I can not seem to find the proper order and/or values to hash. I've been scanning the source code of Jarsigner, but neither can I not find the class reading the attributes.</p>
  
  <p>Does somebody knows how this works ?</p>
  
  <p>[UPDATE: PKCS11 Sun provider]</p>
  
  <p>Using Java PKCS11 provider works, but it yields an empty keystore</p>
  
  <pre><code>name = OpenSC
  description = SunPKCS11 w/ OpenSC Smart card Framework
  library = /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so
  slotListIndex = 0
  </code></pre>
  
  <p>Code sample</p>
  
  <pre><code>final InputStream inputStream = Signer.class.getClassLoader().getResourceAsStream("opensc-java.cfg");
  final SunPKCS11 pkcs11 = new SunPKCS11(inputStream);
  final KeyStore ks = KeyStore.getInstance("PKCS11", pkcs11);
  ks.load(null, "*****".toCharArray());
  </code></pre>