/**************************************************************************** * Copyright (C) 2012 ecsec GmbH. * All rights reserved. * Contact: ecsec GmbH (info@ecsec.de) * * This file is part of the Open eCard App. * * GNU General Public License Usage * This file may be used under the terms of the GNU General Public * License version 3.0 as published by the Free Software Foundation * and appearing in the file LICENSE.GPL included in the packaging of * this file. Please review the following information to ensure the * GNU General Public License version 3.0 requirements will be met: * http://www.gnu.org/copyleft/gpl.html. * * Other Usage * Alternatively, this file may be used in accordance with the terms * and conditions contained in a signed written agreement between * you and ecsec GmbH. * ***************************************************************************/ package org.openecard.crypto.common.asn1.cvc; import java.security.cert.CertificateException; import org.openecard.common.util.StringUtils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import static org.testng.Assert.*; /** * * @author Moritz Horsch <horsch@cdc.informatik.tu-darmstadt.de> */ public class CardVerifiableCertificateVerify { private CardVerifiableCertificate certificate; private CertificateDescription certificateDescription; private CertificateDescription certificateDescriptionMalformed; @BeforeTest public void init() { try { byte[] cert = StringUtils.toByteArray("7F218201447F4E81FD5F290100420F444544567449446D744730303030397F494F060A04007F0007020202020386410429DE2CA270B7F1CD4A121D182F84E1B01F123D021699B427C81D8E02DD7D0D7A6FBF8F9882F3DD12916A41F320831A0E9C4AF76A42CE98F0ECAE8EBB341292A55F200C444541546D744730303030347F4C12060904007F0007030102025305000501FB075F25060102000700045F2406010201000001655E732D060904007F00070301030180203D481284343970B32B336BF6F9316AC990342D275D273CBE3855C1C08F12CECC732D060904007F0007030103028020E0BFAAA425C6673920F25F40C8DCE16086FC9C37F723D6198CFBDFA98FDA2F0C5F374082F5C7985B73C4A46976EB3CC4BC07C6377090FDAB9134BC329A5BA97665EE23564632A9C529009437975A40205E8D5DEF6C0F0621006F0C6C6D404E46ED7616"); certificate = new CardVerifiableCertificate(cert); byte[] bytesA = StringUtils.toByteArray("308201E6060A04007F00070301030101A1160C146D744720426572656368746967756E67732D4341A21A1318687474703A2F2F7777772E6D74672D4265722D43412E6465A3100C0E6D7447206549442D536572766572A41E131C687474703A2F2F7777772E6D74672D6549442D5365727665722E6465A5060C0454657374A60E130C72656469726563742055524CA7820158318201540420080266E8995556FB1D17B06E19D7DE5E73F49C7A718C855BF1E3174D17BB8D200420083061339A63F13176193CA9DFBD27B96B76E15B2DCC82A3D174B0BA7DDCDCC104201C5B6705A31FA9DCB7E5B6C3BF8201111EF098CEE2BF07AA6EC28E7F772D9CBD04202B5C779AEEFA6DB9227AFAE16000798C4268F71F6F29C3F2C07FF4AE8210F9F4042069174A976C6943E37A5987A66D209F8F3EB3EEC2724237A637C3F292EEF768840420937CE0A07B6DADDA2473CE11A2C9C9873FBD5ED17CCE01D916F20339FBE650850420C49D2A6280D0BCDEABC2B577F1E004AB526D0B00A72C087C6B744736EED58D6D0420D955A3AE9C142DC83A3C703779814C598FB733ADD5AB33ACB12CC916ED73146F0420E9B2B7E1430EFDE9E99A25603AD32E2671EFB6B00D921439428DF982CE168D440420FBE5C46C9A2E8AAAAC841917B9D4FC0974138BB3B333B73274F6250B3A735C34"); certificateDescription = CertificateDescription.getInstance(bytesA); byte[] bytesB = StringUtils.toByteArray("308201E6060A04007F00070301030101A1160C146D744720426572656368746967756E67732D4341A21A1318687474703A2F2F7777772E6D74672D4265722D43412E6465A3100C0E6D7447206549442D536572766572A41E131C687474703A2F2F7777772E6D74672D6549442D5365727665722E6465A5060C0454657374A60E130C72656469726563742055524CA7820158318201540420080266E8995556FB1D17B06E19D7DE5E73F49C7A718C855BF1E3174D17BB8D200420083061339A63F13176193CA9DFBD27B96B76E15B2DCC82A3D174B0BA7DDCDCC104201C5B6705A31FA9DCB7E5B6C3BF8201111EF098CEE2BF07AA6EC28E7F772D9CBD04202B5C779AEEFA6DB9227AFAE16000798C4268F71F6F29C3F2C07FF4AE8210F9F4042069174A976C6943E37A5987A66D209F8F3EB3EEC2724237A637C3F292EEF768840420937CE0A07B6DADDA2473CE11A2C9C9873FBD5ED17CCE01D916F20339FBE650850420C49D2A6280D0BCDEABC2B577F1E004AB526D0B00A72C087C6B744736EED58D6D0420D955A3AE9C142DC83A3C703779814C598FB733ADD5AB33ACB12CC916ED73146F0420E9B2B7E1430EFDE9E99A25603AD32E2671EFB6B00D921439428DF982CE168D440420FBE5C46C9A2E8AAAAC841917B9D4FC0974138BB3B333B73274F6250B3A735C35"); certificateDescriptionMalformed = CertificateDescription.getInstance(bytesB); } catch (Exception e) { fail(e.getMessage()); } } @Test(enabled = true) public void testVerifyCertificateDescription() throws Exception { CardVerifiableCertificateVerifier.verify(certificate, certificateDescription); } @Test(enabled = true, expectedExceptions = CertificateException.class) public void testVerifyCertificateDescription2() throws Exception { CardVerifiableCertificateVerifier.verify(certificate, certificateDescriptionMalformed); } }