|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.SignatureHandler
org.faceless.pdf2.PKCS7SignatureHandler
public abstract class PKCS7SignatureHandler
This class represents the subclass of digital signatures that rely on Public/Private key pairs and that meet the requirements laid down in the document "PDF Public-Key Digital Signature and Encryption Specification", published by Adobe. Currently we know of three handlers that meet this requirement - the general purpose PKCS#7 handler supplied with Acrobat 6.0 and later, or (for earlier versions) the Adobe "Self-Sign" handler and the plugin supplied by VeriSign.
AcrobatSignatureHandlerFactory
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.faceless.pdf2.SignatureHandler |
---|
SignatureHandler.Placeholder |
Field Summary | |
---|---|
protected org.faceless.pdf2.PKCS7 |
pkcs7
|
Constructor Summary | |
---|---|
protected |
PKCS7SignatureHandler()
|
Method Summary | |
---|---|
X509Certificate[] |
getCertificates()
Return the list of certificates included in this signature. |
String |
getDefaultName()
Returns an optional default value that can be used to initialize FormSignature.setName(java.lang.String) , or null if no such name
is available. |
int |
getEstimatedContentSize(int additional)
Return the estimated size of the signature object to be embedded, or <= 0 if this cannot be determined. |
protected abstract String |
getHashAlgorithm()
Return the Hash algorithm used by the PKCS#7 object when signing. |
PDFCanvas |
getLayerAppearance(String layername,
PDFStyle textstyle)
Return a PDFCanvas for the specified layer. |
String[] |
getLayerNames()
Return the list of appearance layer names used by this Signature Handler to create a visible appearance on the page, in the order they should be drawn. |
MessageDigest |
getMessageDigest()
Return a MessageDigest that will be used to calculate the digest of the PDF for signing. |
abstract String |
getSubFilter()
Return the SubFilter field, which determines how the PKCS#7 object is encoded. |
X509Certificate[] |
getTimeStampCertificates()
If the PKCS#7 object was digitally time-stamped using an RFC3161 time-stamp server, this method verifies and returns the list of X.509 certificates that verify the timestamp, with the actual signing certificate first and the rest in no particular order. |
protected void |
prepareToSign(KeyStore keystore,
String alias,
char[] password)
This method initialized the handler using the specified values into a state where it's ready to sign. |
void |
setCustomAppearance(PDFCanvas canvas,
float x1,
float y1,
float x2,
float y2)
Set a custom appearance for this signature. |
byte[] |
sign()
Finish the digest calculation on the digest returned from SignatureHandler.getMessageDigest()
and return a signature token the signs it. |
boolean |
verify(InputStream in)
Return a boolean indicating whether or not the signature handler can verify the specified InputStream . |
Methods inherited from class org.faceless.pdf2.SignatureHandler |
---|
containsKey, getArrayValueSize, getBooleanValue, getDictionaryValueKeys, getFilter, getFormSignature, getNameValue, getNumericValue, getStreamValue, getStringValue, getTextStringValue, getVariables, postDigest, preDigest, putArrayValue, putBooleanValue, putDictionaryValue, putNameValue, putNumericValue, putStreamValue, putStringValue, putTextStringValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.faceless.pdf2.PKCS7 pkcs7
Constructor Detail |
---|
protected PKCS7SignatureHandler()
Method Detail |
---|
protected abstract String getHashAlgorithm()
public abstract String getSubFilter()
protected void prepareToSign(KeyStore keystore, String alias, char[] password) throws GeneralSecurityException
SignatureHandler
This method initialized the handler using the specified values into a state where it's ready to sign. This method should be used to set any additional fields in the Signature dictionary, for example "Certs" for the Self-Sign handler.
Those overriding this method must call super.prepareToSign()
before doing anything else.
prepareToSign
in class SignatureHandler
keystore
- the KeyStorealias
- which key to usepassword
- the password to use to decode the key
GeneralSecurityException
public int getEstimatedContentSize(int additional)
SignatureHandler
getEstimatedContentSize
in class SignatureHandler
additional
- the negation of any value previously passed into SignatureHandler.setContentSize(int)
public MessageDigest getMessageDigest()
SignatureHandler
SignatureHandler.sign()
- see the API docs
for that method for more details.
getMessageDigest
in class SignatureHandler
public byte[] sign() throws GeneralSecurityException, IOException
SignatureHandler
Finish the digest calculation on the digest returned from SignatureHandler.getMessageDigest()
and return a signature token the signs it. The returned byte array will be stored
as the "Contents" value of the Signature dictionary.
As well as being called to perform the actual signing, the default behaviour of the
SignatureHandler.getVariables()
method is also to call this method with an empty digest, to
determine the size of the token to store in the PDF (the SignatureHandler.getMessageDigest()
method is called twice as well). This can be overridden, by calling
AcrobatSignatureHandlerFactory.setContentSize(int)
for handlers created by that
factory or, if you're implementing a custom signature handler, by writing your own
SignatureHandler.getVariables()
method.
sign
in class SignatureHandler
GeneralSecurityException
- if the signature cannot be applied for some cryptographic reason
IOException
- if the InputStream cannot be readpublic final boolean verify(InputStream in) throws GeneralSecurityException, IOException
SignatureHandler
InputStream
.
verify
in class SignatureHandler
GeneralSecurityException
- if the signature cannot be verified for some cryptographic reason
IOException
- if the InputStream cannot be readpublic X509Certificate[] getCertificates() throws CertificateException
CertificateException
public String[] getLayerNames()
SignatureHandler
FormSignature
class
when drawing the signature annotations on the page.
For more information see the document "Digital Signature Appearances for Public-Key Interoperability", from Adobes website.
As an example, both the Verisign and the SelfSign handlers return the array
[ "n0", "n1", "n2", "n3" ]
.
getLayerNames
in class SignatureHandler
SignatureHandler.getLayerAppearance(java.lang.String, org.faceless.pdf2.PDFStyle)
public PDFCanvas getLayerAppearance(String layername, PDFStyle textstyle)
SignatureHandler
PDFCanvas
for the specified layer.
This method is called internally by the FormSignature
class
when drawing the signature annotations on the page.
For more information see the document "Digital Signature Appearances for Public-Key Interoperability", from Adobes website.
getLayerAppearance
in class SignatureHandler
layername
- the layer to create (from the list returned by SignatureHandler.getLayerNames()
)textstyle
- the style in which to draw the text, if any
PDFCanvas
of any size containing the specified layer.SignatureHandler.getLayerNames()
public void setCustomAppearance(PDFCanvas canvas, float x1, float y1, float x2, float y2)
Set a custom appearance for this signature. See the AcrobatSignatureHandlerFactory.setCustomAppearance(org.faceless.pdf2.PDFCanvas, float, float, float, float)
method for more details -
unless you're manually overriding this class, that's the method you
should be calling.
canvas
- the canvas to display as the "n2" layer of the signature appearance.x1
- the left-most X co-ordinate to place the (optional) certificate texty1
- the bottom-most Y co-ordinate to place the (optional) certificate textx2
- the right-most X co-ordinate to place the (optional) certificate texty2
- the top-most Y co-ordinate to place the (optional) certificate textpublic X509Certificate[] getTimeStampCertificates() throws GeneralSecurityException, IOException
If the PKCS#7 object was digitally time-stamped using an RFC3161 time-stamp
server, this method verifies and returns the list of X.509 certificates that
verify the timestamp, with the actual signing certificate first and the rest
in no particular order. If this method succeeds, then the date returned by
FormSignature.getSignDate()
is the date guaranteed by the time-stamp.
If the signature was time-stamped but the timestamp is corrupt or invalid,
thie method will throw either a GeneralSecurityException
or a
IOException
detailing why.
null
.
X509Certificate
objects that authorized the timestamp, or null
if there isn't a timestamp.
GeneralSecurityException
- if the TimeStamp is invalid
IOException
- if the TimeStamp is corrupt or can't be parsedpublic String getDefaultName()
SignatureHandler
FormSignature.setName(java.lang.String)
, or null
if no such name
is available.
getDefaultName
in class SignatureHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |