();
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 extends DEREncodable, Operations> 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 extends DEREncodable, Operations> 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 extends DEREncodable, Operations> 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
--------------------------------------------------------------------------------