Search in sources :

Example 6 with TLV

use of org.openecard.common.tlv.TLV in project open-ecard by ecsec.

the class EF_AODTest method readEF_AOD.

@Test
public void readEF_AOD() throws TLVException, IOException {
    TLV tlv = ReadHelper.readCIAFile("EF_AOD.bin");
    AuthenticationObjectChoice pkc = new AuthenticationObjectChoice(tlv);
}
Also used : TLV(org.openecard.common.tlv.TLV) Test(org.testng.annotations.Test)

Example 7 with TLV

use of org.openecard.common.tlv.TLV in project open-ecard by ecsec.

the class EF_CDTest method readEF_CD.

@Test
public void readEF_CD() throws TLVException, IOException {
    TLV tlv = ReadHelper.readCIAFile("EF_CD.bin");
    CertificateChoice pkc = new CertificateChoice(tlv);
}
Also used : TLV(org.openecard.common.tlv.TLV) Test(org.testng.annotations.Test)

Example 8 with TLV

use of org.openecard.common.tlv.TLV in project open-ecard by ecsec.

the class EF_CIAInfoTest method readEF_CIAInfo.

@Test
public void readEF_CIAInfo() throws TLVException, IOException {
    TLV tlv = ReadHelper.readCIAFile("EF_CIAInfo.bin");
    CIAInfo ciaInfo = new CIAInfo(tlv);
}
Also used : TLV(org.openecard.common.tlv.TLV) Test(org.testng.annotations.Test)

Example 9 with TLV

use of org.openecard.common.tlv.TLV in project open-ecard by ecsec.

the class EF_PrKDTest method readEF_PrKD.

@Test
public void readEF_PrKD() throws TLVException, IOException {
    TLV tlv = ReadHelper.readCIAFile("EF_PrKD.bin");
    PrivateKeyChoice pkc = new PrivateKeyChoice(tlv);
}
Also used : TLV(org.openecard.common.tlv.TLV) Test(org.testng.annotations.Test)

Example 10 with TLV

use of org.openecard.common.tlv.TLV in project open-ecard by ecsec.

the class CardVerifiableCertificateVerifier method verify.

/**
 * Verifies that the certificate description matches the certificate.
 * Verification is done by hashing the description and comparing it
 * to the checksum containing in the certificate extention.
 * See BSI-TR-03110, version 2.10, part 3, section C.3.
 *
 * @param certificate Certificate
 * @param description Description
 * @throws CertificateException
 */
public static void verify(CardVerifiableCertificate certificate, CertificateDescription description) throws CertificateException {
    try {
        byte[] extentions = certificate.getExtensions();
        TLV extentionObject = TLV.fromBER(extentions);
        List<TLV> list = extentionObject.asList();
        for (TLV item : list) {
            String oid = ObjectIdentifierUtils.toString(item.getValue());
            if (oid.equals(CVCertificatesObjectIdentifier.id_description)) {
                List<TLV> hashObjects = item.findChildTags(0x80);
                if (hashObjects != null && !hashObjects.isEmpty()) {
                    TLV hashObject = hashObjects.get(0);
                    MessageDigest md = selectDigest(certificate.getPublicKey().getObjectIdentifier());
                    byte[] hash = md.digest(description.getEncoded());
                    if (!ByteUtils.compare(hash, hashObject.getValue())) {
                        throw new CertificateException("The checksum of the certificate description cannot be verified!");
                    }
                }
            } else if (oid.equals(CVCertificatesObjectIdentifier.id_sector)) {
                List<TLV> firstPublicKeyObjects = item.findChildTags(0x80);
                if (firstPublicKeyObjects != null && !firstPublicKeyObjects.isEmpty()) {
                    TLV firstPublicKeyObject = firstPublicKeyObjects.get(0);
                // TODO
                }
                List<TLV> secondPublicKeyObjects = item.findChildTags(0x81);
                if (secondPublicKeyObjects != null && !secondPublicKeyObjects.isEmpty()) {
                    TLV secondPublicKeyObject = secondPublicKeyObjects.get(0);
                // TODO
                }
            } else {
                _logger.warn("Unknown OID: {} ", oid);
            }
        }
    } catch (Exception e) {
        _logger.debug(e.getMessage());
        throw new CertificateException("Verification failed", e);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) List(java.util.List) MessageDigest(java.security.MessageDigest) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertificateException(java.security.cert.CertificateException) TLV(org.openecard.common.tlv.TLV)

Aggregations

TLV (org.openecard.common.tlv.TLV)21 Test (org.testng.annotations.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 GeneralSecurityException (java.security.GeneralSecurityException)3 CardCommandAPDU (org.openecard.common.apdu.common.CardCommandAPDU)3 TLVException (org.openecard.common.tlv.TLVException)3 BigInteger (java.math.BigInteger)2 Cipher (javax.crypto.Cipher)2 CMac (org.openecard.bouncycastle.crypto.macs.CMac)2 ManageSecurityEnvironment (org.openecard.common.apdu.ManageSecurityEnvironment)2 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)2 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)1 DataMaskType (iso.std.iso_iec._24727.tech.schema.DataMaskType)1 DecipherResponse (iso.std.iso_iec._24727.tech.schema.DecipherResponse)1 SignResponse (iso.std.iso_iec._24727.tech.schema.SignResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessageDigest (java.security.MessageDigest)1