Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soporte para uso de AutoFirma mediante JNLP y para firma de varios documentos por petición #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public abstract class UrlParameters {
private static final String DEFAULT_ENCODING = "utf-8"; //$NON-NLS-1$

private byte[] data = null;
// UAL - para firma de multiples documentos
private byte [][] datas = null;
private String [] operaciones;
private boolean multifirma = false;
// fin UAL
private String fileId = null;
private byte[] desKey = null;
private URL retrieveServletUrl = null;
Expand Down Expand Up @@ -165,6 +170,22 @@ public String getId() {
void setSessionId(final String sessionId) {
this.id = sessionId;
}

public byte[][] getDatas() {
return datas;
}

public void setDatas(byte[][] datas) {
this.datas = datas;
}

public String[] getOperaciones() {
return operaciones;
}

public void setOperaciones(String[] operaciones) {
this.operaciones = operaciones;
}

void setCommonParameters(final Map<String, String> params) throws ParameterException {

Expand Down Expand Up @@ -215,6 +236,35 @@ void setCommonParameters(final Map<String, String> params) throws ParameterExcep
setData(
DataDownloader.downloadData(dataPrm)
);

// UAL - para firma de multiples documentos
String [] sDatosAfirmar = URLDecoder.decode(params.get(DATA_PARAM), DEFAULT_ENCODING).split(":");
byte [][] bDatosAfirmar = new byte [sDatosAfirmar.length][];
String [] operaciones = new String [sDatosAfirmar.length];
for (int i = 0; i < sDatosAfirmar.length; i++)
{

if (sDatosAfirmar[i].contains(";"))
{
this.multifirma = true;
String [] sDatoIndividual = sDatosAfirmar[i].split(";");
byte [] bDatoIndividual = DataDownloader.downloadData(sDatoIndividual[1]);
operaciones[i] = sDatoIndividual[0];
bDatosAfirmar[i] = new byte[bDatoIndividual.length];
bDatosAfirmar[i] = bDatoIndividual;
}
else
{
String sDatoIndividual = sDatosAfirmar[i];
byte [] bDatoIndividual = DataDownloader.downloadData(sDatoIndividual);
operaciones[i] = params.get(ProtocolConstants.OPERATION_PARAM);
bDatosAfirmar[i] = new byte[bDatoIndividual.length];
bDatosAfirmar[i] = bDatoIndividual;
}
}
setDatas(bDatosAfirmar);
setOperaciones(operaciones);
// fin UAL
}
catch (final Exception e) {
throw new ParameterException(
Expand Down
64 changes: 36 additions & 28 deletions afirma-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
<version>3.3.2-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<afirma.keytool.keystore>${basedir}/afirma.keystore</afirma.keytool.keystore>
<afirma.keytool.alias>codesign</afirma.keytool.alias>
<afirma.keytool.password>afirma</afirma.keytool.password>
<afirma.keytool.alias>codesign</afirma.keytool.alias>
<afirma.keytool.password>afirma</afirma.keytool.password>
</properties>

<dependencies>
<dependency>

<dependency>
<groupId>com.dmurph</groupId>
<artifactId>JGoogleAnalyticsTracker</artifactId>
<version>1.1.0</version>
<artifactId>JGoogleAnalyticsTracker</artifactId>
<version>1.1.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -70,7 +70,7 @@
<artifactId>afirma-keystores-mozilla</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-core-pkcs7</artifactId>
Expand All @@ -82,7 +82,7 @@
<artifactId>afirma-crypto-cms</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-cms-enveloper</artifactId>
Expand Down Expand Up @@ -130,25 +130,25 @@
<artifactId>afirma-crypto-ooxml</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-cadestri-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-xadestri-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-padestri-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-xmlsignature</artifactId>
Expand All @@ -166,7 +166,7 @@
<artifactId>afirma-core-massive</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-crypto-batch-client</artifactId>
Expand All @@ -184,19 +184,19 @@
<artifactId>prov</artifactId>
<version>1.54.0.0</version>
</dependency>

<dependency>
<groupId>com.madgag.spongycastle</groupId>
<artifactId>pkix</artifactId>
<version>1.54.0.0</version>
</dependency>

<dependency>
<groupId>es.gob</groupId>
<artifactId>jmulticard-jse</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>es.gob</groupId>
<artifactId>jmulticard-ui</artifactId>
Expand All @@ -221,10 +221,10 @@
<version>4.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.11</version>
<exclusions>
<exclusion>
Expand All @@ -241,15 +241,21 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.github.markusbernhardt</groupId>
<artifactId>proxy-vole</artifactId>
<version>1.0.1</version>
</dependency>


<dependency>
<groupId>es.gob.afirma</groupId>
<artifactId>afirma-ui-simpleafirma-configurator</artifactId>
<version>3.3.2-SNAPSHOT</version>
</dependency>

</dependencies>

<scm>
<connection>scm:svn:http://svn-ctt.administracionelectronica.gob.es/svn/clienteafirma/project/afirma-desktop/afirma-simple/trunk</connection>
<url>http://svn-ctt.administracionelectronica.gob.es/svn/clienteafirma/project/afirma-desktop/afirma-simple/trunk</url>
Expand All @@ -268,7 +274,7 @@
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
<!-- <plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
Expand All @@ -289,8 +295,8 @@
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin> -->
</plugin-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand All @@ -305,7 +311,10 @@
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>es.gob.afirma.standalone.SimpleAfirma</mainClass>
<manifestEntries>
<Main-Class>es.gob.afirma.standalone.SimpleAfirma</Main-Class>
<Permissions>all-permissions</Permissions>
</manifestEntries>
</transformer>
</transformers>
</configuration>
Expand Down Expand Up @@ -335,7 +344,6 @@
</filters>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;

import es.gob.afirma.core.misc.AOUtil;
import es.gob.afirma.core.misc.Platform;
import es.gob.afirma.standalone.ui.hash.CheckHashDialog;
Expand Down Expand Up @@ -117,6 +120,15 @@ private static void disableAutoStart() throws IOException {
* @return Directorio de ejecuci&oacute;n. */
public static File getApplicationDirectory() {
File appDir;

try{
ServiceManager.lookup("javax.jnlp.ExtendedService");
appDir = new File(System.getProperty("java.io.tmpdir"));
return appDir;
} catch (UnavailableServiceException e) {

}

try {
appDir = new File(
AutoFirmaUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package es.gob.afirma.standalone.crypto;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
Expand Down Expand Up @@ -76,4 +77,30 @@ public static String cipherData(final byte[] data, final byte[] cipherKey) throw
.append(PADDING_CHAR_SEPARATOR)
.append(Base64.encode(DesCipher.cipher(data, cipherKey), true)).toString();
}

/** Genera una cadena con datos cifrados y codificados en base 64 antecedidos por el n&uacute;mero de
* caracteres que se han tenido que agregar como padding y separados por un car&aacute;cter separador.
* Usado para multiples firmas
* @param data Datos a cifrar.
* @param cipherKey Clave de cifrado.
* @return Cadena con el numero de caracteres agregados manualmente para cumplir la longitud requerida,
* el caracter separador y los datos cifrados y en base 64.
* @throws InvalidKeyException Cuando la clave no es v&aacute;lida.
* @throws GeneralSecurityException Cuando falla el proceso de cifrado.
* @throws IOException En caso de errores en el tratamiento de datos. */
public static String cipherDatas(final byte[][] data, final byte[] cipherKey) throws InvalidKeyException, GeneralSecurityException, IOException
{
StringBuilder cadenaFinal = new StringBuilder ();

for (int i = 0; i < data.length; i++)
{
System.out.println (Base64.encode(data[i]));
if(i>0){
cadenaFinal.append(":");
}
cadenaFinal.append(cipherData(data[i],cipherKey));
}

return cadenaFinal.toString();
}
}
Loading