├── pkcs11-test ├── .classpath ├── .externalToolBuilders │ └── pkcs11-test process-sources.launch ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── opensc │ │ └── test │ │ └── pkcs11 │ │ ├── BaseTest.java │ │ ├── KeyGenerationTest.java │ │ ├── PINEntry.java │ │ ├── PKCS11ProviderTestCase.java │ │ └── SaveCertificateTest.java │ └── resources │ └── log4j.properties ├── pkcs11 ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── LICENSE ├── README ├── TODO ├── conf │ ├── eclipse │ │ ├── classpath.tmpl │ │ └── project.tmpl │ └── keystore │ │ └── README ├── java │ └── src │ │ └── org │ │ └── opensc │ │ ├── pkcs11 │ │ ├── PKCS11EventCallback.java │ │ ├── PKCS11LoadStoreParameter.java │ │ ├── PKCS11Provider.java │ │ ├── PKCS11SessionStore.java │ │ ├── spec │ │ │ ├── PKCS11DSAKeyPairGenParameterSpec.java │ │ │ ├── PKCS11KeyPairGenParams.java │ │ │ ├── PKCS11PrivateKeyGenParams.java │ │ │ ├── PKCS11PublicKeyGenParams.java │ │ │ └── PKCS11RSAKeyPairGenParameterSpec.java │ │ ├── spi │ │ │ ├── PKCS11CipherSpi.java │ │ │ ├── PKCS11KeyPairGeneratorSpi.java │ │ │ ├── PKCS11KeyStoreSpi.java │ │ │ └── PKCS11SignatureSpi.java │ │ └── wrap │ │ │ ├── PKCS11Attribute.java │ │ │ ├── PKCS11Certificate.java │ │ │ ├── PKCS11DSAKeyPairGenerator.java │ │ │ ├── PKCS11DSAPrivateKey.java │ │ │ ├── PKCS11DSAPublicKey.java │ │ │ ├── PKCS11Exception.java │ │ │ ├── PKCS11Key.java │ │ │ ├── PKCS11KeyPairGenerator.java │ │ │ ├── PKCS11Mechanism.java │ │ │ ├── PKCS11NeDSAPrivateKey.java │ │ │ ├── PKCS11NeRSAPrivateKey.java │ │ │ ├── PKCS11Object.java │ │ │ ├── PKCS11PrivateKey.java │ │ │ ├── PKCS11PublicKey.java │ │ │ ├── PKCS11RSAKeyPairGenerator.java │ │ │ ├── PKCS11RSAPrivateKey.java │ │ │ ├── PKCS11RSAPublicKey.java │ │ │ ├── PKCS11Session.java │ │ │ ├── PKCS11SessionChild.java │ │ │ └── PKCS11Slot.java │ │ └── util │ │ ├── DestroyableChild.java │ │ ├── DestroyableHolder.java │ │ ├── DestroyableParent.java │ │ ├── PKCS11Id.java │ │ └── Util.java ├── jni │ ├── build │ │ ├── mingw │ │ │ ├── debug │ │ │ │ └── config.data │ │ │ └── release │ │ │ │ └── config.data │ │ ├── msvc6 │ │ │ ├── README.txt │ │ │ ├── openscPKCS11.dsp │ │ │ ├── openscPKCS11.dsw │ │ │ └── openscPKCS11.mak │ │ └── unix │ │ │ ├── debug │ │ │ └── config.data │ │ │ └── release │ │ │ └── config.data │ └── src │ │ ├── Makefile.in │ │ ├── jniP11 │ │ ├── Makefile.in │ │ ├── jniP11private.h │ │ ├── mk_headers.sh │ │ ├── opensc │ │ │ └── pkcs11.h │ │ ├── org_opensc_pkcs11_PKCS11Provider.c │ │ ├── org_opensc_pkcs11_PKCS11Provider.h │ │ ├── org_opensc_pkcs11_spi_PKCS11CipherSpi.c │ │ ├── org_opensc_pkcs11_spi_PKCS11CipherSpi.h │ │ ├── org_opensc_pkcs11_spi_PKCS11SignatureSpi.c │ │ ├── org_opensc_pkcs11_spi_PKCS11SignatureSpi.h │ │ ├── org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator.c │ │ ├── org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator.h │ │ ├── org_opensc_pkcs11_wrap_PKCS11Object.c │ │ ├── org_opensc_pkcs11_wrap_PKCS11Object.h │ │ ├── org_opensc_pkcs11_wrap_PKCS11Session.c │ │ ├── org_opensc_pkcs11_wrap_PKCS11Session.h │ │ ├── org_opensc_pkcs11_wrap_PKCS11Slot.c │ │ ├── org_opensc_pkcs11_wrap_PKCS11Slot.h │ │ ├── pkcs11_error.c │ │ ├── pkcs11_module.c │ │ └── pkcs11_slot.c │ │ ├── jnix │ │ ├── Makefile.in │ │ ├── jnix.c │ │ └── jnix.h │ │ └── scripts │ │ ├── config.data.default │ │ └── config.pl └── pom.xml └── pkcs15 ├── .classpath ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.ui.prefs ├── conf └── logging │ └── logging.properties ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── opensc │ │ └── pkcs15 │ │ ├── AIDs.java │ │ ├── PKCS15Exception.java │ │ ├── application │ │ ├── Application.java │ │ ├── ApplicationFactory.java │ │ └── impl │ │ │ ├── ApplicationFactoryImpl.java │ │ │ └── PKCS15Application.java │ │ ├── asn1 │ │ ├── Context.java │ │ ├── ContextHolder.java │ │ ├── ISO7816ApplicationTemplate.java │ │ ├── ISO7816Applications.java │ │ ├── PKCS15AuthenticationObject.java │ │ ├── PKCS15Certificate.java │ │ ├── PKCS15Key.java │ │ ├── PKCS15Object.java │ │ ├── PKCS15Objects.java │ │ ├── PKCS15PinAuthenticationObject.java │ │ ├── PKCS15PrivateKey.java │ │ ├── PKCS15PublicKey.java │ │ ├── PKCS15RSAPrivateKey.java │ │ ├── PKCS15RSAPublicKey.java │ │ ├── PKCS15X509Certificate.java │ │ ├── attr │ │ │ ├── CertificateObject.java │ │ │ ├── CommonAuthenticationObjectAttributes.java │ │ │ ├── CommonCertificateAttributes.java │ │ │ ├── CommonKeyAttributes.java │ │ │ ├── CommonObjectAttributes.java │ │ │ ├── CommonPrivateKeyAttributes.java │ │ │ ├── CommonPublicKeyAttributes.java │ │ │ ├── CommonSecretKeyAttributes.java │ │ │ ├── PinAttributes.java │ │ │ ├── PrivateKeyObject.java │ │ │ ├── PrivateRSAKeyAttributes.java │ │ │ ├── PublicKeyObject.java │ │ │ ├── PublicRSAKeyAttributes.java │ │ │ ├── RSAKeyInfoFactory.java │ │ │ ├── RSAPrivateKeyObject.java │ │ │ ├── RSAPrivateKeyObjectFactory.java │ │ │ ├── RSAPrivateKeyObjectImpl.java │ │ │ ├── RSAPublicKeyChoice.java │ │ │ ├── RSAPublicKeyObject.java │ │ │ ├── RSAPublicKeyObjectFactory.java │ │ │ ├── SpecificCertificateAttributes.java │ │ │ ├── SpecificPrivateKeyAttributes.java │ │ │ ├── SpecificPublicKeyAttributes.java │ │ │ ├── X509CertificateAttributes.java │ │ │ ├── X509CertificateObject.java │ │ │ ├── X509CertificateObjectFactory.java │ │ │ └── X509CertificateObjectImpl.java │ │ ├── basic │ │ │ ├── AccessControlRule.java │ │ │ ├── AccessMode.java │ │ │ ├── AlgorithmInfo.java │ │ │ ├── AndSecurityCondition.java │ │ │ ├── AuthIdSecurityCondition.java │ │ │ ├── CommonObjectFlags.java │ │ │ ├── GeneralizedTimeHolder.java │ │ │ ├── GeneralizedTimeHolderImpl.java │ │ │ ├── IssuerAndSerialNumberKeyIdentifier.java │ │ │ ├── KeyAccessFlags.java │ │ │ ├── KeyIdentifier.java │ │ │ ├── KeyIdentifiers.java │ │ │ ├── KeyInfo.java │ │ │ ├── KeyInfoImpl.java │ │ │ ├── KeyUsageFlags.java │ │ │ ├── NotSecurityCondition.java │ │ │ ├── NullAlgorithmInfo.java │ │ │ ├── NullKeyInfo.java │ │ │ ├── NullKeyInfoImpl.java │ │ │ ├── OctetStringKeyIdentifier.java │ │ │ ├── Operations.java │ │ │ ├── OrSecurityCondition.java │ │ │ ├── PinFlags.java │ │ │ ├── PinType.java │ │ │ ├── RecordInfo.java │ │ │ ├── SecurityCondition.java │ │ │ ├── SecurityEnvironmentInfo.java │ │ │ ├── TokenFlags.java │ │ │ ├── TokenInfo.java │ │ │ └── Usage.java │ │ ├── helper │ │ │ └── IntegerHelper.java │ │ ├── proxy │ │ │ ├── Directory.java │ │ │ ├── InstanceFactory.java │ │ │ ├── ReferenceProxy.java │ │ │ ├── ReferenceProxyFactory.java │ │ │ ├── StreamResolver.java │ │ │ └── StreamResolverDirectory.java │ │ ├── ref │ │ │ ├── DDO.java │ │ │ ├── ObjectValueFactory.java │ │ │ ├── Path.java │ │ │ ├── PathOrObjectsFactory.java │ │ │ ├── ReferencedValueFactory.java │ │ │ ├── URL.java │ │ │ ├── URLDirectory.java │ │ │ ├── URLStreamResolver.java │ │ │ └── URLWithDigest.java │ │ └── sequence │ │ │ ├── SequenceOf.java │ │ │ ├── SequenceOfFactory.java │ │ │ ├── SequenceOfImpl.java │ │ │ └── SequenceOfStreamResolverDirectory.java │ │ ├── script │ │ ├── ClassPathScriptResource.java │ │ ├── Command.java │ │ ├── FileScriptResource.java │ │ ├── ScriptParser.java │ │ ├── ScriptParserFactory.java │ │ ├── ScriptResource.java │ │ ├── ScriptResourceFactory.java │ │ ├── SimpleCommand.java │ │ ├── SwitchCommand.java │ │ └── impl │ │ │ ├── CSFScriptParser.java │ │ │ ├── SERScriptParser.java │ │ │ ├── ScriptParserFactoryImpl.java │ │ │ └── ScriptResourceFactoryImpl.java │ │ ├── token │ │ ├── DF.java │ │ ├── DFAcl.java │ │ ├── EF.java │ │ ├── EFAcl.java │ │ ├── MF.java │ │ ├── MFAcl.java │ │ ├── PathHelper.java │ │ ├── Token.java │ │ ├── TokenContext.java │ │ ├── TokenFactory.java │ │ ├── TokenFile.java │ │ ├── TokenFileAcl.java │ │ ├── TokenFileVisitor.java │ │ ├── TokenPath.java │ │ └── impl │ │ │ ├── CardOSToken.java │ │ │ ├── DFAclImpl.java │ │ │ ├── EFAclImpl.java │ │ │ ├── MFAclImpl.java │ │ │ ├── SoftwareToken.java │ │ │ ├── TokenFactoryImpl.java │ │ │ └── TokenFileAclImpl.java │ │ ├── tool │ │ └── Main.java │ │ └── util │ │ └── Util.java └── resources │ ├── META-INF │ └── services │ │ ├── org.opensc.pkcs15.application.ApplicationFactory │ │ ├── org.opensc.pkcs15.script.ScriptParserFactory │ │ ├── org.opensc.pkcs15.script.ScriptResourceFactory │ │ └── org.opensc.pkcs15.token.TokenFactory │ └── org │ └── opensc │ └── pkcs15 │ └── scripts │ └── cardos │ └── v43b_reset.ser └── test ├── java └── test │ └── org │ └── opensc │ └── pkcs15 │ ├── HardwareCardSupport.java │ ├── TestCSFScripts.java │ ├── TestHardwareToken.java │ └── TestSoftwareToken.java └── resources ├── log4j.properties └── test └── org └── opensc └── pkcs15 └── test-ca.zip /pkcs11-test/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pkcs11-test/.externalToolBuilders/pkcs11-test process-sources.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pkcs11-test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | pkcs11-test 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.ui.externaltools.ExternalToolBuilder 10 | full,incremental, 11 | 12 | 13 | LaunchConfigHandle 14 | <project>/.externalToolBuilders/pkcs11-test process-sources.launch 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.maven.ide.eclipse.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jdt.core.javanature 31 | org.maven.ide.eclipse.maven2Nature 32 | 33 | 34 | -------------------------------------------------------------------------------- /pkcs11-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.opensc 4 | pkcs11-test 5 | 0.3.0-svn 6 | Test programs for the opensc PKCS#11 provider. 7 | 8 | 9 | 10 | 11 | org.apache.maven.plugins 12 | maven-compiler-plugin 13 | 14 | 1.5 15 | 1.5 16 | 17 | 18 | 19 | org.apache.maven.plugins 20 | maven-dependency-plugin 21 | 2.0-alpha-1-SNAPSHOT 22 | 23 | 24 | unpack-jni 25 | process-sources 26 | 27 | unpack-dependencies 28 | 29 | 30 | zip 31 | jar 32 | ${project.build.directory}/lib 33 | 34 | 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-surefire-plugin 40 | 41 | -Djava.library.path=${project.build.directory}/lib 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.opensc 50 | opensc-PKCS11 51 | ${project.version} 52 | 53 | 54 | log4j 55 | log4j 56 | 1.2.13 57 | 58 | 59 | org.bouncycastle 60 | bcprov 61 | jdk15-135 62 | test 63 | 64 | 65 | junit 66 | junit 67 | 3.8.1 68 | test 69 | 70 | 71 | 72 | 73 | 74 | central 75 | Central maven repository. 76 | http://repo1.maven.org/maven2 77 | 78 | 79 | org.clazzes 80 | Clazzes.org repository. 81 | http://maven.clazzes.org 82 | 83 | 84 | opensc-java-repo 85 | opensc-java repository. 86 | http://www.opensc-project.org/files/opensc-java/maven 87 | 88 | 89 | 90 | 91 | 92 | codehaus-mojo-repo 93 | codehaus.org mojo plugin repository. 94 | http://repository.codehaus.org/org/codehaus/mojo/ 95 | 96 | 97 | -------------------------------------------------------------------------------- /pkcs11-test/src/test/java/org/opensc/test/pkcs11/PKCS11ProviderTestCase.java: -------------------------------------------------------------------------------- 1 | package org.opensc.test.pkcs11; 2 | 3 | import java.io.IOException; 4 | import java.security.Provider; 5 | import java.security.Security; 6 | import java.util.Random; 7 | 8 | import org.opensc.pkcs11.PKCS11Provider; 9 | 10 | import junit.framework.TestCase; 11 | 12 | public abstract class PKCS11ProviderTestCase extends TestCase { 13 | 14 | protected PKCS11Provider provider; 15 | protected byte[] testData; 16 | 17 | public PKCS11ProviderTestCase() { 18 | super(); 19 | } 20 | 21 | public void setUp() throws IOException { 22 | // Add provider "SunPKCS11-OpenSC" 23 | String pkcs11_path; 24 | 25 | if (System.getProperty("os.name").contains("Windows")) 26 | pkcs11_path = System.getenv("ProgramFiles")+"\\Smart Card Bundle\\opensc-pkcs11.dll"; 27 | else 28 | pkcs11_path = "/usr/lib/opensc-pkcs11.so"; 29 | 30 | this.provider = new PKCS11Provider(pkcs11_path); 31 | Security.addProvider(this.provider); 32 | 33 | Provider providers[] = Security.getProviders(); 34 | for (Provider p : providers) 35 | System.out.println("Found provider: " + p.getName()); 36 | 37 | this.testData = new byte[199]; 38 | 39 | Random random = new Random(System.currentTimeMillis()); 40 | 41 | random.nextBytes(this.testData); 42 | } 43 | 44 | public void tearDown() { 45 | this.provider.cleanup(); 46 | this.provider = null; 47 | this.testData = null; 48 | Security.removeProvider("OpenSC-PKCS11"); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /pkcs11-test/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | #### Use two appenders, one to log to console, another to log to a file 5 | log4j.rootCategory=INFO, R 6 | 7 | # Print only messages of priority WARN or higher for your category 8 | log4j.category.org.opensc=DEBUG 9 | # Specifically inherit the priority level 10 | #log4j.category.your.category.name=INHERITED 11 | 12 | #### First appender writes to console 13 | log4j.appender.R=org.apache.log4j.ConsoleAppender 14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 15 | 16 | # Pattern to output the caller's file name and line number. 17 | log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 18 | -------------------------------------------------------------------------------- /pkcs11/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pkcs11/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | pkcs11 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.maven.ide.eclipse.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /pkcs11/TODO: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | # Author: Wolfgang Glas / ev-i Informationstechnologie GmbH 5 | # 6 | 7 | - Test key pair generation and storing of certificates, which 8 | involve presenting a SO pin to the card. 9 | 10 | - Implement more ciphers, key unwrapping et al. 11 | -------------------------------------------------------------------------------- /pkcs11/conf/eclipse/classpath.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /pkcs11/conf/eclipse/project.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | opensc-PKCS11 4 | PKCS#11 provider of the opensc project. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | -------------------------------------------------------------------------------- /pkcs11/conf/keystore/README: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | OpenCS PKCS#11 provider keystore. 5 | 6 | If you like to deliver a binary packge of the OpenSC PKCS#11 provider 7 | you must get hold of the keystore, which provides the code signing 8 | certificate for the OpenSC project. 9 | 10 | Most likely, you should have gained SVN write access to the OpenSC 11 | repositories by contacting the opensc-devel mailing lists and by 12 | actively contributing code to the OpenSC project. 13 | 14 | If you have SVN write access, you might ask Andreas Jellinghaus for 15 | providing you the follwing two files, which comprise the OpenSC 16 | keystore: opensc-pkcs11.keystore, opensc-pks11.txt 17 | 18 | Additionally you have to set up sour ~/.m2/settings.xml file in 19 | the following manner: 20 | 21 | 22 | /home/wglas/.m2/repository 23 | 24 | 25 | opensc-pkcs11-sign 26 | 27 | opensc-pkcs11-cert 28 | xxxxxxxxxxx 29 | xxxxxxxxxxx 30 | path_of_opensc-pkcs11_keystore 31 | 32 | 33 | 34 | 35 | opensc-pkcs11-sign 36 | 37 | 38 | 39 | The passphrases are of course secret ;-) 40 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/spec/PKCS11KeyPairGenParams.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jan 25, 2007 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.spec; 27 | 28 | import java.security.KeyStore.LoadStoreParameter; 29 | import java.security.spec.DSAParameterSpec; 30 | import java.security.spec.RSAKeyGenParameterSpec; 31 | 32 | import javax.crypto.spec.DHGenParameterSpec; 33 | 34 | import org.opensc.pkcs11.spi.PKCS11KeyPairGeneratorSpi; 35 | 36 | /** 37 | * This interface is implemented by all subclasses of 38 | * {@link RSAKeyGenParameterSpec}, {@link DSAParameterSpec} or 39 | * {@link DHGenParameterSpec} which are used to initialize a key 40 | * pair generator. 41 | * 42 | * @see PKCS11KeyPairGeneratorSpi 43 | * 44 | * @author wglas 45 | */ 46 | public interface PKCS11KeyPairGenParams extends PKCS11PrivateKeyGenParams, PKCS11PublicKeyGenParams 47 | { 48 | /** 49 | * @param loadStoreParameter An optional {@link LoadStoreParameter} setting for 50 | * opening a PKCS11 session in contexts, which require opening 51 | * a new session is required. 52 | */ 53 | void setLoadStoreParameter(LoadStoreParameter loadStoreParameter); 54 | 55 | /** 56 | * @return The optional LoadStoreParameter settings. 57 | */ 58 | LoadStoreParameter getLoadStoreParameter(); 59 | } 60 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11DSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 29, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.wrap; 27 | 28 | import java.math.BigInteger; 29 | import java.security.interfaces.DSAParams; 30 | import java.security.interfaces.DSAPrivateKey; 31 | import java.security.spec.DSAParameterSpec; 32 | 33 | /** 34 | * @author wglas 35 | * 36 | * A DSA private key stored on the token. 37 | */ 38 | public class PKCS11DSAPrivateKey extends PKCS11PrivateKey implements 39 | DSAPrivateKey 40 | { 41 | /** 42 | * To be changed upon class layout change. 43 | */ 44 | private static final long serialVersionUID = 7732884476852711287L; 45 | 46 | BigInteger x; 47 | DSAParams params; 48 | 49 | /** 50 | * @param session The PKCS#11 session to which we belong. 51 | * @param handle The object handle for this key. 52 | * @throws PKCS11Exception Upon errors when retrieving the data from the token. 53 | */ 54 | protected PKCS11DSAPrivateKey(PKCS11Session session, long handle) 55 | throws PKCS11Exception 56 | { 57 | super(session, CKK_DSA, true, handle); 58 | 59 | byte [] raw_x = getRawAttribute(PKCS11Attribute.CKA_VALUE); 60 | this.x = new BigInteger(raw_x); 61 | 62 | raw_x = getRawAttribute(PKCS11Attribute.CKA_PRIME); 63 | BigInteger p = new BigInteger(raw_x); 64 | 65 | raw_x = getRawAttribute(PKCS11Attribute.CKA_SUBPRIME); 66 | BigInteger q = new BigInteger(raw_x); 67 | 68 | raw_x = getRawAttribute(PKCS11Attribute.CKA_BASE); 69 | BigInteger g = new BigInteger(raw_x); 70 | 71 | this.params = new DSAParameterSpec(p,q,g); 72 | } 73 | 74 | /* (non-Javadoc) 75 | * @see java.security.interfaces.DSAPrivateKey#getX() 76 | */ 77 | public BigInteger getX() 78 | { 79 | return this.x; 80 | } 81 | 82 | /* (non-Javadoc) 83 | * @see java.security.interfaces.DSAKey#getParams() 84 | */ 85 | public DSAParams getParams() 86 | { 87 | return this.params; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11DSAPublicKey.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 29, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.wrap; 27 | 28 | import java.math.BigInteger; 29 | import java.security.interfaces.DSAParams; 30 | import java.security.interfaces.DSAPublicKey; 31 | import java.security.spec.DSAParameterSpec; 32 | 33 | /** 34 | * @author wglas 35 | * 36 | * A DSA public key stored on the token. 37 | */ 38 | public class PKCS11DSAPublicKey extends PKCS11PublicKey implements DSAPublicKey 39 | { 40 | /** 41 | * To be changed upon class layout change. 42 | */ 43 | private static final long serialVersionUID = 7040719151736883760L; 44 | 45 | BigInteger y; 46 | DSAParams params; 47 | 48 | /** 49 | * @param session 50 | * @param type 51 | * @param handle 52 | * @throws PKCS11Exception 53 | */ 54 | protected PKCS11DSAPublicKey(PKCS11Session session, long handle) 55 | throws PKCS11Exception 56 | { 57 | super(session, CKK_DSA, handle); 58 | 59 | byte [] raw_x = getRawAttribute(PKCS11Attribute.CKA_VALUE); 60 | this.y = new BigInteger(raw_x); 61 | 62 | raw_x = getRawAttribute(PKCS11Attribute.CKA_PRIME); 63 | BigInteger p = new BigInteger(raw_x); 64 | 65 | raw_x = getRawAttribute(PKCS11Attribute.CKA_SUBPRIME); 66 | BigInteger q = new BigInteger(raw_x); 67 | 68 | raw_x = getRawAttribute(PKCS11Attribute.CKA_BASE); 69 | BigInteger g = new BigInteger(raw_x); 70 | 71 | this.params = new DSAParameterSpec(p,q,g); 72 | } 73 | 74 | /* (non-Javadoc) 75 | * @see java.security.interfaces.DSAPublicKey#getY() 76 | */ 77 | public BigInteger getY() 78 | { 79 | return this.y; 80 | } 81 | 82 | /* (non-Javadoc) 83 | * @see java.security.interfaces.DSAKey#getParams() 84 | */ 85 | public DSAParams getParams() 86 | { 87 | return this.params; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11NeDSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 29, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.wrap; 27 | 28 | import java.math.BigInteger; 29 | import java.security.interfaces.DSAKey; 30 | import java.security.interfaces.DSAParams; 31 | import java.security.spec.DSAParameterSpec; 32 | 33 | /** 34 | * @author wglas 35 | * 36 | * This class represents a non-extractable RSA private key stored on the token. 37 | */ 38 | public class PKCS11NeDSAPrivateKey extends PKCS11PrivateKey implements DSAKey 39 | { 40 | /** 41 | * To be changed upon class layout change. 42 | */ 43 | private static final long serialVersionUID = 6213036895770588731L; 44 | 45 | DSAParams params; 46 | 47 | /** 48 | * @param session The PKCS#11 session to which we belong. 49 | * @param handle The object handle for this key. 50 | * @throws PKCS11Exception Upon errors when retrieving the data from the token. 51 | */ 52 | public PKCS11NeDSAPrivateKey(PKCS11Session session, long handle) throws PKCS11Exception 53 | { 54 | super(session, CKK_DSA, false, handle); 55 | 56 | byte [] raw_x; 57 | 58 | raw_x = getRawAttribute(PKCS11Attribute.CKA_PRIME); 59 | BigInteger p = new BigInteger(raw_x); 60 | 61 | raw_x = getRawAttribute(PKCS11Attribute.CKA_SUBPRIME); 62 | BigInteger q = new BigInteger(raw_x); 63 | 64 | raw_x = getRawAttribute(PKCS11Attribute.CKA_BASE); 65 | BigInteger g = new BigInteger(raw_x); 66 | 67 | this.params = new DSAParameterSpec(p,q,g); 68 | 69 | } 70 | 71 | /* (non-Javadoc) 72 | * @see java.security.interfaces.DSAKey#getParams() 73 | */ 74 | public DSAParams getParams() 75 | { 76 | return this.params; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11NeRSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 29, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.wrap; 27 | 28 | import java.math.BigInteger; 29 | import java.security.interfaces.RSAKey; 30 | 31 | /** 32 | * @author wglas 33 | * 34 | * This is a non-extractable RSA private key stored on the token. 35 | */ 36 | public class PKCS11NeRSAPrivateKey extends PKCS11PrivateKey implements RSAKey 37 | { 38 | /** 39 | * To be changed upon class layout change. 40 | */ 41 | private static final long serialVersionUID = 717071262806506219L; 42 | 43 | BigInteger modulus; 44 | 45 | /** 46 | * @param session The PKCS#11 session to which we belong. 47 | * @param handle The object handle for this key. 48 | * @throws PKCS11Exception Upon errors when retrieving the data from the token. 49 | */ 50 | protected PKCS11NeRSAPrivateKey(PKCS11Session session, long handle) throws PKCS11Exception 51 | { 52 | super(session, CKK_RSA, false, handle); 53 | 54 | byte [] raw_modulus = getRawAttribute(PKCS11Attribute.CKA_MODULUS); 55 | this.modulus = new BigInteger(raw_modulus); 56 | } 57 | 58 | /* (non-Javadoc) 59 | * @see java.security.interfaces.RSAKey#getModulus() 60 | */ 61 | public BigInteger getModulus() 62 | { 63 | return this.modulus; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11RSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 29, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.wrap; 27 | 28 | import java.math.BigInteger; 29 | import java.security.interfaces.RSAPrivateKey; 30 | 31 | /** 32 | * @author wglas 33 | * 34 | * A RSA private key stored on the token. 35 | */ 36 | public class PKCS11RSAPrivateKey extends PKCS11PrivateKey implements RSAPrivateKey 37 | { 38 | /** 39 | * To be changed upon class layout change. 40 | */ 41 | private static final long serialVersionUID = 7992312719342457459L; 42 | 43 | BigInteger privateExponent; 44 | BigInteger modulus; 45 | 46 | /** 47 | * @param session The PKCS#11 session to which we belong. 48 | * @param handle The object handle for this key. 49 | * @throws PKCS11Exception Upon errors when retrieving the data from the token. 50 | */ 51 | protected PKCS11RSAPrivateKey(PKCS11Session session, long handle) 52 | throws PKCS11Exception 53 | { 54 | super(session, CKK_RSA, true, handle); 55 | 56 | byte [] raw_modulus = getRawAttribute(PKCS11Attribute.CKA_MODULUS); 57 | this.modulus = new BigInteger(raw_modulus); 58 | 59 | byte [] raw_exp = getRawAttribute(PKCS11Attribute.CKA_PRIVATE_EXPONENT); 60 | this.privateExponent = new BigInteger(raw_exp); 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see java.security.interfaces.RSAPrivateKey#getPrivateExponent() 65 | */ 66 | public BigInteger getPrivateExponent() 67 | { 68 | return this.privateExponent; 69 | } 70 | 71 | /* (non-Javadoc) 72 | * @see java.security.interfaces.RSAKey#getModulus() 73 | */ 74 | public BigInteger getModulus() 75 | { 76 | return this.modulus; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11RSAPublicKey.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 29, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.pkcs11.wrap; 27 | 28 | import java.math.BigInteger; 29 | import java.security.interfaces.RSAPublicKey; 30 | 31 | /** 32 | * @author wglas 33 | * 34 | * A RSA public key stored on the token. 35 | */ 36 | public class PKCS11RSAPublicKey extends PKCS11PublicKey implements RSAPublicKey 37 | { 38 | /** 39 | * To be changed upon class layout change. 40 | */ 41 | private static final long serialVersionUID = -3378514468395316553L; 42 | 43 | private BigInteger publicExponent; 44 | private BigInteger modulus; 45 | 46 | /** 47 | * @param session 48 | * @param type 49 | * @param handle 50 | * @throws PKCS11Exception 51 | */ 52 | protected PKCS11RSAPublicKey(PKCS11Session session, long handle) 53 | throws PKCS11Exception 54 | { 55 | super(session, CKK_RSA, handle); 56 | 57 | byte [] raw_modulus = getRawAttribute(PKCS11Attribute.CKA_MODULUS); 58 | this.modulus = new BigInteger(raw_modulus); 59 | 60 | byte [] raw_exp = getRawAttribute(PKCS11Attribute.CKA_PUBLIC_EXPONENT); 61 | this.publicExponent = new BigInteger(raw_exp); 62 | } 63 | 64 | /* (non-Javadoc) 65 | * @see java.security.interfaces.RSAPublicKey#getPublicExponent() 66 | */ 67 | public BigInteger getPublicExponent() 68 | { 69 | return this.publicExponent; 70 | } 71 | 72 | /* (non-Javadoc) 73 | * @see java.security.interfaces.RSAKey#getModulus() 74 | */ 75 | public BigInteger getModulus() 76 | { 77 | return this.modulus; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/pkcs11/wrap/PKCS11SessionChild.java: -------------------------------------------------------------------------------- 1 | package org.opensc.pkcs11.wrap; 2 | 3 | import javax.security.auth.Destroyable; 4 | 5 | /** 6 | * @author wglas 7 | * 8 | * This interface is used by any signature/decryption service, which 9 | * calls PKCS#11 operations on objects, which life in the PKCS#11 10 | * session context. 11 | */ 12 | public interface PKCS11SessionChild extends Destroyable 13 | { 14 | 15 | /** 16 | * @return Returns the C handle of the underlying provider. 17 | */ 18 | public long getPvh(); 19 | 20 | /** 21 | * @return Returns the C handle of the slot. 22 | */ 23 | public long getSlotHandle(); 24 | 25 | /** 26 | * @return Returns the C handle of the session. 27 | */ 28 | public long getSessionHandle(); 29 | 30 | /** 31 | * @return Returns the C handle of the object. 32 | */ 33 | public long getHandle(); 34 | 35 | } -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/util/DestroyableChild.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 17, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.util; 27 | 28 | import javax.security.auth.DestroyFailedException; 29 | import javax.security.auth.Destroyable; 30 | 31 | 32 | /** 33 | * A class, that is a destroyable and a child of a DestroybleParent. 34 | * 35 | * @author wglas 36 | */ 37 | public class DestroyableChild implements Destroyable 38 | { 39 | DestroyableParent parent; 40 | 41 | /** 42 | * Constructs a child with no parent. 43 | */ 44 | public DestroyableChild() 45 | { 46 | super(); 47 | this.parent = null; 48 | } 49 | 50 | /** 51 | * Constructs a child for a given parent. 52 | */ 53 | public DestroyableChild(DestroyableParent parent) 54 | { 55 | super(); 56 | this.parent = parent; 57 | parent.register(this); 58 | } 59 | 60 | /** 61 | * Used internally by DEstroyableHodler.destroy in order tp 62 | * avoid double acces to a Colletion. 63 | */ 64 | protected final void unlink() 65 | { 66 | this.parent = null; 67 | } 68 | 69 | /* (non-Javadoc) 70 | * @see javax.security.auth.Destroyable#destroy() 71 | */ 72 | public void destroy() throws DestroyFailedException 73 | { 74 | if (this.parent==null) return; 75 | 76 | this.parent.deregister(this); 77 | this.parent = null; 78 | } 79 | 80 | /* (non-Javadoc) 81 | * @see javax.security.auth.Destroyable#isDestroyed() 82 | */ 83 | public boolean isDestroyed() 84 | { 85 | return this.parent==null; 86 | } 87 | 88 | /** 89 | * @return Returns the parent. 90 | */ 91 | public DestroyableParent getParent() 92 | { 93 | return this.parent; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/util/DestroyableHolder.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 17, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.util; 27 | 28 | import java.util.HashSet; 29 | import java.util.Set; 30 | 31 | import javax.security.auth.DestroyFailedException; 32 | import javax.security.auth.Destroyable; 33 | 34 | 35 | /** 36 | * This class holds a map of destroyables, which will be 37 | * destroyed recursively. 38 | * 39 | * @author wglas 40 | */ 41 | public class DestroyableHolder extends DestroyableChild implements DestroyableParent 42 | { 43 | private Set children; 44 | 45 | /** 46 | * Constructs a holder without a parent. 47 | */ 48 | public DestroyableHolder() 49 | { 50 | super(); 51 | this.children = null; 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see org.opensc.pkcs11.util.DestroyableParent#register(javax.security.auth.Destroyable) 56 | */ 57 | public void register(Destroyable destroyable) 58 | { 59 | if (this.children == null) 60 | this.children = new HashSet(); 61 | 62 | this.children.add(destroyable); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see org.opensc.pkcs11.util.DestroyableParent#deregister(javax.security.auth.Destroyable) 67 | */ 68 | public void deregister(Destroyable destroyable) 69 | { 70 | if (this.children == null) return; 71 | 72 | this.children.remove(destroyable); 73 | } 74 | 75 | /** 76 | * Constructs a holder with a parent. 77 | */ 78 | public DestroyableHolder(DestroyableParent parent) 79 | { 80 | super(parent); 81 | this.children = null; 82 | } 83 | 84 | /* (non-Javadoc) 85 | * @see javax.security.auth.Destroyable#destroy() 86 | */ 87 | public void destroy() throws DestroyFailedException 88 | { 89 | if (this.children != null) 90 | { 91 | for (Destroyable destroyable : this.children) 92 | { 93 | if (destroyable.isDestroyed()) continue; 94 | 95 | if (destroyable instanceof DestroyableChild) 96 | ((DestroyableChild)destroyable).unlink(); 97 | 98 | destroyable.destroy(); 99 | } 100 | 101 | this.children = null; 102 | } 103 | super.destroy(); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/util/DestroyableParent.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 17, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.util; 27 | 28 | import javax.security.auth.Destroyable; 29 | 30 | /** 31 | * This interface is omplemented by all classes, which act as a parent 32 | * for Destroyables. 33 | * 34 | * @author wglas 35 | */ 36 | public interface DestroyableParent 37 | { 38 | 39 | /** 40 | * Register a Destroyable for recursive destruction. 41 | * 42 | * @param destroyable The child to be registered. 43 | */ 44 | public void register(Destroyable destroyable); 45 | 46 | /** 47 | * Deregister a Destroyable from recursive destruction. 48 | * 49 | * @param destroyable The child to be deregistered. 50 | */ 51 | public void deregister(Destroyable destroyable); 52 | 53 | } -------------------------------------------------------------------------------- /pkcs11/java/src/org/opensc/util/Util.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS11 provider of the OpenSC project http://www.opensc-project.org 5 | * 6 | * Copyright (C) 2002-2006 ev-i Informationstechnologie GmbH 7 | * 8 | * Created: Jul 17, 2006 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | * 24 | ***********************************************************/ 25 | 26 | package org.opensc.util; 27 | 28 | import java.nio.ByteBuffer; 29 | import java.nio.CharBuffer; 30 | import java.nio.charset.Charset; 31 | 32 | /** 33 | * Utilitiy functions for implementing PKCS11 wrappers. 34 | * 35 | * @author wglas 36 | */ 37 | public class Util 38 | { 39 | /** 40 | * private constructor, because we only define static public methods. 41 | */ 42 | private Util() 43 | { 44 | super(); 45 | } 46 | 47 | /** 48 | * Translate a character array to an utf-8 encoded byte array. 49 | * 50 | * @param pin The chracter array. 51 | * @return The UTF-8 encoded byte-equivalent. 52 | */ 53 | public static byte[] translatePin(char[] pin) 54 | { 55 | if (pin == null) return null; 56 | Charset charset = Charset.forName("UTF-8"); 57 | CharBuffer cb = CharBuffer.wrap(pin); 58 | ByteBuffer bb = charset.encode(cb); 59 | return bb.array(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pkcs11/jni/build/mingw/debug/config.data: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: config.data.default,v 1.2 2005/09/16 07:39:04 wglas Exp $ 3 | # 4 | # makefile variable settings for mingw. 5 | # 6 | ac DEFS=-DHAVE_CONFIG_H -DWIN32 -D_WIN32 -D_WINDOWS -D_MBCS -D_WIN32_WINNT=0x501 7 | ac LIBS= 8 | ac CFLAGS=-g -Wall -mthreads 9 | ac LDFLAGS=-mthreads 10 | ac NCLDFLAGS=-Wl,-subsystem,windows -mthreads 11 | ac EXEEXT=.exe 12 | ac CXXFLAGS=-g -Wall -mthreads 13 | ac RC=windres 14 | ac LIBDYN=dll 15 | ac LIBDYNPFX= 16 | ac DYN_LDFLAGS=-shared -Wl,--dll 17 | ac DYN_CFLAGS= 18 | ac PKCS11_CFLAGS= 19 | ac PKCS11_LDFLAGS= 20 | ac PKCS11_LIBS=-lkernel32 21 | ac prefix=/c/Programme/ev-i 22 | ac JNI_CFLAGS=-I$(subst \,/,$(JAVA_HOME)/include) -I$(subst \,/,$(JAVA_HOME))/include/win32 23 | -------------------------------------------------------------------------------- /pkcs11/jni/build/mingw/release/config.data: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: config.data.default,v 1.2 2005/09/16 07:39:04 wglas Exp $ 3 | # 4 | # makefile variable settings for mingw. 5 | # 6 | ac DEFS=-DHAVE_CONFIG_H -DWIN32 -D_WIN32 -D_WINDOWS -D_MBCS -D_WIN32_WINNT=0x501 7 | ac LIBS= 8 | ac CFLAGS=-O2 -Wall -mthreads 9 | ac LDFLAGS=-mthreads 10 | ac NCLDFLAGS=-Wl,-subsystem,windows -mthreads 11 | ac EXEEXT=.exe 12 | ac CXXFLAGS=-O2 -Wall -mthreads 13 | ac RC=windres 14 | ac LIBDYN=dll 15 | ac LIBDYNPFX= 16 | ac DYN_LDFLAGS=-shared -Wl,--dll 17 | ac DYN_CFLAGS= 18 | ac PKCS11_CFLAGS="-I/c/Programme/Smart Card Bundle/include" 19 | ac PKCS11_LDFLAGS= 20 | ac PKCS11_LIBS=-lkernel32 21 | ac prefix=/c/Programme/ev-i 22 | ac JNI_CFLAGS=-I$(subst \,/,$(JAVA_HOME)/include) -I$(subst \,/,$(JAVA_HOME))/include/win32 23 | -------------------------------------------------------------------------------- /pkcs11/jni/build/msvc6/README.txt: -------------------------------------------------------------------------------- 1 | Compiling opensc-PKCS11-0.2.dll using MS Visual C/C++ 6.0 2 | 3 | Before you start the IDE, you will need to make sure, that two environment variables are set: 4 | 5 | JAVA_HOME must point to the root directory of your JDK installation (e.g. C:\Programme\Java\jdk1.5.0_10) 6 | 7 | Environment variables can be set using the SET command from the command shell or in the system settings 8 | 9 | -------------------------------------------------------------------------------- /pkcs11/jni/build/msvc6/openscPKCS11.dsw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenSC/OpenSC-Java/407052dfca26fa93b1e6178bb001003982df8c45/pkcs11/jni/build/msvc6/openscPKCS11.dsw -------------------------------------------------------------------------------- /pkcs11/jni/build/unix/debug/config.data: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: config.data,v 1.1 2005/12/09 09:37:50 wglas Exp $ 3 | # 4 | # Default makefile variable settings. 5 | # 6 | ac CFLAGS=-g -Wall 7 | ac CXXFLAGS=-g -Wall 8 | -------------------------------------------------------------------------------- /pkcs11/jni/build/unix/release/config.data: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: config.data,v 1.1 2005/12/09 09:37:50 wglas Exp $ 3 | # 4 | # Default makefile variable settings. 5 | # 6 | ac CFLAGS=-O2 -Wall 7 | ac CXXFLAGS=-O2 -Wall 8 | -------------------------------------------------------------------------------- /pkcs11/jni/src/Makefile.in: -------------------------------------------------------------------------------- 1 | # 2 | # toplevel Makefile 3 | # 4 | 5 | SUBDIRS=@SUBDIRS@ 6 | srcdir = @srcdir@ 7 | 8 | all: Makefile bin 9 | 10 | install: Makefile bin-install 11 | 12 | bin: 13 | $(MAKE) bin-recursive 14 | 15 | bin-install: 16 | $(MAKE) bin-install-recursive 17 | 18 | Makefile: $(srcdir)/Makefile.in 19 | echo "Updating out-of-date Makefiles..." 20 | ./reconfigure.sh 21 | 22 | clean: Makefile 23 | rm -f *~ \#* .*~ *.bak .*.bak core 24 | for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done 25 | 26 | bin-recursive: 27 | for dir in $(SUBDIRS); do $(MAKE) -C $$dir; done 28 | 29 | bin-install-recursive: 30 | for dir in $(SUBDIRS); do $(MAKE) -C $$dir install; done 31 | 32 | distclean: 33 | rm -f *~ \#* .*~ *.bak .*.bak core 34 | rm -f config.h reconfigure.sh 35 | rm -f Makefile 36 | for dir in $(SUBDIRS); do $(MAKE) -C $$dir distclean; rmdir $$dir; done 37 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/Makefile.in: -------------------------------------------------------------------------------- 1 | srcdir = @srcdir@ 2 | top_srcdir = @top_srcdir@ 3 | 4 | # The API version. 5 | # This value has to correspond to the value of version in build.xml 6 | VERSION=0.3 7 | 8 | # Where does the installation go ? 9 | PREFIX=@prefix@ 10 | DESTDIR=@DESTDIR@ 11 | LIBSUBDIR=@LIBSUBDIR@ 12 | BINDIR=$(DESTDIR)$(PREFIX)/bin 13 | LIBDIR=$(DESTDIR)$(PREFIX)/$(LIBSUBDIR) 14 | INCLUDEDIR=$(DESTDIR)$(PREFIX)/include 15 | 16 | # filename conventions 17 | EXE=@EXEEXT@ 18 | OBJ=@OBJEXT@ 19 | 20 | # compilers used. 21 | LIBDYNPFX=@LIBDYNPFX@ 22 | LIBDYN=@LIBDYN@ 23 | 24 | LIBPFX=@LIBPFX@ 25 | LIBEXT=@LIBEXT@ 26 | 27 | CC = @CC@ 28 | CXX = @CXX@ 29 | LD = @CC@ 30 | STRIP = @STRIP@ 31 | 32 | # add -I.. in order to find config.h 33 | CFLAGS = \ 34 | @CFLAGS@ @DEFS@ @PKCS11_CFLAGS@ @JNI_CFLAGS@ @DYN_CFLAGS@ -I.. -I$(srcdir) -I$(top_srcdir)/jnix 35 | 36 | CXXFLAGS = \ 37 | @CXXFLAGS@ @DEFS@ @PKCS11_CFLAGS@ @JNI_CFLAGS@ @DYN_CFLAGS@ -I.. -I$(srcdir) -I$(top_srcdir)/jnix 38 | 39 | LDFLAGS = @LDFLAGS@ @PKCS11_LDFLAGS@ @JNI_LDFLAGS@ @DYN_LDFLAGS@ 40 | 41 | LIBS=@PKCS11_LIBS@ @JNI_LIBS@ @LIBS@ 42 | 43 | #libraries, which are in the same source tree. 44 | BASELIBRARIES=../jnix/$(LIBPFX)jnix.$(LIBEXT) 45 | 46 | %.depend: $(srcdir)/%.c 47 | $(CC) $(CFLAGS) -M $< -o $@ 48 | 49 | %.depend: $(srcdir)/%.cpp 50 | $(CXX) $(CXXFLAGS) -M $< -o $@ 51 | 52 | %.depend: %.cc 53 | $(CXX) $(CXXFLAGS) -M $< -o $@ 54 | 55 | %.$(OBJ): $(srcdir)/%.c 56 | $(CC) $(CFLAGS) -c $< -o $@ 57 | 58 | %.$(OBJ): $(srcdir)/%.cpp 59 | $(CXX) $(CXXFLAGS) -c $< -o $@ 60 | 61 | %.$(OBJ): %.cc 62 | $(CXX) $(CXXFLAGS) -c $< -o $@ 63 | 64 | # 65 | # objects 66 | # 67 | JNIOBJECTS = org_opensc_pkcs11_PKCS11Provider.$(OBJ) \ 68 | org_opensc_pkcs11_wrap_PKCS11Slot.$(OBJ) \ 69 | org_opensc_pkcs11_wrap_PKCS11Session.$(OBJ) \ 70 | org_opensc_pkcs11_wrap_PKCS11Object.$(OBJ) \ 71 | org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator.$(OBJ) \ 72 | org_opensc_pkcs11_spi_PKCS11SignatureSpi.$(OBJ) \ 73 | org_opensc_pkcs11_spi_PKCS11CipherSpi.$(OBJ) \ 74 | pkcs11_module.$(OBJ) \ 75 | pkcs11_slot.$(OBJ) \ 76 | pkcs11_error.$(OBJ) 77 | 78 | ALLOBJECTS=$(JNIOBJECTS) 79 | 80 | LIBRARY = $(LIBDYNPFX)opensc-PKCS11-$(VERSION).$(LIBDYN) 81 | 82 | all: Makefile build-dep 83 | 84 | Makefile: $(srcdir)/Makefile.in 85 | echo "Updating out-of-date Makefiles..." 86 | ../reconfigure.sh 87 | 88 | build-dep: 89 | $(MAKE) dep=yes build 90 | 91 | build: $(LIBRARY) 92 | 93 | clean:: 94 | rm -f *.depend *.$(OBJ) *~ *.bak .*~ .*.bak core $(LIBRARY) 95 | 96 | distclean:: clean 97 | rm -f Makefile 98 | 99 | 100 | foo: 101 | 102 | ../jnix/$(LIBPFX)jnix.$(LIBEXT): foo 103 | $(MAKE) -C ../jnix $(LIBPFX)jnix.$(LIBEXT) 104 | 105 | $(LIBRARY): $(BASELIBRARIES) $(JNIOBJECTS) 106 | rm -f $@ 107 | $(LD) $(LDFLAGS) $(JNIOBJECTS) $(BASELIBRARIES) $(LIBS) -o $@ 108 | 109 | install: all 110 | mkdir -p $(LIBDIR) 111 | cp $(LIBRARY) $(LIBDIR) 112 | chmod 775 $(LIBDIR)/$(LIBRARY) 113 | strip $(LIBDIR)/$(LIBRARY) 114 | 115 | # 116 | # dependencies 117 | # 118 | ifeq ($(dep),yes) 119 | include $(addsuffix .depend, $(basename $(ALLOBJECTS))) 120 | endif 121 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/jniP11private.h: -------------------------------------------------------------------------------- 1 | /* jniP11, a JCE cryptographic povider in top of PKCS#11 API 2 | * 3 | * Copyright (C) 2006 by ev-i Informationstechnologie GmbH www.ev-i.at 4 | * 5 | * Many code-snippets imported from libp11, which is 6 | * 7 | * Copyright (C) 2005 Olaf Kirch 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | #ifndef __JNI_P11_PRIVATE_H__ 24 | #define __JNI_P11_PRIVATE_H__ 1 25 | 26 | #include 27 | #include 28 | 29 | typedef struct pkcs11_module_st pkcs11_module_t; 30 | 31 | #define PKCS11_MODULE_MAGIC 0xd0bed0be 32 | 33 | #ifdef WIN32 34 | #define PKCS11_MOD_NAME_FMT "%S" 35 | #else 36 | #define PKCS11_MOD_NAME_FMT "%s" 37 | #endif 38 | 39 | struct pkcs11_module_st 40 | { 41 | int _magic; 42 | #ifdef WIN32 43 | wchar_t *name; 44 | #else 45 | char *name; 46 | #endif 47 | CK_INFO ck_info; 48 | CK_FUNCTION_LIST_PTR method; 49 | void *handle; 50 | 51 | }; 52 | 53 | typedef struct pkcs11_slot_st pkcs11_slot_t; 54 | 55 | #define PKCS11_SLOT_MAGIC 0x0bed0bed 56 | 57 | struct pkcs11_slot_st 58 | { 59 | int _magic; 60 | CK_SLOT_ID id; 61 | CK_SLOT_INFO ck_slot_info; 62 | CK_TOKEN_INFO ck_token_info; 63 | }; 64 | 65 | /* functions in pkcs11_error.c */ 66 | const char JNIX_INTERNAL_API * pkcs11_strerror(int rv); 67 | 68 | /* functions in pkcs11_module.c */ 69 | pkcs11_module_t JNIX_INTERNAL_API * new_pkcs11_module(JNIEnv *env, jstring filename); 70 | 71 | jlong JNIX_INTERNAL_API pkcs11_module_to_jhandle(JNIEnv *env, pkcs11_module_t *mod); 72 | pkcs11_module_t JNIX_INTERNAL_API * pkcs11_module_from_jhandle(JNIEnv *env, jlong handle); 73 | 74 | void JNIX_INTERNAL_API destroy_pkcs11_module(JNIEnv *env, pkcs11_module_t *mod); 75 | 76 | /* functions in pkcs11_slot.c */ 77 | pkcs11_slot_t JNIX_INTERNAL_API * new_pkcs11_slot(JNIEnv *env, pkcs11_module_t *mod, CK_SLOT_ID id); 78 | 79 | jlong JNIX_INTERNAL_API pkcs11_slot_to_jhandle(JNIEnv *env, pkcs11_slot_t *mod); 80 | pkcs11_slot_t JNIX_INTERNAL_API * pkcs11_slot_from_jhandle(JNIEnv *env, jlong handle); 81 | 82 | void JNIX_INTERNAL_API destroy_pkcs11_slot(JNIEnv *env, pkcs11_module_t *mod, pkcs11_slot_t *slot); 83 | 84 | jobjectArray JNIX_INTERNAL_API pkcs11_slot_make_jmechanisms(JNIEnv *env, pkcs11_module_t *mod, pkcs11_slot_t *slot, 85 | CK_MECHANISM_TYPE_PTR mechanisms, CK_ULONG n_mechanisms); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/mk_headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id$ 4 | # 5 | # Author: Wolfgang Glas/ev-i 6 | # 7 | # This script updates the C header files and should be 8 | # executed each time you update the JNI function interfaces 9 | # in the JAVA classes org.opensc.pkcs11.* 10 | # 11 | 12 | classes="org.opensc.pkcs11.PKCS11Provider \ 13 | org.opensc.pkcs11.wrap.PKCS11Slot \ 14 | org.opensc.pkcs11.wrap.PKCS11Session \ 15 | org.opensc.pkcs11.wrap.PKCS11Object \ 16 | org.opensc.pkcs11.wrap.PKCS11KeyPairGenerator \ 17 | org.opensc.pkcs11.spi.PKCS11SignatureSpi \ 18 | org.opensc.pkcs11.spi.PKCS11CipherSpi" 19 | 20 | for class in $classes 21 | do 22 | 23 | file=`echo $class | sed 's/\./_/g'` 24 | 25 | $JAVA_HOME/bin/javah -classpath ../../../java/bin -d . $class 26 | rm -f ${file}_*.h 27 | 28 | mv $file.h $file.h~ 29 | sed -e 's/JNICALL Java_\([a-zA-Z0-9_]*\)/JNICALL JNIX_FUNC_NAME(Java_\1)/' -e 's/#include /#include /' < $file.h~ > $file.h 30 | done 31 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/org_opensc_pkcs11_PKCS11Provider.c: -------------------------------------------------------------------------------- 1 | /* jniP11, a JCE cryptographic povider in top of PKCS#11 API 2 | * 3 | * Copyright (C) 2006 by ev-i Informationstechnologie GmbH www.ev-i.at 4 | * 5 | * Many code-snippets imported from libp11, which is 6 | * 7 | * Copyright (C) 2005 Olaf Kirch 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | 26 | #include 27 | 28 | /* 29 | * Class: org_opensc_pkcs11_PKCS11Provider 30 | * Method: loadPKCS11Module 31 | * Signature: ([B)J 32 | */ 33 | jlong JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_PKCS11Provider_loadNativePKCS11Module) 34 | (JNIEnv *env, jobject provider, jstring filename) 35 | { 36 | pkcs11_module_t *mod = new_pkcs11_module(env,filename); 37 | 38 | if (!mod) return 0; 39 | 40 | return pkcs11_module_to_jhandle(env,mod); 41 | } 42 | 43 | /* 44 | * Class: org_opensc_pkcs11_PKCS11Provider 45 | * Method: unloadPKCS11Module 46 | * Signature: (J)V 47 | */ 48 | void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_PKCS11Provider_unloadPKCS11Module) 49 | (JNIEnv *env, jobject provider, jlong handle) 50 | { 51 | pkcs11_module_t *mod = pkcs11_module_from_jhandle(env,handle); 52 | 53 | if (!mod) return; 54 | 55 | destroy_pkcs11_module(env,mod); 56 | } 57 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/org_opensc_pkcs11_PKCS11Provider.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class org_opensc_pkcs11_PKCS11Provider */ 4 | 5 | #ifndef _Included_org_opensc_pkcs11_PKCS11Provider 6 | #define _Included_org_opensc_pkcs11_PKCS11Provider 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef org_opensc_pkcs11_PKCS11Provider_serialVersionUID 11 | #define org_opensc_pkcs11_PKCS11Provider_serialVersionUID 1421746759512286392LL 12 | #undef org_opensc_pkcs11_PKCS11Provider_KEYS 13 | #define org_opensc_pkcs11_PKCS11Provider_KEYS 0L 14 | #undef org_opensc_pkcs11_PKCS11Provider_VALUES 15 | #define org_opensc_pkcs11_PKCS11Provider_VALUES 1L 16 | #undef org_opensc_pkcs11_PKCS11Provider_ENTRIES 17 | #define org_opensc_pkcs11_PKCS11Provider_ENTRIES 2L 18 | #undef org_opensc_pkcs11_PKCS11Provider_serialVersionUID 19 | #define org_opensc_pkcs11_PKCS11Provider_serialVersionUID 4112578634029874840LL 20 | #undef org_opensc_pkcs11_PKCS11Provider_serialVersionUID 21 | #define org_opensc_pkcs11_PKCS11Provider_serialVersionUID -4298000515446427739LL 22 | #undef org_opensc_pkcs11_PKCS11Provider_serialVersionUID 23 | #define org_opensc_pkcs11_PKCS11Provider_serialVersionUID -2568219416560640437LL 24 | #undef org_opensc_pkcs11_PKCS11Provider_version 25 | #define org_opensc_pkcs11_PKCS11Provider_version 0.2 26 | #undef org_opensc_pkcs11_PKCS11Provider_patchlevel 27 | #define org_opensc_pkcs11_PKCS11Provider_patchlevel 0.0 28 | /* 29 | * Class: org_opensc_pkcs11_PKCS11Provider 30 | * Method: loadNativePKCS11Module 31 | * Signature: (Ljava/lang/String;)J 32 | */ 33 | JNIEXPORT jlong JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_PKCS11Provider_loadNativePKCS11Module) 34 | (JNIEnv *, jobject, jstring); 35 | 36 | /* 37 | * Class: org_opensc_pkcs11_PKCS11Provider 38 | * Method: unloadPKCS11Module 39 | * Signature: (J)V 40 | */ 41 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_PKCS11Provider_unloadPKCS11Module) 42 | (JNIEnv *, jobject, jlong); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif 48 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/org_opensc_pkcs11_spi_PKCS11SignatureSpi.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class org_opensc_pkcs11_spi_PKCS11SignatureSpi */ 4 | 5 | #ifndef _Included_org_opensc_pkcs11_spi_PKCS11SignatureSpi 6 | #define _Included_org_opensc_pkcs11_spi_PKCS11SignatureSpi 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 12 | * Method: initSignNative 13 | * Signature: (JJJJI)V 14 | */ 15 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_initSignNative) 16 | (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jint); 17 | 18 | /* 19 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 20 | * Method: updateSignNative 21 | * Signature: (JJJ[BII)V 22 | */ 23 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_updateSignNative) 24 | (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray, jint, jint); 25 | 26 | /* 27 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 28 | * Method: updateSignNative1 29 | * Signature: (JJJB)V 30 | */ 31 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_updateSignNative1) 32 | (JNIEnv *, jobject, jlong, jlong, jlong, jbyte); 33 | 34 | /* 35 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 36 | * Method: signNative 37 | * Signature: (JJJ)[B 38 | */ 39 | JNIEXPORT jbyteArray JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_signNative) 40 | (JNIEnv *, jobject, jlong, jlong, jlong); 41 | 42 | /* 43 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 44 | * Method: initVerifyNative 45 | * Signature: (JJJJI)V 46 | */ 47 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_initVerifyNative) 48 | (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jint); 49 | 50 | /* 51 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 52 | * Method: updateVerifyNative 53 | * Signature: (JJJ[BII)V 54 | */ 55 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_updateVerifyNative) 56 | (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray, jint, jint); 57 | 58 | /* 59 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 60 | * Method: updateVerifyNative1 61 | * Signature: (JJJB)V 62 | */ 63 | JNIEXPORT void JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_updateVerifyNative1) 64 | (JNIEnv *, jobject, jlong, jlong, jlong, jbyte); 65 | 66 | /* 67 | * Class: org_opensc_pkcs11_spi_PKCS11SignatureSpi 68 | * Method: verifyNative 69 | * Signature: (JJJ[B)Z 70 | */ 71 | JNIEXPORT jboolean JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_spi_PKCS11SignatureSpi_verifyNative) 72 | (JNIEnv *, jobject, jlong, jlong, jlong, jbyteArray); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | #endif 78 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator */ 4 | 5 | #ifndef _Included_org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator 6 | #define _Included_org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator_N_STATIC_PRIVATE_ATTRIBUTES 11 | #define org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator_N_STATIC_PRIVATE_ATTRIBUTES 9L 12 | #undef org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator_N_STATIC_PUBLIC_ATTRIBUTES 13 | #define org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator_N_STATIC_PUBLIC_ATTRIBUTES 4L 14 | /* 15 | * Class: org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator 16 | * Method: generateKeyPairNative 17 | * Signature: (JJJI[Lorg/opensc/pkcs11/wrap/PKCS11Attribute;[Lorg/opensc/pkcs11/wrap/PKCS11Attribute;)[J 18 | */ 19 | JNIEXPORT jlongArray JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11KeyPairGenerator_generateKeyPairNative) 20 | (JNIEnv *, jobject, jlong, jlong, jlong, jint, jobjectArray, jobjectArray); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jniP11/org_opensc_pkcs11_wrap_PKCS11Object.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class org_opensc_pkcs11_wrap_PKCS11Object */ 4 | 5 | #ifndef _Included_org_opensc_pkcs11_wrap_PKCS11Object 6 | #define _Included_org_opensc_pkcs11_wrap_PKCS11Object 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef org_opensc_pkcs11_wrap_PKCS11Object_CKO_CERTIFICATE 11 | #define org_opensc_pkcs11_wrap_PKCS11Object_CKO_CERTIFICATE 1L 12 | #undef org_opensc_pkcs11_wrap_PKCS11Object_CKO_PUBLIC_KEY 13 | #define org_opensc_pkcs11_wrap_PKCS11Object_CKO_PUBLIC_KEY 2L 14 | #undef org_opensc_pkcs11_wrap_PKCS11Object_CKO_PRIVATE_KEY 15 | #define org_opensc_pkcs11_wrap_PKCS11Object_CKO_PRIVATE_KEY 3L 16 | #undef org_opensc_pkcs11_wrap_PKCS11Object_CKO_SECRET_KEY 17 | #define org_opensc_pkcs11_wrap_PKCS11Object_CKO_SECRET_KEY 4L 18 | /* 19 | * Class: org_opensc_pkcs11_wrap_PKCS11Object 20 | * Method: enumObjectsNative 21 | * Signature: (JJJ[Lorg/opensc/pkcs11/wrap/PKCS11Attribute;)[J 22 | */ 23 | JNIEXPORT jlongArray JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11Object_enumObjectsNative) 24 | (JNIEnv *, jclass, jlong, jlong, jlong, jobjectArray); 25 | 26 | /* 27 | * Class: org_opensc_pkcs11_wrap_PKCS11Object 28 | * Method: getAttributeNative 29 | * Signature: (JJJJI)[B 30 | */ 31 | JNIEXPORT jbyteArray JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11Object_getAttributeNative) 32 | (JNIEnv *, jclass, jlong, jlong, jlong, jlong, jint); 33 | 34 | /* 35 | * Class: org_opensc_pkcs11_wrap_PKCS11Object 36 | * Method: getULongAttributeNative 37 | * Signature: (JJJJI)I 38 | */ 39 | JNIEXPORT jint JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11Object_getULongAttributeNative) 40 | (JNIEnv *, jclass, jlong, jlong, jlong, jlong, jint); 41 | 42 | /* 43 | * Class: org_opensc_pkcs11_wrap_PKCS11Object 44 | * Method: getBooleanAttributeNative 45 | * Signature: (JJJJI)Z 46 | */ 47 | JNIEXPORT jboolean JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11Object_getBooleanAttributeNative) 48 | (JNIEnv *, jclass, jlong, jlong, jlong, jlong, jint); 49 | 50 | /* 51 | * Class: org_opensc_pkcs11_wrap_PKCS11Object 52 | * Method: getAllowedMechanismsNative 53 | * Signature: (JJJJ)[Lorg/opensc/pkcs11/wrap/PKCS11Mechanism; 54 | */ 55 | JNIEXPORT jobjectArray JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11Object_getAllowedMechanismsNative) 56 | (JNIEnv *, jclass, jlong, jlong, jlong, jlong); 57 | 58 | /* 59 | * Class: org_opensc_pkcs11_wrap_PKCS11Object 60 | * Method: createObjectNative 61 | * Signature: (JJJ[Lorg/opensc/pkcs11/wrap/PKCS11Attribute;)J 62 | */ 63 | JNIEXPORT jlong JNICALL JNIX_FUNC_NAME(Java_org_opensc_pkcs11_wrap_PKCS11Object_createObjectNative) 64 | (JNIEnv *, jclass, jlong, jlong, jlong, jobjectArray); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | #endif 70 | -------------------------------------------------------------------------------- /pkcs11/jni/src/jnix/Makefile.in: -------------------------------------------------------------------------------- 1 | srcdir = @srcdir@ 2 | top_srcdir = @top_srcdir@ 3 | 4 | # Where does the installation go ? 5 | PREFIX=@prefix@ 6 | DESTDIR=@DESTDIR@ 7 | LIBSUBDIR=@LIBSUBDIR@ 8 | BINDIR=$(DESTDIR)$(PREFIX)/bin 9 | LIBDIR=$(DESTDIR)$(PREFIX)/$(LIBSUBDIR) 10 | INCLUDEDIR=$(DESTDIR)$(PREFIX)/include 11 | 12 | # filename conventions 13 | EXE=@EXEEXT@ 14 | OBJ=@OBJEXT@ 15 | 16 | # compilers used. 17 | LIBPFX=@LIBPFX@ 18 | LIBEXT=@LIBEXT@ 19 | 20 | CC = @CC@ 21 | CXX = @CXX@ 22 | LD = @CXX@ 23 | AR = @AR@ 24 | ARFLAGS = @ARFLAGS@ 25 | 26 | # add -I.. in order to find config.h 27 | CFLAGS = \ 28 | @CFLAGS@ @DEFS@ @JNI_CFLAGS@ @DYN_CFLAGS@ -I.. -I$(srcdir) 29 | 30 | CXXFLAGS = \ 31 | @CXXFLAGS@ @DEFS@ @JNI_CFLAGS@ @DYN_CFLAGS@ -I.. -I$(srcdir) 32 | 33 | %.depend: $(srcdir)/%.c 34 | $(CC) $(CFLAGS) -M $< -o $@ 35 | 36 | %.depend: $(srcdir)/%.cpp 37 | $(CXX) $(CXXFLAGS) -M $< -o $@ 38 | 39 | %.depend: %.cc 40 | $(CXX) $(CXXFLAGS) -M $< -o $@ 41 | 42 | %.$(OBJ): $(srcdir)/%.c 43 | $(CC) $(CFLAGS) -c $< -o $@ 44 | 45 | %.$(OBJ): $(srcdir)/%.cpp 46 | $(CXX) $(CXXFLAGS) -c $< -o $@ 47 | 48 | %.$(OBJ): %.cc 49 | $(CXX) $(CXXFLAGS) -c $< -o $@ 50 | 51 | # 52 | # objects 53 | # 54 | JNIOBJECTS = jnix.$(OBJ) 55 | 56 | ALLOBJECTS=$(JNIOBJECTS) 57 | 58 | LIBRARY = $(LIBPFX)jnix.$(LIBEXT) 59 | 60 | all: Makefile build-dep 61 | 62 | Makefile: $(srcdir)/Makefile.in 63 | echo "Updating out-of-date Makefiles..." 64 | ../reconfigure.sh 65 | 66 | build-dep: 67 | $(MAKE) dep=yes build 68 | 69 | build: $(LIBRARY) 70 | 71 | clean:: 72 | rm -f *.depend *.$(OBJ) *~ *.bak .*~ .*.bak core $(LIBRARY) 73 | 74 | distclean:: clean 75 | rm -f Makefile 76 | 77 | $(LIBRARY): $(JNIOBJECTS) 78 | rm -f $@ 79 | $(AR) $(ARFLAGS) $@ $(JNIOBJECTS) 80 | 81 | install: all 82 | 83 | # 84 | # dependencies 85 | # 86 | ifeq ($(dep),yes) 87 | include $(addsuffix .depend, $(basename $(ALLOBJECTS))) 88 | endif 89 | -------------------------------------------------------------------------------- /pkcs11/jni/src/scripts/config.data.default: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: config.data.default,v 1.4 2006/01/11 16:38:31 wglas Exp $ 3 | # 4 | # Default makefile variable settings. 5 | # 6 | ac prefix=/usr/local 7 | ac LIBSUBDIR= 8 | ac DESTDIR= 9 | ac EXEC= 10 | ac DEFS=-DHAVE_CONFIG_H 11 | ac LIBS= 12 | ac CC=gcc 13 | ac CFLAGS=-g -O2 -Wall 14 | ac LDFLAGS= 15 | ac NCLDFLAGS= 16 | ac CPPFLAGS= 17 | ac EXEEXT= 18 | ac OBJEXT=o 19 | ac CPP=gcc -E 20 | ac CXX=g++ 21 | ac CXXFLAGS=-g -O2 -Wall 22 | ac RANLIB=ranlib 23 | ac STRIP=strip 24 | ac AR=ar 25 | ac ARFLAGS=cq 26 | ac RC= 27 | ac LIBPFX=lib 28 | ac LIBEXT=a 29 | ac LIBDYN=so 30 | ac LIBDYNPFX=lib 31 | ac DYN_LDFLAGS=-shared 32 | ac DYN_CFLAGS=-fPIC 33 | ac SSL_LDFLAGS= 34 | ac SSL_LIBS=-lcrypto -lssl 35 | ac SSL_CFLAGS= 36 | ac JNI_CFLAGS=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux 37 | ac JNI_LDFLAGS= 38 | ac JNI_LIBS= 39 | ac OPENSC_CFLAGS= 40 | ac OPENSC_LDFLAGS= 41 | ac OPENSC_LIBS=-lopensc 42 | ac PKCS11_CFLAGS= 43 | ac PKCS11_LDFLAGS= 44 | ac PKCS11_LIBS=-lltdl 45 | ac RESOLV_LIBS= 46 | test { $LIBSUBDIR eq "" && $ARCHNAME =~ /^x86_64-/ } then {ac LIBSUBDIR=lib64} 47 | test { $LIBSUBDIR eq ""} then {ac LIBSUBDIR=lib} 48 | test { $RESOLV_LIBS eq "" && $ARCHNAME =~ /^x86_64-/ } then {ac RESOLV_LIBS=/usr/lib64/libresolv.a} 49 | test { $RESOLV_LIBS eq "" } then {ac RESOLV_LIBS=/usr/lib/libresolv.a} 50 | -------------------------------------------------------------------------------- /pkcs15/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pkcs15/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | pkcs15 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.maven.ide.eclipse.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /pkcs15/conf/logging/logging.properties: -------------------------------------------------------------------------------- 1 | handlers= java.util.logging.ConsoleHandler 2 | 3 | .level= INFO 4 | 5 | java.util.logging.ConsoleHandler.level = FINE 6 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 7 | 8 | org.opensc.pkcs15.level = FINE 9 | -------------------------------------------------------------------------------- /pkcs15/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | org.opensc 5 | pkcs15 6 | 0.0.1-SNAPSHOT 7 | Tools for handling Siemens' CardOS Smart Cards 8 | 9 | 10 | 11 | 12 | org.apache.maven.plugins 13 | maven-compiler-plugin 14 | 15 | 1.6 16 | 1.6 17 | 18 | 19 | 20 | org.apache.maven.plugins 21 | maven-source-plugin 22 | 23 | 24 | pkg-sources 25 | jar 26 | package 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-surefire-plugin 33 | 34 | 35 | **/TestHardwareToken.java 36 | **/TestCSFScripts.java 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | commons-logging 45 | commons-logging-api 46 | 1.1 47 | 48 | 49 | org.bouncycastle 50 | bcprov 51 | jdk15-138 52 | 53 | 54 | commons-logging 55 | commons-logging 56 | 1.1 57 | test 58 | 59 | 60 | junit 61 | junit 62 | 3.8.2 63 | test 64 | 65 | 66 | 67 | 68 | clazzes.org-repository 69 | clazzes.org repository 70 | http://maven.clazzes.org 71 | 72 | 73 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/AIDs.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 26.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15; 24 | 25 | /** 26 | * This class holds all known application IDs. 27 | * 28 | * @author wglas 29 | */ 30 | public abstract class AIDs { 31 | 32 | /** 33 | * The application ID of PKCS#15 applications. 34 | */ 35 | public static final byte[] PKCS15_AID = 36 | new byte[] { // PKCS#15 RID: A0 00 00 00 63 37 | (byte)0xA0, 0x00, 0x00, 0x00, 0x63, 38 | // "PKCS-15 39 | 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 }; 40 | } 41 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/application/Application.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 26.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.application; 24 | 25 | import org.opensc.pkcs15.asn1.ISO7816ApplicationTemplate; 26 | import org.opensc.pkcs15.token.Token; 27 | 28 | /** 29 | * This interface describes a smart card application cf. to ISO7816. 30 | * 31 | * The functionality in this interface is very terse, because the scope of 32 | * applications may range from PKI application to specialized applications for 33 | * public health care. 34 | * 35 | * @author wglas 36 | */ 37 | public interface Application { 38 | 39 | /** 40 | * @return The application ID. 41 | */ 42 | byte[] getAID(); 43 | 44 | /** 45 | * @return The application template as stored inside the EF(DIR) object 46 | * in the root path of a token. 47 | */ 48 | public ISO7816ApplicationTemplate getApplicationTemplate(); 49 | 50 | /** 51 | * @return The token on which this application resides. 52 | */ 53 | public Token getToken(); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/application/ApplicationFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 26.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.application; 24 | 25 | import java.io.IOException; 26 | import java.util.List; 27 | 28 | import javax.imageio.spi.ServiceRegistry; 29 | 30 | import org.opensc.pkcs15.token.Token; 31 | 32 | /** 33 | * A factory for application instances. 34 | * 35 | * @author wglas 36 | */ 37 | public abstract class ApplicationFactory { 38 | 39 | /** 40 | * @return The first instance registered under the resource path 41 | * META-INF/serivces/org.opensc.pkcs15.application.ApplicationFactory. 42 | * 43 | * @see ServiceRegistry#lookupProviders(Class) 44 | */ 45 | public static ApplicationFactory newInstance() 46 | { 47 | return ServiceRegistry.lookupProviders(ApplicationFactory.class).next(); 48 | } 49 | 50 | /** 51 | * @param token A token instance. 52 | * @return The list of all supported applications on the token. 53 | * @throws IOException Upon errors. 54 | */ 55 | public abstract List listApplications(Token token) throws IOException; 56 | 57 | /** 58 | * @param token A token instance. 59 | * @return The first application on the token matching the given AID. 60 | * @throws IOException Upon errors. 61 | */ 62 | public abstract Application newApplication(Token token, byte[] aid) throws IOException; 63 | 64 | /** 65 | * @return A newly instantiated application, which is appended to the list of applications 66 | * on the token. 67 | * @throws IOException Upon errors. 68 | */ 69 | public abstract Application createApplication(Token token, byte[] aid) throws IOException; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/Context.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 01.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1; 24 | 25 | import org.bouncycastle.asn1.DERInteger; 26 | import org.opensc.pkcs15.asn1.attr.RSAPrivateKeyObject; 27 | import org.opensc.pkcs15.asn1.attr.RSAPublicKeyObject; 28 | import org.opensc.pkcs15.asn1.attr.X509CertificateObject; 29 | import org.opensc.pkcs15.asn1.basic.NullKeyInfo; 30 | import org.opensc.pkcs15.asn1.proxy.Directory; 31 | import org.opensc.pkcs15.asn1.proxy.StreamResolver; 32 | import org.opensc.pkcs15.asn1.ref.Path; 33 | 34 | /** 35 | * This interface represents a context for deserializing references. 36 | * 37 | * @author wglas 38 | */ 39 | public interface Context { 40 | 41 | public Directory getRSAPrivateKeyDirectory(); 42 | 43 | public Directory getRSAPublicKeyDirectory(); 44 | 45 | public Directory getNullKeyInfoDirectory(); 46 | 47 | public Directory getX509CertificateDirectory(); 48 | 49 | public StreamResolver getPathResolver(); 50 | } 51 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/ContextHolder.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 01.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1; 24 | 25 | /** 26 | * The static thread-local context registry. 27 | * 28 | * @author wglas 29 | */ 30 | public abstract class ContextHolder { 31 | 32 | private static final ThreadLocal holder = new ThreadLocal(); 33 | 34 | /** 35 | * @param context Register the given context for this thread. 36 | */ 37 | public static void setContext(Context context) 38 | { 39 | holder.set(context); 40 | } 41 | 42 | /** 43 | * Remove the context from this thread. 44 | */ 45 | public static void removeContext() 46 | { 47 | holder.remove(); 48 | } 49 | 50 | /** 51 | * @return The thread-local context registered using {@link #setContext(Context)}. 52 | */ 53 | public static Context getContext() 54 | { 55 | return holder.get(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/ISO7816Applications.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * A sequence of ISO7816ApplicationTaemplate as stored in the 30 | * EF(DIR) object in the root path of a token. 31 | * 32 | * @author wglas 33 | */ 34 | public class ISO7816Applications { 35 | 36 | private List applications; 37 | 38 | /** 39 | * Default constructor. 40 | */ 41 | public ISO7816Applications() { 42 | } 43 | 44 | /** 45 | * @return The list of applications found. 46 | */ 47 | public List getApplications() { 48 | return this.applications; 49 | } 50 | 51 | /** 52 | * @param applications the applications to set 53 | */ 54 | public void setApplications(List applications) { 55 | this.applications = applications; 56 | } 57 | 58 | /** 59 | * @param application the application to add 60 | */ 61 | public void addApplication(ISO7816ApplicationTemplate application) { 62 | 63 | if (this.applications == null) 64 | this.applications = new ArrayList(); 65 | 66 | this.applications.add(application); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/PKCS15Key.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1; 24 | 25 | import org.opensc.pkcs15.asn1.attr.CommonKeyAttributes; 26 | 27 | /** 28 | * This interface is implemented by all private and public key objects. 29 | * 30 | * @author wglas 31 | */ 32 | public interface PKCS15Key extends PKCS15Object { 33 | 34 | /** 35 | * @return the commonKeyAttributes 36 | */ 37 | public CommonKeyAttributes getCommonKeyAttributes(); 38 | 39 | /** 40 | * @param commonKeyAttributes the commonKeyAttributes to set 41 | */ 42 | public void setCommonKeyAttributes(CommonKeyAttributes commonKeyAttributes); 43 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/PKCS15Object.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.opensc.pkcs15.asn1.attr.CommonObjectAttributes; 27 | 28 | /** 29 | * This interface is implemented by all toplevel ASN.1 objects. 30 | * 31 | * @author wglas 32 | */ 33 | public interface PKCS15Object extends DEREncodable { 34 | 35 | /** 36 | * @return the commonObjectAttributes 37 | */ 38 | public CommonObjectAttributes getCommonObjectAttributes(); 39 | 40 | /** 41 | * @param commonObjectAttributes the commonObjectAttributes to set 42 | */ 43 | public void setCommonObjectAttributes( 44 | CommonObjectAttributes commonObjectAttributes); 45 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/CertificateObject.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import java.security.cert.Certificate; 26 | import java.security.cert.CertificateParsingException; 27 | 28 | import org.bouncycastle.asn1.DEREncodable; 29 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxy; 30 | 31 | /** 32 | * This interface is extended by all interfaces, which represent 33 | * a certificate stored on a token. Please note, that most of the 34 | * time a ReferencedValue{CertificateObject} is stored on the 35 | * card, so instances of this interface implement 36 | * {@link ReferenceProxy} too in this case. 37 | * 38 | * @author wglas 39 | */ 40 | public interface CertificateObject extends DEREncodable { 41 | 42 | /** 43 | * @return The certificate as interpreted by most 44 | * JAV security providers. 45 | */ 46 | Certificate getCertificate() throws CertificateParsingException; 47 | } 48 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/PrivateKeyObject.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 06.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import java.security.PrivateKey; 26 | 27 | import org.bouncycastle.asn1.DEREncodable; 28 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxy; 29 | 30 | /** 31 | * This interface is extended by all interfaces, which represent 32 | * a private key stored on a token. Please note, that most of the 33 | * time a ReferencedValue{PrivateKeyObject} is stored on the 34 | * card, so instances of this interface implement 35 | * {@link ReferenceProxy} too in this case. 36 | * 37 | * @author wglas 38 | */ 39 | public interface PrivateKeyObject extends DEREncodable, PrivateKey { 40 | } 41 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/PublicKeyObject.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import java.security.interfaces.RSAPublicKey; 26 | 27 | import org.bouncycastle.asn1.DEREncodable; 28 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxy; 29 | 30 | /** 31 | * This interface is extended by all interfaces, which represent 32 | * a public key stored on a token. Please note, that most of the 33 | * time a ReferencedValue{PublicKeyObject} is stored on the 34 | * card, so instances of this interface implement 35 | * {@link ReferenceProxy} too in this case. 36 | * 37 | * @author wglas 38 | */ 39 | public interface PublicKeyObject extends RSAPublicKey, DEREncodable { 40 | } 41 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/RSAKeyInfoFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.bouncycastle.asn1.DERInteger; 26 | import org.opensc.pkcs15.asn1.Context; 27 | import org.opensc.pkcs15.asn1.ContextHolder; 28 | import org.opensc.pkcs15.asn1.basic.NullKeyInfo; 29 | import org.opensc.pkcs15.asn1.basic.NullKeyInfoImpl; 30 | import org.opensc.pkcs15.asn1.proxy.Directory; 31 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxyFactory; 32 | 33 | /** 34 | * A factory which instantiates KeyInfo instances as used by RSA private keys. 35 | * 36 | *
37 |  * KeyInfo {NULL, PublicKeyOperations} 
38 |  * 
39 | * 40 | * where 41 | * 42 | *
43 |  * KeyInfo {ParameterType, OperationsType} ::= CHOICE {
44 |  *       reference           Reference,
45 |  *       paramsAndOps        SEQUENCE {
46 |  *           parameters      ParameterType,
47 |  *           supportedOperations OperationsType OPTIONAL
48 |  *          }
49 |  *       }
50 |  * 
51 | * 52 | * @author wglas 53 | */ 54 | public abstract class RSAKeyInfoFactory { 55 | 56 | private static ReferenceProxyFactory 57 | proxyFactory = 58 | new ReferenceProxyFactory(NullKeyInfo.class); 59 | 60 | /** 61 | * This method implements the static getInstance factory pattern by 62 | * using the thread-local context stored in {@link ContextHolder}. 63 | * 64 | * @param obj ASN.1 object to be decoded. 65 | * @return A KeyInfo object suitable for RSA Private keys. 66 | */ 67 | static public NullKeyInfo getInstance(Object obj) 68 | { 69 | Context context = ContextHolder.getContext(); 70 | 71 | Directory directory = 72 | context == null ? null : context.getNullKeyInfoDirectory(); 73 | 74 | return getInstance(obj,directory); 75 | } 76 | 77 | /** 78 | * @param obj ASN.1 object to be decoded. 79 | * @param directory A directory for resolving integer references. 80 | * @return A KeyInfo object suitable for RSA Private keys. 81 | */ 82 | static public NullKeyInfo getInstance(Object obj, 83 | Directory directory) 84 | { 85 | if (obj instanceof NullKeyInfo) { 86 | return (NullKeyInfo) obj; 87 | } 88 | 89 | if (obj instanceof DERInteger) { 90 | return proxyFactory.getProxy((DERInteger)obj,directory); 91 | } 92 | 93 | return NullKeyInfoImpl.getInstance(obj); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/RSAPrivateKeyObject.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import java.security.interfaces.RSAPrivateCrtKey; 26 | 27 | /** 28 | * This interface is implemented by RSAPrivateKeyObject instances 29 | * and proxies. 30 | * 31 | * @author wglas 32 | */ 33 | public interface RSAPrivateKeyObject extends RSAPrivateCrtKey, PrivateKeyObject { 34 | } 35 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/RSAPrivateKeyObjectFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.opensc.pkcs15.asn1.Context; 26 | import org.opensc.pkcs15.asn1.ContextHolder; 27 | import org.opensc.pkcs15.asn1.proxy.Directory; 28 | import org.opensc.pkcs15.asn1.ref.ObjectValueFactory; 29 | import org.opensc.pkcs15.asn1.ref.Path; 30 | 31 | 32 | /** 33 | * Decode the ASN.1 ObjectValue {RSAPrivateKeyObject} choice. 34 | * 35 | * @author wglas 36 | */ 37 | public abstract class RSAPrivateKeyObjectFactory { 38 | 39 | private static ObjectValueFactory factory 40 | = new ObjectValueFactory(RSAPrivateKeyObject.class,RSAPrivateKeyObjectImpl.class); 41 | 42 | /** 43 | * This method implements the static getInstance factory pattern by 44 | * using the thread-local context stored in {@link ContextHolder}. 45 | * 46 | * @param obj ASN.1 object to be decoded. 47 | * @return A KeyInfo object suitable for RSA Private keys. 48 | */ 49 | static public RSAPrivateKeyObject getInstance(Object obj) 50 | { 51 | Context context = ContextHolder.getContext(); 52 | 53 | Directory directory = 54 | context == null ? null : context.getRSAPrivateKeyDirectory(); 55 | 56 | return getInstance(obj,directory); 57 | } 58 | 59 | /** 60 | * @param obj An ASN.1 object to resolve. 61 | * @param directory The directory used to resolve path references. 62 | * @return An RSAPrivateKeyObjectImpl instance or a RSAPrivateKeyObject proxy 63 | * depending on the type of the ReferencedValue. 64 | */ 65 | public static RSAPrivateKeyObject getInstance(Object obj, 66 | Directory directory) { 67 | 68 | return factory.getInstance(obj, directory); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/RSAPublicKeyObject.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import java.security.interfaces.RSAPublicKey; 26 | 27 | /** 28 | * This interface is implemented by all public key objects stored on the token 29 | * and proxies. 30 | * 31 | * @author wglas 32 | */ 33 | public interface RSAPublicKeyObject extends RSAPublicKey, PublicKeyObject { 34 | } 35 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/RSAPublicKeyObjectFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.opensc.pkcs15.asn1.proxy.Directory; 26 | import org.opensc.pkcs15.asn1.ref.ObjectValueFactory; 27 | import org.opensc.pkcs15.asn1.ref.Path; 28 | 29 | 30 | /** 31 | * Decode the ASN.1 ObjectValue {RSAPrivateKeyObject} choice. 32 | * 33 | * @author wglas 34 | */ 35 | public abstract class RSAPublicKeyObjectFactory { 36 | 37 | private static ObjectValueFactory factory 38 | = new ObjectValueFactory(RSAPublicKeyObject.class,RSAPublicKeyChoice.class); 39 | 40 | /** 41 | * @param obj An ASN.1 object to resolve. 42 | * @param directory The directory used to resolve path references. 43 | * @return An RSAPublicKeyChoice instance or a RSAPublicKeyObject proxy 44 | * depending on the type of the ReferencedValue. 45 | */ 46 | public static RSAPublicKeyObject getInstance(Object obj, 47 | Directory directory) { 48 | 49 | return factory.getInstance(obj, directory); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/SpecificCertificateAttributes.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 06.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxy; 27 | 28 | /** 29 | * All *CertificateAttributes objects fulfill this interface. 30 | * 31 | * @author wglas 32 | */ 33 | public interface SpecificCertificateAttributes extends DEREncodable { 34 | 35 | /** 36 | * @return The stored public key object on the token. Please note, 37 | * that it is likely, that the returned object is an instance 38 | * of {@link ReferenceProxy}, if it originated from a 39 | * ReferencedValue{CertificateObject}, which 40 | * points to a Path or an URL. 41 | */ 42 | public CertificateObject getCertificateObject(); 43 | 44 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/SpecificPrivateKeyAttributes.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 06.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.opensc.pkcs15.asn1.basic.KeyInfo; 27 | import org.opensc.pkcs15.asn1.basic.Operations; 28 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxy; 29 | 30 | /** 31 | * All Private*KeyAttributes objects fulfill this interface 32 | * 33 | * @author wglas 34 | */ 35 | public interface SpecificPrivateKeyAttributes extends DEREncodable { 36 | 37 | /** 38 | * @return The stored private key object on the token. Please note, 39 | * that it is likely, that the returned object is an instance 40 | * of {@link ReferenceProxy}, if it originated from a 41 | * ReferencedValue{PrivateKeyObject}, which 42 | * points to a Path or an URL. 43 | */ 44 | public PrivateKeyObject getPrivateKeyObject(); 45 | 46 | /** 47 | * @return The KeyInfo object stored for the private key. 48 | * All KeyInfo's have the second type parameter set 49 | * to {@link Operations}, so this parameter is tied by 50 | * this method. The first type parameter is dependent on the 51 | * cryptographic algorithm performed by the private key. 52 | */ 53 | public KeyInfo getGenericKeyInfo(); 54 | 55 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/SpecificPublicKeyAttributes.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 06.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.opensc.pkcs15.asn1.basic.KeyInfo; 27 | import org.opensc.pkcs15.asn1.basic.Operations; 28 | import org.opensc.pkcs15.asn1.proxy.ReferenceProxy; 29 | 30 | /** 31 | * All Public*KeyAttributes objects fulfill this interface 32 | * 33 | * @author wglas 34 | */ 35 | public interface SpecificPublicKeyAttributes extends DEREncodable { 36 | 37 | /** 38 | * @return The stored public key object on the token. Please note, 39 | * that it is likely, that the returned object is an instance 40 | * of {@link ReferenceProxy}, if it originated from a 41 | * ReferencedValue{PublicKeyObject}, which 42 | * points to a Path or an URL. 43 | */ 44 | public PublicKeyObject getPublicKeyObject(); 45 | 46 | /** 47 | * @return The KeyInfo object stored for the public key. 48 | * All KeyInfo's have the second type parameter set 49 | * to {@link Operations}, so this parameter is tied by 50 | * this method. The first type parameter is dependent on the 51 | * cryptographic algorithm performed by the public key. 52 | */ 53 | public KeyInfo getGenericKeyInfo(); 54 | 55 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/X509CertificateObject.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import java.security.cert.CertificateParsingException; 26 | import java.security.cert.X509Certificate; 27 | 28 | import org.bouncycastle.asn1.DERBitString; 29 | import org.bouncycastle.asn1.DERInteger; 30 | import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 31 | import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; 32 | import org.bouncycastle.asn1.x509.TBSCertificateStructure; 33 | import org.bouncycastle.asn1.x509.Time; 34 | import org.bouncycastle.asn1.x509.X509Name; 35 | 36 | /** 37 | * This interface is implemented by X509Certificate instances 38 | * and proxies. 39 | * 40 | * @author wglas 41 | */ 42 | public interface X509CertificateObject extends CertificateObject { 43 | 44 | public X509Certificate getX509Certificate() throws CertificateParsingException; 45 | 46 | public TBSCertificateStructure getTBSCertificate(); 47 | 48 | public int getVersion(); 49 | 50 | public DERInteger getSerialNumber(); 51 | 52 | public X509Name getIssuer(); 53 | 54 | public Time getStartDate(); 55 | 56 | public Time getEndDate(); 57 | 58 | public X509Name getSubject(); 59 | 60 | public SubjectPublicKeyInfo getSubjectPublicKeyInfo(); 61 | 62 | public AlgorithmIdentifier getSignatureAlgorithm(); 63 | 64 | public DERBitString getSignature(); 65 | } 66 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/attr/X509CertificateObjectFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.attr; 24 | 25 | import org.opensc.pkcs15.asn1.proxy.Directory; 26 | import org.opensc.pkcs15.asn1.ref.ObjectValueFactory; 27 | import org.opensc.pkcs15.asn1.ref.Path; 28 | 29 | 30 | /** 31 | * Decode the ASN.1 ObjectValue {RSAPrivateKeyObject} choice. 32 | * 33 | * @author wglas 34 | */ 35 | public abstract class X509CertificateObjectFactory { 36 | 37 | private static ObjectValueFactory factory 38 | = new ObjectValueFactory(X509CertificateObject.class,X509CertificateObjectImpl.class); 39 | 40 | /** 41 | * @param obj An ASN.1 object to resolve. 42 | * @param directory The directory used to resolve path references. 43 | * @return An X509CertificateObjectImpl instance or a X509CertificateObject proxy 44 | * depending on the type of the ReferencedValue. 45 | */ 46 | public static X509CertificateObject getInstance(Object obj, 47 | Directory directory) { 48 | 49 | return factory.getInstance(obj, directory); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/AuthIdSecurityCondition.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.ASN1OctetString; 26 | import org.bouncycastle.asn1.DERObject; 27 | 28 | /** 29 | * The authId choice of a SecurityCondition. 30 | * 31 | * @author wglas 32 | */ 33 | public class AuthIdSecurityCondition extends SecurityCondition { 34 | 35 | private ASN1OctetString authId; 36 | 37 | /** 38 | * @param authId The The Id of the object covered by this condition. 39 | */ 40 | public AuthIdSecurityCondition(ASN1OctetString authId) { 41 | 42 | this.authId = authId; 43 | } 44 | 45 | /* (non-Javadoc) 46 | * @see org.opensc.pkcs15.asn1.SecurityCondition#checkIdentifier(org.bouncycastle.asn1.ASN1OctetString) 47 | */ 48 | @Override 49 | public boolean checkIdentifier(ASN1OctetString identifier) { 50 | 51 | if (this.authId == null) return false; 52 | return this.authId.equals(identifier); 53 | } 54 | 55 | /** 56 | * @return The The Id of the object covered by this condition. 57 | */ 58 | public ASN1OctetString getAuthId() { 59 | return this.authId; 60 | } 61 | 62 | /** 63 | * @param authId the authId to set 64 | */ 65 | public void setAuthId(ASN1OctetString authId) { 66 | this.authId = authId; 67 | } 68 | 69 | /* (non-Javadoc) 70 | * @see org.bouncycastle.asn1.ASN1Encodable#toASN1Object() 71 | */ 72 | @Override 73 | public DERObject toASN1Object() { 74 | return this.authId; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/GeneralizedTimeHolder.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 06.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.bouncycastle.asn1.DERGeneralizedTime; 27 | 28 | /** 29 | * This interface is needed as a facade for bouncycastle's 30 | * {@link DERGeneralizedTime} class in order to generate 31 | * ReferencedValue{GeneralizedTime} proxies. 32 | * 33 | * @author wglas 34 | */ 35 | public interface GeneralizedTimeHolder extends DEREncodable { 36 | 37 | /** 38 | * @return The ASN.1 generalized time hold by this instance. 39 | */ 40 | public DERGeneralizedTime getGeneralizedTime(); 41 | 42 | /** 43 | * @param generalizedTime the ASN.1 gerneralized time to hold. 44 | */ 45 | public void setGeneralizedTime(DERGeneralizedTime generalizedTime); 46 | } 47 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/GeneralizedTimeHolderImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 06.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.DERGeneralizedTime; 26 | import org.bouncycastle.asn1.DERObject; 27 | 28 | /** 29 | * The actual implementation of a {@link GeneralizedTimeHolder}. 30 | * 31 | * @author wglas 32 | */ 33 | public class GeneralizedTimeHolderImpl implements GeneralizedTimeHolder { 34 | 35 | private DERGeneralizedTime generalizedTime; 36 | 37 | public GeneralizedTimeHolderImpl() { 38 | } 39 | 40 | public GeneralizedTimeHolderImpl(DERGeneralizedTime generalizedTime) { 41 | this.generalizedTime = generalizedTime; 42 | } 43 | 44 | /** 45 | * @param obj The ASN.1 object to parse. 46 | * @return A GeneralizedTimeHoledr instance. 47 | */ 48 | public static GeneralizedTimeHolder getInstance(Object obj) { 49 | 50 | if (obj instanceof GeneralizedTimeHolder) 51 | return (GeneralizedTimeHolder) obj; 52 | 53 | return new GeneralizedTimeHolderImpl(DERGeneralizedTime.getInstance(obj)); 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see org.opensc.pkcs15.asn1.basic.GeneralizedTimeHolder#getGeneralizedTime() 58 | */ 59 | @Override 60 | public DERGeneralizedTime getGeneralizedTime() { 61 | 62 | return this.generalizedTime; 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see org.opensc.pkcs15.asn1.basic.GeneralizedTimeHolder#setGeneralizedTime(org.bouncycastle.asn1.DERGeneralizedTime) 67 | */ 68 | @Override 69 | public void setGeneralizedTime(DERGeneralizedTime generalizedTime) { 70 | 71 | this.generalizedTime = generalizedTime; 72 | } 73 | 74 | /* (non-Javadoc) 75 | * @see org.bouncycastle.asn1.DEREncodable#getDERObject() 76 | */ 77 | @Override 78 | public DERObject getDERObject() { 79 | 80 | return this.generalizedTime; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/IssuerAndSerialNumberKeyIdentifier.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.bouncycastle.asn1.cms.IssuerAndSerialNumber; 27 | 28 | /** 29 | * A KeyIdentifier with an RFC 2630 (CMS) IssuerAndSerialNumber as value. 30 | * 31 | * @author wglas 32 | */ 33 | public class IssuerAndSerialNumberKeyIdentifier extends KeyIdentifier { 34 | 35 | private IssuerAndSerialNumber identifier; 36 | 37 | protected IssuerAndSerialNumberKeyIdentifier(IssuerAndSerialNumber identifier) { 38 | super(issuerAndSerialNumber); 39 | this.identifier = identifier; 40 | } 41 | 42 | /* (non-Javadoc) 43 | * @see org.opensc.pkcs15.asn1.KeyIdentifier#getValue() 44 | */ 45 | @Override 46 | public DEREncodable getValue() { 47 | 48 | return this.identifier; 49 | } 50 | 51 | /** 52 | * @return the identifier 53 | */ 54 | public IssuerAndSerialNumber getIdentifier() { 55 | return this.identifier; 56 | } 57 | 58 | /** 59 | * @param identifier the identifier to set 60 | */ 61 | public void setIdentifier(IssuerAndSerialNumber identifier) { 62 | this.identifier = identifier; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/KeyIdentifiers.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Enumeration; 27 | import java.util.List; 28 | 29 | import org.bouncycastle.asn1.ASN1Encodable; 30 | import org.bouncycastle.asn1.ASN1EncodableVector; 31 | import org.bouncycastle.asn1.ASN1Sequence; 32 | import org.bouncycastle.asn1.DERObject; 33 | import org.bouncycastle.asn1.DERSequence; 34 | 35 | /** 36 | * The ASN.1 representation of a sequence of KeyIdentifiers. 37 | * 38 | * @author wglas 39 | */ 40 | public class KeyIdentifiers extends ASN1Encodable { 41 | 42 | private List identifiers; 43 | 44 | /** 45 | * Default constructor. 46 | */ 47 | protected KeyIdentifiers() { 48 | } 49 | 50 | /** 51 | * Default constructor. 52 | */ 53 | protected KeyIdentifiers(List identifiers) { 54 | this.identifiers = identifiers; 55 | } 56 | 57 | /** 58 | * @param o An ASN.1 object to decode. 59 | * @return A KeyIdentifier instance. 60 | */ 61 | public static KeyIdentifiers getInstance(Object obj) 62 | { 63 | if (obj instanceof KeyIdentifiers) 64 | return (KeyIdentifiers) obj; 65 | 66 | if (obj instanceof ASN1Sequence) 67 | { 68 | ASN1Sequence seq = (ASN1Sequence)obj; 69 | 70 | Enumeration objs = seq.getObjects(); 71 | 72 | List identifiers = new ArrayList(seq.size()); 73 | 74 | while (objs.hasMoreElements()) { 75 | 76 | identifiers.add(KeyIdentifier.getInstance(objs.nextElement())); 77 | } 78 | 79 | return new KeyIdentifiers(identifiers); 80 | } 81 | 82 | throw new IllegalArgumentException("KeyIdentifiers must be encoded as an ASN.1 SEQUENCE."); 83 | } 84 | 85 | /* (non-Javadoc) 86 | * @see org.bouncycastle.asn1.ASN1Encodable#toASN1Object() 87 | */ 88 | @Override 89 | public DERObject toASN1Object() { 90 | ASN1EncodableVector v = new ASN1EncodableVector(); 91 | 92 | if (this.identifiers != null) { 93 | 94 | for (KeyIdentifier identifier : this.identifiers) { 95 | 96 | v.add(identifier); 97 | } 98 | } 99 | 100 | return new DERSequence(v); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/KeyInfo.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | 27 | 28 | /** 29 | *
30 |  * KeyInfo {ParameterType, OperationsType} ::= CHOICE {
31 |  *      reference           Reference,
32 |  *      paramsAndOps        SEQUENCE {
33 |  *          parameters            ParameterType,
34 |  *          supportedOperations OperationsType OPTIONAL
35 |  *             }
36 |  *      }
37 |  * 
38 | * 39 | * @author wglas 40 | * 41 | */ 42 | public interface KeyInfo extends DEREncodable { 44 | 45 | ParameterType getParameters(); 46 | 47 | void setParameters(ParameterType parameters); 48 | 49 | OperationsType getSupportedOperations(); 50 | 51 | void setSupportedOperations(OperationsType supportedOperations); 52 | } 53 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/NotSecurityCondition.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.ASN1OctetString; 26 | import org.bouncycastle.asn1.DERObject; 27 | import org.bouncycastle.asn1.DERTaggedObject; 28 | 29 | /** 30 | * The not choice of a SecurityCondition. 31 | * 32 | * @author wglas 33 | */ 34 | public class NotSecurityCondition extends SecurityCondition { 35 | 36 | private SecurityCondition condition; 37 | 38 | /** 39 | * @param condition The SecurityCondition negated by this condition. 40 | */ 41 | public NotSecurityCondition(SecurityCondition condition) { 42 | 43 | this.condition = condition; 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see org.opensc.pkcs15.asn1.SecurityCondition#checkIdentifier(org.bouncycastle.asn1.ASN1OctetString) 48 | */ 49 | @Override 50 | public boolean checkIdentifier(ASN1OctetString identifier) { 51 | 52 | if (this.condition == null) return false; 53 | return !this.condition.checkIdentifier(identifier); 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see org.bouncycastle.asn1.ASN1Encodable#toASN1Object() 58 | */ 59 | @Override 60 | public DERObject toASN1Object() { 61 | 62 | return new DERTaggedObject(0,this.condition); 63 | } 64 | 65 | /** 66 | * @return The SecurityCondition negated by this condition. 67 | */ 68 | public SecurityCondition getCondition() { 69 | return this.condition; 70 | } 71 | 72 | /** 73 | * @param condition the condition to set 74 | */ 75 | public void setCondition(SecurityCondition condition) { 76 | this.condition = condition; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/NullAlgorithmInfo.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 08.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | 27 | /** 28 | * An AlgorithmInfo with a NULL parameters member. 29 | * 30 | * @author wglas 31 | */ 32 | public class NullAlgorithmInfo extends AlgorithmInfo { 33 | 34 | private NullKeyInfoImpl nullKeyInfo; 35 | 36 | protected NullAlgorithmInfo(int reference, int algorithm, NullKeyInfoImpl nullKeyInfo) { 37 | super(reference, algorithm); 38 | this.nullKeyInfo = nullKeyInfo; 39 | } 40 | 41 | /* (non-Javadoc) 42 | * @see org.opensc.pkcs15.asn1.basic.AlgorithmInfo#getKeyInfo() 43 | */ 44 | @Override 45 | public KeyInfoImpl getKeyInfo() { 46 | 47 | return this.nullKeyInfo; 48 | } 49 | 50 | /** 51 | * @return the nullKeyInfo 52 | */ 53 | public NullKeyInfoImpl getNullKeyInfo() { 54 | return this.nullKeyInfo; 55 | } 56 | 57 | /** 58 | * @param nullKeyInfo the nullKeyInfo to set 59 | */ 60 | public void setNullKeyInfo(NullKeyInfoImpl nullKeyInfo) { 61 | this.nullKeyInfo = nullKeyInfo; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/NullKeyInfo.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | import org.bouncycastle.asn1.DERNull; 25 | 26 | /** 27 | *
28 |  * KeyInfo {NULL, PublicKeyOperations} 
29 |  * 
30 | * 31 | * @author wglas 32 | */ 33 | public interface NullKeyInfo extends KeyInfo { 34 | } 35 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/OctetStringKeyIdentifier.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.ASN1OctetString; 26 | import org.bouncycastle.asn1.DEREncodable; 27 | 28 | /** 29 | * A KeyIdentifier with an OCTET STRING as value. 30 | * 31 | * @author wglas 32 | */ 33 | public class OctetStringKeyIdentifier extends KeyIdentifier { 34 | 35 | private ASN1OctetString octets; 36 | 37 | public OctetStringKeyIdentifier(int id, ASN1OctetString octets) { 38 | super(id); 39 | if (id == issuerAndSerialNumber) 40 | throw new IllegalArgumentException("nullAlgotihmId is incompatible with OctetStringKeyIdentifier."); 41 | this.octets = octets; 42 | } 43 | 44 | /* (non-Javadoc) 45 | * @see org.opensc.pkcs15.asn1.KeyIdentifier#getValue() 46 | */ 47 | @Override 48 | public DEREncodable getValue() { 49 | 50 | return this.octets; 51 | } 52 | 53 | /** 54 | * @return the octets 55 | */ 56 | public ASN1OctetString getOctets() { 57 | return this.octets; 58 | } 59 | 60 | /** 61 | * @param octets the octets to set 62 | */ 63 | public void setOctets(ASN1OctetString octets) { 64 | this.octets = octets; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/basic/SecurityCondition.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 30.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.basic; 24 | 25 | import org.bouncycastle.asn1.ASN1Encodable; 26 | import org.bouncycastle.asn1.ASN1OctetString; 27 | import org.bouncycastle.asn1.ASN1TaggedObject; 28 | 29 | /** 30 | *
31 |  * SecurityCondition ::= CHOICE {
32 |  *         authId Identifier,
33 |  *         not[0] SecurityCondition,
34 |  *         and         [1] SEQUENCE SIZE (2..pkcs15-ub-securityConditions) OF SecurityCondition,
35 |  *         or          [2] SEQUENCE SIZE (2..pkcs15-ub-securityConditions) OF SecurityCondition,
36 |  *         ... -- For future extensions
37 |  *         }
38 |  * 
39 | * 40 | * @author wglas 41 | */ 42 | public abstract class SecurityCondition extends ASN1Encodable { 43 | 44 | /** 45 | * Check, whether this security condition allows access to the given 46 | * identifier. 47 | * 48 | * @param identifier The identifier to check. 49 | * @return Whether this identifier is granted access by this security condition. 50 | */ 51 | public abstract boolean checkIdentifier(ASN1OctetString identifier); 52 | 53 | /** 54 | * Constructor to be used by subclasses. 55 | */ 56 | protected SecurityCondition() { 57 | } 58 | 59 | /** 60 | * @param obj The ASN.1 object to be decoded. 61 | * @return A SecurityCondition instance. 62 | */ 63 | public static SecurityCondition getInstance (Object obj) 64 | { 65 | if (obj instanceof SecurityCondition) 66 | return (SecurityCondition) obj; 67 | 68 | if (obj instanceof ASN1OctetString) 69 | return new AuthIdSecurityCondition((ASN1OctetString)obj); 70 | 71 | if (obj instanceof ASN1TaggedObject) 72 | { 73 | ASN1TaggedObject to = ASN1TaggedObject.getInstance(obj); 74 | 75 | switch(to.getTagNo()) { 76 | 77 | case 0: 78 | return new NotSecurityCondition(SecurityCondition.getInstance(to.getObject())); 79 | 80 | case 1: 81 | return AndSecurityCondition.getInstance(to.getObject()); 82 | 83 | default: 84 | throw new IllegalArgumentException("Invalid SecurityCondition member tag ["+to.getTagNo()+"]."); 85 | 86 | } 87 | } 88 | 89 | throw new IllegalArgumentException("SecurityCondition must be encoded as an ASN.1 OCTET STRING or ASN.1 tagged object."); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/helper/IntegerHelper.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 01.01.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.helper; 24 | 25 | import java.math.BigInteger; 26 | 27 | /** 28 | * static helpers for manipulating integer values. 29 | * 30 | * @author wglas 31 | */ 32 | public abstract class IntegerHelper { 33 | 34 | private static BigInteger MIN_INT_BIG_INTEGER = BigInteger.valueOf(Integer.MIN_VALUE); 35 | private static BigInteger MAX_INT_BIG_INTEGER = BigInteger.valueOf(Integer.MAX_VALUE); 36 | 37 | /** 38 | * Checks, whether a BigInteger my be converted to an integer, 39 | * i.e. {@link BigInteger#intValue()} does neither overflow nor underflow. 40 | * 41 | * @param bi The BigInteger to convert. 42 | * @return If bi is in the correct range return true, 43 | * otherwise return false. 44 | */ 45 | public static boolean isIntValue(BigInteger bi) 46 | { 47 | if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0) 48 | return false; 49 | if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0) 50 | return false; 51 | 52 | return true; 53 | } 54 | 55 | /** 56 | * Converts a BigInteger to an integer, if the BigInteger is 57 | * in the correct range. Otherwise, an IllegalArgumentException is thrown. 58 | * 59 | * @param bi The BigInteger to convert. 60 | * @return The integer value. 61 | */ 62 | public static int intValue(BigInteger bi) 63 | { 64 | if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0) 65 | throw new IllegalArgumentException("BigInteger ["+bi+"] is too small to convert to int."); 66 | if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0) 67 | throw new IllegalArgumentException("BigInteger ["+bi+"] is too big to convert to int."); 68 | 69 | return bi.intValue(); 70 | } 71 | 72 | /** 73 | * Converts a BigInteger to an integer, if the BigInteger is 74 | * in the correct range. Otherwise, an IllegalArgumentException is thrown. 75 | * 76 | * This method is null-aware. 77 | * 78 | * @param bi The BigInteger to convert. 79 | * @return The integer value. 80 | */ 81 | public static Integer toInteger(BigInteger bi) 82 | { 83 | if (bi == null) return null; 84 | 85 | if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0) 86 | throw new IllegalArgumentException("BigInteger ["+bi+"] is too small to convert to int."); 87 | if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0) 88 | throw new IllegalArgumentException("BigInteger ["+bi+"] is too big to convert to int."); 89 | 90 | return bi.intValue(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/proxy/Directory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.proxy; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | 27 | /** 28 | * A directory for resolving references, as e.g. implemented by 29 | * TokenInfo. 30 | * 31 | * @author wglas 32 | */ 33 | public interface Directory { 34 | 35 | /** 36 | * @param ref The reference to resolve. 37 | * @return The resolved entity or null, of the reference could not be resolved. 38 | */ 39 | EntityType resolveReference(ReferenceType ref); 40 | 41 | /** 42 | * @param ref The reference to store to. 43 | * @param entity A new entity to be registered. 44 | * @return A reference to the registered entity 45 | */ 46 | void updateEntity(ReferenceType ref, EntityType entity); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/proxy/ReferenceProxy.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.proxy; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | 27 | /** 28 | * A marker interface for explicitly resolving the referenced entity. 29 | * Any value, that is stored as a ReferncedValue{EntityType} on 30 | * the token, will be returned as a proxy to the EntityType 31 | * interface. The returned proxy will always implement the ReferenceProxy 32 | * interface in order to allow updating the referenced EF of URL or to get access to 33 | * the proxied implementation of the EntityType interface. 34 | * 35 | * A proxy to an entity is serialized as the entity (Path or URL 36 | * and not as the contents of the entity, i.e. the method {@link DEREncodable#getDERObject()} 37 | * is overwritten for the proxy to return the reference instead of the implementation. 38 | * 39 | * You can get the actual implementation, which is serialized as the contents of the 40 | * referenced entity by callig {@link #resolveEntity()}. 41 | * 42 | * @param The interface of the application object. 43 | * 44 | * @see ReferenceProxyFactory 45 | * 46 | * @author wglas 47 | */ 48 | public interface ReferenceProxy extends DEREncodable { 49 | 50 | /** 51 | * @return The delegate, which is hidden by this proxy. 52 | */ 53 | public EntityType resolveEntity(); 54 | 55 | /** 56 | * Update the referenced entity. 57 | */ 58 | public void updateEntity(); 59 | } 60 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/proxy/StreamResolver.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.proxy; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | 29 | import org.bouncycastle.asn1.DEREncodable; 30 | 31 | /** 32 | * A directory for resolving references, as e.g. implemented by 33 | * TokenInfo. 34 | * 35 | * @author wglas 36 | */ 37 | public interface StreamResolver { 38 | 39 | /** 40 | * @param ref The reference to resolve. 41 | * @return An InputStream which reads from the resolved entity. 42 | * @throws IOException 43 | */ 44 | InputStream readReference(ReferenceType ref) throws IOException; 45 | 46 | /** 47 | * @param ref The reference to store to. 48 | * @return An OutputStream which writes to the resolved entity. 49 | */ 50 | OutputStream writeReference(ReferenceType ref) throws IOException; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/ref/URLDirectory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.ref; 24 | 25 | import org.bouncycastle.asn1.DEREncodable; 26 | import org.opensc.pkcs15.asn1.proxy.InstanceFactory; 27 | import org.opensc.pkcs15.asn1.proxy.StreamResolverDirectory; 28 | 29 | /** 30 | * This directory resolves URLs. 31 | * 32 | * @author wglas 33 | */ 34 | public class URLDirectory 35 | extends StreamResolverDirectory { 36 | 37 | /** 38 | * @param clazz The ASN.1 class which is instantiated. Note, 39 | * that this might be the class of an actual implementation, 40 | * if EntityType is an interface. 41 | */ 42 | public URLDirectory(Class clazz) { 43 | 44 | super(new URLStreamResolver(),clazz); 45 | } 46 | 47 | /** 48 | * @param instanceFactory The factory for ASN.1 instances. 49 | */ 50 | public URLDirectory(InstanceFactory instanceFactory) { 51 | 52 | super(new URLStreamResolver(),instanceFactory); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/ref/URLStreamResolver.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.ref; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | import java.net.MalformedURLException; 29 | 30 | import org.opensc.pkcs15.asn1.proxy.StreamResolver; 31 | 32 | /** 33 | * This StreamResolver resolves URLs. 34 | * 35 | * @author wglas 36 | */ 37 | public class URLStreamResolver 38 | implements StreamResolver { 39 | 40 | /** 41 | * Default constructor. 42 | */ 43 | public URLStreamResolver() { 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see org.opensc.pkcs15.asn1.StreamResolver#readReference(org.bouncycastle.asn1.DEREncodable) 48 | */ 49 | @Override 50 | public InputStream readReference(URL ref) { 51 | try { 52 | java.net.URL jURL = new java.net.URL(ref.getUrl()); 53 | return jURL.openStream(); 54 | } catch (MalformedURLException e) { 55 | throw new IllegalArgumentException("URL ["+ref.getUrl()+"] is malformed.",e); 56 | } catch (IOException e) { 57 | throw new IllegalArgumentException("URL ["+ref.getUrl()+"] cannot be opened.",e); 58 | } 59 | } 60 | 61 | /* (non-Javadoc) 62 | * @see org.opensc.pkcs15.asn1.StreamResolver#writeReference(org.bouncycastle.asn1.DEREncodable) 63 | */ 64 | @Override 65 | public OutputStream writeReference(URL ref) { 66 | java.net.URL jURL; 67 | 68 | try { 69 | jURL = new java.net.URL(ref.getUrl()); 70 | return jURL.openConnection().getOutputStream(); 71 | 72 | } catch (MalformedURLException e) { 73 | throw new IllegalArgumentException("URL ["+ref.getUrl()+"] is malformed.",e); 74 | } catch (IOException e) { 75 | throw new IllegalArgumentException("URL ["+ref.getUrl()+"] cannot be opened.",e); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/sequence/SequenceOf.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.sequence; 24 | 25 | import java.util.List; 26 | 27 | import org.bouncycastle.asn1.DEREncodable; 28 | 29 | /** 30 | * An ASN.1 SEQUENCE OF, which may be read from an InputStream in 31 | * or to decode referenced PathOrObjects instances. 32 | * 33 | * @author wglas 34 | * 35 | * @param 36 | */ 37 | public interface SequenceOf extends DEREncodable { 38 | 39 | /** 40 | * @return the sequence 41 | */ 42 | public List getSequence(); 43 | 44 | /** 45 | * @param sequence the sequence to set 46 | */ 47 | public void setSequence(List sequence); 48 | 49 | /** 50 | * @param e The element to add to the internal sequence. 51 | */ 52 | public void addEntity(EntityType e); 53 | 54 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/asn1/sequence/SequenceOfImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 31.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.asn1.sequence; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | import org.bouncycastle.asn1.ASN1Encodable; 29 | import org.bouncycastle.asn1.ASN1EncodableVector; 30 | import org.bouncycastle.asn1.DEREncodable; 31 | import org.bouncycastle.asn1.DERObject; 32 | import org.bouncycastle.asn1.DERSequence; 33 | 34 | /** 35 | * An ASN.1 SEQUENCE OF, which may be read from an InputStream in 36 | * or to decode referenced PathOrObjects instances. 37 | * 38 | * @author wglas 39 | */ 40 | public class SequenceOfImpl extends ASN1Encodable 41 | implements SequenceOf { 42 | 43 | private List sequence; 44 | 45 | /** 46 | * Default constructor. 47 | */ 48 | SequenceOfImpl() { 49 | } 50 | 51 | /** 52 | * @param sequence The list of elements. 53 | */ 54 | public SequenceOfImpl(List sequence) { 55 | super(); 56 | this.sequence = sequence; 57 | } 58 | 59 | /* (non-Javadoc) 60 | * @see org.bouncycastle.asn1.ASN1Encodable#toASN1Object() 61 | */ 62 | @Override 63 | public DERObject toASN1Object() { 64 | 65 | ASN1EncodableVector v = new ASN1EncodableVector(); 66 | 67 | if (this.sequence != null) { 68 | 69 | for (EntityType entity : this.sequence) 70 | v.add(entity); 71 | } 72 | 73 | return new DERSequence(v); 74 | } 75 | 76 | /* (non-Javadoc) 77 | * @see org.opensc.pkcs15.asn1.SequenceOf#getSequence() 78 | */ 79 | public List getSequence() { 80 | return this.sequence; 81 | } 82 | 83 | /* (non-Javadoc) 84 | * @see org.opensc.pkcs15.asn1.SequenceOf#setSequence(java.util.List) 85 | */ 86 | public void setSequence(List sequence) { 87 | this.sequence = sequence; 88 | } 89 | 90 | /* (non-Javadoc) 91 | * @see org.opensc.pkcs15.asn1.SequenceOf#addEntity(EntityType) 92 | */ 93 | public void addEntity(EntityType e) { 94 | 95 | if (this.sequence == null) 96 | this.sequence = new ArrayList(); 97 | 98 | this.sequence.add(e); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/ClassPathScriptResource.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | /** 29 | * A script resource, which resides on the class path. 30 | * 31 | * @author wglas 32 | */ 33 | public class ClassPathScriptResource implements ScriptResource { 34 | 35 | private final ClassLoader classLoader; 36 | private final String path; 37 | 38 | /** 39 | * @param classLoader The class loader on which to find the resource. 40 | * @param path The class path of the resource. 41 | */ 42 | public ClassPathScriptResource(ClassLoader classLoader, String path) { 43 | super(); 44 | this.classLoader = classLoader; 45 | this.path = path; 46 | } 47 | 48 | /* (non-Javadoc) 49 | * @see org.opensc.pkcs15.script.ScriptResource#asInputStream() 50 | */ 51 | @Override 52 | public InputStream asInputStream() throws IOException { 53 | 54 | return this.classLoader.getResourceAsStream(this.path); 55 | } 56 | 57 | /* (non-Javadoc) 58 | * @see org.opensc.pkcs15.script.ScriptResource#exists() 59 | */ 60 | @Override 61 | public boolean exists() { 62 | 63 | return this.classLoader.getResource(this.path) != null; 64 | } 65 | 66 | /* (non-Javadoc) 67 | * @see org.opensc.pkcs15.script.ScriptResource#openInclude(java.lang.String) 68 | */ 69 | @Override 70 | public ScriptResource openInclude(String relPath) throws IOException { 71 | 72 | int sep = this.path.lastIndexOf('/'); 73 | 74 | String newPath; 75 | 76 | if (sep >= 0) 77 | newPath = this.path.substring(0,sep+1) + relPath; 78 | else 79 | newPath = relPath; 80 | 81 | return new ClassPathScriptResource(this.classLoader,newPath); 82 | } 83 | 84 | /** 85 | * @return the class loader used to search this resource. 86 | */ 87 | public ClassLoader getClassLoader() { 88 | return this.classLoader; 89 | } 90 | 91 | /** 92 | * @return the path on the class loader of this resource. 93 | */ 94 | public String getPath() { 95 | return this.path; 96 | } 97 | 98 | public String toString() { 99 | 100 | return "classpath:"+this.path; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/Command.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import java.io.Serializable; 26 | 27 | import javax.smartcardio.CardChannel; 28 | import javax.smartcardio.CardException; 29 | 30 | /** 31 | * A command, which may be executed on a smart card channel. 32 | * 33 | * @author wglas 34 | */ 35 | public interface Command extends Serializable { 36 | 37 | /** 38 | * Execute this command on the given connected smart card channel. 39 | * 40 | * @param channel The channel to which we send the command. 41 | * @return The next command in line to execute or null, if the execution has terminated. 42 | * @throws CardException upon errors. 43 | */ 44 | public Command execute(CardChannel channel) throws CardException; 45 | } 46 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/FileScriptResource.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | /** 31 | * A script resource that can be found in the file system. 32 | * 33 | * @author wglas 34 | */ 35 | public class FileScriptResource implements ScriptResource { 36 | 37 | private final File file; 38 | 39 | /** 40 | * @param file 41 | */ 42 | public FileScriptResource(File file) { 43 | super(); 44 | this.file = file; 45 | } 46 | 47 | /* (non-Javadoc) 48 | * @see org.opensc.pkcs15.script.ScriptResource#asInputStream() 49 | */ 50 | @Override 51 | public InputStream asInputStream() throws IOException { 52 | 53 | return new FileInputStream(this.file); 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see org.opensc.pkcs15.script.ScriptResource#exists() 58 | */ 59 | @Override 60 | public boolean exists() { 61 | 62 | return this.file.exists() && this.file.isFile(); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see org.opensc.pkcs15.script.ScriptResource#openInclude(java.lang.String) 67 | */ 68 | @Override 69 | public ScriptResource openInclude(String relPath) throws IOException { 70 | 71 | if (new File(relPath).isAbsolute()) 72 | throw new IOException("The given path ["+relPath+"] is not relative."); 73 | 74 | if (relPath.contains("..")) 75 | throw new IOException("The given path ["+relPath+"] tries to escape the directory hierarchy."); 76 | 77 | return new FileScriptResource(new File(this.file.getParent(),relPath)); 78 | } 79 | 80 | /** 81 | * @return the underlying file of this resource. 82 | */ 83 | public File getFile() { 84 | return this.file; 85 | } 86 | 87 | /* (non-Javadoc) 88 | * @see java.lang.Object#toString() 89 | */ 90 | public String toString() { 91 | 92 | return "file:"+this.file.getAbsolutePath(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/ScriptParser.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * This interface is implemented by parsers of card scripts. 29 | * 30 | * @author wglas 31 | */ 32 | public interface ScriptParser { 33 | 34 | /** 35 | * @param resource The script resource to parse- 36 | * @return The first command of the script. 37 | * @throws IOException Upon errors reading or parsing the script. 38 | */ 39 | public Command parseScript(ScriptResource resource) throws IOException; 40 | } 41 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/ScriptParserFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import javax.imageio.spi.ServiceRegistry; 26 | 27 | /** 28 | * A scipt resource factory. 29 | * 30 | * @author wglas 31 | */ 32 | public abstract class ScriptParserFactory { 33 | 34 | /** 35 | * @return The script resource factory registered under 36 | * META-INF/services/org.opensc.pkcs15.script.ScriptParserFactory. 37 | */ 38 | static public ScriptParserFactory getInstance() { 39 | 40 | return ServiceRegistry.lookupProviders(ScriptParserFactory.class).next(); 41 | } 42 | 43 | /** 44 | * Construct a script parser for a script type. 45 | * 46 | * Currently supported types are ser for JAVA-serialized 47 | * scripts and csf for Siemens-style APSU scripts. 48 | * 49 | * @param type A script type. 50 | * @return A script parser. 51 | */ 52 | public abstract ScriptParser getScriptParser(String type); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/ScriptResource.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | /** 29 | * A resource, which may be opened as an {@link InputStream} and may open another resource 30 | * using a relative path, which is needed to handle include files in scripts. 31 | * 32 | * @author wglas 33 | */ 34 | public interface ScriptResource { 35 | 36 | /** 37 | * @return The content of the script resource as an input stream. 38 | * @throws IOException Upon I/O errors. 39 | */ 40 | public InputStream asInputStream() throws IOException; 41 | 42 | /** 43 | * @return Whether this resource exists. 44 | */ 45 | public boolean exists(); 46 | 47 | /** 48 | * @param relPath A relative path using / as separator. 49 | * @return A script resource representing the relative path to this resource. 50 | * @throws IOException Upon I/O errors. 51 | */ 52 | public ScriptResource openInclude(String relPath) throws IOException; 53 | } 54 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/ScriptResourceFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script; 24 | 25 | import java.io.IOException; 26 | 27 | import javax.imageio.spi.ServiceRegistry; 28 | 29 | /** 30 | * A scipt resource factory. 31 | * 32 | * @author wglas 33 | */ 34 | public abstract class ScriptResourceFactory { 35 | 36 | /** 37 | * @return The script resource factory registered under 38 | * META-INF/services/org.opensc.pkcs15.script.ScriptResourceFactory. 39 | */ 40 | static public ScriptResourceFactory getInstance() { 41 | 42 | return ServiceRegistry.lookupProviders(ScriptResourceFactory.class).next(); 43 | } 44 | 45 | /** 46 | * Construct a resource from a colon-separated scheme and path. 47 | * 48 | * Currently supported are file:/some/fs/sample.script and 49 | * classpath:org/example/scripts/sample.script. 50 | * 51 | * @param schemeAndPath A schema, a colon and a path. 52 | * @return A script resource of the given scheme and path. 53 | */ 54 | public abstract ScriptResource getScriptResource(String schemeAndPath) throws IOException; 55 | 56 | /** 57 | * Construct a resource from a scheme and a path. 58 | * 59 | * file and 60 | * classpath. 61 | * 62 | * @param scheme The scheme 63 | * @param path The path of the resource. 64 | * @return A script resource of the given scheme and path. 65 | */ 66 | public abstract ScriptResource getScriptResource(String scheme, String path) throws IOException; 67 | } 68 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/impl/SERScriptParser.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script.impl; 24 | 25 | import java.io.IOException; 26 | import java.io.ObjectInputStream; 27 | import java.io.ObjectOutputStream; 28 | 29 | import org.opensc.pkcs15.script.Command; 30 | import org.opensc.pkcs15.script.ScriptParser; 31 | import org.opensc.pkcs15.script.ScriptResource; 32 | 33 | /** 34 | * A script parser, which parses a script serialized through {@link ObjectOutputStream}. 35 | * 36 | * @author wglas 37 | */ 38 | public class SERScriptParser implements ScriptParser { 39 | 40 | /* (non-Javadoc) 41 | * @see org.opensc.pkcs15.script.ScriptParser#parseScript(org.opensc.pkcs15.script.ScriptResource) 42 | */ 43 | @Override 44 | public Command parseScript(ScriptResource resource) throws IOException { 45 | 46 | ObjectInputStream ois = new ObjectInputStream(resource.asInputStream()); 47 | 48 | try { 49 | Object obj = ois.readObject(); 50 | 51 | if (!(obj instanceof Command)) 52 | throw new IOException("Invalid object ["+obj.getClass()+"] in serialized script ["+resource+"]."); 53 | 54 | return (Command)obj; 55 | 56 | } catch (ClassNotFoundException e) { 57 | throw new IOException("Failed to load a serialized class",e); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/impl/ScriptParserFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script.impl; 24 | 25 | import org.opensc.pkcs15.script.ScriptParser; 26 | import org.opensc.pkcs15.script.ScriptParserFactory; 27 | 28 | /** 29 | * The default script parser factory implementation. 30 | * 31 | * @author wglas 32 | */ 33 | public class ScriptParserFactoryImpl extends ScriptParserFactory { 34 | 35 | /* (non-Javadoc) 36 | * @see org.opensc.pkcs15.script.ScriptParserFactory#getScriptParser(java.lang.String) 37 | */ 38 | @Override 39 | public ScriptParser getScriptParser(String type) { 40 | 41 | if ("ser".equals(type)) 42 | return new SERScriptParser(); 43 | 44 | if ("csf".equals(type)) 45 | return new CSFScriptParser(); 46 | 47 | return null; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/script/impl/ScriptResourceFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 27.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.script.impl; 24 | 25 | import java.io.File; 26 | import java.io.FileNotFoundException; 27 | import java.io.IOException; 28 | 29 | import org.opensc.pkcs15.script.ClassPathScriptResource; 30 | import org.opensc.pkcs15.script.FileScriptResource; 31 | import org.opensc.pkcs15.script.ScriptResource; 32 | import org.opensc.pkcs15.script.ScriptResourceFactory; 33 | 34 | /** 35 | * The default script resource factory implementation. 36 | * 37 | * @author wglas 38 | */ 39 | public class ScriptResourceFactoryImpl extends ScriptResourceFactory { 40 | 41 | /* (non-Javadoc) 42 | * @see org.opensc.pkcs15.script.ScriptResourceFactory#getScriptResource(java.lang.String) 43 | */ 44 | @Override 45 | public ScriptResource getScriptResource(String schemeAndPath) throws IOException { 46 | 47 | int cp = schemeAndPath.indexOf(':'); 48 | 49 | if (cp < 0) 50 | throw new IOException("The identifier ["+schemeAndPath+"] contains no colon."); 51 | 52 | return this.getScriptResource(schemeAndPath.substring(0,cp),schemeAndPath.substring(cp+1)); 53 | } 54 | 55 | /* (non-Javadoc) 56 | * @see org.opensc.pkcs15.script.ScriptResourceFactory#getScriptResource(java.lang.String, java.lang.String) 57 | */ 58 | @Override 59 | public ScriptResource getScriptResource(String scheme, String path) throws IOException { 60 | 61 | if ("file".equals(scheme)) 62 | return new FileScriptResource(new File(path)); 63 | 64 | if ("classpath".equals(scheme)) 65 | return new ClassPathScriptResource(Thread.currentThread().getContextClassLoader(),path); 66 | 67 | throw new FileNotFoundException("Unsupported scheme ["+scheme+"]."); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/DF.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * A dedicated file on the token. 27 | * 28 | * @author wglas 29 | */ 30 | public class DF extends TokenFile implements DFAcl { 31 | 32 | private final int acLifeCycle; 33 | private final int acCreate; 34 | 35 | /** 36 | * @param path 37 | * @param acLifeCycle 38 | * @param acUpdate 39 | * @param acAppend 40 | * @param acDeactivate 41 | * @param acActivate 42 | * @param acDelete 43 | * @param acAdmin 44 | * @param acCreate 45 | */ 46 | public DF(TokenPath path, long size, 47 | int acLifeCycle, int acUpdate, int acAppend, 48 | int acDeactivate, int acActivate, int acDelete, int acAdmin, int acCreate) { 49 | super(path, size, 50 | acUpdate, acAppend, acDeactivate, 51 | acActivate, acDelete, acAdmin); 52 | this.acLifeCycle = acLifeCycle; 53 | this.acCreate = acCreate; 54 | } 55 | 56 | public DF(TokenPath path, long size, DFAcl acl) 57 | { 58 | super(path,size,acl); 59 | this.acLifeCycle = acl.getAcLifeCycle(); 60 | this.acCreate = acl.getAcCreate(); 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see org.opensc.pkcs15.token.TokenFile#accept(org.opensc.pkcs15.token.TokenFileVisitor) 65 | */ 66 | @Override 67 | void accept(TokenFileVisitor visitor) { 68 | visitor.visit(this); 69 | } 70 | 71 | /* (non-Javadoc) 72 | * @see org.opensc.pkcs15.token.DFAcl#getAcLifeCycle() 73 | */ 74 | public int getAcLifeCycle() { 75 | return this.acLifeCycle; 76 | } 77 | 78 | /* (non-Javadoc) 79 | * @see org.opensc.pkcs15.token.DFAcl#getAcCreate() 80 | */ 81 | public int getAcCreate() { 82 | return this.acCreate; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/DFAcl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * This interface describes the access control list of dedicated files. 27 | * 28 | * @author wglas 29 | */ 30 | public interface DFAcl extends TokenFileAcl { 31 | 32 | /** 33 | * @return the acLifeCycle 34 | */ 35 | public int getAcLifeCycle(); 36 | 37 | /** 38 | * @return the acCreate 39 | */ 40 | public int getAcCreate(); 41 | 42 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/EF.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * An elementary file on the token. 27 | * 28 | * @author wglas 29 | */ 30 | public class EF extends TokenFile implements EFAcl { 31 | 32 | private final int acRead; 33 | private final int acIncrease; 34 | private final int acDecrease; 35 | 36 | /** 37 | * @param path 38 | * @param acRead 39 | * @param acUpdate 40 | * @param acAppend 41 | * @param acDeactivate 42 | * @param acActivate 43 | * @param acDelete 44 | * @param acAdmin 45 | */ 46 | public EF(TokenPath path, long size, 47 | int acRead, int acUpdate, int acAppend, 48 | int acDeactivate, int acActivate, int acDelete, int acAdmin, 49 | int acIncrease, int acDecrease) { 50 | super(path, size, acUpdate, acAppend, acDeactivate, acActivate, acDelete, 51 | acAdmin); 52 | this.acRead = acRead; 53 | this.acIncrease = acIncrease; 54 | this.acDecrease = acDecrease; 55 | } 56 | 57 | public EF(TokenPath path, long size, EFAcl acl) 58 | { 59 | super(path,size,acl); 60 | this.acRead = acl.getAcRead(); 61 | this.acIncrease = acl.getAcIncrease(); 62 | this.acDecrease = acl.getAcDecrease(); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see org.opensc.pkcs15.token.TokenFile#accept(org.opensc.pkcs15.token.TokenFileVisitor) 67 | */ 68 | @Override 69 | void accept(TokenFileVisitor visitor) { 70 | visitor.visit(this); 71 | } 72 | 73 | /* (non-Javadoc) 74 | * @see org.opensc.pkcs15.token.EFAcl#getAcRead() 75 | */ 76 | public int getAcRead() { 77 | return this.acRead; 78 | } 79 | 80 | /* (non-Javadoc) 81 | * @see org.opensc.pkcs15.token.EFAcl#getAcIncrease() 82 | */ 83 | public int getAcIncrease() { 84 | return this.acIncrease; 85 | } 86 | 87 | /* (non-Javadoc) 88 | * @see org.opensc.pkcs15.token.EFAcl#getAcDecrease() 89 | */ 90 | public int getAcDecrease() { 91 | return this.acDecrease; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/EFAcl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * This interface describes the access control list of an 27 | * elementary file. 28 | * 29 | * @author wglas 30 | */ 31 | public interface EFAcl extends TokenFileAcl { 32 | 33 | /** 34 | * @return the acRead 35 | */ 36 | public int getAcRead(); 37 | 38 | /** 39 | * @return the acIncrease 40 | */ 41 | public int getAcIncrease(); 42 | 43 | /** 44 | * @return the acDecrease 45 | */ 46 | public int getAcDecrease(); 47 | 48 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/MF.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * A master file on the token. 27 | * 28 | * @author wglas 29 | */ 30 | public class MF extends DF implements MFAcl { 31 | 32 | private final int acExecute; 33 | private final int acAllocate; 34 | 35 | /** 36 | * @param path 37 | * @param acLifeCycle 38 | * @param acUpdate 39 | * @param acAppend 40 | * @param acDeactivate 41 | * @param acActivate 42 | * @param acDelete 43 | * @param acAdmin 44 | * @param acCreate 45 | * @param acExecute 46 | * @param acAllocate 47 | */ 48 | public MF(TokenPath path, long size, int acLifeCycle, int acUpdate, int acAppend, 49 | int acDeactivate, int acActivate, int acDelete, int acAdmin, 50 | int acCreate, int acExecute, int acAllocate) { 51 | super(path, size, 52 | acLifeCycle, acUpdate, acAppend, acDeactivate, acActivate, acDelete, 53 | acAdmin,acCreate); 54 | this.acExecute = acExecute; 55 | this.acAllocate = acAllocate; 56 | } 57 | 58 | public MF(TokenPath path, long size, MFAcl acl) 59 | { 60 | super(path,size,acl); 61 | this.acExecute = acl.getAcExecute(); 62 | this.acAllocate = acl.getAcAllocate(); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see org.opensc.pkcs15.token.TokenFile#accept(org.opensc.pkcs15.token.TokenFileVisitor) 67 | */ 68 | @Override 69 | void accept(TokenFileVisitor visitor) { 70 | visitor.visit(this); 71 | } 72 | 73 | /* (non-Javadoc) 74 | * @see org.opensc.pkcs15.token.MFAcl#getAcExecute() 75 | */ 76 | public int getAcExecute() { 77 | return this.acExecute; 78 | } 79 | 80 | /* (non-Javadoc) 81 | * @see org.opensc.pkcs15.token.MFAcl#getAcAllocate() 82 | */ 83 | public int getAcAllocate() { 84 | return this.acAllocate; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/MFAcl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * This interface describes the access control list of the master file 27 | * on a token. 28 | * 29 | * @author wglas 30 | */ 31 | public interface MFAcl extends DFAcl { 32 | 33 | /** 34 | * @return the acExecute 35 | */ 36 | public int getAcExecute(); 37 | 38 | /** 39 | * @return the acAllocate 40 | */ 41 | public int getAcAllocate(); 42 | 43 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/TokenFactory.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 26.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | import java.io.File; 26 | import java.io.IOException; 27 | 28 | import javax.imageio.spi.ServiceRegistry; 29 | import javax.smartcardio.Card; 30 | 31 | /** 32 | * A factory for token instances. 33 | * 34 | * @author wglas 35 | */ 36 | public abstract class TokenFactory { 37 | 38 | /** 39 | * @return The first instance registered under the resource path 40 | * META-INF/serivces/org.opensc.pkcs15.token.TokenFactory. 41 | * 42 | * @see ServiceRegistry#lookupProviders(Class) 43 | */ 44 | public static TokenFactory newInstance() 45 | { 46 | return ServiceRegistry.lookupProviders(TokenFactory.class).next(); 47 | } 48 | 49 | /** 50 | * @param card A connected smart card. 51 | * @return The token instance depending on the ATR of the supplied card. 52 | * @throws IOException Upon errors. 53 | */ 54 | public abstract Token newHardwareToken(Card card) throws IOException; 55 | 56 | /** 57 | * @param file A zip file or a directory containing the token infrastructure. 58 | * @return A token instance for the software token. 59 | * @throws IOException Upon errors. 60 | */ 61 | public abstract Token newSoftwareToken(File file) throws IOException; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/TokenFileAcl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * This interface describes the access control list common to all token 27 | * files. 28 | * 29 | * @author wglas 30 | */ 31 | public interface TokenFileAcl { 32 | 33 | public static final int AC_ALWAYS = 0; 34 | 35 | public static final int AC_NEVER = 0xff; 36 | 37 | /** 38 | * @return the acUpdate 39 | */ 40 | public int getAcUpdate(); 41 | 42 | /** 43 | * @return the acAppend 44 | */ 45 | public int getAcAppend(); 46 | 47 | /** 48 | * @return the acActivate 49 | */ 50 | public int getAcActivate(); 51 | 52 | /** 53 | * @return the acDeactivate 54 | */ 55 | public int getAcDeactivate(); 56 | 57 | /** 58 | * @return the acDelete 59 | */ 60 | public int getAcDelete(); 61 | 62 | /** 63 | * @return the acAdmin 64 | */ 65 | public int getAcAdmin(); 66 | 67 | } -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/TokenFileVisitor.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token; 24 | 25 | /** 26 | * @author wglas 27 | * 28 | */ 29 | public interface TokenFileVisitor { 30 | 31 | void visit(DFAcl df); 32 | 33 | void visit(EFAcl ef); 34 | 35 | void visit(MFAcl mf); 36 | } 37 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/impl/DFAclImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token.impl; 24 | 25 | import org.opensc.pkcs15.token.DFAcl; 26 | 27 | /** 28 | * A dedicated file on the token. 29 | * 30 | * @author wglas 31 | */ 32 | public class DFAclImpl extends TokenFileAclImpl implements DFAcl { 33 | 34 | private final int acLifeCycle; 35 | private final int acCreate; 36 | 37 | /** 38 | * @param path 39 | * @param acLifeCycle 40 | * @param acUpdate 41 | * @param acAppend 42 | * @param acDeactivate 43 | * @param acActivate 44 | * @param acDelete 45 | * @param acAdmin 46 | * @param acCreate 47 | */ 48 | public DFAclImpl(int acLifeCycle, int acUpdate, int acAppend, 49 | int acDeactivate, int acActivate, int acDelete, int acAdmin, int acCreate) { 50 | super(acUpdate, acAppend, acDeactivate, acActivate, acDelete, 51 | acAdmin); 52 | this.acLifeCycle = acLifeCycle; 53 | this.acCreate = acCreate; 54 | } 55 | 56 | public DFAclImpl(DFAcl acl) 57 | { 58 | super(acl); 59 | this.acLifeCycle = acl.getAcLifeCycle(); 60 | this.acCreate = acl.getAcCreate(); 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see org.opensc.pkcs15.token.DFAcl#getAcLifeCycle() 65 | */ 66 | public int getAcLifeCycle() { 67 | return this.acLifeCycle; 68 | } 69 | 70 | /* (non-Javadoc) 71 | * @see org.opensc.pkcs15.token.DFAcl#getAcCreate() 72 | */ 73 | public int getAcCreate() { 74 | return this.acCreate; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/impl/EFAclImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token.impl; 24 | 25 | import org.opensc.pkcs15.token.EFAcl; 26 | 27 | /** 28 | * An implementation of an ACL for elementary files. 29 | * 30 | * @author wglas 31 | */ 32 | public class EFAclImpl extends TokenFileAclImpl implements EFAcl { 33 | 34 | private final int acRead; 35 | private final int acIncrease; 36 | private final int acDecrease; 37 | 38 | /** 39 | * @param path 40 | * @param acRead 41 | * @param acUpdate 42 | * @param acAppend 43 | * @param acDeactivate 44 | * @param acActivate 45 | * @param acDelete 46 | * @param acAdmin 47 | */ 48 | public EFAclImpl(int acRead, int acUpdate, int acAppend, 49 | int acDeactivate, int acActivate, int acDelete, int acAdmin, 50 | int acIncrease, int acDecrease) { 51 | super(acUpdate, acAppend, acDeactivate, acActivate, acDelete, 52 | acAdmin); 53 | this.acRead = acRead; 54 | this.acIncrease = acIncrease; 55 | this.acDecrease = acDecrease; 56 | } 57 | 58 | public EFAclImpl(EFAcl acl) 59 | { 60 | super(acl); 61 | this.acRead = acl.getAcRead(); 62 | this.acIncrease = acl.getAcIncrease(); 63 | this.acDecrease = acl.getAcDecrease(); 64 | } 65 | 66 | /* (non-Javadoc) 67 | * @see org.opensc.pkcs15.token.EFAcl#getAcRead() 68 | */ 69 | public int getAcRead() { 70 | return this.acRead; 71 | } 72 | 73 | /* (non-Javadoc) 74 | * @see org.opensc.pkcs15.token.EFAcl#getAcIncrease() 75 | */ 76 | public int getAcIncrease() { 77 | return this.acIncrease; 78 | } 79 | 80 | /* (non-Javadoc) 81 | * @see org.opensc.pkcs15.token.EFAcl#getAcDecrease() 82 | */ 83 | public int getAcDecrease() { 84 | return this.acDecrease; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/impl/MFAclImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 25.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token.impl; 24 | 25 | import org.opensc.pkcs15.token.MFAcl; 26 | 27 | /** 28 | * An implementation of an ACL for the master file on the token. 29 | * 30 | * @author wglas 31 | */ 32 | public class MFAclImpl extends DFAclImpl implements MFAcl { 33 | 34 | private final int acExecute; 35 | private final int acAllocate; 36 | 37 | /** 38 | * @param path 39 | * @param acLifeCycle 40 | * @param acUpdate 41 | * @param acAppend 42 | * @param acDeactivate 43 | * @param acActivate 44 | * @param acDelete 45 | * @param acAdmin 46 | * @param acCreate 47 | * @param acExecute 48 | * @param acAllocate 49 | */ 50 | public MFAclImpl(int acLifeCycle, int acUpdate, int acAppend, 51 | int acDeactivate, int acActivate, int acDelete, int acAdmin, 52 | int acCreate, int acExecute, int acAllocate) { 53 | super(acLifeCycle, acUpdate, acAppend, acDeactivate, acActivate, acDelete, 54 | acAdmin,acCreate); 55 | this.acExecute = acExecute; 56 | this.acAllocate = acAllocate; 57 | } 58 | 59 | public MFAclImpl(MFAcl acl) 60 | { 61 | super(acl); 62 | this.acExecute = acl.getAcExecute(); 63 | this.acAllocate = acl.getAcAllocate(); 64 | } 65 | 66 | /* (non-Javadoc) 67 | * @see org.opensc.pkcs15.token.MFAcl#getAcExecute() 68 | */ 69 | public int getAcExecute() { 70 | return this.acExecute; 71 | } 72 | 73 | /* (non-Javadoc) 74 | * @see org.opensc.pkcs15.token.MFAcl#getAcAllocate() 75 | */ 76 | public int getAcAllocate() { 77 | return this.acAllocate; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /pkcs15/src/main/java/org/opensc/pkcs15/token/impl/TokenFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 26.12.2007 20 | * 21 | ***********************************************************/ 22 | 23 | package org.opensc.pkcs15.token.impl; 24 | 25 | import java.io.File; 26 | import java.io.IOException; 27 | 28 | import javax.smartcardio.ATR; 29 | import javax.smartcardio.Card; 30 | 31 | import org.opensc.pkcs15.token.Token; 32 | import org.opensc.pkcs15.token.TokenFactory; 33 | import org.opensc.pkcs15.util.Util; 34 | 35 | /** 36 | * @author wglas 37 | * 38 | */ 39 | public class TokenFactoryImpl extends TokenFactory { 40 | 41 | /* (non-Javadoc) 42 | * @see org.opensc.pkcs15.token.TokenFactory#newHardwareToken(javax.smartcardio.Card) 43 | */ 44 | @Override 45 | public Token newHardwareToken(Card card) throws IOException { 46 | 47 | ATR atr = card.getATR(); 48 | 49 | if (CardOSToken.CARDOS_4_3_b_ATR.equals(atr)) 50 | return new CardOSToken(card.getBasicChannel()); 51 | 52 | throw new IOException("Card has an unrecognized ATR ["+Util.asHex(atr.getBytes())+"]."); 53 | } 54 | 55 | /* (non-Javadoc) 56 | * @see org.opensc.pkcs15.token.TokenFactory#newSoftwareToken(java.io.File) 57 | */ 58 | @Override 59 | public Token newSoftwareToken(File file) throws IOException { 60 | 61 | return new SoftwareToken(file); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /pkcs15/src/main/resources/META-INF/services/org.opensc.pkcs15.application.ApplicationFactory: -------------------------------------------------------------------------------- 1 | org.opensc.pkcs15.application.impl.ApplicationFactoryImpl -------------------------------------------------------------------------------- /pkcs15/src/main/resources/META-INF/services/org.opensc.pkcs15.script.ScriptParserFactory: -------------------------------------------------------------------------------- 1 | org.opensc.pkcs15.script.impl.ScriptParserFactoryImpl -------------------------------------------------------------------------------- /pkcs15/src/main/resources/META-INF/services/org.opensc.pkcs15.script.ScriptResourceFactory: -------------------------------------------------------------------------------- 1 | org.opensc.pkcs15.script.impl.ScriptResourceFactoryImpl -------------------------------------------------------------------------------- /pkcs15/src/main/resources/META-INF/services/org.opensc.pkcs15.token.TokenFactory: -------------------------------------------------------------------------------- 1 | org.opensc.pkcs15.token.impl.TokenFactoryImpl -------------------------------------------------------------------------------- /pkcs15/src/main/resources/org/opensc/pkcs15/scripts/cardos/v43b_reset.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenSC/OpenSC-Java/407052dfca26fa93b1e6178bb001003982df8c45/pkcs15/src/main/resources/org/opensc/pkcs15/scripts/cardos/v43b_reset.ser -------------------------------------------------------------------------------- /pkcs15/src/test/java/test/org/opensc/pkcs15/HardwareCardSupport.java: -------------------------------------------------------------------------------- 1 | package test.org.opensc.pkcs15; 2 | 3 | import java.awt.Frame; 4 | import java.awt.GraphicsConfiguration; 5 | import java.awt.Label; 6 | import java.awt.Point; 7 | import java.awt.Rectangle; 8 | 9 | import javax.smartcardio.Card; 10 | import javax.smartcardio.CardTerminal; 11 | import javax.smartcardio.CardTerminals; 12 | import javax.smartcardio.TerminalFactory; 13 | import javax.smartcardio.CardTerminals.State; 14 | 15 | import junit.framework.TestCase; 16 | 17 | public abstract class HardwareCardSupport extends TestCase { 18 | 19 | private static TerminalFactory terminalFactory = TerminalFactory.getDefault(); 20 | protected Card card; 21 | 22 | public HardwareCardSupport() { 23 | super(); 24 | } 25 | 26 | public HardwareCardSupport(String name) { 27 | super(name); 28 | } 29 | 30 | protected void setUp() throws Exception { 31 | 32 | CardTerminal terminal = null; 33 | 34 | CardTerminals terminals = terminalFactory.terminals(); 35 | 36 | for (CardTerminal ct : terminals.list()) 37 | { 38 | if (ct.isCardPresent()) 39 | { 40 | terminal = ct; 41 | break; 42 | } 43 | } 44 | 45 | if (terminal==null) 46 | { 47 | Frame frame = new Frame("Enter card"); 48 | 49 | Label label = new Label("Please insert smart card."); 50 | frame.add(label); 51 | frame.pack(); 52 | frame.setVisible(true); 53 | GraphicsConfiguration gc = frame.getGraphicsConfiguration(); 54 | Rectangle r = gc.getBounds(); 55 | Point p = new Point((r.width-frame.getWidth())/2,(r.height-frame.getHeight())/2); 56 | 57 | frame.setLocation(p); 58 | 59 | terminals.waitForChange(60000); 60 | 61 | for (CardTerminal ct : terminals.list(State.CARD_INSERTION)) 62 | { 63 | if (ct.isCardPresent()) 64 | { 65 | terminal = ct; 66 | break; 67 | } 68 | } 69 | 70 | frame.setVisible(false); 71 | frame.dispose(); 72 | if (terminal == null) 73 | throw new RuntimeException("No card inserted after 60 seconds."); 74 | } 75 | 76 | this.card = terminal.connect("*"); 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /pkcs15/src/test/java/test/org/opensc/pkcs15/TestCSFScripts.java: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | * $Id$ 3 | * 4 | * PKCS#15 cryptographic provider of the opensc project. 5 | * http://www.opensc-project.org 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Created: 29.12.2008 20 | * 21 | ***********************************************************/ 22 | 23 | package test.org.opensc.pkcs15; 24 | 25 | import java.io.IOException; 26 | 27 | import javax.smartcardio.CardException; 28 | 29 | import org.opensc.pkcs15.script.Command; 30 | import org.opensc.pkcs15.script.ScriptParser; 31 | import org.opensc.pkcs15.script.ScriptParserFactory; 32 | import org.opensc.pkcs15.script.ScriptResource; 33 | import org.opensc.pkcs15.script.ScriptResourceFactory; 34 | 35 | /** 36 | * Test Siemens' CSF sccripts. 37 | * 38 | * @author wglas 39 | */ 40 | public class TestCSFScripts extends HardwareCardSupport { 41 | 42 | private static final ScriptResourceFactory scriptResourceFactory = ScriptResourceFactory.getInstance(); 43 | private static final ScriptParserFactory scriptParserFactory = ScriptParserFactory.getInstance(); 44 | 45 | private String getResourceBase() { 46 | 47 | String s = System.getProperty("org.opensc.pkcs15.test.resourceBase"); 48 | 49 | if (s != null) return s; 50 | 51 | return "file:/home/ev-i/Siemens/SmartCard/Unterlagen/CardOS_V4.3B/Packages_and_Release_Notes/V43B_CSF_Files_2005_05/Run_CSF"; 52 | } 53 | 54 | private String getScript() { 55 | 56 | String s = System.getProperty("org.opensc.pkcs15.test.script"); 57 | 58 | if (s != null) return s; 59 | 60 | return "Run_V43B_Erase_Profile_Default.csf"; 61 | } 62 | 63 | public void testInitScripts() throws IOException, CardException { 64 | 65 | String resPath= this.getResourceBase() + "/" + this.getScript(); 66 | 67 | ScriptResource res = scriptResourceFactory.getScriptResource(resPath); 68 | 69 | ScriptParser csfParser = scriptParserFactory.getScriptParser("csf"); 70 | 71 | Command cmd = csfParser.parseScript(res); 72 | 73 | while (cmd != null) 74 | cmd = cmd.execute(this.card.getBasicChannel()); 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /pkcs15/src/test/java/test/org/opensc/pkcs15/TestHardwareToken.java: -------------------------------------------------------------------------------- 1 | package test.org.opensc.pkcs15; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | 7 | 8 | import org.opensc.pkcs15.AIDs; 9 | import org.opensc.pkcs15.application.Application; 10 | import org.opensc.pkcs15.application.ApplicationFactory; 11 | import org.opensc.pkcs15.token.Token; 12 | import org.opensc.pkcs15.token.TokenFactory; 13 | 14 | public class TestHardwareToken extends HardwareCardSupport { 15 | 16 | private static TokenFactory tokenFactory = TokenFactory.newInstance(); 17 | private static ApplicationFactory applicationFactory = ApplicationFactory.newInstance(); 18 | 19 | public void testApplicationFactory() throws IOException 20 | { 21 | Token token = tokenFactory.newHardwareToken(this.card); 22 | List apps = applicationFactory.listApplications(token); 23 | 24 | assertNotNull(apps); 25 | assertEquals(1,apps.size()); 26 | assertEquals(AIDs.PKCS15_AID,apps.get(0).getAID()); 27 | } 28 | 29 | public void testApplicationCreation() throws IOException 30 | { 31 | Token token = tokenFactory.newHardwareToken(this.card); 32 | 33 | token.reset(); 34 | 35 | Application app = applicationFactory.createApplication(token,AIDs.PKCS15_AID); 36 | 37 | assertNotNull(app); 38 | 39 | List apps = applicationFactory.listApplications(token); 40 | 41 | assertNotNull(apps); 42 | assertEquals(1,apps.size()); 43 | assertEquals(AIDs.PKCS15_AID,apps.get(0).getAID()); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /pkcs15/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | #### Use two appenders, one to log to console, another to log to a file 5 | log4j.rootCategory=INFO, R 6 | 7 | # Print only messages of priority WARN or higher for your category 8 | log4j.category.org.opensc=DEBUG 9 | # Specifically inherit the priority level 10 | #log4j.category.your.category.name=INHERITED 11 | 12 | #### First appender writes to console 13 | log4j.appender.R=org.apache.log4j.ConsoleAppender 14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 15 | 16 | # Pattern to output the caller's file name and line number. 17 | log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 18 | -------------------------------------------------------------------------------- /pkcs15/src/test/resources/test/org/opensc/pkcs15/test-ca.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenSC/OpenSC-Java/407052dfca26fa93b1e6178bb001003982df8c45/pkcs15/src/test/resources/test/org/opensc/pkcs15/test-ca.zip --------------------------------------------------------------------------------