-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPNA-008 - Permitir el uso de certificados de empleado público
- Loading branch information
Showing
4 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...-lib/src/main/java/ieci/tdw/ispac/ispaclib/sign/FMNTEmpleadoPublicoCertificateParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package ieci.tdw.ispac.ispaclib.sign; | ||
|
||
import ieci.tdw.ispac.api.ISignAPI; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.security.cert.X509Certificate; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.bouncycastle.asn1.ASN1InputStream; | ||
import org.bouncycastle.asn1.ASN1OctetString; | ||
|
||
|
||
/** | ||
* @author josemi.bobadilla | ||
* @since 08/01/2009 | ||
* | ||
* Paser para los certificados de personal al servicio de la administracion (software) de la FMNT | ||
*/ | ||
public class FMNTEmpleadoPublicoCertificateParser extends ASN1Parser { | ||
|
||
/** | ||
* Nombre | ||
*/ | ||
public static final String FIRST_NAME_OID = "2.16.724.1.3.5.7.2.6"; | ||
|
||
/** | ||
* Primer apellido | ||
*/ | ||
public static final String SURNAME_OID = "2.16.724.1.3.5.7.2.7"; | ||
|
||
/** | ||
* Segundo apellido | ||
*/ | ||
public static final String SECOND_SURNAME_OID = "2.16.724.1.3.5.7.2.8"; | ||
|
||
/** | ||
* Nif | ||
*/ | ||
public static final String DNI_OID = "2.16.724.1.3.5.7.2.4"; | ||
|
||
|
||
/** | ||
* CERTIFICADO DE EMPLEADO PUBLICO (de nivel medio) | ||
*/ | ||
public static final String TIPO_CERTIFICATE_OID = "2.16.724.1.3.5.7.2.1"; | ||
|
||
|
||
public Map parse(X509Certificate x509Cert) throws IOException{ | ||
|
||
Map result = new TreeMap(); | ||
Map oids = this.readPropertiesOid(x509Cert); | ||
|
||
Iterator itr= oids.keySet().iterator(); | ||
while (itr.hasNext()) { | ||
String oid= (String) itr.next(); | ||
if (oid.equals(FIRST_NAME_OID)){ | ||
result.put(ISignAPI.NOMBRE, oids.get(FIRST_NAME_OID)); | ||
}else if (oid.equals(SURNAME_OID)){ | ||
result.put(ISignAPI.PRIMER_APELLIDO, oids.get(SURNAME_OID)); | ||
}else if (oid.equals(SECOND_SURNAME_OID)){ | ||
result.put(ISignAPI.SEGUNDO_APELLIDO, oids.get(SECOND_SURNAME_OID)); | ||
|
||
}else if (oid.equals(DNI_OID)){ | ||
result.put(ISignAPI.NIF, oids.get(DNI_OID)); | ||
}else if (oid.equals(TIPO_CERTIFICATE_OID)){ | ||
result.put(ISignAPI.TIPO_CERTIFICADO, oids.get(TIPO_CERTIFICATE_OID)); | ||
}else if (StringUtils.isAsciiPrintable( (String) oids.get(oid))){ | ||
result.put(oid, oids.get(oid)); | ||
} | ||
} | ||
|
||
String apellidos = ""; | ||
apellidos.concat((String) oids.get(SURNAME_OID)); | ||
|
||
if (StringUtils.isNotBlank((String)oids.get(SECOND_SURNAME_OID))){ | ||
apellidos.concat(" " + oids.get(SECOND_SURNAME_OID)); | ||
} | ||
result.put(ISignAPI.APELLIDOS, apellidos); | ||
return result; | ||
} | ||
|
||
/*** | ||
* Parsea un certificado X509 para extraer todos sus oids | ||
* | ||
* @param certificadoX509 | ||
* @return | ||
* @throws IOException | ||
*/ | ||
public Map readPropertiesOid(X509Certificate certificadoX509) throws IOException { | ||
Map propiedadesOid = new HashMap(); | ||
// obtengo los Oids | ||
Set oids = certificadoX509.getNonCriticalExtensionOIDs(); | ||
|
||
if (oids != null) { | ||
// iteramos sobre los Oids // TODO ( este es el mecanismo para FNMT) | ||
Iterator itr= oids.iterator(); | ||
while (itr.hasNext()) { | ||
String oid= (String) itr.next(); | ||
ASN1InputStream aIn = new ASN1InputStream( | ||
new ByteArrayInputStream(certificadoX509.getExtensionValue(oid))); | ||
ASN1OctetString extValue = (ASN1OctetString) aIn.readObject(); | ||
aIn = new ASN1InputStream(new ByteArrayInputStream(extValue.getOctets())); | ||
|
||
super.readPropiedadesOid(oid, extValue, propiedadesOid); | ||
} | ||
} | ||
|
||
// retornamos el conjunto de oids recuperados. | ||
return propiedadesOid; | ||
} | ||
|
||
|
||
} |