Class CreateEmbeddedTimeStamp


  • public class CreateEmbeddedTimeStamp
    extends java.lang.Object
    An example for timestamp-signing a PDF for PADeS-Specification. The document will only be changed in its existing signature by a signed timestamp (A timestamp and the Hash-Value of the document are signed by a Time Stamp Authority (TSA)). This method only changes the unsigned parameters of a signature, so that it is kept valid. Use case: sign offline to avoid zero-day attacks against the signing machine. Once the signature is there and the pdf is transferred to a network connected machine, one is likely to want to add a timestamp. (Ralf Hauser)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void embedNewSignatureIntoDocument​(byte[] docBytes, java.io.OutputStream output)
      Embeds the new signature into the document, by copying the rest of the document
      void embedTimeStamp​(java.io.File file)
      Embeds the given PDF file with signed timestamp(s).
      void embedTimeStamp​(java.io.File inFile, java.io.File outFile)
      Embeds signed timestamp(s) into existing signatures of the given document
      static void main​(java.lang.String[] args)  
      private void processRelevantSignatures​(byte[] documentBytes)
      Create changed Signature with embedded TimeStamp from TSA
      private void processTimeStamping​(java.io.File inFile, java.io.File outFile)
      Processes the time-stamping of the signature.
      private static void usage()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • tsaUrl

        private final java.lang.String tsaUrl
      • changedEncodedSignature

        private byte[] changedEncodedSignature
    • Constructor Detail

      • CreateEmbeddedTimeStamp

        public CreateEmbeddedTimeStamp​(java.lang.String tsaUrl)
    • Method Detail

      • embedTimeStamp

        public void embedTimeStamp​(java.io.File file)
                            throws java.io.IOException,
                                   java.net.URISyntaxException
        Embeds the given PDF file with signed timestamp(s). Alters the original file on disk.
        Parameters:
        file - the PDF file to sign and to overwrite
        Throws:
        java.io.IOException
        java.net.URISyntaxException
      • embedTimeStamp

        public void embedTimeStamp​(java.io.File inFile,
                                   java.io.File outFile)
                            throws java.io.IOException,
                                   java.net.URISyntaxException
        Embeds signed timestamp(s) into existing signatures of the given document
        Parameters:
        inFile - The pdf file possibly containing signatures
        outFile - Where the changed document will be saved
        Throws:
        java.io.IOException
        java.net.URISyntaxException
      • processTimeStamping

        private void processTimeStamping​(java.io.File inFile,
                                         java.io.File outFile)
                                  throws java.io.IOException,
                                         java.net.URISyntaxException
        Processes the time-stamping of the signature.
        Parameters:
        inFile - The existing PDF file
        outFile - Where the new file will be written to
        Throws:
        java.io.IOException
        java.net.URISyntaxException
      • processRelevantSignatures

        private void processRelevantSignatures​(byte[] documentBytes)
                                        throws java.io.IOException,
                                               org.bouncycastle.cms.CMSException,
                                               java.security.NoSuchAlgorithmException,
                                               java.net.URISyntaxException
        Create changed Signature with embedded TimeStamp from TSA
        Parameters:
        documentBytes - byte[] of the input file
        Throws:
        java.io.IOException
        org.bouncycastle.cms.CMSException
        java.security.NoSuchAlgorithmException
        java.net.URISyntaxException
      • embedNewSignatureIntoDocument

        private void embedNewSignatureIntoDocument​(byte[] docBytes,
                                                   java.io.OutputStream output)
                                            throws java.io.IOException
        Embeds the new signature into the document, by copying the rest of the document
        Parameters:
        docBytes - byte array of the document
        output - target, where the file will be written
        Throws:
        java.io.IOException
      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException,
                                java.net.URISyntaxException
        Throws:
        java.io.IOException
        java.net.URISyntaxException
      • usage

        private static void usage()