|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectat.knowcenter.wag.egov.egiz.pdf.BinarySignature
public abstract class BinarySignature
Contains various extension functions to digitally sign documents.
These functions are used to replace parts of the original Egiz plain text signature mechanism.
Field Summary | |
---|---|
static byte[] |
BREV_DAT
The date brev. |
static byte[] |
BREV_ISS
The issure brev. |
static byte[] |
BREV_NIL
The nil brev used to define an unrecognized value. |
static byte[] |
BREV_SID
The SIG_ID brev. |
static byte[] |
BREV_SNR
The serial number brev. |
static byte[] |
BREV_VAL
The value brev. |
static int |
CERTIFICATE_PLACEHOLDER_LENGTH
The number of bytes left out for the certificate placeholder. |
static PdfName |
EGIZ_BYTERANGES_NAME
The PDFName of the byte ranges array. |
static PdfName |
EGIZ_CERTIFICATE_NAME
The PdfName of the certificate array. |
static PdfName |
EGIZ_DICT_NAME
The PDFName of the Egiz Dictionary. |
static PdfName |
EGIZ_ENCODINGS_NAME
The PDFName of the /encodings field in an Egiz Dictionary. |
static PdfName |
EGIZ_KZ_NAME
The PDFName of the Kennzeichnung attribute. |
static PdfName |
EGIZ_ODS_NAME
The PDFName of the Original Document Size (ODS) field in an Egiz Dictionary. |
static PdfName |
EGIZ_REPLACES_NAME
The PDFName of the /replaces field in an Egiz Dictionary. |
static PdfName |
EGIZ_XOBJ_NAME
The PDFName of the Signature XObject field in an Egiz Dictionary. |
static byte[] |
ENCODING_NIL
No explicit encoding. |
static byte[] |
ENCODING_URL
URL encoding. |
static byte[] |
ENCODING_WIN
PDF WinAnsiEncoding. |
static byte |
LAYOUT_PLACEHOLDER
The placeholder character used to fill out Strings in the layout process. |
static int |
LINE_BREAK_TOLERANCE
The tolerance area of the line break algorithm. |
protected static PdfNumber |
NUMBER_PLACEHOLDER
The number placeholder that is used to give numbers a fixed length. |
static byte |
SIGN_PLACEHOLDER
This placeholder is used to fill out holes between the byte ranges before the document is signed. |
Constructor Summary | |
---|---|
BinarySignature()
|
Method Summary | |
---|---|
static byte[] |
buildDigest(byte[] data,
int length)
Builds a digest of the given data. |
protected static int |
calcNumReps(List replaces)
Calculates the number of actual String replaces from a given ReplaceInfo list. |
protected static void |
createEgizDict(PdfStamper stamper,
PdfTemplate table_template,
IncrementalUpdateInformation iui,
List variable_field_definitions,
List all_field_definitions)
Creates the EGIZ Dictionary and adds it to the document. |
protected static List |
determineKZ(byte[] pdf,
int begin,
int end,
List field_definitions)
Determines the Kennzeichnug in the content stream. |
protected static List |
determineReplacesInContentStream(byte[] pdf,
int begin,
int end,
List field_definitions)
Determines the List of ReplaceInfo objects of replaces in the content stream regarding the given field definitions. |
static List |
extractSignatureHoldersBinary(byte[] pdf)
Retrieves the List of SignatureHolders containing the information of all digital signatures of the given document. |
static String |
extractSignatureTextOnly(PdfDictionary egiz_dict)
Extracts the signature text only. |
static String |
extractTextBinary(byte[] pdf)
Extracts the signable text from a binary pdf document. |
static String |
extractTextBinary(File doc)
Extracts the binary 'text' of a document. |
static String |
extractTextBinary(InputStream is)
Extracts the text binary. |
protected static int |
findFirstNotPlaceholder(List strings,
int start)
Finds the first string after and at the given index not being a placeholder string. |
protected static int |
findIndex(List strings,
byte[] caption)
Finds the index of the StringInfo within the StringInfo list that has the given content (caption). |
static List |
getEgizDictChainFromReader(PdfReader reader)
Retrieves the chain of Egiz Dictionaries from the reader. |
static PdfDictionary |
getEgizDictFromReader(PdfReader reader)
Retrieves the Egiz Dictionary from the document if present. |
static PdfIndirectReference |
getEgizDictIndRefFromReader(PdfReader reader)
Retrieves the Egiz Dictionary's indirect reference from the reader. |
static int |
getOriginalDocumentSizeFromEgizDict(PdfDictionary egiz_dict)
Retrieves the size of the original document from the Egiz Dictionary. |
static PdfDictionary |
getPreviousFromEgizDict(PdfDictionary egiz_dict)
Retrieves the previous Egiz dictionary from the given one, if a previous dictionary exists. |
protected static boolean |
isCaption(List strings,
int index,
byte[] caption)
|
protected static boolean |
isPlaceholder(StringInfo si,
byte placeholder)
Tells, if the given StringInfo contains only placeholder characters. |
static void |
main(String[] args)
For debugging purposes. |
static void |
markByteRanges(IncrementalUpdateInformation iui)
Updates the information in the egiz dictionary to reflect the real offsets of the byte ranges. |
static byte[] |
prepareDataToSign(byte[] data,
List byte_ranges)
Fills the holes in the byte ranges with the SIGN_PLACEHOLDER. |
static int |
readNumber(byte[] pdf,
int start_index,
int num_digits)
Reads an unsigned integer number. |
static List |
reconstructReplaces(byte[] pdf,
byte[][] brevs,
StringInfo[] sis,
byte[][] encodings)
Reconstructs the replaces from the PDF and forms suitable value strings. |
static void |
replaceCertificate(IncrementalUpdateInformation iui)
Replaces the certificate placeholder with the certificate from the signed Signature Object. |
static void |
replaceNumber(byte[] pdf,
int start_index,
int number,
int num_digits)
Replaces a number by the new value. |
static void |
replacePlaceholders(IncrementalUpdateInformation iui)
Replaces the placeholders with values from the signed SignatureObject. |
static void |
restorePlaceholder(byte[] pdf,
StringInfo si,
byte placeholder)
Restores the given String to its placeholder. |
static String |
retrieveSignableTextFromData(byte[] data,
int ods)
Retrieves the signable text from the given document. |
protected static int |
skipStrings(List strings,
int index,
byte[] caption)
|
protected static boolean |
startsWithCaption(StringInfo si,
List field_definitions)
|
protected static byte[] |
typeToBrev(String type)
Converts a field name (type) to the corresponding BREV. |
static IncrementalUpdateInformation |
writeIncrementalUpdate(byte[] original_document,
PdfPTable pdf_table,
PositioningInstruction pi,
List variable_field_definitions,
List all_field_definitions)
Signs a document with the given signature table using the Incremental Update method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int LINE_BREAK_TOLERANCE
Placeholder.replacePlaceholderWithTolerance(byte[], List, byte[], int)
,
Constant Field Valuespublic static final int CERTIFICATE_PLACEHOLDER_LENGTH
public static final byte LAYOUT_PLACEHOLDER
public static final byte SIGN_PLACEHOLDER
public static final byte[] BREV_NIL
public static final byte[] BREV_DAT
public static final byte[] BREV_ISS
public static final byte[] BREV_SNR
public static final byte[] BREV_VAL
public static final byte[] BREV_SID
public static final byte[] ENCODING_NIL
public static final byte[] ENCODING_WIN
public static final byte[] ENCODING_URL
public static final PdfName EGIZ_DICT_NAME
Used to locate and identify the Egiz Dictionary in the document.
public static final PdfName EGIZ_ODS_NAME
The ODS must be a positive integral number.
public static final PdfName EGIZ_KZ_NAME
public static final PdfName EGIZ_REPLACES_NAME
public static final PdfName EGIZ_ENCODINGS_NAME
public static final PdfName EGIZ_BYTERANGES_NAME
public static final PdfName EGIZ_CERTIFICATE_NAME
public static final PdfName EGIZ_XOBJ_NAME
This must be an indirect reference to the XObject containing the Signature table.
protected static final PdfNumber NUMBER_PLACEHOLDER
Constructor Detail |
---|
public BinarySignature()
Method Detail |
---|
public static String extractSignatureTextOnly(PdfDictionary egiz_dict) throws IOException
The signature text is the text of the Signature XObject.
egiz_dict
- The Egiz Dictionary.
IOException
public static int getOriginalDocumentSizeFromEgizDict(PdfDictionary egiz_dict)
egiz_dict
- The Egiz Dictionary.
public static PdfDictionary getPreviousFromEgizDict(PdfDictionary egiz_dict)
egiz_dict
- The Egiz Dictionary.
public static PdfDictionary getEgizDictFromReader(PdfReader reader)
reader
- The reader to retrieve the dictionary from.
public static PdfIndirectReference getEgizDictIndRefFromReader(PdfReader reader)
reader
- The reader.
public static List getEgizDictChainFromReader(PdfReader reader)
The first element in the List will be the top most (oldest) Egiz Dictionary. The last element in the List will be the bottom most (latest) Egiz Dictionary. If the list is empty, no dictionary could be found at all, which means that the document is not digitally signed.
reader
- The reader.
public static byte[] buildDigest(byte[] data, int length) throws PDFDocumentException
data
- The data to be digested.length
- The length of the data portion that should be used for digesting.
This allows to build the digest only over parts of the data.
PDFDocumentException
- Forwarded exception.public static String retrieveSignableTextFromData(byte[] data, int ods)
data
- The data.ods
- The original document size.
public static byte[] prepareDataToSign(byte[] data, List byte_ranges)
data
- The given byte ranged data.byte_ranges
- The byte ranges.
public static String extractTextBinary(File doc) throws PDFDocumentException
If the document contains an Egiz Dictionary, which means that it is already signed, the binary text is the Base64 coded string of the original document followed by the Ascii representation of the signature block.
If the document does not contain an Egiz Dictionary, which means that it is unsigned, only the binary Base64 coded original document is returned as binary text.
This function is intented for being used instead of the "text extraction" mechanism used in the plain text Egiz project.
doc
- The file.
PDFDocumentException
- Forwarded exception.public static String extractTextBinary(InputStream is) throws PDFDocumentException
is
-
PDFDocumentException
public static String extractTextBinary(byte[] pdf) throws PDFDocumentException
The signable text is the text that will be signed or verified afterwards.
pdf
- The pdf document.
PDFDocumentException
- Forwarded exception.public static List extractSignatureHoldersBinary(byte[] pdf) throws PDFDocumentException, SignatureTypesException, SignatureException
If the List of SignatureHolders is empty, the document is not signed anyways.
pdf
- The complete pdf document.
PDFDocumentException
SignatureTypesException
SignatureException
public static IncrementalUpdateInformation writeIncrementalUpdate(byte[] original_document, PdfPTable pdf_table, PositioningInstruction pi, List variable_field_definitions, List all_field_definitions) throws PresentableException
The table containing the signature text will be appended. As specified by the parameters, the signature will be appended to the last page, or a plain new page will be created for the signature to hold.
The table will be completely wrapped by an XObject, which will also be indirectly referenced by the Egiz Dictionary. This will ease the verification process.
An Egiz Dictionary will be added to the new document that contains information about the signature. Basically the size of the original document and the reference of the signature table.
original_document
- The original document.pdf_table
- The PdfPTable that contains the signature block.pi
- The PositioningInstruction telling the algorithm where to place
the signature block.
PresentableException
- Forwarded exception.protected static void createEgizDict(PdfStamper stamper, PdfTemplate table_template, IncrementalUpdateInformation iui, List variable_field_definitions, List all_field_definitions) throws IOException, SettingNotFoundException
stamper
- The PdfStamper.table_template
- The Template of the Signature block.iui
- The IncrementalUpdateInformation.variable_field_definitions
- The field definitions.
IOException
SettingNotFoundException
protected static byte[] typeToBrev(String type)
type
- The field name (type).
public static void markByteRanges(IncrementalUpdateInformation iui) throws PDFDocumentException
This replaces the "dummy numbers" in the egiz dictionary with the correct values.
iui
- The IncrementalUpdateInformation.
PDFDocumentException
public static void replaceCertificate(IncrementalUpdateInformation iui) throws PDFDocumentException
iui
- The IncrementalUpdateInformation.
PDFDocumentException
public static void replacePlaceholders(IncrementalUpdateInformation iui) throws PDFDocumentException
iui
- The IncrementalUpdateInformation.
PDFDocumentException
protected static int calcNumReps(List replaces)
This is used to determine the number of actual replaces that has to be carried out. Accordingly to this number, entries in the dictionary are created.
replaces
- The ReplaceInfo list.
protected static List determineReplacesInContentStream(byte[] pdf, int begin, int end, List field_definitions)
This method collects all variable String fields in a content stream and orders them according to their start offset.
pdf
- The PDF.begin
- The start of the content stream.end
- The end of the content stream.field_definitions
- The field definitions that are counceled to find out which and
where varaible strings are.
protected static List determineKZ(byte[] pdf, int begin, int end, List field_definitions) throws SettingNotFoundException
pdf
- The PDF.begin
- The start of the content stream.end
- The end of the content stream.field_definitions
- The field definitions.
SettingNotFoundException
- F.e.protected static int findIndex(List strings, byte[] caption)
strings
- The list of StringInfos.caption
- The text to be matched to the strings.
protected static boolean isCaption(List strings, int index, byte[] caption)
protected static int skipStrings(List strings, int index, byte[] caption)
protected static boolean isPlaceholder(StringInfo si, byte placeholder)
si
- The StringInfo.placeholder
- The placeholder character.
protected static boolean startsWithCaption(StringInfo si, List field_definitions)
protected static int findFirstNotPlaceholder(List strings, int start)
strings
- The list of StringInfos.start
- The index where to start the search.
public static void restorePlaceholder(byte[] pdf, StringInfo si, byte placeholder)
pdf
- The PDF.si
- The string.placeholder
- The placeholder the string should be filled with.public static List reconstructReplaces(byte[] pdf, byte[][] brevs, StringInfo[] sis, byte[][] encodings) throws PDFDocumentException
pdf
- The PDF.brevs
- The brevs.sis
- The StringInfo objects of the strings.
PDFDocumentException
public static int readNumber(byte[] pdf, int start_index, int num_digits)
pdf
- The PDF.start_index
- The start index of the number.num_digits
- The number of digits.
public static void replaceNumber(byte[] pdf, int start_index, int number, int num_digits)
pdf
- The PDF.start_index
- The start index of the number.number
- The new number.num_digits
- The number of digits.public static void main(String[] args) throws IOException
args
-
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |