diff options
-rw-r--r-- | src/main/java/org/bouncycastle/asn1/eac/EACTags.java | 200 | ||||
-rw-r--r-- | src/main/java/org/bouncycastle/eac/CertificateBody.java | 460 | ||||
-rw-r--r-- | src/main/java/org/bouncycastle/eac/EACTags.java | 207 |
3 files changed, 106 insertions, 761 deletions
diff --git a/src/main/java/org/bouncycastle/asn1/eac/EACTags.java b/src/main/java/org/bouncycastle/asn1/eac/EACTags.java index 4ee9df10..3988d809 100644 --- a/src/main/java/org/bouncycastle/asn1/eac/EACTags.java +++ b/src/main/java/org/bouncycastle/asn1/eac/EACTags.java @@ -5,117 +5,118 @@ import org.bouncycastle.asn1.DERApplicationSpecific; public class EACTags { - public static final int OBJECT_IDENTIFIER = 0x06; + public static final int OBJECT_IDENTIFIER = 0x06; public static final int COUNTRY_CODE_NATIONAL_DATA = 0x41; - public static final int ISSUER_IDENTIFICATION_NUMBER = 0x02; //0x42; - public static final int CARD_SERVICE_DATA = 0x43; + public static final int ISSUER_IDENTIFICATION_NUMBER = 0x02; //0x42; + public static final int CARD_SERVICE_DATA = 0x43; public static final int INITIAL_ACCESS_DATA = 0x44; - public static final int CARD_ISSUER_DATA = 0x45; - public static final int PRE_ISSUING_DATA = 0x46; - public static final int CARD_CAPABILITIES = 0x47; - public static final int STATUS_INFORMATION = 0x48; - public static final int EXTENDED_HEADER_LIST = 0x4D; - public static final int APPLICATION_IDENTIFIER = 0x4F; - public static final int APPLICATION_LABEL = 0x50; - public static final int FILE_REFERENCE = 0x51; - public static final int COMMAND_TO_PERFORM = 0x52; - public static final int DISCRETIONARY_DATA = 0x53; - public static final int OFFSET_DATA_OBJECT = 0x54; - public static final int TRACK1_APPLICATION = 0x56; - public static final int TRACK2_APPLICATION = 0x57; - public static final int TRACK3_APPLICATION = 0x58; - public static final int CARD_EXPIRATION_DATA = 0x59; - public static final int PRIMARY_ACCOUNT_NUMBER = 0x5A;// PAN - public static final int NAME = 0x5B; - public static final int TAG_LIST = 0x5C; + public static final int CARD_ISSUER_DATA = 0x45; + public static final int PRE_ISSUING_DATA = 0x46; + public static final int CARD_CAPABILITIES = 0x47; + public static final int STATUS_INFORMATION = 0x48; + public static final int EXTENDED_HEADER_LIST = 0x4D; + public static final int APPLICATION_IDENTIFIER = 0x4F; + public static final int APPLICATION_LABEL = 0x50; + public static final int FILE_REFERENCE = 0x51; + public static final int COMMAND_TO_PERFORM = 0x52; + public static final int DISCRETIONARY_DATA = 0x53; + public static final int OFFSET_DATA_OBJECT = 0x54; + public static final int TRACK1_APPLICATION = 0x56; + public static final int TRACK2_APPLICATION = 0x57; + public static final int TRACK3_APPLICATION = 0x58; + public static final int CARD_EXPIRATION_DATA = 0x59; + public static final int PRIMARY_ACCOUNT_NUMBER = 0x5A;// PAN + public static final int NAME = 0x5B; + public static final int TAG_LIST = 0x5C; public static final int HEADER_LIST = 0x5D; - public static final int LOGIN_DATA = 0x5E; + public static final int LOGIN_DATA = 0x5E; public static final int CARDHOLDER_NAME = 0x20; // 0x5F20; public static final int TRACK1_CARD = 0x5F21; public static final int TRACK2_CARD = 0x5F22; public static final int TRACK3_CARD = 0x5F23; public static final int APPLICATION_EXPIRATION_DATE = 0x24; // 0x5F24; - public static final int APPLICATION_EFFECTIVE_DATE = 0x25; // 0x5F25; + public static final int APPLICATION_EFFECTIVE_DATE = 0x25; // 0x5F25; public static final int CARD_EFFECTIVE_DATE = 0x5F26; public static final int INTERCHANGE_CONTROL = 0x5F27; - public static final int COUNTRY_CODE = 0x5F28; + public static final int COUNTRY_CODE = 0x5F28; public static final int INTERCHANGE_PROFILE = 0x29; // 0x5F29; - public static final int CURRENCY_CODE = 0x5F2A; - public static final int DATE_OF_BIRTH = 0x5F2B; - public static final int CARDHOLDER_NATIONALITY = 0x5F2C; - public static final int LANGUAGE_PREFERENCES = 0x5F2D; - public static final int CARDHOLDER_BIOMETRIC_DATA = 0x5F2E; - public static final int PIN_USAGE_POLICY = 0x5F2F; - public static final int SERVICE_CODE = 0x5F30; + public static final int CURRENCY_CODE = 0x5F2A; + public static final int DATE_OF_BIRTH = 0x5F2B; + public static final int CARDHOLDER_NATIONALITY = 0x5F2C; + public static final int LANGUAGE_PREFERENCES = 0x5F2D; + public static final int CARDHOLDER_BIOMETRIC_DATA = 0x5F2E; + public static final int PIN_USAGE_POLICY = 0x5F2F; + public static final int SERVICE_CODE = 0x5F30; public static final int TRANSACTION_COUNTER = 0x5F32; - public static final int TRANSACTION_DATE = 0x5F33; + public static final int TRANSACTION_DATE = 0x5F33; public static final int CARD_SEQUENCE_NUMBER = 0x5F34; - public static final int SEX = 0x5F35; - public static final int CURRENCY_EXPONENT = 0x5F36; - public static final int STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP = 0x37; // 0x5F37; - public static final int SIGNATURE = 0x5F37; - public static final int STATIC_INTERNAL_AUTHENTIFICATION_FIRST_DATA = 0x5F38; + public static final int SEX = 0x5F35; + public static final int CURRENCY_EXPONENT = 0x5F36; + public static final int STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP = 0x37; // 0x5F37; + public static final int SIGNATURE = 0x5F37; + public static final int STATIC_INTERNAL_AUTHENTIFICATION_FIRST_DATA = 0x5F38; public static final int STATIC_INTERNAL_AUTHENTIFICATION_SECOND_DATA = 0x5F39; - public static final int DYNAMIC_INTERNAL_AUTHENTIFICATION = 0x5F3A; - public static final int DYNAMIC_EXTERNAL_AUTHENTIFICATION = 0x5F3B; + public static final int DYNAMIC_INTERNAL_AUTHENTIFICATION = 0x5F3A; + public static final int DYNAMIC_EXTERNAL_AUTHENTIFICATION = 0x5F3B; public static final int DYNAMIC_MUTUAL_AUTHENTIFICATION = 0x5F3C; - public static final int CARDHOLDER_PORTRAIT_IMAGE = 0x5F40; - public static final int ELEMENT_LIST = 0x5F41; + public static final int CARDHOLDER_PORTRAIT_IMAGE = 0x5F40; + public static final int ELEMENT_LIST = 0x5F41; public static final int ADDRESS = 0x5F42; - public static final int CARDHOLDER_HANDWRITTEN_SIGNATURE = 0x5F43; - public static final int APPLICATION_IMAGE = 0x5F44; - public static final int DISPLAY_IMAGE = 0x5F45; - public static final int TIMER = 0x5F46; - public static final int MESSAGE_REFERENCE = 0x5F47; - public static final int CARDHOLDER_PRIVATE_KEY = 0x5F48; - public static final int CARDHOLDER_PUBLIC_KEY = 0x5F49; - public static final int CERTIFICATION_AUTHORITY_PUBLIC_KEY = 0x5F4A; - public static final int DEPRECATED = 0x5F4B; - public static final int CERTIFICATE_HOLDER_AUTHORIZATION = 0x5F4C;// Not yet defined in iso7816. The allocation is requested - public static final int INTEGRATED_CIRCUIT_MANUFACTURER_ID = 0x5F4D; + public static final int CARDHOLDER_HANDWRITTEN_SIGNATURE = 0x5F43; + public static final int APPLICATION_IMAGE = 0x5F44; + public static final int DISPLAY_IMAGE = 0x5F45; + public static final int TIMER = 0x5F46; + public static final int MESSAGE_REFERENCE = 0x5F47; + public static final int CARDHOLDER_PRIVATE_KEY = 0x5F48; + public static final int CARDHOLDER_PUBLIC_KEY = 0x5F49; + public static final int CERTIFICATION_AUTHORITY_PUBLIC_KEY = 0x5F4A; + public static final int DEPRECATED = 0x5F4B; + public static final int CERTIFICATE_HOLDER_AUTHORIZATION = 0x5F4C;// Not yet defined in iso7816. The allocation is requested + public static final int INTEGRATED_CIRCUIT_MANUFACTURER_ID = 0x5F4D; public static final int CERTIFICATE_CONTENT = 0x5F4E; - public static final int UNIFORM_RESOURCE_LOCATOR = 0x5F50; + public static final int UNIFORM_RESOURCE_LOCATOR = 0x5F50; public static final int ANSWER_TO_RESET = 0x5F51; - public static final int HISTORICAL_BYTES = 0x5F52; - public static final int DIGITAL_SIGNATURE = 0x5F3D; - public static final int APPLICATION_TEMPLATE = 0x61; - public static final int FCP_TEMPLATE = 0x62; + public static final int HISTORICAL_BYTES = 0x5F52; + public static final int DIGITAL_SIGNATURE = 0x5F3D; + public static final int APPLICATION_TEMPLATE = 0x61; + public static final int FCP_TEMPLATE = 0x62; public static final int WRAPPER = 0x63; - public static final int FMD_TEMPLATE = 0x64; - public static final int CARDHOLDER_RELATIVE_DATA = 0x65; - public static final int CARD_DATA = 0x66; - public static final int AUTHENTIFICATION_DATA = 0x67; - public static final int SPECIAL_USER_REQUIREMENTS = 0x68; - public static final int LOGIN_TEMPLATE = 0x6A; - public static final int QUALIFIED_NAME = 0x6B; - public static final int CARDHOLDER_IMAGE_TEMPLATE = 0x6C; - public static final int APPLICATION_IMAGE_TEMPLATE = 0x6D; - public static final int APPLICATION_RELATED_DATA = 0x6E; - public static final int FCI_TEMPLATE = 0x6F; - public static final int DISCRETIONARY_DATA_OBJECTS = 0x73; - public static final int COMPATIBLE_TAG_ALLOCATION_AUTHORITY = 0x78; + public static final int FMD_TEMPLATE = 0x64; + public static final int CARDHOLDER_RELATIVE_DATA = 0x65; + public static final int CARD_DATA = 0x66; + public static final int AUTHENTIFICATION_DATA = 0x67; + public static final int SPECIAL_USER_REQUIREMENTS = 0x68; + public static final int LOGIN_TEMPLATE = 0x6A; + public static final int QUALIFIED_NAME = 0x6B; + public static final int CARDHOLDER_IMAGE_TEMPLATE = 0x6C; + public static final int APPLICATION_IMAGE_TEMPLATE = 0x6D; + public static final int APPLICATION_RELATED_DATA = 0x6E; + public static final int FCI_TEMPLATE = 0x6F; + public static final int DISCRETIONARY_DATA_OBJECTS = 0x73; + public static final int COMPATIBLE_TAG_ALLOCATION_AUTHORITY = 0x78; public static final int COEXISTANT_TAG_ALLOCATION_AUTHORITY = 0x79; - public static final int SECURITY_SUPPORT_TEMPLATE = 0x7A; - public static final int SECURITY_ENVIRONMENT_TEMPLATE = 0x7B; - public static final int DYNAMIC_AUTHENTIFICATION_TEMPLATE = 0x7C; + public static final int SECURITY_SUPPORT_TEMPLATE = 0x7A; + public static final int SECURITY_ENVIRONMENT_TEMPLATE = 0x7B; + public static final int DYNAMIC_AUTHENTIFICATION_TEMPLATE = 0x7C; public static final int SECURE_MESSAGING_TEMPLATE = 0x7D; - public static final int NON_INTERINDUSTRY_DATA_OBJECT_NESTING_TEMPLATE = 0x7E; + public static final int NON_INTERINDUSTRY_DATA_OBJECT_NESTING_TEMPLATE = 0x7E; public static final int DISPLAY_CONTROL = 0x7F20; - public static final int CARDHOLDER_CERTIFICATE = 0x21; // 0x7F21; - public static final int CV_CERTIFICATE = 0x7F21; + public static final int CARDHOLDER_CERTIFICATE = 0x21; // 0x7F21; + public static final int CV_CERTIFICATE = 0x7F21; public static final int CARDHOLER_REQUIREMENTS_INCLUDED_FEATURES = 0x7F22; - public static final int CARDHOLER_REQUIREMENTS_EXCLUDED_FEATURES = 0x7F23; + public static final int CARDHOLER_REQUIREMENTS_EXCLUDED_FEATURES = 0x7F23; public static final int BIOMETRIC_DATA_TEMPLATE = 0x7F2E; public static final int DIGITAL_SIGNATURE_BLOCK = 0x7F3D; public static final int CARDHOLDER_PRIVATE_KEY_TEMPLATE = 0x7F48; - public static final int CARDHOLDER_PUBLIC_KEY_TEMPLATE = 0x49; // 0x7F49; - public static final int CERTIFICATE_HOLDER_AUTHORIZATION_TEMPLATE = 0x4C; // 0x7F4C; - public static final int CERTIFICATE_CONTENT_TEMPLATE = 0x4E; // 0x7F4E; - public static final int CERTIFICATE_BODY = 0x4E; // 0x7F4E; - public static final int BIOMETRIC_INFORMATION_TEMPLATE = 0x7F60; + public static final int CARDHOLDER_PUBLIC_KEY_TEMPLATE = 0x49; // 0x7F49; + public static final int CERTIFICATE_HOLDER_AUTHORIZATION_TEMPLATE = 0x4C; // 0x7F4C; + public static final int CERTIFICATE_CONTENT_TEMPLATE = 0x4E; // 0x7F4E; + public static final int CERTIFICATE_BODY = 0x4E; // 0x7F4E; + public static final int BIOMETRIC_INFORMATION_TEMPLATE = 0x7F60; public static final int BIOMETRIC_INFORMATION_GROUP_TEMPLATE = 0x7F61; - - public static int getTag(int encodedTag) { + + public static int getTag(int encodedTag) + { /* int i; for (i = 24; i>=0; i-=8) { @@ -126,13 +127,17 @@ public class EACTags */ return decodeTag(encodedTag); } - - public static int getTagNo(int tag) { + + public static int getTagNo(int tag) + { int i; - for (i = 24; i>=0; i -=8) { - if (((0xFF<<i) & tag) != 0) - return ((~(0xFF<<i)) & tag); - } + for (i = 24; i >= 0; i -= 8) + { + if (((0xFF << i) & tag) != 0) + { + return ((~(0xFF << i)) & tag); + } + } return 0; } @@ -164,20 +169,25 @@ public class EACTags } } else + { retValue |= tag; + } return retValue; } - + public static int decodeTag(int tag) { int retValue = 0; boolean multiBytes = false; - for (int i = 24; i>=0; i -=8) { + for (int i = 24; i >= 0; i -= 8) + { int currentByte = tag >> i & 0xFF; if (currentByte == 0) + { continue; - + } + if (multiBytes) { retValue <<= 7; @@ -188,8 +198,10 @@ public class EACTags multiBytes = true; } else + { return currentByte & 0x1F; // higher order bit are for DER.Constructed and type - } + } + } return retValue; } } diff --git a/src/main/java/org/bouncycastle/eac/CertificateBody.java b/src/main/java/org/bouncycastle/eac/CertificateBody.java deleted file mode 100644 index 39443b0c..00000000 --- a/src/main/java/org/bouncycastle/eac/CertificateBody.java +++ /dev/null @@ -1,460 +0,0 @@ -package org.bouncycastle.asn1.eac; - -import java.io.IOException; - -import org.bouncycastle.asn1.ASN1EncodableVector; -import org.bouncycastle.asn1.ASN1InputStream; -import org.bouncycastle.asn1.ASN1Object; -import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.BERTags; -import org.bouncycastle.asn1.DERApplicationSpecific; -import org.bouncycastle.asn1.DEROctetString; - - -/** - * an Iso7816CertificateBody structure. - * <p/> - * <pre> - * CertificateBody ::= SEQUENCE { - * // version of the certificate format. Must be 0 (version 1) - * CertificateProfileIdentifer DERApplicationSpecific, - * //uniquely identifies the issuinng CA's signature key pair - * // contains the iso3166-1 alpha2 encoded country code, the - * // name of issuer and the sequence number of the key pair. - * CertificationAuthorityReference DERApplicationSpecific, - * // stores the encoded public key - * PublicKey Iso7816PublicKey, - * //associates the public key contained in the certificate with a unique name - * // contains the iso3166-1 alpha2 encoded country code, the - * // name of the holder and the sequence number of the key pair. - * certificateHolderReference DERApplicationSpecific, - * // Encodes the role of the holder (i.e. CVCA, DV, IS) and assigns read/write - * // access rights to data groups storing sensitive data - * certificateHolderAuthorization Iso7816CertificateHolderAuthorization, - * // the date of the certificate generation - * CertificateEffectiveDate DERApplicationSpecific, - * // the date after wich the certificate expires - * certificateExpirationDate DERApplicationSpecific - * } - * </pre> - */ -public class CertificateBody - extends ASN1Object -{ - ASN1InputStream seq; - private DERApplicationSpecific certificateProfileIdentifier;// version of the certificate format. Must be 0 (version 1) - private DERApplicationSpecific certificationAuthorityReference;//uniquely identifies the issuinng CA's signature key pair - private PublicKeyDataObject publicKey;// stores the encoded public key - private DERApplicationSpecific certificateHolderReference;//associates the public key contained in the certificate with a unique name - private CertificateHolderAuthorization certificateHolderAuthorization;// Encodes the role of the holder (i.e. CVCA, DV, IS) and assigns read/write access rights to data groups storing sensitive data - private DERApplicationSpecific certificateEffectiveDate;// the date of the certificate generation - private DERApplicationSpecific certificateExpirationDate;// the date after wich the certificate expires - private int certificateType = 0;// bit field of initialized data. This will tell us if the data are valid. - private static final int CPI = 0x01;//certificate Profile Identifier - private static final int CAR = 0x02;//certification Authority Reference - private static final int PK = 0x04;//public Key - private static final int CHR = 0x08;//certificate Holder Reference - private static final int CHA = 0x10;//certificate Holder Authorization - private static final int CEfD = 0x20;//certificate Effective Date - private static final int CExD = 0x40;//certificate Expiration Date - - public static final int profileType = 0x7f;//Profile type Certificate - public static final int requestType = 0x0D;// Request type Certificate - - private void setIso7816CertificateBody(DERApplicationSpecific appSpe) - throws IOException - { - byte[] content; - if (appSpe.getApplicationTag() == EACTags.CERTIFICATE_CONTENT_TEMPLATE) - { - content = appSpe.getContents(); - } - else - { - throw new IOException("Bad tag : not an iso7816 CERTIFICATE_CONTENT_TEMPLATE"); - } - ASN1InputStream aIS = new ASN1InputStream(content); - ASN1Primitive obj; - while ((obj = aIS.readObject()) != null) - { - DERApplicationSpecific aSpe; - - if (obj instanceof DERApplicationSpecific) - { - aSpe = (DERApplicationSpecific)obj; - } - else - { - throw new IOException("Not a valid iso7816 content : not a DERApplicationSpecific Object :" + EACTags.encodeTag(appSpe) + obj.getClass()); - } - switch (aSpe.getApplicationTag()) - { - case EACTags.INTERCHANGE_PROFILE: - setCertificateProfileIdentifier(aSpe); - break; - case EACTags.ISSUER_IDENTIFICATION_NUMBER: - setCertificationAuthorityReference(aSpe); - break; - case EACTags.CARDHOLDER_PUBLIC_KEY_TEMPLATE: - setPublicKey(PublicKeyDataObject.getInstance(aSpe.getObject(BERTags.SEQUENCE))); - break; - case EACTags.CARDHOLDER_NAME: - setCertificateHolderReference(aSpe); - break; - case EACTags.CERTIFICATE_HOLDER_AUTHORIZATION_TEMPLATE: - setCertificateHolderAuthorization(new CertificateHolderAuthorization(aSpe)); - break; - case EACTags.APPLICATION_EFFECTIVE_DATE: - setCertificateEffectiveDate(aSpe); - break; - case EACTags.APPLICATION_EXPIRATION_DATE: - setCertificateExpirationDate(aSpe); - break; - default: - certificateType = 0; - throw new IOException("Not a valid iso7816 DERApplicationSpecific tag " + aSpe.getApplicationTag()); - } - } - } - - /** - * builds an Iso7816CertificateBody by settings each parameters. - * - * @param certificateProfileIdentifier - * @param certificationAuthorityReference - * - * @param publicKey - * @param certificateHolderReference - * @param certificateHolderAuthorization - * @param certificateEffectiveDate - * @param certificateExpirationDate - * @throws IOException - */ - public CertificateBody( - DERApplicationSpecific certificateProfileIdentifier, - CertificationAuthorityReference certificationAuthorityReference, - PublicKeyDataObject publicKey, - CertificateHolderReference certificateHolderReference, - CertificateHolderAuthorization certificateHolderAuthorization, - PackedDate certificateEffectiveDate, - PackedDate certificateExpirationDate - ) - { - setCertificateProfileIdentifier(certificateProfileIdentifier); - setCertificationAuthorityReference(new DERApplicationSpecific( - EACTags.ISSUER_IDENTIFICATION_NUMBER, certificationAuthorityReference.getEncoded())); - setPublicKey(publicKey); - setCertificateHolderReference(new DERApplicationSpecific( - EACTags.CARDHOLDER_NAME, certificateHolderReference.getEncoded())); - setCertificateHolderAuthorization(certificateHolderAuthorization); - try - { - setCertificateEffectiveDate(new DERApplicationSpecific( - false, EACTags.APPLICATION_EFFECTIVE_DATE, new DEROctetString(certificateEffectiveDate.getEncoding()))); - setCertificateExpirationDate(new DERApplicationSpecific( - false, EACTags.APPLICATION_EXPIRATION_DATE, new DEROctetString(certificateExpirationDate.getEncoding()))); - } - catch (IOException e) - { - throw new IllegalArgumentException("unable to encode dates: " + e.getMessage()); - } - } - - /** - * builds an Iso7816CertificateBody with an ASN1InputStream. - * - * @param obj DERApplicationSpecific containing the whole body. - * @throws IOException if the body is not valid. - */ - private CertificateBody(DERApplicationSpecific obj) - throws IOException - { - setIso7816CertificateBody(obj); - } - - /** - * create a profile type Iso7816CertificateBody. - * - * @return return the "profile" type certificate body. - * @throws IOException if the DERApplicationSpecific cannot be created. - */ - private ASN1Primitive profileToASN1Object() - throws IOException - { - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(certificateProfileIdentifier); - v.add(certificationAuthorityReference); - v.add(new DERApplicationSpecific(false, EACTags.CARDHOLDER_PUBLIC_KEY_TEMPLATE, publicKey)); - v.add(certificateHolderReference); - v.add(certificateHolderAuthorization); - v.add(certificateEffectiveDate); - v.add(certificateExpirationDate); - return new DERApplicationSpecific(EACTags.CERTIFICATE_CONTENT_TEMPLATE, v); - } - - private void setCertificateProfileIdentifier(DERApplicationSpecific certificateProfileIdentifier) - throws IllegalArgumentException { - if (certificateProfileIdentifier.getApplicationTag() == EACTags.INTERCHANGE_PROFILE) { - this.certificateProfileIdentifier = certificateProfileIdentifier; - certificateType |= CPI; - } - else - throw new IllegalArgumentException("Not an Iso7816Tags.INTERCHANGE_PROFILE tag :"+ EACTags.encodeTag(certificateProfileIdentifier)); - } - - private void setCertificateHolderReference(DERApplicationSpecific certificateHolderReference) - throws IllegalArgumentException { - if (certificateHolderReference.getApplicationTag() == EACTags.CARDHOLDER_NAME) { - this.certificateHolderReference = certificateHolderReference; - certificateType |= CHR; - } - else - throw new IllegalArgumentException("Not an Iso7816Tags.CARDHOLDER_NAME tag"); - } - - /** - * set the CertificationAuthorityReference. - * @param certificationAuthorityReference the DERApplicationSpecific containing the CertificationAuthorityReference. - * @throws IllegalArgumentException if the DERApplicationSpecific is not valid. - */ - private void setCertificationAuthorityReference( - DERApplicationSpecific certificationAuthorityReference) - throws IllegalArgumentException { - if (certificationAuthorityReference.getApplicationTag() == EACTags.ISSUER_IDENTIFICATION_NUMBER) { - this.certificationAuthorityReference = certificationAuthorityReference; - certificateType |= CAR; - } - else - throw new IllegalArgumentException("Not an Iso7816Tags.ISSUER_IDENTIFICATION_NUMBER tag"); - } - - /** - * set the public Key - * @param publicKey : the DERApplicationSpecific containing the public key - * @throws java.io.IOException - */ - private void setPublicKey(PublicKeyDataObject publicKey) - { - this.publicKey = PublicKeyDataObject.getInstance(publicKey); - this.certificateType |= PK; - } - - /** - * create a request type Iso7816CertificateBody. - * - * @return return the "request" type certificate body. - * @throws IOException if the DERApplicationSpecific cannot be created. - */ - private ASN1Primitive requestToASN1Object() - throws IOException - { - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(certificateProfileIdentifier); - v.add(new DERApplicationSpecific(false, EACTags.CARDHOLDER_PUBLIC_KEY_TEMPLATE, publicKey)); - v.add(certificateHolderReference); - return new DERApplicationSpecific(EACTags.CERTIFICATE_CONTENT_TEMPLATE, v); - } - - /** - * create a "request" or "profile" type Iso7816CertificateBody according to the variables sets. - * - * @return return the ASN1Primitive representing the "request" or "profile" type certificate body. - * @throws IOException if the DERApplicationSpecific cannot be created or if data are missings to create a valid certificate. - */ - public ASN1Primitive toASN1Primitive() - { - try - { - if (certificateType == profileType) - { - return profileToASN1Object(); - } - if (certificateType == requestType) - { - return requestToASN1Object(); - } - } - catch (IOException e) - { - return null; - } - return null; - } - - /** - * gives the type of the certificate (value should be profileType or requestType if all data are set). - * - * @return the int representing the data already set. - */ - public int getCertificateType() - { - return certificateType; - } - - /** - * Gives an instance of Iso7816CertificateBody taken from Object obj - * - * @param obj is the Object to extract the certificate body from. - * @return the Iso7816CertificateBody taken from Object obj. - * @throws IOException if object is not valid. - */ - public static CertificateBody getInstance(Object obj) - throws IOException - { - if (obj instanceof CertificateBody) - { - return (CertificateBody)obj; - } - else if (obj != null) - { - return new CertificateBody(DERApplicationSpecific.getInstance(obj)); - } - - return null; - } - - /** - * @return the date of the certificate generation - */ - public PackedDate getCertificateEffectiveDate() - { - if ((this.certificateType & CertificateBody.CEfD) == - CertificateBody.CEfD) - { - return new PackedDate(certificateEffectiveDate.getContents()); - } - return null; - } - - /** - * set the date of the certificate generation - * - * @param ced DERApplicationSpecific containing the date of the certificate generation - * @throws IllegalArgumentException if the tag is not Iso7816Tags.APPLICATION_EFFECTIVE_DATE - */ - private void setCertificateEffectiveDate(DERApplicationSpecific ced) - throws IllegalArgumentException - { - if (ced.getApplicationTag() == EACTags.APPLICATION_EFFECTIVE_DATE) - { - this.certificateEffectiveDate = ced; - certificateType |= CEfD; - } - else - { - throw new IllegalArgumentException("Not an Iso7816Tags.APPLICATION_EFFECTIVE_DATE tag :" + EACTags.encodeTag(ced)); - } - } - - /** - * @return the date after wich the certificate expires - */ - public PackedDate getCertificateExpirationDate() - throws IOException - { - if ((this.certificateType & CertificateBody.CExD) == - CertificateBody.CExD) - { - return new PackedDate(certificateExpirationDate.getContents()); - } - throw new IOException("certificate Expiration Date not set"); - } - - /** - * set the date after wich the certificate expires - * - * @param ced DERApplicationSpecific containing the date after wich the certificate expires - * @throws IllegalArgumentException if the tag is not Iso7816Tags.APPLICATION_EXPIRATION_DATE - */ - private void setCertificateExpirationDate(DERApplicationSpecific ced) - throws IllegalArgumentException - { - if (ced.getApplicationTag() == EACTags.APPLICATION_EXPIRATION_DATE) - { - this.certificateExpirationDate = ced; - certificateType |= CExD; - } - else - { - throw new IllegalArgumentException("Not an Iso7816Tags.APPLICATION_EXPIRATION_DATE tag"); - } - } - - /** - * the Iso7816CertificateHolderAuthorization encodes the role of the holder - * (i.e. CVCA, DV, IS) and assigns read/write access rights to data groups - * storing sensitive data. This functions returns the Certificate Holder - * Authorization - * - * @return the Iso7816CertificateHolderAuthorization - */ - public CertificateHolderAuthorization getCertificateHolderAuthorization() - throws IOException - { - if ((this.certificateType & CertificateBody.CHA) == - CertificateBody.CHA) - { - return certificateHolderAuthorization; - } - throw new IOException("Certificate Holder Authorisation not set"); - } - - /** - * set the CertificateHolderAuthorization - * - * @param cha the Certificate Holder Authorization - */ - private void setCertificateHolderAuthorization( - CertificateHolderAuthorization cha) - { - this.certificateHolderAuthorization = cha; - certificateType |= CHA; - } - - /** - * certificateHolderReference : associates the public key contained in the certificate with a unique name - * - * @return the certificateHolderReference. - */ - public CertificateHolderReference getCertificateHolderReference() - { - return new CertificateHolderReference(certificateHolderReference.getContents()); - } - - /** - * CertificateProfileIdentifier : version of the certificate format. Must be 0 (version 1) - * - * @return the CertificateProfileIdentifier - */ - public DERApplicationSpecific getCertificateProfileIdentifier() - { - return certificateProfileIdentifier; - } - - /** - * get the certificationAuthorityReference - * certificationAuthorityReference : uniquely identifies the issuinng CA's signature key pair - * - * @return the certificationAuthorityReference - */ - public CertificationAuthorityReference getCertificationAuthorityReference() - throws IOException - { - if ((this.certificateType & CertificateBody.CAR) == - CertificateBody.CAR) - { - return new CertificationAuthorityReference(certificationAuthorityReference.getContents()); - } - throw new IOException("Certification authority reference not set"); - } - - /** - * @return the PublicKey - */ - public PublicKeyDataObject getPublicKey() - { - return publicKey; - } -} diff --git a/src/main/java/org/bouncycastle/eac/EACTags.java b/src/main/java/org/bouncycastle/eac/EACTags.java deleted file mode 100644 index 3988d809..00000000 --- a/src/main/java/org/bouncycastle/eac/EACTags.java +++ /dev/null @@ -1,207 +0,0 @@ -package org.bouncycastle.asn1.eac; - -import org.bouncycastle.asn1.BERTags; -import org.bouncycastle.asn1.DERApplicationSpecific; - -public class EACTags -{ - public static final int OBJECT_IDENTIFIER = 0x06; - public static final int COUNTRY_CODE_NATIONAL_DATA = 0x41; - public static final int ISSUER_IDENTIFICATION_NUMBER = 0x02; //0x42; - public static final int CARD_SERVICE_DATA = 0x43; - public static final int INITIAL_ACCESS_DATA = 0x44; - public static final int CARD_ISSUER_DATA = 0x45; - public static final int PRE_ISSUING_DATA = 0x46; - public static final int CARD_CAPABILITIES = 0x47; - public static final int STATUS_INFORMATION = 0x48; - public static final int EXTENDED_HEADER_LIST = 0x4D; - public static final int APPLICATION_IDENTIFIER = 0x4F; - public static final int APPLICATION_LABEL = 0x50; - public static final int FILE_REFERENCE = 0x51; - public static final int COMMAND_TO_PERFORM = 0x52; - public static final int DISCRETIONARY_DATA = 0x53; - public static final int OFFSET_DATA_OBJECT = 0x54; - public static final int TRACK1_APPLICATION = 0x56; - public static final int TRACK2_APPLICATION = 0x57; - public static final int TRACK3_APPLICATION = 0x58; - public static final int CARD_EXPIRATION_DATA = 0x59; - public static final int PRIMARY_ACCOUNT_NUMBER = 0x5A;// PAN - public static final int NAME = 0x5B; - public static final int TAG_LIST = 0x5C; - public static final int HEADER_LIST = 0x5D; - public static final int LOGIN_DATA = 0x5E; - public static final int CARDHOLDER_NAME = 0x20; // 0x5F20; - public static final int TRACK1_CARD = 0x5F21; - public static final int TRACK2_CARD = 0x5F22; - public static final int TRACK3_CARD = 0x5F23; - public static final int APPLICATION_EXPIRATION_DATE = 0x24; // 0x5F24; - public static final int APPLICATION_EFFECTIVE_DATE = 0x25; // 0x5F25; - public static final int CARD_EFFECTIVE_DATE = 0x5F26; - public static final int INTERCHANGE_CONTROL = 0x5F27; - public static final int COUNTRY_CODE = 0x5F28; - public static final int INTERCHANGE_PROFILE = 0x29; // 0x5F29; - public static final int CURRENCY_CODE = 0x5F2A; - public static final int DATE_OF_BIRTH = 0x5F2B; - public static final int CARDHOLDER_NATIONALITY = 0x5F2C; - public static final int LANGUAGE_PREFERENCES = 0x5F2D; - public static final int CARDHOLDER_BIOMETRIC_DATA = 0x5F2E; - public static final int PIN_USAGE_POLICY = 0x5F2F; - public static final int SERVICE_CODE = 0x5F30; - public static final int TRANSACTION_COUNTER = 0x5F32; - public static final int TRANSACTION_DATE = 0x5F33; - public static final int CARD_SEQUENCE_NUMBER = 0x5F34; - public static final int SEX = 0x5F35; - public static final int CURRENCY_EXPONENT = 0x5F36; - public static final int STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP = 0x37; // 0x5F37; - public static final int SIGNATURE = 0x5F37; - public static final int STATIC_INTERNAL_AUTHENTIFICATION_FIRST_DATA = 0x5F38; - public static final int STATIC_INTERNAL_AUTHENTIFICATION_SECOND_DATA = 0x5F39; - public static final int DYNAMIC_INTERNAL_AUTHENTIFICATION = 0x5F3A; - public static final int DYNAMIC_EXTERNAL_AUTHENTIFICATION = 0x5F3B; - public static final int DYNAMIC_MUTUAL_AUTHENTIFICATION = 0x5F3C; - public static final int CARDHOLDER_PORTRAIT_IMAGE = 0x5F40; - public static final int ELEMENT_LIST = 0x5F41; - public static final int ADDRESS = 0x5F42; - public static final int CARDHOLDER_HANDWRITTEN_SIGNATURE = 0x5F43; - public static final int APPLICATION_IMAGE = 0x5F44; - public static final int DISPLAY_IMAGE = 0x5F45; - public static final int TIMER = 0x5F46; - public static final int MESSAGE_REFERENCE = 0x5F47; - public static final int CARDHOLDER_PRIVATE_KEY = 0x5F48; - public static final int CARDHOLDER_PUBLIC_KEY = 0x5F49; - public static final int CERTIFICATION_AUTHORITY_PUBLIC_KEY = 0x5F4A; - public static final int DEPRECATED = 0x5F4B; - public static final int CERTIFICATE_HOLDER_AUTHORIZATION = 0x5F4C;// Not yet defined in iso7816. The allocation is requested - public static final int INTEGRATED_CIRCUIT_MANUFACTURER_ID = 0x5F4D; - public static final int CERTIFICATE_CONTENT = 0x5F4E; - public static final int UNIFORM_RESOURCE_LOCATOR = 0x5F50; - public static final int ANSWER_TO_RESET = 0x5F51; - public static final int HISTORICAL_BYTES = 0x5F52; - public static final int DIGITAL_SIGNATURE = 0x5F3D; - public static final int APPLICATION_TEMPLATE = 0x61; - public static final int FCP_TEMPLATE = 0x62; - public static final int WRAPPER = 0x63; - public static final int FMD_TEMPLATE = 0x64; - public static final int CARDHOLDER_RELATIVE_DATA = 0x65; - public static final int CARD_DATA = 0x66; - public static final int AUTHENTIFICATION_DATA = 0x67; - public static final int SPECIAL_USER_REQUIREMENTS = 0x68; - public static final int LOGIN_TEMPLATE = 0x6A; - public static final int QUALIFIED_NAME = 0x6B; - public static final int CARDHOLDER_IMAGE_TEMPLATE = 0x6C; - public static final int APPLICATION_IMAGE_TEMPLATE = 0x6D; - public static final int APPLICATION_RELATED_DATA = 0x6E; - public static final int FCI_TEMPLATE = 0x6F; - public static final int DISCRETIONARY_DATA_OBJECTS = 0x73; - public static final int COMPATIBLE_TAG_ALLOCATION_AUTHORITY = 0x78; - public static final int COEXISTANT_TAG_ALLOCATION_AUTHORITY = 0x79; - public static final int SECURITY_SUPPORT_TEMPLATE = 0x7A; - public static final int SECURITY_ENVIRONMENT_TEMPLATE = 0x7B; - public static final int DYNAMIC_AUTHENTIFICATION_TEMPLATE = 0x7C; - public static final int SECURE_MESSAGING_TEMPLATE = 0x7D; - public static final int NON_INTERINDUSTRY_DATA_OBJECT_NESTING_TEMPLATE = 0x7E; - public static final int DISPLAY_CONTROL = 0x7F20; - public static final int CARDHOLDER_CERTIFICATE = 0x21; // 0x7F21; - public static final int CV_CERTIFICATE = 0x7F21; - public static final int CARDHOLER_REQUIREMENTS_INCLUDED_FEATURES = 0x7F22; - public static final int CARDHOLER_REQUIREMENTS_EXCLUDED_FEATURES = 0x7F23; - public static final int BIOMETRIC_DATA_TEMPLATE = 0x7F2E; - public static final int DIGITAL_SIGNATURE_BLOCK = 0x7F3D; - public static final int CARDHOLDER_PRIVATE_KEY_TEMPLATE = 0x7F48; - public static final int CARDHOLDER_PUBLIC_KEY_TEMPLATE = 0x49; // 0x7F49; - public static final int CERTIFICATE_HOLDER_AUTHORIZATION_TEMPLATE = 0x4C; // 0x7F4C; - public static final int CERTIFICATE_CONTENT_TEMPLATE = 0x4E; // 0x7F4E; - public static final int CERTIFICATE_BODY = 0x4E; // 0x7F4E; - public static final int BIOMETRIC_INFORMATION_TEMPLATE = 0x7F60; - public static final int BIOMETRIC_INFORMATION_GROUP_TEMPLATE = 0x7F61; - - public static int getTag(int encodedTag) - { - /* - int i; - for (i = 24; i>=0; i-=8) { - if (((0xFF<<i) & tag) != 0) - return (((0xFF<<i) & tag) >> i); - } - return 0; - */ - return decodeTag(encodedTag); - } - - public static int getTagNo(int tag) - { - int i; - for (i = 24; i >= 0; i -= 8) - { - if (((0xFF << i) & tag) != 0) - { - return ((~(0xFF << i)) & tag); - } - } - return 0; - } - - public static int encodeTag(DERApplicationSpecific spec) - { - int retValue = BERTags.APPLICATION; - boolean constructed = spec.isConstructed(); - if (constructed) - retValue |= BERTags.CONSTRUCTED; - - int tag = spec.getApplicationTag(); - - if (tag > 31) - { - retValue |= 0x1F; - retValue <<= 8; - - int currentByte = tag & 0x7F; - retValue |= currentByte; - tag >>= 7; - - while (tag > 0) - { - retValue |= 0x80; - retValue <<= 8; - - currentByte = tag & 0x7F; - tag >>= 7; - } - } - else - { - retValue |= tag; - } - - return retValue; - } - - public static int decodeTag(int tag) - { - int retValue = 0; - boolean multiBytes = false; - for (int i = 24; i >= 0; i -= 8) - { - int currentByte = tag >> i & 0xFF; - if (currentByte == 0) - { - continue; - } - - if (multiBytes) - { - retValue <<= 7; - retValue |= currentByte & 0x7F; - } - else if ((currentByte & 0x1F) == 0x1F) - { - multiBytes = true; - } - else - { - return currentByte & 0x1F; // higher order bit are for DER.Constructed and type - } - } - return retValue; - } -} |