Search in sources :

Example 1 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class TerminalAuthentication method mseSetAT.

/**
 * Initializes the Terminal Authentication protocol.
 * Sends an MSE:Set AT APDU. (Protocol step 2)
 * See BSI-TR-03110, version 2.10, part 3, B.11.1.
 *
 * @param oID Terminal Authentication object identifier
 * @param chr Certificate Holder Reference (CHR)
 * @param key Ephemeral public key
 * @param aad Authenticated Auxiliary Data (AAD)
 * @throws ProtocolException
 */
public void mseSetAT(byte[] oID, byte[] chr, byte[] key, byte[] aad) throws ProtocolException {
    try {
        CardCommandAPDU mseSetAT = new MSESetATTA(oID, chr, key, aad);
        mseSetAT.transmit(dispatcher, slotHandle);
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) MSESetATTA(org.openecard.sal.protocol.eac.apdu.MSESetATTA)

Example 2 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class TerminalAuthentication method verifyCertificates.

/**
 * Verify certificates.
 * Sends an MSE:Set DST APDU and PSO:Verify Certificate APDU per certificate. (Protocol step 1)
 * See BSI-TR-03110, version 2.10, part 3, B.11.4.
 * See BSI-TR-03110, version 2.10, part 3, B.11.5.
 *
 * @param certificateChain Certificate chain
 * @throws ProtocolException
 */
public void verifyCertificates(CardVerifiableCertificateChain certificateChain) throws ProtocolException {
    try {
        for (CardVerifiableCertificate cvc : certificateChain.getCertificates()) {
            // MSE:SetDST APDU
            CardCommandAPDU mseSetDST = new MSESetDST(cvc.getCAR().toByteArray());
            mseSetDST.transmit(dispatcher, slotHandle);
            // PSO:Verify Certificate  APDU
            CardCommandAPDU psovc = new PSOVerifyCertificate(cvc.getCertificate().getValue());
            psovc.transmit(dispatcher, slotHandle);
        }
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) CardVerifiableCertificate(org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate) PSOVerifyCertificate(org.openecard.sal.protocol.eac.apdu.PSOVerifyCertificate) MSESetDST(org.openecard.sal.protocol.eac.apdu.MSESetDST)

Example 3 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class ChipAuthentication method mseSetAT.

/**
 * Initializes the Chip Authentication protocol.
 * Sends an MSE:Set AT APDU. (Protocol step 1)
 * See BSI-TR-03110, version 2.10, part 3, B.11.1.
 *
 * @param oID Chip Authentication object identifier
 * @param keyID Key identifier
 * @throws ProtocolException
 */
public void mseSetAT(byte[] oID, byte[] keyID) throws ProtocolException {
    try {
        CardCommandAPDU mseSetAT = new MSESetATCA(oID, keyID);
        mseSetAT.transmit(dispatcher, slotHandle);
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) MSESetATCA(org.openecard.sal.protocol.eac.apdu.MSESetATCA)

Example 4 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class ChipAuthentication method readEFCardSecurity.

/**
 * Reads the EFCardSecurity from the card.
 *
 * @return EFCardSecurtiy
 * @throws ProtocolException Thrown in case there is a problem reading the file.
 */
public byte[] readEFCardSecurity() throws ProtocolException {
    try {
        byte[] file = ShortUtils.toByteArray(EACConstants.EF_CARDSECURITY_FID);
        CardResponseAPDU resp = CardUtils.selectFileWithOptions(dispatcher, slotHandle, file, null, CardUtils.FCP_RESPONSE_DATA);
        FCP efCardSecurityFCP = new FCP(TLV.fromBER(resp.getData()));
        byte[] efCardSecurity = CardUtils.readFile(efCardSecurityFCP, dispatcher, slotHandle);
        return efCardSecurity;
    } catch (APDUException ex) {
        throw new ProtocolException(ex.getResult());
    } catch (TLVException ex) {
        throw new ProtocolException("Failed to parse FCP.", ex);
    }
}
Also used : ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) FCP(org.openecard.common.tlv.iso7816.FCP) APDUException(org.openecard.common.apdu.exception.APDUException) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) TLVException(org.openecard.common.tlv.TLVException)

Example 5 with ProtocolException

use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.

the class ChipAuthentication method generalAuthenticate.

/**
 * Performs a General Authenticate.
 * Sends an General Authenticate APDU. (Protocol step 2)
 * See BSI-TR-03110, version 2.10, part 3, B.11.2.
 *
 * @param key Ephemeral Public Key
 * @return Response APDU
 * @throws ProtocolException
 */
public byte[] generalAuthenticate(byte[] key) throws ProtocolException {
    try {
        if (key[0] != (byte) 0x04) {
            key = ByteUtils.concatenate((byte) 0x04, key);
        }
        CardCommandAPDU generalAuthenticate = new GeneralAuthenticate((byte) 0x80, key);
        CardResponseAPDU response = generalAuthenticate.transmit(dispatcher, slotHandle);
        return response.getData();
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) GeneralAuthenticate(org.openecard.common.apdu.GeneralAuthenticate)

Aggregations

ProtocolException (org.openecard.common.sal.protocol.exception.ProtocolException)8 APDUException (org.openecard.common.apdu.exception.APDUException)7 CardCommandAPDU (org.openecard.common.apdu.common.CardCommandAPDU)6 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)3 TLVException (org.openecard.common.tlv.TLVException)2 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DynamicContext (org.openecard.common.DynamicContext)1 ExternalAuthentication (org.openecard.common.apdu.ExternalAuthentication)1 GeneralAuthenticate (org.openecard.common.apdu.GeneralAuthenticate)1 GetChallenge (org.openecard.common.apdu.GetChallenge)1 ObjectSchemaValidator (org.openecard.common.interfaces.ObjectSchemaValidator)1 ObjectValidatorException (org.openecard.common.interfaces.ObjectValidatorException)1 FCP (org.openecard.common.tlv.iso7816.FCP)1 Promise (org.openecard.common.util.Promise)1 CardVerifiableCertificate (org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate)1 EAC2OutputType (org.openecard.sal.protocol.eac.anytype.EAC2OutputType)1 EACAdditionalInputType (org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType)1 MSESetATCA (org.openecard.sal.protocol.eac.apdu.MSESetATCA)1 MSESetATTA (org.openecard.sal.protocol.eac.apdu.MSESetATTA)1