Search in sources :

Example 1 with PrKdf

use of es.gob.jmulticard.asn1.der.pkcs15.PrKdf in project jmulticard by ctt-gob-es.

the class TestPrKdfCreation method testPrKdf.

/**
 * Prueba la creación de PrKDK con volcados en disco.
 * @throws Exception en caso de cualquier tipo de error
 */
@Test
public static void testPrKdf() throws Exception {
    byte[] prkdfdata;
    for (final String element : TEST_FILES) {
        prkdfdata = getDataFromInputStream(ClassLoader.getSystemResourceAsStream(element));
        // LOGGER.info("\n\nPrKDF completo (" + Integer.toString(prkdfdata.length) + "):"); //$NON-NLS-1$ //$NON-NLS-2$
        // LOGGER.info(HexUtils.hexify(prkdfdata, true));
        final PrKdf prkdf = new PrKdf();
        Assert.assertNotNull(prkdf);
        prkdf.setDerValue(prkdfdata);
        // $NON-NLS-1$ //$NON-NLS-2$
        LOGGER.info("\n" + prkdf.toString() + "\n");
    }
}
Also used : PrKdf(es.gob.jmulticard.asn1.der.pkcs15.PrKdf) Test(org.junit.Test)

Example 2 with PrKdf

use of es.gob.jmulticard.asn1.der.pkcs15.PrKdf in project jmulticard by ctt-gob-es.

the class TestPrKdfCreation method testSamplePrKdf.

/**
 * Prueba de análisis de PrKDF de prueba.
 * @throws Exception En cualquier error.
 */
@Test
public static void testSamplePrKdf() throws Exception {
    final PrKdf prkdf = new PrKdf();
    Assert.assertNotNull(prkdf);
    prkdf.setDerValue(SAMPLE_PRKDF);
    // $NON-NLS-1$ //$NON-NLS-2$
    LOGGER.info("\n" + prkdf.toString() + "\n");
}
Also used : PrKdf(es.gob.jmulticard.asn1.der.pkcs15.PrKdf) Test(org.junit.Test)

Example 3 with PrKdf

use of es.gob.jmulticard.asn1.der.pkcs15.PrKdf 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();
}
Also used : CeresPrKdf(es.gob.jmulticard.card.fnmt.ceres.asn1.CeresPrKdf) Pkcs15Cdf(es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf) Pkcs15Cdf(es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf) Cdf(es.gob.jmulticard.asn1.der.pkcs15.Cdf) CeresCdf(es.gob.jmulticard.card.fnmt.ceres.asn1.CeresCdf) IOException(java.io.IOException) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) FileNotFoundException(es.gob.jmulticard.card.iso7816four.FileNotFoundException) CryptoCardException(es.gob.jmulticard.card.CryptoCardException) InvalidCardException(es.gob.jmulticard.card.InvalidCardException) BadPinException(es.gob.jmulticard.card.BadPinException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) PinException(es.gob.jmulticard.card.PinException) TlvException(es.gob.jmulticard.asn1.TlvException) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) X509Certificate(java.security.cert.X509Certificate) CeresCdf(es.gob.jmulticard.card.fnmt.ceres.asn1.CeresCdf) CeresPrKdf(es.gob.jmulticard.card.fnmt.ceres.asn1.CeresPrKdf) PrKdf(es.gob.jmulticard.asn1.der.pkcs15.PrKdf) Pkcs15PrKdf(es.gob.jmulticard.asn1.der.pkcs15.Pkcs15PrKdf) Pkcs15PrKdf(es.gob.jmulticard.asn1.der.pkcs15.Pkcs15PrKdf) Location(es.gob.jmulticard.card.Location)

Example 4 with PrKdf

use of es.gob.jmulticard.asn1.der.pkcs15.PrKdf 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();
}
Also used : Pkcs15Cdf(es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf) Pkcs15Cdf(es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf) Cdf(es.gob.jmulticard.asn1.der.pkcs15.Cdf) PrKdf(es.gob.jmulticard.asn1.der.pkcs15.PrKdf) X509Certificate(java.security.cert.X509Certificate) Location(es.gob.jmulticard.card.Location)

Aggregations

PrKdf (es.gob.jmulticard.asn1.der.pkcs15.PrKdf)4 Cdf (es.gob.jmulticard.asn1.der.pkcs15.Cdf)2 Pkcs15Cdf (es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf)2 Location (es.gob.jmulticard.card.Location)2 X509Certificate (java.security.cert.X509Certificate)2 Test (org.junit.Test)2 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)1 TlvException (es.gob.jmulticard.asn1.TlvException)1 Pkcs15PrKdf (es.gob.jmulticard.asn1.der.pkcs15.Pkcs15PrKdf)1 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)1 BadPinException (es.gob.jmulticard.card.BadPinException)1 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)1 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)1 PinException (es.gob.jmulticard.card.PinException)1 CeresCdf (es.gob.jmulticard.card.fnmt.ceres.asn1.CeresCdf)1 CeresPrKdf (es.gob.jmulticard.card.fnmt.ceres.asn1.CeresPrKdf)1 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)1 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)1 IOException (java.io.IOException)1