001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.security.tests.support;
019:
020: import java.security.InvalidKeyException;
021: import java.security.KeyStore;
022: import java.security.NoSuchAlgorithmException;
023: import java.security.NoSuchProviderException;
024: import java.security.PrivateKey;
025: import java.security.Provider;
026: import java.security.PublicKey;
027: import java.security.SignatureException;
028: import java.security.cert.Certificate;
029: import java.security.cert.CertificateEncodingException;
030: import java.security.cert.CertificateException;
031:
032: import javax.crypto.SecretKey;
033:
034: /**
035: * Support class for KeyStore tests
036: *
037: */
038:
039: public class KeyStoreTestSupport {
040:
041: public static final String srvKeyStore = "KeyStore";
042:
043: public static String[] validValues = { "bks", "BKS", "bKS", "Bks",
044: "bKs", "BkS" };
045:
046: public static String defaultType = "bks";
047:
048: public static boolean JKSSupported = false;
049:
050: public static String defaultProviderName = null;
051:
052: public static Provider defaultProvider = null;
053:
054: static {
055: defaultProvider = SpiEngUtils.isSupport(defaultType,
056: srvKeyStore);
057: JKSSupported = (defaultProvider != null);
058: defaultProviderName = (JKSSupported ? defaultProvider.getName()
059: : null);
060: }
061:
062: /**
063: * Additional class to create SecretKey object
064: */
065: public static class SKey implements SecretKey {
066: private String type;
067:
068: private byte[] encoded;
069:
070: public SKey(String type, byte[] encoded) {
071: this .type = type;
072: this .encoded = encoded;
073: }
074:
075: public String getAlgorithm() {
076: return type;
077: }
078:
079: public byte[] getEncoded() {
080: return encoded;
081: }
082:
083: public String getFormat() {
084: return "test";
085: }
086: }
087:
088: /**
089: * Additional class to create PrivateKey object
090: */
091: public static class MyPrivateKey implements PrivateKey {
092: private String algorithm;
093:
094: private String format;
095:
096: private byte[] encoded;
097:
098: public MyPrivateKey(String algorithm, String format,
099: byte[] encoded) {
100: this .algorithm = algorithm;
101: this .format = format;
102: this .encoded = encoded;
103: }
104:
105: public String getAlgorithm() {
106: return algorithm;
107: }
108:
109: public String getFormat() {
110: return format;
111: }
112:
113: public byte[] getEncoded() {
114: return encoded;
115: }
116: }
117:
118: /**
119: * Additional class to create Certificate and Key objects
120: */
121: public static class MCertificate extends Certificate {
122: private final byte[] encoding;
123:
124: private final String type;
125:
126: public MCertificate(String type, byte[] encoding) {
127: super (type);
128: this .encoding = encoding;
129: this .type = type;
130: }
131:
132: public byte[] getEncoded() throws CertificateEncodingException {
133: return encoding.clone();
134: }
135:
136: public void verify(PublicKey key) throws CertificateException,
137: NoSuchAlgorithmException, InvalidKeyException,
138: NoSuchProviderException, SignatureException {
139: }
140:
141: public void verify(PublicKey key, String sigProvider)
142: throws CertificateException, NoSuchAlgorithmException,
143: InvalidKeyException, NoSuchProviderException,
144: SignatureException {
145: }
146:
147: public String toString() {
148: return "[MCertificate, type: " + getType() + "]";
149: }
150:
151: public PublicKey getPublicKey() {
152: return new PublicKey() {
153: public String getAlgorithm() {
154: return type;
155: }
156:
157: public byte[] getEncoded() {
158: return encoding;
159: }
160:
161: public String getFormat() {
162: return "test";
163: }
164: };
165: }
166: }
167:
168: /**
169: * Additional class to create ProtectionParameter object
170: */
171: public static class ProtPar implements KeyStore.ProtectionParameter {
172: }
173:
174: /**
175: * Additional class to create KeyStore.Entry object
176: */
177: public static class AnotherEntry implements KeyStore.Entry {
178: }
179: }
|