use of com.github.zhenwei.core.asn1.ASN1Exception in project jmulticard by ctt-gob-es.
the class Dnie3 method getCom.
@Override
public Com getCom() throws IOException {
try {
final Com com = new Com();
com.setDerValue(selectFileByLocationAndRead(FILE_COM_LOCATION));
return com;
} catch (final es.gob.jmulticard.card.iso7816four.FileNotFoundException e) {
// $NON-NLS-1$
throw (IOException) new FileNotFoundException("COM no encontrado").initCause(e);
} catch (final Iso7816FourCardException | TlvException | Asn1Exception e) {
// $NON-NLS-1$
throw new CryptoCardException("Error leyendo el 'Common Data' (COM)", e);
}
}
use of com.github.zhenwei.core.asn1.ASN1Exception in project jmulticard by ctt-gob-es.
the class TuiR5 method preloadCertificates.
private void preloadCertificates() throws IOException, Iso7816FourCardException {
selectMasterFile();
final Cdf cdf = new Cdf();
try {
cdf.setDerValue(selectFileByLocationAndRead(CDF_LOCATION));
} catch (final Asn1Exception | TlvException e) {
// $NON-NLS-1$
throw new IOException("Error en la lectura del CDF", e);
}
for (int i = 0; i < cdf.getCertificateCount(); i++) {
try {
CERTIFICATES_BY_ALIAS.put(cdf.getCertificateAlias(i), CertificateUtils.generateCertificate(selectFileByLocationAndRead(new Location(cdf.getCertificatePath(i)))));
} catch (final CertificateException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new IOException("Error en la lectura del certificado " + i + " del dispositivo", e);
}
}
}
use of com.github.zhenwei.core.asn1.ASN1Exception in project jmulticard by ctt-gob-es.
the class SmartCafePkcs15Applet method preloadCertificates.
private void preloadCertificates() throws FileNotFoundException, Iso7816FourCardException, IOException, Asn1Exception, TlvException {
selectMasterFile();
// Seleccionamos el ODF, no nos devuelve FCI ni nada
selectFileById(ODF_PATH);
// Leemos el ODF
final byte[] odfBytes = readBinaryComplete(162);
final Odf odf = new Odf();
odf.setDerValue(odfBytes);
// Sacamos del ODF la ruta del CDF
final Path cdfPath = odf.getCdfPath();
// Leemos el CDF
final Cdf cdf = new Cdf();
try {
selectMasterFile();
final byte[] cdfBytes = selectFileByIdAndRead(cdfPath.getPathBytes());
cdf.setDerValue(cdfBytes);
} catch (final Exception e) {
throw new ApduConnectionException(// $NON-NLS-1$
"No se ha podido cargar el CDF de la tarjeta", // $NON-NLS-1$
e);
}
if (cdf.getCertificateCount() < 1) {
// $NON-NLS-1$
LOGGER.warning("La tarjeta no contiene ningun certificado");
}
for (int i = 0; i < cdf.getCertificateCount(); i++) {
try {
int fileLength = -1;
Location certLocation = new Location(cdf.getCertificatePath(i));
while (certLocation != null) {
final byte[] id = certLocation.getFile();
try {
fileLength = selectFileById(id);
} catch (final FileNotFoundException e) {
LOGGER.warning(// $NON-NLS-1$//$NON-NLS-2$
"El CDF indicaba un certificado en la ruta '" + certLocation + "', pero un elemento de esta no existe, se ignorara: " + e);
}
certLocation = certLocation.getChild();
}
final byte[] certBytes;
if (fileLength <= 0) {
// A veces hay punteros que apuntan a localizaciones vacias
LOGGER.warning(// $NON-NLS-1$ //$NON-NLS-2$
"El certificado " + i + " del dispositivo esta vacio");
continue;
}
certBytes = readBinaryComplete(fileLength);
CERTS_BY_ALIAS.put(cdf.getCertificateAlias(i), CertificateUtils.generateCertificate(certBytes));
} catch (final Exception e) {
// Puede darse el caso de que el puntero apunte a algo que no es un certificado
LOGGER.severe(// $NON-NLS-1$ //$NON-NLS-2$
"Error en la lectura del certificado " + i + " del dispositivo: " + e);
continue;
}
}
}
use of com.github.zhenwei.core.asn1.ASN1Exception 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();
}
use of com.github.zhenwei.core.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.
the class EncKrbPrivPart method init.
/**
* Initializes an EncKrbPrivPart object.
* @param encoding a single DER-encoded value.
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
* @exception IOException if an I/O error occurs while reading encoded data.
*/
private void init(DerValue encoding) throws Asn1Exception, IOException {
DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C) || (encoding.isApplication() != true) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) {
userData = subDer.getData().getOctetString();
} else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true);
if ((der.getData().peekByte() & 0x1F) == 0x02) {
subDer = der.getData().getDerValue();
usec = new Integer(subDer.getData().getBigInteger().intValue());
} else {
usec = null;
}
if ((der.getData().peekByte() & 0x1F) == 0x03) {
subDer = der.getData().getDerValue();
seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
} else {
seqNumber = null;
}
sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false);
if (der.getData().available() > 0) {
rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true);
}
if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
}
Aggregations