Search in sources :

Example 6 with Location

use of es.gob.jmulticard.card.Location 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

Location (es.gob.jmulticard.card.Location)6 Cdf (es.gob.jmulticard.asn1.der.pkcs15.Cdf)5 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)4 BadPinException (es.gob.jmulticard.card.BadPinException)4 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)4 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)4 IOException (java.io.IOException)4 CertificateException (java.security.cert.CertificateException)4 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)3 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)3 PinException (es.gob.jmulticard.card.PinException)3 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)2 TlvException (es.gob.jmulticard.asn1.TlvException)2 Pkcs15Cdf (es.gob.jmulticard.asn1.der.pkcs15.Pkcs15Cdf)2 PrKdf (es.gob.jmulticard.asn1.der.pkcs15.PrKdf)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CertificateFactory (java.security.cert.CertificateFactory)2 X509Certificate (java.security.cert.X509Certificate)2