use of es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf in project jmulticard by ctt-gob-es.
the class Ceres method preload.
private void preload() throws ApduConnectionException, Iso7816FourCardException, IOException, CertificateException, Asn1Exception, TlvException {
// Nos vamos al raiz antes de nada
selectMasterFile();
// Leemos el CDF
final byte[] cdfBytes = selectFileByLocationAndRead(CDF_LOCATION);
// Cargamos el CDF
Pkcs15Cdf cdf = new CeresCdf();
try {
cdf.setDerValue(cdfBytes);
} catch (final Exception e) {
// Si ha fallado la inicializacion del CDF tipo CERES probamos con el CDF generico PKCS#15,
// presente en las nuevas tarjetas FNMT-CERES
cdf = new Cdf();
cdf.setDerValue(cdfBytes);
}
// Leemos los certificados segun las rutas del CDF
this.certs = new LinkedHashMap<>(cdf.getCertificateCount());
this.aliasByCertAndKeyId = new LinkedHashMap<>(cdf.getCertificateCount());
for (int i = 0; i < cdf.getCertificateCount(); i++) {
final Location l = new Location(// $NON-NLS-1$ //$NON-NLS-2$
cdf.getCertificatePath(i).replace("\\", "").trim());
X509Certificate cert;
try {
cert = CompressionUtils.getCertificateFromCompressedOrNotData(selectFileByLocationAndRead(l));
} catch (final IOException e) {
// $NON-NLS-1$
LOGGER.warning("No se ha encontrado un certificado referenciado, se pasa al siguiente: " + e);
continue;
}
// $NON-NLS-1$
final String alias = i + " " + cert.getSerialNumber();
this.aliasByCertAndKeyId.put(HexUtils.hexify(cdf.getCertificateId(i), false), alias);
this.certs.put(alias, cert);
}
// Leemos el PrKDF
final byte[] prkdfValue = selectFileByLocationAndRead(PRKDF_LOCATION);
// Establecemos el valor del PrKDF
Pkcs15PrKdf prkdf = new CeresPrKdf();
try {
prkdf.setDerValue(prkdfValue);
} catch (final Exception e) {
// Si no carga el estructura PrKDF especifica de CERES probamos con la
// generica PKCS#15, presente en las ultimas versiones de la tarjeta
prkdf = new PrKdf();
prkdf.setDerValue(prkdfValue);
}
this.keys = new LinkedHashMap<>();
for (int i = 0; i < prkdf.getKeyCount(); i++) {
final String alias = this.aliasByCertAndKeyId.get(HexUtils.hexify(prkdf.getKeyId(i), false));
if (alias != null) {
this.keys.put(alias, Byte.valueOf(prkdf.getKeyReference(i)));
}
}
// Sincronizamos claves y certificados
hideCertsWithoutKey();
}
use of es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf in project jmulticard by ctt-gob-es.
the class CeresSc method preload.
private void preload() throws ApduConnectionException, Iso7816FourCardException, IOException, CertificateException, Asn1Exception, TlvException {
// Nos vamos al raiz antes de nada
selectMasterFile();
// Leemos el CDF
final byte[] cdfBytes = selectFileByLocationAndRead(CDF_LOCATION);
// Cargamos el CDF
final Pkcs15Cdf cdf = new Cdf();
cdf.setDerValue(cdfBytes);
this.certs = new LinkedHashMap<>(cdf.getCertificateCount());
this.aliasByCertAndKeyId = new LinkedHashMap<>(cdf.getCertificateCount());
for (int i = 0; i < cdf.getCertificateCount(); i++) {
final Location l = new Location(// $NON-NLS-1$ //$NON-NLS-2$
cdf.getCertificatePath(i).replace("\\", "").trim());
final X509Certificate cert = CompressionUtils.getCertificateFromCompressedOrNotData(selectFileByLocationAndRead(l));
// $NON-NLS-1$
final String alias = i + " " + cert.getSerialNumber();
this.aliasByCertAndKeyId.put(HexUtils.hexify(cdf.getCertificateId(i), false), alias);
this.certs.put(alias, cert);
}
// Leemos el PrKDF
final byte[] prkdfValue = selectFileByLocationAndRead(PRKDF_LOCATION);
// Establecemos el valor del PrKDF
final PrKdf prkdf = new PrKdf();
prkdf.setDerValue(prkdfValue);
this.keyReferences = new LinkedHashMap<>();
for (int i = 0; i < prkdf.getKeyCount(); i++) {
final String alias = this.aliasByCertAndKeyId.get(HexUtils.hexify(prkdf.getKeyId(i), false));
if (alias != null) {
this.keyReferences.put(alias, new DniePrivateKeyReference(this, prkdf.getKeyIdentifier(i), new Location(prkdf.getKeyPath(i)), prkdf.getKeyName(i), prkdf.getKeyReference(i), ((RSAPublicKey) this.certs.get(alias).getPublicKey()).getModulus().bitLength()));
}
}
// Sincronizamos claves y certificados
hideCertsWithoutKey();
}
Aggregations