Search in sources :

Example 11 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class MseSetComputationApduCommand method createDst.

private static byte[] createDst(final byte[] privateKeyReference, final byte[] algorithmReference) {
    if (privateKeyReference == null) {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "La referencia a la clave privada no puede ser nula");
    }
    final Tlv prkRefTlv = new Tlv(PRIVATE_KEY_REFERENCE, privateKeyReference);
    Tlv algRefTlv = null;
    if (algorithmReference != null) {
        algRefTlv = new Tlv(ALGORITHM_REFERENCE, algorithmReference);
    }
    final ByteArrayOutputStream dstData = new ByteArrayOutputStream();
    try {
        dstData.write(prkRefTlv.getBytes());
        if (algRefTlv != null) {
            dstData.write(algRefTlv.getBytes());
        }
    } catch (final Exception e) {
        throw new IllegalStateException(// $NON-NLS-1$
        "Error creando el cuerpo del DST: " + e, // $NON-NLS-1$
        e);
    }
    return dstData.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Tlv(es.gob.jmulticard.asn1.Tlv)

Example 12 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class ContextSpecific method decodeValue.

@Override
protected void decodeValue() throws Asn1Exception, TlvException {
    final Tlv tlv = new Tlv(this.getRawDerValue());
    final DecoderObject tmpDo;
    try {
        tmpDo = this.elementType.getConstructor().newInstance();
    } catch (final Exception e) {
        throw new Asn1Exception(// $NON-NLS-1$ //$NON-NLS-2$
        "No se ha podido instanciar un " + this.elementType.getName() + " en el contexto especifico: " + e, // $NON-NLS-1$ //$NON-NLS-2$
        e);
    }
    tmpDo.setDerValue(tlv.getValue());
    this.object = tmpDo;
}
Also used : DecoderObject(es.gob.jmulticard.asn1.DecoderObject) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) TlvException(es.gob.jmulticard.asn1.TlvException) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) Tlv(es.gob.jmulticard.asn1.Tlv)

Example 13 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class DerBoolean method decodeValue.

@Override
protected void decodeValue() throws Asn1Exception, TlvException {
    final Tlv tmpTlv = new Tlv(this.getRawDerValue());
    checkTag(tmpTlv.getTag());
    this.booleanValue = Boolean.valueOf(tmpTlv.getValue()[0] == (byte) 0x00);
}
Also used : Tlv(es.gob.jmulticard.asn1.Tlv)

Example 14 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class OctectString method decodeValue.

@Override
protected void decodeValue() throws TlvException {
    final Tlv tlv = new Tlv(this.getRawDerValue());
    if (TAG_OCTECTSTRING != tlv.getTag()) {
        throw new TlvException(// $NON-NLS-1$
        "Se esperaba un TLV de tipo OctectString pero se ha encontrado uno de tipo " + HexUtils.hexify(new byte[] { tlv.getTag() }, false));
    }
    this.value = tlv.getValue();
}
Also used : TlvException(es.gob.jmulticard.asn1.TlvException) Tlv(es.gob.jmulticard.asn1.Tlv)

Example 15 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class Record method decodeValue.

@Override
protected void decodeValue() throws Asn1Exception, TlvException {
    if (getRawDerValue().length == 0) {
        // $NON-NLS-1$
        throw new Asn1Exception("El valor del objeto ASN.1 esta vacio");
    }
    int offset = 0;
    Tlv tlv;
    byte[] remainingBytes;
    DecoderObject tmpDo;
    for (int i = 0; i < this.elementsTypes.length; i++) {
        try {
            remainingBytes = new byte[getRawDerValue().length - offset];
            System.arraycopy(getRawDerValue(), offset, remainingBytes, 0, remainingBytes.length);
            tlv = new Tlv(remainingBytes);
            try {
                tmpDo = this.elementsTypes[i].getElementType().getConstructor().newInstance();
            } catch (final Exception e) {
                throw new Asn1Exception(// $NON-NLS-1$
                "No se ha podido instanciar un " + this.elementsTypes[i].getElementType().getName() + " en la posicion " + Integer.toString(i) + " del registro: " + // $NON-NLS-1$ //$NON-NLS-2$
                e, // $NON-NLS-1$ //$NON-NLS-2$
                e);
            }
            tmpDo.checkTag(tlv.getTag());
        } catch (final Exception e) {
            if (this.elementsTypes[i].isOptional()) {
                // Como no ha avanzado el offset, se reutilizara el tipo en el proximo elemento
                continue;
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new Asn1Exception("Error en el elemento " + i + " del registro ASN.1: " + e, e);
        }
        offset = offset + tlv.getBytes().length;
        tmpDo.setDerValue(tlv.getBytes());
        this.elements.add(tmpDo);
    }
}
Also used : DecoderObject(es.gob.jmulticard.asn1.DecoderObject) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) TlvException(es.gob.jmulticard.asn1.TlvException) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) Tlv(es.gob.jmulticard.asn1.Tlv)

Aggregations

Tlv (es.gob.jmulticard.asn1.Tlv)11 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)6 TlvException (es.gob.jmulticard.asn1.TlvException)6 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 ByteBuf (io.netty.buffer.ByteBuf)3 Test (org.junit.Test)3 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Tlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv)2 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)1 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 SecureChannelException (es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException)1 GeneralAuthenticateApduCommand (es.gob.jmulticard.apdu.iso7816four.GeneralAuthenticateApduCommand)1 MseSetPaceAlgorithmApduCommand (es.gob.jmulticard.apdu.iso7816four.pace.MseSetPaceAlgorithmApduCommand)1 BerTlv (es.gob.jmulticard.asn1.bertlv.BerTlv)1 BitString (es.gob.jmulticard.asn1.der.BitString)1 DerBoolean (es.gob.jmulticard.asn1.der.DerBoolean)1 Utf8String (es.gob.jmulticard.asn1.der.Utf8String)1 AccessFlags (es.gob.jmulticard.asn1.der.pkcs15.AccessFlags)1 AmAESCrypto (es.gob.jmulticard.de.tsenger.androsmex.crypto.AmAESCrypto)1