2 * Copyright (C) 2014 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 package org.strongswan.android.security;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.security.Key;
22 import java.security.KeyStoreException;
23 import java.security.KeyStoreSpi;
24 import java.security.NoSuchAlgorithmException;
25 import java.security.UnrecoverableKeyException;
26 import java.security.cert.Certificate;
27 import java.security.cert.CertificateException;
28 import java.util.Collections;
29 import java.util.Date;
30 import java.util.Enumeration;
32 public class LocalCertificateKeyStoreSpi extends KeyStoreSpi
34 private final LocalCertificateStore mStore = new LocalCertificateStore();
37 public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException
43 public Certificate[] engineGetCertificateChain(String alias)
49 public Certificate engineGetCertificate(String alias)
51 return mStore.getCertificate(alias);
55 public Date engineGetCreationDate(String alias)
57 return mStore.getCreationDate(alias);
61 public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException
63 throw new UnsupportedOperationException();
67 public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException
69 throw new UnsupportedOperationException();
73 public void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException
75 /* we ignore the given alias as the store calculates it on its own,
76 * duplicates are replaced */
77 if (!mStore.addCertificate(cert))
79 throw new KeyStoreException();
84 public void engineDeleteEntry(String alias) throws KeyStoreException
86 mStore.deleteCertificate(alias);
90 public Enumeration<String> engineAliases()
92 return Collections.enumeration(mStore.aliases());
96 public boolean engineContainsAlias(String alias)
98 return mStore.containsAlias(alias);
102 public int engineSize()
104 return mStore.aliases().size();
108 public boolean engineIsKeyEntry(String alias)
114 public boolean engineIsCertificateEntry(String alias)
116 return engineContainsAlias(alias);
120 public String engineGetCertificateAlias(Certificate cert)
122 return mStore.getCertificateAlias(cert);
126 public void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
128 throw new UnsupportedOperationException();
132 public void engineLoad(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
136 throw new UnsupportedOperationException();