KeyStore.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef _CLASS_BEE_SECURITY_KEYSTORE_H
00024 #define _CLASS_BEE_SECURITY_KEYSTORE_H
00025
00026 #ifdef __cplusplus
00027
00028 #include "beecrypt/c++/array.h"
00029 using beecrypt::array;
00030 #include "beecrypt/c++/security/KeyStoreSpi.h"
00031 using beecrypt::security::KeyStoreSpi;
00032 #include "beecrypt/c++/security/PrivateKey.h"
00033 using beecrypt::security::PrivateKey;
00034 #include "beecrypt/c++/crypto/SecretKey.h"
00035 using beecrypt::crypto::SecretKey;
00036 #include "beecrypt/c++/security/Provider.h"
00037 using beecrypt::security::Provider;
00038 #include "beecrypt/c++/security/auth/Destroyable.h"
00039 using beecrypt::security::auth::Destroyable;
00040
00041 namespace beecrypt {
00042 namespace security {
00045 class BEECRYPTCXXAPI KeyStore : public Object
00046 {
00047 public:
00048 class BEECRYPTCXXAPI ProtectionParameter
00049 {
00050 public:
00051 virtual ~ProtectionParameter() {}
00052 };
00053
00054 class BEECRYPTCXXAPI LoadStoreParameter
00055 {
00056 public:
00057 virtual ~LoadStoreParameter() {}
00058
00059 virtual KeyStore::ProtectionParameter* getProtectionParameter() = 0;
00060 };
00061
00062
00063 class BEECRYPTCXXAPI PasswordProtection : public beecrypt::lang::Object, public virtual ProtectionParameter, public virtual beecrypt::security::auth::Destroyable
00064 {
00065 private:
00066 array<jchar>* _pwd;
00067 bool _destroyed;
00068
00069 public:
00070 PasswordProtection(const array<jchar>* password);
00071 virtual ~PasswordProtection();
00072
00073 virtual void destroy() throw (DestroyFailedException);
00074
00075 const array<jchar>* getPassword() const;
00076
00077 virtual bool isDestroyed() const throw ();
00078 };
00079
00080 class BEECRYPTCXXAPI Entry
00081 {
00082 public:
00083 virtual ~Entry() {}
00084 };
00085
00086 class BEECRYPTCXXAPI PrivateKeyEntry : public beecrypt::lang::Object, public virtual beecrypt::security::KeyStore::Entry
00087 {
00088 private:
00089 PrivateKey* _pri;
00090 array<Certificate*> _chain;
00091
00092 public:
00093 PrivateKeyEntry(PrivateKey* privateKey, const array<Certificate*>& chain);
00094 virtual ~PrivateKeyEntry();
00095
00096 const Certificate& getCertificate() const;
00097 const array<Certificate*>& getCertificateChain() const;
00098 const PrivateKey& getPrivateKey() const;
00099
00100 virtual String toString() const throw ();
00101 };
00102
00103 class BEECRYPTCXXAPI SecretKeyEntry : public beecrypt::lang::Object, public virtual beecrypt::security::KeyStore::Entry
00104 {
00105 private:
00106 SecretKey* _sec;
00107
00108 public:
00109 SecretKeyEntry(SecretKey* secretKey);
00110 virtual ~SecretKeyEntry();
00111
00112 const SecretKey& getSecretKey() const;
00113
00114 virtual String toString() const throw ();
00115 };
00116
00117 class TrustedCertificateEntry : public beecrypt::lang::Object, public virtual beecrypt::security::KeyStore::Entry
00118 {
00119 private:
00120 Certificate* _cert;
00121
00122 public:
00123 TrustedCertificateEntry(Certificate* cert);
00124 virtual ~TrustedCertificateEntry();
00125
00126 const Certificate& getTrustedCertificate() const;
00127
00128 virtual String toString() const throw ();
00129 };
00130
00131 public:
00132 static KeyStore* getInstance(const String& type) throw (KeyStoreException);
00133 static KeyStore* getInstance(const String& type, const String& provider) throw (KeyStoreException, NoSuchProviderException);
00134 static KeyStore* getInstance(const String& type, const Provider& provider) throw (KeyStoreException);
00135
00136 static const String& getDefaultType();
00137
00138 private:
00139 KeyStoreSpi* _kspi;
00140 const Provider* _prov;
00141 String _type;
00142 bool _init;
00143
00144 protected:
00145 KeyStore(KeyStoreSpi* spi, const Provider* provider, const String& type);
00146
00147 public:
00148 virtual ~KeyStore();
00149
00150 Enumeration<const String>* aliases();
00151 bool containsAlias(const String& alias) throw (KeyStoreException);
00152
00153 const Certificate* getCertificate(const String& alias) throw (KeyStoreException);
00154 const String* getCertificateAlias(const Certificate& cert) throw (KeyStoreException);
00155 const array<Certificate*>* getCertificateChain(const String& alias) throw (KeyStoreException);
00156 bool isCertificateEntry(const String& alias) throw (KeyStoreException);
00157 void setCertificateEntry(const String& alias, const Certificate& cert) throw (KeyStoreException);
00158
00159 void deleteEntry(const String& alias) throw (KeyStoreException);
00160
00161
00162 Key* getKey(const String& alias, const array<jchar>& password) throw (KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException);
00163 bool isKeyEntry(const String& alias) throw (KeyStoreException);
00169 void setKeyEntry(const String& alias, const bytearray& key, const array<Certificate*>& chain) throw (KeyStoreException);
00175 void setKeyEntry(const String& alias, const Key& key, const array<jchar>& password, const array<Certificate*>& chain) throw (KeyStoreException);
00176
00177 jint size() const throw (KeyStoreException);
00178
00179 void load(InputStream* in, const array<jchar>* password) throw (IOException, NoSuchAlgorithmException, CertificateException);
00180 void store(OutputStream& out, const array<jchar>* password) throw (KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException);
00181
00182 const String& getType() const throw ();
00183 const Provider& getProvider() const throw ();
00184 };
00185 }
00186 }
00187
00188 #endif
00189
00190 #endif