ctt-gob-es / clienteafirma

Cliente @firma
http://administracionelectronica.gob.es/ctt/clienteafirma
252 stars 119 forks source link

Error al realizar la operacion de firma: es.gob.afirma.signers.pades.InvalidPdfException: El fichero no es un PDF o es un PDF no soportado #120

Open JaviBonilla opened 4 years ago

JaviBonilla commented 4 years ago

Tengo instalado Autofirma y en local funciona perfectamente, pero a utilizarlo a través de portafirmas me da un error (adjunto log) tanto en Chrome como en Firefox en Linux.

Sistema operativo: Opensuse Tumbleweed Autorfirma: 1.6.5 Java: OpenJDK 64bit 1.8.0_242

The AutoFirma ROOT CA certificate is already installed in Firefox
The AutoFirma ROOT CA certificate is already installed in ~/.pki/nssdb
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.ProxyUtil clearJavaProxy
INFO: No se usara Proxy para las conexiones de red
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.SimpleAfirma main
INFO: No se buscaran nuevas versiones de la aplicacion
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.SimpleAfirma printSystemInfo
INFO: AutoFirma 1.6.5
Resolucion DPI de pantalla: 0
Sistema operativo: Linux
Version del SO: 5.5.2-1-default
Version de Java: 1.8.0_242
Arquitectura del JRE: 64
Java Vendor: IcedTea
Localizacion por defecto: en_US
Tamano actual en memoria: 119MB
Tamano maximo de memoria: 1742MB
Memoria actualmente libre: 105MB
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.SimpleAfirma main
INFO: Invocacion por protocolo con URL:
afirma://service?ports=58647,61214,52219&v=1&idsession=on40VikdaQnTjCEAzYVt
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncher launch
INFO: Se inicia la invocacion por servicio: afirma://service?ports=58647,61214,52219&v=1&idsession=on40VikdaQnTjCEAzYVt
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.protocol.ServiceInvocationManager startService
INFO: Se utilizara el siguiente almacen para establecer el socket SSL: /usr/share/java/autofirma/autofirma.pfx
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.protocol.ServiceInvocationManager startService
INFO: Iniciando servicio local de firma: afirma://service?ports=58647,61214,52219&v=1&idsession=on40VikdaQnTjCEAzYVt
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.protocol.ServiceInvocationManager getChannelInfo
INFO: Se ha recibido un idSesion para la transaccion: on40VikdaQnTjCEAzYVt
Feb 20, 2020 12:10:00 PM es.gob.afirma.standalone.protocol.ServiceInvocationManager tryPorts
INFO: Establecido el puerto 58647 para el servicio Cliente @firma
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread run
INFO: Detectada conexion entrante
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread processCommand
INFO: Recibido comando de tipo: echo=
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread doEchoPetition
INFO: Comando URI recibido por HTTP: echo=
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread sendData
INFO: Mandando respuesta a la aplicacion: echo=
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread run
INFO: Detectada conexion entrante
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread processCommand
INFO: Recibido comando de tipo: cmd=
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.CommandProcessorThread doCmdPetition
INFO: Comando URI recibido por HTTP: afirma://sign?op=sign&algorithm=SHA1withRSA&format=XAdES&properties=ZmlsdGVyPW5vbmV4cGlyZWQ6&dat=Ni43Mjc0MDQ3NTA5MDUwMDU%3D&sticky=true
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncher launch
INFO: Se invoca a la aplicacion para realizar una operacion de firma/multifirma
Feb 20, 2020 12:10:01 PM es.gob.afirma.core.misc.protocol.ProtocolInvocationUriParser parserUri
INFO: URI recibida: afirma://sign?op=sign&algorithm=SHA1withRSA&format=XAdES&properties=ZmlsdGVyPW5vbmV4cGlyZWQ6&dat=Ni43Mjc0MDQ3NTA5MDUwMDU%3D&sticky=true
Feb 20, 2020 12:10:01 PM es.gob.afirma.core.misc.http.DataDownloader downloadData
INFO: El contenido a obtener es Base64
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncher launch
INFO: Se inicia la operacion de firma
Feb 20, 2020 12:10:01 PM es.gob.afirma.signers.xml.Utils installXmlDSigProvider
INFO: Instalamos el proveedor de firma XML de Apache
Feb 20, 2020 12:10:01 PM es.gob.afirma.signers.xml.Utils installXmlDSigProvider
INFO: Se usara el proveedor 'ApacheXMLDSig': org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.MozillaKeyStoreUtilitiesUnix getNSSLibDirUnix
INFO: Se usara el NSS encontrado en '/usr/lib64'
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.shared.SharedNssUtil getSharedUserProfileDirectory
INFO: Detectado directorio de perfil de NSS: ̴/.pki/nssdb
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.MozillaKeyStoreUtilities loadNSS
INFO: Configuracion de NSS para SunPKCS11:
name=NSSCrypto-AFirma
library=/usr/lib64/libsoftokn3.so
attributes=compatibility
slot=2
showInfo=false
allowSingleThreadedModules=true
nssArgs="configdir='sql:/USERHOME/.pki/nssdb' certPrefix='' keyPrefix='' flags='readOnly'"
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.MozillaKeyStoreUtilities loadNSS
INFO: Proveedor PKCS#11 para NSS anadido para perfil compartido: SunPKCS11-NSSCrypto-AFirma
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.AOKeyStoreManager init
INFO: Inicializamos el almacen de tipo: DNIe y tarjetas FNMT-TIF
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.KeyStoreUtilities addPreferredKeyStoreManagers
INFO: No se ha encontrado un DNIe: java.security.ProviderException: No se ha podido inicializar el proveedor de DNIe: es.gob.jmulticard.apdu.connection.NoReadersFoundException: No se han podido listar los lectores del sistema: javax.smartcardio.CardException: list() failed: javax.smartcardio.CardException: list() failed
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.AOKeyStoreManager init
INFO: Inicializamos el almacen de tipo: Tarjeta FNMT-RCM CERES 4.30 o superior
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.KeyStoreUtilities addPreferredKeyStoreManagers
INFO: No se ha encontrado una tarjeta CERES 4.30 o superior: java.security.ProviderException: No se ha podido inicializar el proveedor de Ceres 4.30 y superior: es.gob.jmulticard.apdu.connection.NoReadersFoundException: No se han podido listar los lectores del sistema: javax.smartcardio.CardException: list() failed: javax.smartcardio.CardException: list() failed
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.AOKeyStoreManager init
INFO: Inicializamos el almacen de tipo: Tarjeta FNMT-RCM CERES
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.KeyStoreUtilities addPreferredKeyStoreManagers
INFO: No se ha encontrado una tarjeta CERES: java.security.ProviderException: No se ha podido conectar con la tarjeta CERES: es.gob.jmulticard.apdu.connection.NoReadersFoundException: No se han podido listar los lectores del sistema: javax.smartcardio.CardException: list() failed: javax.smartcardio.CardException: list() failed
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.MozillaKeyStoreUtilities getMozillaPKCS11Modules
INFO: Se incluiran los modulos nativos de DNIe/CERES si se encuentran configurados
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.MozillaKeyStoreUtilities getMozillaPKCS11Modules
INFO: Obtenidos los modulos externos de Mozilla desde 'pkcs11.txt'
Feb 20, 2020 12:10:01 PM es.gob.afirma.keystores.mozilla.MozillaUnifiedKeyStoreManager init
INFO: No se han encontrado modulos PKCS#11 externos instalados en Firefox
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign processSign
INFO: Obtenido gestor de almacenes de claves: Gestor de almacenes de claves NSS con nombre NSS
Feb 20, 2020 12:10:01 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign processSign
INFO: Cargando dialogo de seleccion de certificados...
[Fatal Error] :1:1: Content is not allowed in prolog.
Feb 20, 2020 12:10:12 PM es.gob.afirma.signers.xades.XAdESSigner sign
INFO: El documento no es un XML valido. Se convertira a Base64: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
Feb 20, 2020 12:10:12 PM es.gob.afirma.signers.xades.XAdESSigner sign
INFO: El documento se considera binario, se convertira a Base64 antes de insertarlo en el XML y se declarara la transformacion
Feb 20, 2020 12:10:13 PM es.gob.afirma.signers.xml.Utils getDOMFactory
INFO: Se usara la factoria XML de Apache
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign processSign
WARNING: Se omite el cifrado de los datos resultantes por no haberse proporcionado una clave de cifrado
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign processSign
INFO: Se omite el envio por red de los datos resultantes por no haberse proporcionado una URL de destino
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread calculateNumberPartsResponse
INFO: Se mandaran 1partes
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread calculateNumberPartsResponse
INFO: tam total=11241
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread calculateNumberPartsResponse
INFO: Tamano de la parte 1 =11241
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread sendData
INFO: Mandando respuesta a la aplicacion: Se mandaran 1 partes
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread run
INFO: Detectada conexion entrante
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread processCommand
INFO: Recibido comando de tipo: send=
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread doSendPetition
INFO: Comando URI recibido por HTTP: @1@1
Feb 20, 2020 12:10:13 PM es.gob.afirma.standalone.protocol.CommandProcessorThread sendData
INFO: Mandando respuesta a la aplicacion: Mandada la parte 1 de 1
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread run
INFO: Detectada conexion entrante
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread processCommand
INFO: Recibido comando de tipo: echo=
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread doEchoPetition
INFO: Comando URI recibido por HTTP: echo=
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread sendData
INFO: Mandando respuesta a la aplicacion: echo=
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread run
INFO: Detectada conexion entrante
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread processCommand
INFO: Recibido comando de tipo: cmd=
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.CommandProcessorThread doCmdPetition
INFO: Comando URI recibido por HTTP: afirma://sign?op=sign&algorithm=SHA1withRSA&format=Adobe%20PDF&properties=ZXhwUG9.......
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncher launch
INFO: Se invoca a la aplicacion para realizar una operacion de firma/multifirma
Feb 20, 2020 12:10:14 PM es.gob.afirma.core.misc.protocol.ProtocolInvocationUriParser parserUri
INFO: URI recibida: afirma://sign?op=sign&algorithm=SHA1withRSA&format=Adobe%20PDF&properties=ZXhwUG9saWN5PUZpcm1hQUdFCmhlYWRsZXNzPXRydWUKc2lnbmF0dXJlU3ViRmlsdGVyPUVUU0kuQ0FkRVMuZGV0YWNoZWQKZmlsdGVyPXF1YWxpZmllZDo3ZWY2NzMxZDdlMTNmZjMxNTllMDhjYTM2MDBjZjMwZQ%3D%3D&dat=JVBERi0xLjQKMSAwIG9iago8PAovQ3JlYXRvciAoT3JhY2xlMTFnU...
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncher launch
INFO: Se inicia la operacion de firma
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign processSign
INFO: Se usa Sticky Signature y tenemos valor de clave privada
Feb 20, 2020 12:10:14 PM es.gob.afirma.signers.pades.PdfSessionManager getSessionData
WARNING: No ha podido registrarse la firma en el historico XMP: java.io.IOException: PDF header signature not found.
Feb 20, 2020 12:10:14 PM es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign processSign
SEVERE: Error al realizar la operacion de firma: es.gob.afirma.signers.pades.InvalidPdfException: El fichero no es un PDF o es un PDF no soportado
es.gob.afirma.signers.pades.InvalidPdfException: El fichero no es un PDF o es un PDF no soportado
        at es.gob.afirma.signers.pades.PdfUtil.getPdfReader(PdfUtil.java:180)
        at es.gob.afirma.signers.pades.PdfSessionManager.getSessionData(PdfSessionManager.java:253)
        at es.gob.afirma.signers.pades.PAdESTriPhaseSigner.preSign(PAdESTriPhaseSigner.java:183)
        at es.gob.afirma.signers.pades.AOPDFSigner.sign(AOPDFSigner.java:180)
        at es.gob.afirma.standalone.protocol.ProtocolInvocationLauncherSign.processSign(ProtocolInvocationLauncherSign.java:409)
        at es.gob.afirma.standalone.protocol.ProtocolInvocationLauncher.launch(ProtocolInvocationLauncher.java:429)
        at es.gob.afirma.standalone.protocol.CommandProcessorThread.doCmdPetition(CommandProcessorThread.java:344)
        at es.gob.afirma.standalone.protocol.CommandProcessorThread.processCommand(CommandProcessorThread.java:193)
        at es.gob.afirma.standalone.protocol.CommandProcessorThread.run(CommandProcessorThread.java:123)
