Search in sources :

Example 36 with Tlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project jmulticard by ctt-gob-es.

the class TestTlvCreation method testTlv.

/**
 * Prueba la creación de TLV con volcados de CDF.
 * @throws Exception en caso de cualquier tipo de error
 */
public static void testTlv() throws Exception {
    byte[] cdfdata;
    for (final String element : TEST_FILES) {
        cdfdata = getDataFromInputStream(ClassLoader.getSystemResourceAsStream(element));
        final Tlv tlv = new Tlv(cdfdata);
        Assert.assertNotNull(tlv);
        LOGGER.info(tlv.toString());
        // $NON-NLS-1$
        LOGGER.info("\n\nProbando " + element);
        // $NON-NLS-1$ //$NON-NLS-2$
        LOGGER.info("\nTLV completo (" + Integer.toString(tlv.getBytes().length) + "):");
        LOGGER.info(HexUtils.hexify(tlv.getBytes(), true));
        // $NON-NLS-1$
        LOGGER.info("\nTipo TLV:");
        LOGGER.info(HexUtils.hexify(new byte[] { tlv.getTag() }, true));
        // $NON-NLS-1$
        LOGGER.info("\nLongitud TLV:");
        LOGGER.info(Integer.toString(tlv.getLength()));
        // $NON-NLS-1$ //$NON-NLS-2$
        LOGGER.info("\nValor TLV (" + Integer.toString(tlv.getValue().length) + "):");
        LOGGER.info(HexUtils.hexify(tlv.getValue(), true));
    }
}
Also used : Tlv(es.gob.jmulticard.asn1.Tlv)

Example 37 with Tlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project jmulticard by ctt-gob-es.

the class ApduEncrypter method getDataTlv.

private byte[] getDataTlv(final byte[] data, final byte[] keyCipher, final byte[] sendSequenceCounter, final CryptoHelper cryptoHelper, final int paddingSize) throws IOException {
    // Si hay datos calculamos el TLV con estos datos cifrados
    if (data != null && data.length > 0) {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        baos.write(TLV_VALUE_PREFIX_TO_MAC);
        final byte[] paddedData = addPadding7816(data, paddingSize);
        baos.write(encryptData(paddedData, keyCipher, sendSequenceCounter, cryptoHelper));
        // Sobrescribimos los datos de la APDU inmediatamente despues de cifrarla, para que este
        // el minimo tiempo en memoria. Como los arrays son mutables con escribir esta copia se
        // sobreescriben todas las referencias.
        wipeByteArray(paddedData);
        wipeByteArray(data);
        return new Tlv(TAG_DATA_TLV, baos.toByteArray()).getBytes();
    }
    return new byte[0];
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Tlv(es.gob.jmulticard.asn1.Tlv)

Example 38 with Tlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project jmulticard by ctt-gob-es.

the class Sequence method decodeValue.

@Override
protected void decodeValue() throws Asn1Exception, TlvException {
    final Tlv mainTlv = new Tlv(getRawDerValue());
    checkTag(mainTlv.getTag());
    int offset = 0;
    Tlv tlv;
    byte[] remainingBytes;
    DecoderObject tmpDo;
    final byte[] rawValue = mainTlv.getValue();
    for (int i = 0; i < this.elementsTypes.length; i++) {
        remainingBytes = new byte[rawValue.length - offset];
        System.arraycopy(rawValue, offset, remainingBytes, 0, remainingBytes.length);
        try {
            tlv = new Tlv(remainingBytes);
            tmpDo = this.elementsTypes[i].getElementType().getConstructor().newInstance();
            tmpDo.checkTag(tlv.getTag());
            tmpDo.setDerValue(tlv.getBytes());
        } 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$ //$NON-NLS-3$
            throw new Asn1Exception("Error en el elemento " + i + " (" + this.elementsTypes[i].getElementType().getName() + ") de la secuencia ASN.1: " + e, e);
        }
        // El offset se avanza antes del continue de la opcionalidad
        offset = offset + tlv.getBytes().length;
        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)

Example 39 with Tlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project jmulticard by ctt-gob-es.

the class SequenceOf method decodeValue.

@Override
protected void decodeValue() throws Asn1Exception, TlvException {
    Tlv tlv = new Tlv(getRawDerValue());
    checkTag(tlv.getTag());
    int offset = 0;
    byte[] remainingBytes;
    DecoderObject tmpDo;
    final byte[] valueBytes = tlv.getValue();
    this.sequenceObjects = new Vector<>();
    while (offset < valueBytes.length) {
        remainingBytes = new byte[valueBytes.length - offset];
        System.arraycopy(valueBytes, offset, remainingBytes, 0, remainingBytes.length);
        tlv = new Tlv(remainingBytes);
        try {
            tmpDo = this.elementsType.getConstructor().newInstance();
        } catch (final Exception e) {
            throw new Asn1Exception(// $NON-NLS-1$
            "No se ha podido instanciar un " + this.elementsType.getName() + " en la secuencia: " + // $NON-NLS-1$
            e, // $NON-NLS-1$
            e);
        }
        offset = offset + tlv.getBytes().length;
        tmpDo.checkTag(tlv.getTag());
        tmpDo.setDerValue(tlv.getBytes());
        this.sequenceObjects.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)

Example 40 with Tlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.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)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)53 Test (org.junit.Test)29 Tlv (es.gob.jmulticard.asn1.Tlv)11 ArrayList (java.util.ArrayList)8 TlvException (es.gob.jmulticard.asn1.TlvException)6 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)4 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)4 LspIdentifiersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.LspIdentifiersBuilder)4 Stateful (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.stateful.capability.tlv.Stateful)4 LspId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId)4 TunnelId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId)4 EnterpriseNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber)3 LspIdentifiers (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.LspIdentifiers)3 RsvpErrorSpec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.rsvp.error.spec.tlv.RsvpErrorSpec)3 VendorInformationTlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 BmpDeserializationException (org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)2 Stateful07RSVPErrorSpecTlvParser (org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser)2 BitArray (org.opendaylight.protocol.util.BitArray)2