Incomplete Armored Detached Signature
Russell Haley <[email protected]>
| Newsgroups | gmane.comp.encryption.bouncy-castle.devel |
|---|---|
| Message-ID | <CABx9NuTJavsh_6nR5cAf1ryao+jS7pVSin-cxhKXUpUzbf2W6g@mail.gmail.com> |
Hi,
I have a function that creates a detached signature and returns a
ByteArrayOutputStream. That signature is put in a zip file comment. When I
run create the signature without armor and
use DatatypeConverter.printHexBinary to "encode" it, everything works.
However, when I have tried to use the armor API my signature is incomplete:
-----BEGIN PGP SIGNATURE-----
Version: BCPG v1.59
iJwEAAECAAYFAlsqpWQACgkQQmMlIjYrRyEkTwP/TJAULzklDhQ49fJwpdxd8AD2
rtVktEq5gFupRBp4Zoi9BqzHbhrymhiCRuZgq1jAJGd5+qpErfwrFCmPevTq6ksE
4qtauuUw30WRzDbNzO53+6ZENUA2EDQFawfSQPG1/VpI9NOLsKsbEGBrdax7BJJO
wHx9Lab29VPPBXCb
When attempting to verify the signature I get "premature end of stream in
PartialInputStream". When using my on 'encoding' I get a verified
signature.
The createSignature function I'm using is pretty close to the example code
(I changed where the final output stream lives and I don't close it
explicitly in this function):
private OutputStream createSignature(InputStream script, InputStream keyIn,
char[] pass, boolean armor)
throws GeneralSecurityException, IOException, PGPException
{
OutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream aOut = null;
if (armor){
aOut = new ArmoredOutputStream(out);
}
PGPSecretKey pgpSec = readSecretKey(keyIn);
PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new
JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new
JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
PGPUtil.SHA1).setProvider("BC"));
sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
BCPGOutputStream bOut = new BCPGOutputStream((aOut!=null)?aOut:out);
InputStream fIn = new BufferedInputStream(script);
int ch;
while ((ch = fIn.read()) >= 0){
sGen.update((byte)ch);
}
fIn.close();
sGen.generate().encode(bOut);
return out;
}
I've put a breakpoint at the "return out" and the signature is truncated
before it leaves the function. I checked the ArmouredOutputStream and
nothing looks suspect to my untrained eye. Does anyone have some thoughts
on what I've missed?
Thanks,
Russ