Search in sources :

Example 1 with SecureMessagingException

use of es.gob.jmulticard.de.tsenger.androsmex.iso7816.SecureMessagingException in project jmulticard by ctt-gob-es.

the class PaceConnection method transmit.

/**
 * {@inheritDoc}
 */
@Override
public ResponseApdu transmit(final CommandApdu command) throws ApduConnectionException {
    // Si es el comando para verificar el PIN se creara una instancia nueva de la clase
    // CommandApdu ya que la clase VerifyApduCommand no incluye la contrasena como parte
    // la APDU, sino en un attributo aparte
    final CommandApdu finalCommand = new CommandApdu(command.getCla(), command.getIns(), command.getP1(), command.getP2(), command.getData(), command.getLe());
    // Encriptacion de la APDU para su envio por el canal seguro
    CommandApdu protectedApdu = null;
    if (DEBUG) {
        // $NON-NLS-1$
        Logger.getLogger("es.gob.jmulticard").info(HexUtils.hexify(finalCommand.getBytes(), true));
    }
    try {
        protectedApdu = this.sm.wrap(finalCommand);
    } catch (final SecureMessagingException e) {
        // $NON-NLS-1$
        throw new ApduConnectionException("No ha sido posible cifrar un mensaje seguro con el canal PACE: " + e);
    }
    final ResponseApdu responseApdu = this.subConnection.transmit(protectedApdu);
    ResponseApdu decipherApdu = null;
    try {
        decipherApdu = this.sm.unwrap(responseApdu);
    } catch (final SecureMessagingException e1) {
        // $NON-NLS-1$
        throw new ApduConnectionException("No ha sido posible descifrar un mensaje seguro con el canal PACE: " + e1);
    }
    if (DEBUG) {
        // $NON-NLS-1$
        Logger.getLogger("es.gob.jmulticard").info(HexUtils.hexify(decipherApdu.getBytes(), true));
    }
    if (INVALID_CRYPTO_CHECKSUM.equals(decipherApdu.getStatusWord())) {
        throw new InvalidCryptographicChecksum();
    }
    // a enviar el comando indicando la longitud correcta
    if (decipherApdu.getStatusWord().getMsb() == MSB_INCORRECT_LE) {
        command.setLe(decipherApdu.getStatusWord().getLsb());
        return transmit(command);
    }
    return decipherApdu;
}
Also used : InvalidCryptographicChecksum(es.gob.jmulticard.apdu.connection.cwa14890.InvalidCryptographicChecksum) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) SecureMessagingException(es.gob.jmulticard.de.tsenger.androsmex.iso7816.SecureMessagingException) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException)

Aggregations

CommandApdu (es.gob.jmulticard.apdu.CommandApdu)1 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)1 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 InvalidCryptographicChecksum (es.gob.jmulticard.apdu.connection.cwa14890.InvalidCryptographicChecksum)1 SecureMessagingException (es.gob.jmulticard.de.tsenger.androsmex.iso7816.SecureMessagingException)1