Caused by: java.io.IOException: PDF header signature not found.
        at com.aowagie.text.pdf.PRTokeniser.checkPdfHeader(PRTokeniser.java:199)
        at com.aowagie.text.pdf.PdfReader.readPdf(PdfReader.java:462)
        at com.aowagie.text.pdf.PdfReader.<init>(PdfReader.java:187)
        at com.aowagie.text.pdf.PdfReader.<init>(PdfReader.java:176)
        at es.gob.afirma.signers.pades.PdfUtil.getPdfReader(PdfUtil.java:148)
        ... 8 more
alfem commented 4 years ago

¿Qué tipo de archivo intentas firmar? Por el log no parece ser un pdf válido.

JaviBonilla commented 4 years ago

@alfem Es un PDF válido, si me descargo el archivo puedo firmarlo en local con Autofirma sin problemas.

alfem commented 4 years ago

¿Podrías hacer un 'file nombredefichero.pdf' a ver qué dice?

JaviBonilla commented 4 years ago

@alfem Sí, dice esto de document.pdf:

document.pdf: PDF document, version 1.4

alfem commented 4 years ago

Diría que es algo de Portafirmas. Parece está enviando mal el documento. A lo mejor en la consola de Firefox ves algo más.

Yo firmo con Portafirmas con una combinación parecida (Linux+Firefox (68.5.0esr)+OpenJDK1.8), así que funcionar, puede funcionar.

JaviBonilla commented 4 years ago

Gracias @alfem,

Voy a probar entonces con Firefox (68.5.0esr) y comento por aquí si me ha funcionado.