es.caib.signatura.impl
Class CAIBSigner

java.lang.Object
  extended by es.caib.signatura.impl.CAIBSigner
All Implemented Interfaces:
Signer

public class CAIBSigner
extends java.lang.Object
implements Signer

Implementator class of the Signer interface.


Field Summary
 
Fields inherited from interface es.caib.signatura.api.Signer
PDF_SIGN_DEFAULT_SIGNATURE_APPERANCE, PDF_SIGN_PAGE_LAST, PDF_SIGN_PDF417_SIGNATURE_APPERANCE, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_LEFT, PDF_SIGN_POSITION_NONE, PDF_SIGN_POSITION_RIGHT, PDF_SIGN_POSITION_TOP
 
Constructor Summary
CAIBSigner()
          Deprecated.  
CAIBSigner(java.util.Map signerConfiguration)
           
CAIBSigner(java.lang.String updateSite, java.net.URL configurationFile, java.lang.String propertiesCachePath)
           
 
Method Summary
 void certifyDigitalCopy(java.io.InputStream contentStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, java.lang.String localidad, float x, float y, float rotation)
          Compulsa de un documento PDF
 void generateSMIME(java.io.InputStream document, Signature signature, java.io.OutputStream smime)
          Generates SMIME document from the document and its digital signature.
 void generateSMIMEParalell(java.io.InputStream document, Signature[] signatures, java.io.OutputStream smime)
          Obtiene el documento SMIME a partir del documento original y el conjunto de firmas digitales obtenidas de firmas el documento.
 java.lang.String getAPIVersion()
          Gets the API version number.
 java.lang.String[] getCertList(java.lang.String contentType)
          Gets the available certificate names list to the API: hard disk, USB devices, cryptographic cards, etc.
 java.util.Date getCurrentDate(java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Obtiene la hora oficial que tendría un sello de tiempo generado en ese mismo instante
 SMIMEParser getSMIMEParser(java.io.InputStream smime)
          Returns an SMIMEParser object to access to the SMIME document information.
static java.lang.String getWindowsShortPath(java.io.File f)
           
protected  void initialize()
           
 ParsedCertificate parseCertificate(java.security.cert.X509Certificate certificate)
          Returns basic certificate information.
protected  void preInitialize()
           
 Signature sign(java.io.InputStream contentStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Gets the digital signature of an input data stream and encapusulates it into a Signature object without timestamp.
 Signature sign(java.lang.String fileName, java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Gets the digital signature of a hard disk document and encapsulates it into a signature object without timestamp.
 Signature sign(java.net.URL url, java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Signs a document obtained from an URL.
 void signPDF(java.io.InputStream contentStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position)
          Firma un PDF sin soporte para múltiples firmas.
 void signPDF(java.io.InputStream contentStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position, boolean allowMultipleSignature)
          Firma un PDF dejando la opción de si se soportan múltiples firmas o no (parámetro allowMultipleSignature).
 void signPDF(java.io.InputStream pdfInputStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String textoAdicional, int stampOptions, float top, float left, float height, float width, float rotation, boolean allowMultipleSignature)
          Firma digitalmente de un documento PDF pasado como InputStream y devuelve el mismo PDF firmado y modificado.
 java.io.OutputStream signPDF(java.io.InputStream contentStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position)
          Deprecated.  
 java.io.OutputStream signPDF(java.io.InputStream contentStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position, boolean allowMultipleSignature)
          Deprecated.  
 boolean verify(java.io.InputStream contentStream, Signature signatureData)
          Verifies the digital signature of a document obtained from an URL.
 boolean verify(java.lang.String fileName, Signature signatureData)
          Verifies the digital signature of a document contained into the hard disk.
 boolean verify(java.net.URL url, Signature signatureData)
          Verifies the digital signature of a document obtained from an URL.
 boolean verifyAPosterioriTimeStamp(java.io.InputStream contentStream, Signature signatureData)
          Verifies the signature of an input data stream.
 boolean verifyAPosterioriTimeStamp(java.lang.String fileName, Signature signatureData)
          Verifies the digital signature of an input data stream.
 boolean verifyAPosterioriTimeStamp(java.net.URL url, Signature signatureData)
          Verifies the digital signature of a document obtained from an URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CAIBSigner

public CAIBSigner()
           throws java.io.FileNotFoundException
Deprecated. 

Throws:
java.io.FileNotFoundException

CAIBSigner

public CAIBSigner(java.lang.String updateSite,
                  java.net.URL configurationFile,
                  java.lang.String propertiesCachePath)
           throws java.io.FileNotFoundException
Parameters:
updateSite -
configurationFile -
propertiesCachePath -
Throws:
java.io.FileNotFoundException

CAIBSigner

public CAIBSigner(java.util.Map signerConfiguration)
           throws java.io.FileNotFoundException
Parameters:
signerConfiguration -
Throws:
java.io.FileNotFoundException
Method Detail

getCertList

public java.lang.String[] getCertList(java.lang.String contentType)
                               throws SignatureCertNotFoundException,
                                      SignaturePrivKeyException
Description copied from interface: Signer
Gets the available certificate names list to the API: hard disk, USB devices, cryptographic cards, etc.

Specified by:
getCertList in interface Signer
Returns:
the names of the available certificates.
Throws:
SignatureCertNotFoundException - if no available certificates.
SignaturePrivKeyException - if unable to access to private keys.

sign

public Signature sign(java.lang.String fileName,
                      java.lang.String certificateName,
                      java.lang.String password,
                      java.lang.String contentType)
               throws java.io.IOException,
                      SignatureException
Description copied from interface: Signer
Gets the digital signature of a hard disk document and encapsulates it into a signature object without timestamp.

Specified by:
sign in interface Signer
Parameters:
fileName - path of the document.
certificateName - name of the certificate used to sign the document.
password - private key password of the certificate.
contentType - MIME type of the document to sign.
Returns:
Signature the document signature.
Throws:
java.io.FileNotFoundException - if unable to find the document.
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

sign

public Signature sign(java.io.InputStream contentStream,
                      java.lang.String certificateName,
                      java.lang.String password,
                      java.lang.String contentType)
               throws java.io.IOException,
                      SignatureException
Description copied from interface: Signer
Gets the digital signature of an input data stream and encapusulates it into a Signature object without timestamp.

Specified by:
sign in interface Signer
Parameters:
contentStream - data stream to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
Returns:
Signature the signature of the data stream.
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

sign

public Signature sign(java.net.URL url,
                      java.lang.String certificateName,
                      java.lang.String password,
                      java.lang.String contentType)
               throws java.io.IOException,
                      SignatureException
Description copied from interface: Signer
Signs a document obtained from an URL.

Specified by:
sign in interface Signer
Parameters:
url - URL address where is located the document to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
Returns:
Signature the signature of the document.
Throws:
java.io.FileNotFoundException - if original file not found.
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

signPDF

public void signPDF(java.io.InputStream contentStream,
                    java.io.OutputStream signedStream,
                    java.lang.String certificateName,
                    java.lang.String password,
                    java.lang.String contentType,
                    java.lang.String url,
                    int position,
                    boolean allowMultipleSignature)
             throws java.io.IOException,
                    SignatureException
Firma un PDF dejando la opción de si se soportan múltiples firmas o no (parámetro allowMultipleSignature).

Specified by:
signPDF in interface Signer
Parameters:
contentStream - data stream to sign.
signedStream - resulting signed data stream.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL to add to the document.
position - Position in each page of the document where the URL will be added. The possible values are: PDF_SIGN_POSITION_TOP, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_RIGHT o PDF_SIGN_POSITION_LEFT.
allowMultipleSignature - allow to sign an already signed PDF
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

signPDF

public void signPDF(java.io.InputStream pdfInputStream,
                    java.io.OutputStream signedStream,
                    java.lang.String certificateName,
                    java.lang.String password,
                    java.lang.String contentType,
                    java.lang.String textoAdicional,
                    int stampOptions,
                    float top,
                    float left,
                    float height,
                    float width,
                    float rotation,
                    boolean allowMultipleSignature)
             throws java.io.IOException,
                    SignatureException
Description copied from interface: Signer
Firma digitalmente de un documento PDF pasado como InputStream y devuelve el mismo PDF firmado y modificado. Las opciones de firma PDF estan establecidas en la clase Signer.

Specified by:
signPDF in interface Signer
certificateName - Nombre del certificado obtenido de la llamada a Signer.getCertList()
password - contraseña de la clave privada del usuario
contentType - tipo MIME del documento a firmar
textoAdicional - URL en caso de estampado PDF417, o motivo de firma para firmas con estampado ABODE
stampOptions - Opciones de firma PDF definidas en la clase Signer
top - El 0 corresponde al borde inferior del documento.
left - El 0 corresponde al borde izquierdo del documento
height - Anchura máxima de la estampa, el texto de dividirà en las líneas necesarias para que quepa en la anchura establecida.
width - Altura máxima de la estampa. Debe tenerse en cuenta que si la altura no es suficientemente grande para el texto que se divide en múltiples líneas, este se corta y desaparece.
rotation - Sólo permite rotación la firma con estampado PDF417. En caso de rotación el estampado se rotarà desde la esquina inferior izquierda (top, left).
allowMultipleSignature - Permitir o no refirmado del documento PDF si el documento de entrada ya está firmado
Throws:
java.io.IOException
SignatureException

signPDF

public void signPDF(java.io.InputStream contentStream,
                    java.io.OutputStream signedStream,
                    java.lang.String certificateName,
                    java.lang.String password,
                    java.lang.String contentType,
                    java.lang.String url,
                    int position)
             throws java.io.IOException,
                    SignatureException
Firma un PDF sin soporte para múltiples firmas.

Specified by:
signPDF in interface Signer
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL address where is located the document to sign.
Throws:
java.io.FileNotFoundException - if original file not found.
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

signPDF

public java.io.OutputStream signPDF(java.io.InputStream contentStream,
                                    java.lang.String certificateName,
                                    java.lang.String password,
                                    java.lang.String contentType,
                                    java.lang.String url,
                                    int position,
                                    boolean allowMultipleSignature)
                             throws java.io.IOException,
                                    SignatureException
Deprecated. 

Genera un PDF firmado, dando la opción de soportar múltiples firmas.

Specified by:
signPDF in interface Signer
Parameters:
contentStream - data stream to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL to add to the document.
position - Position in each page of the document where the URL will be added. The possible values are: PDF_SIGN_POSITION_TOP, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_RIGHT o PDF_SIGN_POSITION_LEFT.
allowMultipleSignature - allow to sign an already signed PDF
Returns:
the signed PDF document.
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

signPDF

public java.io.OutputStream signPDF(java.io.InputStream contentStream,
                                    java.lang.String certificateName,
                                    java.lang.String password,
                                    java.lang.String contentType,
                                    java.lang.String url,
                                    int position)
                             throws java.io.IOException,
                                    SignatureException
Deprecated. 

Genera un PDF firmado, sin la opción de soportar múltiples firmas.

Specified by:
signPDF in interface Signer
Parameters:
contentStream - data stream to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL to add to the document.
position - Position in each page of the document where the URL will be added. The possible values are: PDF_SIGN_POSITION_TOP, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_RIGHT o PDF_SIGN_POSITION_LEFT.
Returns:
the signed PDF document.
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
SignatureException - if any signature error occurs.

certifyDigitalCopy

public void certifyDigitalCopy(java.io.InputStream contentStream,
                               java.io.OutputStream signedStream,
                               java.lang.String certificateName,
                               java.lang.String password,
                               java.lang.String contentType,
                               java.lang.String url,
                               java.lang.String localidad,
                               float x,
                               float y,
                               float rotation)
                        throws java.io.IOException,
                               SignatureException
Compulsa de un documento PDF

Specified by:
certifyDigitalCopy in interface Signer
Throws:
java.io.IOException
SignatureException

verify

public boolean verify(java.io.InputStream contentStream,
                      Signature signatureData)
               throws SignatureProviderException,
                      java.io.IOException,
                      SignatureVerifyException
Description copied from interface: Signer
Verifies the digital signature of a document obtained from an URL. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Specified by:
verify in interface Signer
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verifyAPosterioriTimeStamp

public boolean verifyAPosterioriTimeStamp(java.io.InputStream contentStream,
                                          Signature signatureData)
                                   throws SignatureProviderException,
                                          java.io.IOException,
                                          SignatureVerifyException
Description copied from interface: Signer
Verifies the signature of an input data stream. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Specified by:
verifyAPosterioriTimeStamp in interface Signer
Parameters:
contentStream - data stream of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verify

public boolean verify(java.lang.String fileName,
                      Signature signatureData)
               throws java.io.FileNotFoundException,
                      SignatureProviderException,
                      java.io.IOException,
                      SignatureVerifyException
Description copied from interface: Signer
Verifies the digital signature of a document contained into the hard disk. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Specified by:
verify in interface Signer
Parameters:
fileName - path of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
java.io.FileNotFoundException - if original file not found.
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verify

public boolean verify(java.net.URL url,
                      Signature signatureData)
               throws SignatureProviderException,
                      java.io.IOException,
                      SignatureVerifyException
Description copied from interface: Signer
Verifies the digital signature of a document obtained from an URL. The verification process is independent of signature timestamp.

Specified by:
verify in interface Signer
Parameters:
url - URL address where is located the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.FileNotFoundException - if original file not found.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verifyAPosterioriTimeStamp

public boolean verifyAPosterioriTimeStamp(java.lang.String fileName,
                                          Signature signatureData)
                                   throws java.io.FileNotFoundException,
                                          SignatureProviderException,
                                          java.io.IOException,
                                          SignatureVerifyException
Description copied from interface: Signer
Verifies the digital signature of an input data stream. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Specified by:
verifyAPosterioriTimeStamp in interface Signer
Parameters:
fileName - path of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.
java.io.FileNotFoundException

verifyAPosterioriTimeStamp

public boolean verifyAPosterioriTimeStamp(java.net.URL url,
                                          Signature signatureData)
                                   throws SignatureProviderException,
                                          java.io.IOException,
                                          SignatureVerifyException
Description copied from interface: Signer
Verifies the digital signature of a document obtained from an URL. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Specified by:
verifyAPosterioriTimeStamp in interface Signer
Parameters:
url - URL of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

generateSMIME

public void generateSMIME(java.io.InputStream document,
                          Signature signature,
                          java.io.OutputStream smime)
                   throws java.io.IOException
Description copied from interface: Signer
Generates SMIME document from the document and its digital signature.

Specified by:
generateSMIME in interface Signer
Parameters:
document - input stream of the original document.
signature - digital signature of the document.
smime - output stream to write the generated SMIME document.
Throws:
java.io.IOException - if I/O errors occurs.

generateSMIMEParalell

public void generateSMIMEParalell(java.io.InputStream document,
                                  Signature[] signatures,
                                  java.io.OutputStream smime)
                           throws java.io.IOException,
                                  SignatureException
Description copied from interface: Signer
Obtiene el documento SMIME a partir del documento original y el conjunto de firmas digitales obtenidas de firmas el documento.

Specified by:
generateSMIMEParalell in interface Signer
Parameters:
document - InputStream con el documento que se firmó
signatures - firmas digital del documento
smime - OutputStream con el SMIME obtenido
Throws:
java.io.IOException
SignatureException

getCurrentDate

public java.util.Date getCurrentDate(java.lang.String certificateName,
                                     java.lang.String password,
                                     java.lang.String contentType)
                              throws SignatureTimestampException,
                                     SignatureException,
                                     java.io.IOException
Description copied from interface: Signer
Obtiene la hora oficial que tendría un sello de tiempo generado en ese mismo instante

Specified by:
getCurrentDate in interface Signer
Parameters:
certificateName - nombre del certificado que se usará para firmar
password - contraseña de la clave privada del usuario
contentType - tipo MIME del documento a firmar
Returns:
Hora Oficial
Throws:
SignatureException
java.io.IOException
SignatureTimestampException

getAPIVersion

public java.lang.String getAPIVersion()
Description copied from interface: Signer
Gets the API version number.

Specified by:
getAPIVersion in interface Signer
Returns:
the API version number;

preInitialize

protected void preInitialize()
                      throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

initialize

protected void initialize()
                   throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

getSMIMEParser

public SMIMEParser getSMIMEParser(java.io.InputStream smime)
                           throws java.lang.InstantiationException,
                                  java.lang.IllegalAccessException,
                                  java.io.IOException,
                                  SignatureException
Description copied from interface: Signer
Returns an SMIMEParser object to access to the SMIME document information.

Specified by:
getSMIMEParser in interface Signer
Parameters:
smime - the SMIME document to read.
Returns:
an SMIMEParser object to access to the SMIME document information.
Throws:
java.lang.InstantiationException - if problems instanciating the SMIMEParserObject.
java.lang.IllegalAccessException - if problems instanciating the SMIMEParserObject.
java.io.FileNotFoundException - if smime file not found.
java.io.IOException - if I/O errors occurs.
SignatureException - if any signature error occurs.

parseCertificate

public ParsedCertificate parseCertificate(java.security.cert.X509Certificate certificate)
Description copied from interface: Signer
Returns basic certificate information.

Specified by:
parseCertificate in interface Signer
Returns:
Parsed certificate.

getWindowsShortPath

public static java.lang.String getWindowsShortPath(java.io.File f)
                                            throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException


Copyright © 2011 Direcció General de Tecnologia i Comunicacions. Govern de les Illes Balears. All Rights Reserved.