Search in sources :

Example 1 with PrKdfCeres

use of es.gob.jmulticard.asn1.custom.fnmt.ceressc.PrKdfCeres 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
    PrKdf prkdf;
    try {
        prkdf = new PrKdf();
        prkdf.setDerValue(prkdfValue);
    } catch (final Exception e) {
        LOGGER.warning(// $NON-NLS-1$
        "Detectado posible PrKDF con CommonPrivateKeyAttributes vacio, se prueba con estructura alternativa: " + e);
        prkdf = new PrKdfCeres();
        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 : PrKdfCeres(es.gob.jmulticard.asn1.custom.fnmt.ceressc.PrKdfCeres) 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) DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference) X509Certificate(java.security.cert.X509Certificate) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException) CryptoCardException(es.gob.jmulticard.card.CryptoCardException) LostChannelException(es.gob.jmulticard.apdu.connection.LostChannelException) InvalidCardException(es.gob.jmulticard.card.InvalidCardException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) DnieCardException(es.gob.jmulticard.card.dnie.DnieCardException) 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) Location(es.gob.jmulticard.card.Location)

Aggregations

ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 LostChannelException (es.gob.jmulticard.apdu.connection.LostChannelException)1 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)1 TlvException (es.gob.jmulticard.asn1.TlvException)1 PrKdfCeres (es.gob.jmulticard.asn1.custom.fnmt.ceressc.PrKdfCeres)1 Cdf (es.gob.jmulticard.asn1.der.pkcs15.Cdf)1 Pkcs15Cdf (es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf)1 PrKdf (es.gob.jmulticard.asn1.der.pkcs15.PrKdf)1 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)1 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)1 Location (es.gob.jmulticard.card.Location)1 PinException (es.gob.jmulticard.card.PinException)1 DnieCardException (es.gob.jmulticard.card.dnie.DnieCardException)1 DniePrivateKeyReference (es.gob.jmulticard.card.dnie.DniePrivateKeyReference)1 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)1 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1