Class EGIZSignatureHandler
- java.lang.Object
-
- org.faceless.pdf2.SignatureHandler
-
- org.faceless.pdf2.EGIZSignatureHandler
-
public class EGIZSignatureHandler extends SignatureHandler
The EGIZSignatureHandlerSignatureHandler
provides the framework for signing documents according to the requirements set by http://www.egiz.gv.at/. In order for this class to do anything useful, aEGIZSignatureHandler.Factory
must be created.- Since:
- 2.11.12
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
EGIZSignatureHandler.Factory
An implementation of this Factory is required to create and control the EGIZSignatureHandler-
Nested classes/interfaces inherited from class org.faceless.pdf2.SignatureHandler
SignatureHandler.Placeholder
-
-
Field Summary
Fields Modifier and Type Field Description static int
FONTCONSTANT
A constant that must be added to the value passed in to theStandardFont
constructor for any fonts used within thepopulateCanvas
method
-
Constructor Summary
Constructors Constructor Description EGIZSignatureHandler(EGIZSignatureHandler.Factory factory)
Create a a new EGIZSignatureHandler from the specified Factory
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
createToken(String type, int line, int length)
Create a new token to be inserted into the canvas.X509Certificate[]
getCertificates()
Get the X.509 Certificates used to sign this Signatureint
getCertificationType()
String
getFilter()
Return the name of the filter, eg "Adobe.PPKLite".String
getIssuerInfo()
Return the "Issuer Information" field of this siganturePDFCanvas
getLayerAppearance(String value, PDFStyle style)
Return aPDFCanvas
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.PDFPage
getPage()
Return the page this signature is on (if signed) or will be (if unsigned).String
getParameter()
Get the "Parameter" field of this SignatureBigInteger
getSerialNumber()
Get the "Serial Number" field of this Signaturebyte[]
getSignatureValue()
Get the "Signature Value" of this signature.Calendar
getSignDate()
Get the time this signature was appliedMap<String,SignatureHandler.Placeholder>
getVariables()
Return the list of "variables" which will be set by the handler after the PDF is rendered.void
postDigest(long filelength, Map<String,SignatureHandler.Placeholder> variables)
Update any Variables that need to be updated after the Digest is calculated (eg Contents).void
preDigest(long filelength, Map<String,SignatureHandler.Placeholder> variables)
Update any Variables that need to be updated before the Digest is calculated (eg ByteRange).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
setCertificates(X509Certificate[] certs)
Set the X.509 Certificates for this signature.void
setIssuerInfo(String value)
Set the "Issuer Information" field of this siganture.void
setParameter(String value)
Set the "Parameter" field of this Signaturevoid
setSerialNumber(BigInteger serial)
Set the "Serial Number" field of this Signaturevoid
setSignatureValue(byte[] data)
Set the "Signature Value" of this signature.void
setSignDate(Calendar calender)
Set the time this signature was appliedvoid
setSignerInfo(String value)
Set the "Signer Information" field of this siganture.boolean
verify(InputStream in)
Return a boolean indicating whether or not the signature handler can verify the specifiedInputStream
.-
Methods inherited from class org.faceless.pdf2.SignatureHandler
containsKey, getArrayValueSize, getBooleanValue, getDefaultName, getDictionaryValueKeys, getEstimatedContentSize, getFormSignature, getHandlerName, getNameValue, getNumericValue, getStreamValue, getStringValue, getTextStringValue, putArrayValue, putBooleanValue, putDictionaryValue, putNameValue, putNumericValue, putStreamValue, putStringValue, putTextStringValue, sign
-
-
-
-
Field Detail
-
FONTCONSTANT
public static final int FONTCONSTANT
A constant that must be added to the value passed in to theStandardFont
constructor for any fonts used within thepopulateCanvas
method- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EGIZSignatureHandler
public EGIZSignatureHandler(EGIZSignatureHandler.Factory factory)
Create a a new EGIZSignatureHandler from the specified Factory
-
-
Method Detail
-
getFilter
public String getFilter()
Description copied from class:SignatureHandler
Return the name of the filter, eg "Adobe.PPKLite".- Specified by:
getFilter
in classSignatureHandler
-
createToken
public String createToken(String type, int line, int length)
Create a new token to be inserted into the canvas. The token type must be one of "date" for the signature date, "serial" for the serial number, "parameter" for the parameter field, "value" for the signature value, "issuer" or "signer" for the signature issuer/signer, or "method" for the signature method. All these fields except for method can be split over multiple lines if necessary - the "line" parameter can range from 0 to 9.
This method should be called by the
populateCanvas
method, which is passed a reference to thisEGIZSignatureHandler
for this reason.- Parameters:
type
- one of "date", "serial", "signer", "issuer", "method", "parameter" or "value"line
- the line number, from 0 to 9 (for type="method", this must be 0)length
- the length of the field in the canvas- Returns:
- the piece of text to be inserted into the canvas for later substitution
-
prepareToSign
public void prepareToSign(KeyStore keystore, String alias, char[] password) throws GeneralSecurityException
Description copied from class: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.- Overrides:
prepareToSign
in classSignatureHandler
- Parameters:
keystore
- the KeyStorealias
- which key to usepassword
- the password to use to decode the key- Throws:
GeneralSecurityException
-
getPage
public PDFPage getPage()
Return the page this signature is on (if signed) or will be (if unsigned). Returns null if this cannot be determined.- Since:
- 2.13.1
-
setSignatureValue
public void setSignatureValue(byte[] data)
Set the "Signature Value" of this signature. Must be called fromEGIZSignatureHandler.Factory.doSign(org.faceless.pdf2.EGIZSignatureHandler, java.security.MessageDigest)
-
setCertificates
public void setCertificates(X509Certificate[] certs)
Set the X.509 Certificates for this signature. Must be called fromEGIZSignatureHandler.Factory.doSign(org.faceless.pdf2.EGIZSignatureHandler, java.security.MessageDigest)
-
getSignatureValue
public byte[] getSignatureValue()
Get the "Signature Value" of this signature.
-
setSignerInfo
public void setSignerInfo(String value)
Set the "Signer Information" field of this siganture. The supplied String may be split into multiple lines with "\n"
-
getCertificates
public X509Certificate[] getCertificates()
Get the X.509 Certificates used to sign this Signature
-
getIssuerInfo
public String getIssuerInfo()
Return the "Issuer Information" field of this siganture
-
setIssuerInfo
public void setIssuerInfo(String value)
Set the "Issuer Information" field of this siganture. The supplied String may be split into multiple lines with "\n"
-
setSignDate
public void setSignDate(Calendar calender)
Set the time this signature was applied
-
getSignDate
public Calendar getSignDate()
Get the time this signature was applied
-
setSerialNumber
public void setSerialNumber(BigInteger serial)
Set the "Serial Number" field of this Signature
-
getSerialNumber
public BigInteger getSerialNumber()
Get the "Serial Number" field of this Signature
-
getParameter
public String getParameter()
Get the "Parameter" field of this Signature
-
setParameter
public void setParameter(String value)
Set the "Parameter" field of this Signature
-
getMessageDigest
public MessageDigest getMessageDigest()
Description copied from class:SignatureHandler
Return a MessageDigest that will be used to calculate the digest of the PDF for signing. This message will be called beforeSignatureHandler.sign()
- see the API docs for that method for more details.- Specified by:
getMessageDigest
in classSignatureHandler
-
getVariables
public Map<String,SignatureHandler.Placeholder> getVariables() throws GeneralSecurityException
Description copied from class:SignatureHandler
Return the list of "variables" which will be set by the handler after the PDF is rendered. Entries in the returned map should have a
String
as a key and aSignatureHandler.Placeholder
as a value. These placeholders will be inserted into the PDF at the correct points.For most SignatureHandlers, the only variables are the "ByteRange" and "Contents" array containing the signature token, which is what this method returns (it may be overridden if more variables are required).
This method was updated for a new signing architecture in release 2.11.12.
- Overrides:
getVariables
in classSignatureHandler
- Returns:
- a Map containing the variables to be substituted into the PDF during signing
- Throws:
GeneralSecurityException
- See Also:
AcrobatSignatureHandlerFactory.setContentSize(int)
-
preDigest
public void preDigest(long filelength, Map<String,SignatureHandler.Placeholder> variables) throws IOException, GeneralSecurityException, CertificateException
Description copied from class:SignatureHandler
Update any Variables that need to be updated before the Digest is calculated (eg ByteRange).- Overrides:
preDigest
in classSignatureHandler
- Parameters:
filelength
- the length of the PDF file, in bytesvariables
- the Map of variables, ordered by their position in the file.- Throws:
IOException
GeneralSecurityException
CertificateException
-
postDigest
public void postDigest(long filelength, Map<String,SignatureHandler.Placeholder> variables) throws Exception
Description copied from class:SignatureHandler
Update any Variables that need to be updated after the Digest is calculated (eg Contents).- Overrides:
postDigest
in classSignatureHandler
- Parameters:
filelength
- the length of the PDF file, in bytesvariables
- the Map of variables, ordered by their position in the file.- Throws:
Exception
-
getCertificationType
public int getCertificationType()
Return the value ofEGIZSignatureHandler.Factory.getCertificationType(org.faceless.pdf2.EGIZSignatureHandler)
- Overrides:
getCertificationType
in classSignatureHandler
- See Also:
FormSignature.getCertificationType()
,FormSignature.setCertificationType(int, java.lang.String)
-
verify
public boolean verify(InputStream in) throws IOException, GeneralSecurityException
Description copied from class:SignatureHandler
Return a boolean indicating whether or not the signature handler can verify the specifiedInputStream
.- Specified by:
verify
in classSignatureHandler
- Returns:
- true if the signature matches the specified InputStream
- Throws:
IOException
- if the InputStream cannot be readGeneralSecurityException
- if the signature cannot be verified for some cryptographic reason
-
getLayerNames
public String[] getLayerNames()
Description copied from class:SignatureHandler
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. 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.As an example, both the Verisign and the SelfSign handlers return the array
[ "n0", "n1", "n2", "n3" ]
.- Specified by:
getLayerNames
in classSignatureHandler
- Returns:
- the ordered list of layer names that should to used to create a visible representation of this signature on a page.
- See Also:
SignatureHandler.getLayerAppearance(java.lang.String, org.faceless.pdf2.PDFStyle)
-
getLayerAppearance
public PDFCanvas getLayerAppearance(String value, PDFStyle style)
Description copied from class:SignatureHandler
Return aPDFCanvas
for the specified layer. This method is called internally by theFormSignature
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.- Specified by:
getLayerAppearance
in classSignatureHandler
- Parameters:
value
- the layer to create (from the list returned bySignatureHandler.getLayerNames()
)style
- the style in which to draw the text, if any- Returns:
- a new
PDFCanvas
of any size containing the specified layer. - See Also:
SignatureHandler.getLayerNames()
-
-