1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.apache.harmony.xnet.provider.jsse; 18 19 import java.io.InputStream; 20 import java.io.OutputStream; 21 import java.security.Key; 22 import java.security.KeyStoreSpi; 23 import java.security.cert.Certificate; 24 import java.util.Collections; 25 import java.util.Date; 26 import java.util.Enumeration; 27 28 /** 29 * A KeyStoreSpi wrapper for the TrustedCertificateStore. 30 */ 31 public final class TrustedCertificateKeyStoreSpi extends KeyStoreSpi { 32 33 private final TrustedCertificateStore store = new TrustedCertificateStore(); 34 35 @Override public Key engineGetKey(String alias, char[] password) { 36 if (alias == null) { 37 throw new NullPointerException("alias == null"); 38 } 39 return null; 40 } 41 42 @Override public Certificate[] engineGetCertificateChain(String alias) { 43 if (alias == null) { 44 throw new NullPointerException("alias == null"); 45 } 46 return null; 47 } 48 49 @Override public Certificate engineGetCertificate(String alias) { 50 return store.getCertificate(alias); 51 } 52 53 @Override public Date engineGetCreationDate(String alias) { 54 return store.getCreationDate(alias); 55 } 56 57 @Override public void engineSetKeyEntry( 58 String alias, Key key, char[] password, Certificate[] chain) { 59 throw new UnsupportedOperationException(); 60 } 61 62 @Override public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) { 63 throw new UnsupportedOperationException(); 64 } 65 66 @Override public void engineSetCertificateEntry(String alias, Certificate cert) { 67 if (alias == null) { 68 throw new NullPointerException("alias == null"); 69 } 70 throw new UnsupportedOperationException(); 71 } 72 73 @Override public void engineDeleteEntry(String alias) { 74 throw new UnsupportedOperationException(); 75 } 76 77 @Override public Enumeration<String> engineAliases() { 78 return Collections.enumeration(store.aliases()); 79 } 80 81 @Override public boolean engineContainsAlias(String alias) { 82 return store.containsAlias(alias); 83 } 84 85 @Override public int engineSize() { 86 return store.aliases().size(); 87 } 88 89 @Override public boolean engineIsKeyEntry(String alias) { 90 if (alias == null) { 91 throw new NullPointerException("alias == null"); 92 } 93 return false; 94 } 95 96 @Override public boolean engineIsCertificateEntry(String alias) { 97 return engineContainsAlias(alias); 98 } 99 100 @Override public String engineGetCertificateAlias(Certificate c) { 101 return store.getCertificateAlias(c); 102 } 103 104 @Override public void engineStore(OutputStream stream, char[] password) { 105 throw new UnsupportedOperationException(); 106 } 107 108 @Override public void engineLoad(InputStream stream, char[] password) { 109 if (stream != null) { 110 throw new UnsupportedOperationException(); 111 } 112 } 113 } 114