1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19 * @author Vera Y. Petrashkova 20 * @version $Revision$ 21 */ 22 23package org.apache.harmony.security.tests.support; 24 25import java.io.ByteArrayOutputStream; 26import java.io.IOException; 27import java.io.InputStream; 28import java.io.OutputStream; 29import java.security.Key; 30import java.security.KeyStoreException; 31import java.security.KeyStoreSpi; 32import java.security.NoSuchAlgorithmException; 33import java.security.PublicKey; 34import java.security.UnrecoverableKeyException; 35import java.security.cert.Certificate; 36import java.security.cert.CertificateException; 37import java.util.Date; 38import java.util.Enumeration; 39 40/** 41 * Additional class for KeyStoreSpi and KeyStore verification 42 * 43 */ 44 45public class MyKeyStoreSpi extends KeyStoreSpi { 46 47 @SuppressWarnings("unused") 48 public Key engineGetKey(String alias, char[] password) 49 throws NoSuchAlgorithmException, UnrecoverableKeyException { 50 return null; 51 } 52 53 public Certificate[] engineGetCertificateChain(String alias) { 54 return null; 55 } 56 57 public Certificate engineGetCertificate(String alias) { 58 if (alias.equals("test_engineEntryInstanceOf_Alias1")) { 59 return new MyCertificate("TestType"); 60 } 61 return null; 62 } 63 64 public Date engineGetCreationDate(String alias) { 65 return new Date(0); 66 } 67 68 public void engineSetKeyEntry(String alias, Key key, char[] password, 69 Certificate[] chain) throws KeyStoreException { 70 throw new KeyStoreException( 71 "engineSetKeyEntry is not supported in myKeyStoreSpi"); 72 } 73 74 public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) 75 throws KeyStoreException { 76 throw new KeyStoreException( 77 "engineSetKeyEntry is not supported in myKeyStoreSpi"); 78 } 79 80 public void engineSetCertificateEntry(String alias, Certificate cert) 81 throws KeyStoreException { 82 throw new KeyStoreException( 83 "engineSetCertificateEntry is not supported in myKeyStoreSpi"); 84 } 85 86 public void engineDeleteEntry(String alias) throws KeyStoreException { 87 throw new KeyStoreException( 88 "engineDeleteEntry is not supported in myKeyStoreSpi"); 89 } 90 91 public Enumeration<String> engineAliases() { 92 return null; 93 } 94 95 public boolean engineContainsAlias(String alias) { 96 if (alias != null) 97 { 98 return alias.startsWith("test_engineEntry"); 99 } 100 return false; 101 } 102 103 public int engineSize() { 104 return 0; 105 } 106 107 public boolean engineIsKeyEntry(String alias) { 108 if (alias.equals("test_engineEntryInstanceOf_Alias1")) { 109 return true; 110 } else { 111 return false; 112 } 113 114 } 115 116 public boolean engineIsCertificateEntry(String alias) { 117 if (alias.equals("test_engineEntryInstanceOf_Alias2")) { 118 return true; 119 } else { 120 return false; 121 } 122 } 123 124 public String engineGetCertificateAlias(Certificate cert) { 125 return ""; 126 } 127 128 @SuppressWarnings("unused") 129 public void engineStore(OutputStream stream, char[] password) 130 throws IOException, NoSuchAlgorithmException, CertificateException { 131 if (!(stream instanceof ByteArrayOutputStream)) { 132 throw new IOException("Incorrect stream"); 133 } 134 if (((ByteArrayOutputStream) stream).size() == 0) { 135 throw new IOException("Incorrect stream size "); 136 137 } 138 139 } 140 141 @SuppressWarnings("unused") 142 public void engineLoad(InputStream stream, char[] password) 143 throws IOException, NoSuchAlgorithmException, CertificateException { 144 } 145 146 class MyCertificate extends Certificate { 147 public MyCertificate(String type) { 148 super(type); 149 } 150 151 public byte[] getEncoded() { 152 return null; 153 } 154 155 public PublicKey getPublicKey() { 156 return null; 157 } 158 159 public String toString() { 160 return null; 161 } 162 163 public void verify(PublicKey key) { 164 165 } 166 167 public void verify(PublicKey key, String sigProvider) { 168 169 } 170 } 171}