00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __CODEX_KEYSERVICE_STATEINFO_H__
00026 #define __CODEX_KEYSERVICE_STATEINFO_H__
00027
00028 #include <map>
00029 #include <list>
00030
00031 #include "CODEX_ASN1/Base.h"
00032 #include "CODEX_ASN1/OctetString.h"
00033 #include "CODEX_Events/Activity.h"
00034 #include "CODEX_Client/Message.h"
00035 #include "CODEX_Server/ServerState.h"
00036
00040 namespace CODEX_KeyService
00041 {
00042 class ClientActivity;
00043
00047 class KeyInfo : public CODEX_ASN1::Base
00048 {
00049 public :
00051 KeyInfo();
00053 KeyInfo( const CODEX_Client::BoundNameMsg& binding );
00055 KeyInfo( const CODEX_Client::BoundNameMsg& binding,
00056 const CODEX_Ciphers::RSASignature& signature );
00058 KeyInfo( const CODEX_Client::SignedBoundNameMsg& binding );
00060 KeyInfo( const CODEX_Client::BoundNameMsg& binding,
00061 const CODEX_Ciphers::RSASignature& signature,
00062 const CODEX_Client::RequestCipherTextType& keyValue );
00064 KeyInfo( const CODEX_Client::SignedBoundNameMsg& binding,
00065 const CODEX_Client::RequestCipherTextType& keyValue );
00067 KeyInfo( const KeyInfo& aKI );
00069 virtual ~KeyInfo();
00070
00072 void operator=( const KeyInfo& aKI );
00073
00075 void setBinding( const CODEX_Client::BoundNameMsg& binding );
00076
00078 void setSignature( const CODEX_Ciphers::RSASignature& signature );
00079
00081 void setKeyValue(
00082 const CODEX_Client::RequestCipherTextType& keyValue );
00083
00085 void setVerified() { m_verified = true; }
00086
00088 const CODEX_Client::BoundNameMsg& binding() const
00089 {
00090 return m_binding;
00091 }
00092
00094 const CODEX_Ciphers::RSASignature& signature() const
00095 {
00096 return m_signature;
00097 }
00098
00100 const CODEX_Client::RequestCipherTextType& keyValue() const
00101 {
00102 return m_keyValue;
00103 }
00104
00106 bool verified() const { return m_verified; }
00107
00109 int marshal( unsigned char ** pp ) const;
00111 void* unmarshal( void* bogus, unsigned char ** pp, long length );
00112
00113 private :
00114 CODEX_Client::BoundNameMsg m_binding;
00115 CODEX_Ciphers::RSASignature m_signature;
00116 CODEX_Client::RequestCipherTextType m_keyValue;
00117 bool m_verified;
00118 };
00119
00120
00122 template< class CT , class ST > class CryptoSystem;
00123
00125 template< class ST >
00126 class CryptoSystem< CODEX_Ciphers::RSACipherText , ST >
00127 {
00128 public :
00130 typedef CODEX_ThresholdCrypto::ThresholdRSACrypto< ST > ThresholdType;
00131 };
00132
00134 template< class ST >
00135 class CryptoSystem< CODEX_Ciphers::ElGamalCipherText , ST >
00136 {
00137 public :
00139 typedef CODEX_ThresholdCrypto::ThresholdElGamalCrypto< ST >
00140 ThresholdType;
00141 };
00142
00144 template< class ST >
00145 class CryptoSystem< CODEX_Ciphers::VarRSACipherText , ST >
00146 {
00147 public :
00149 typedef CODEX_ThresholdCrypto::ThresholdVarRSACrypto< ST >
00150 ThresholdType;
00151 };
00152
00153
00169 class StateInfo
00170 {
00171
00172
00173
00174
00175 public :
00176
00178 enum SynchronyState
00179 {
00180 kFailed,
00181 kWrote,
00182 kRead
00183 };
00184
00185
00186
00187
00188
00189
00191 typedef map< CODEX_Events::Activity* , ClientActivity* > ClientMap;
00192
00194 typedef map< const unsigned char* ,
00195 CODEX_Events::Activity* ,
00196 CODEX_Quorum::memless< CODEX_Server::ServerState::nMID > >
00197 RequestMap;
00198
00200 typedef map< CODEX_ASN1::ustring , KeyInfo* > KeyMap;
00201
00203 typedef CODEX_Server::ServerState::ShareType ShareType;
00204
00206 typedef CODEX_Server::ServerState::LSType LSType;
00207
00209 typedef CryptoSystem< CODEX_Client::CipherTextType, ShareType >
00210 CryptoSystemType;
00211
00213 typedef
00214 CryptoSystemType::ThresholdType ThresholdDecryptionType;
00215
00216
00217
00218
00219
00220
00222 static StateInfo* instance();
00223
00225 static void destroy();
00226
00227
00228
00229
00230
00231
00233 void configure( const CONF* conf,
00234 const char* sec,
00235 const string& fname );
00236
00238 void setMessageDomain( unsigned char d ) {m_messageDomain = d;}
00239
00241 void setDelegationDomain( unsigned char d ) {m_delegationDomain = d;}
00242
00244 unsigned char messageDomain() { return m_messageDomain; }
00245
00247 unsigned char delegationDomain() { return m_delegationDomain; }
00248
00249
00250
00251
00252
00253
00255 long clientPort() const { return m_clientPort; }
00256
00262 bool addClient( ClientActivity* clientAct );
00263
00265 ClientActivity*
00266 getClient( CODEX_Events::Activity* clientAct ) const;
00267
00269 bool removeClient( CODEX_Events::Activity* clientAct );
00270
00275 bool registerSequenceNumber( const unsigned char* seqNum,
00276 CODEX_Events::Activity* clientAct );
00277
00284 CODEX_Events::Activity* getActFromSeqNum(
00285 const unsigned char* seqNum ) const;
00286
00290 bool removeSequenceNumber( const unsigned char* seqNum );
00291
00292
00293
00294
00295
00296
00298 bool addKeyName( const CODEX_ASN1::ustring& name,
00299 const CODEX_Client::SignedBoundNameMsg& binding );
00300
00302 bool addKeyName( const CODEX_ASN1::ustring& name,
00303 const CODEX_Client::BoundNameMsg& binding );
00304
00306 const KeyInfo* getKeyInfo( const CODEX_ASN1::ustring& name ) const;
00307
00309 bool addKeySignature( const CODEX_ASN1::ustring& name,
00310 const CODEX_Ciphers::RSASignature& signature );
00311
00313 bool replaceKeyBinding(
00314 const CODEX_ASN1::ustring& name,
00315 const CODEX_Client::SignedBoundNameMsg& binding );
00316
00318 bool addKeyValue(
00319 const CODEX_ASN1::ustring& name,
00320 const CODEX_Client::RequestCipherTextType& keyValue );
00321
00323 bool verifyKeyValue( const CODEX_ASN1::ustring& name );
00324
00325
00326
00327
00328
00329
00339 const LSType& decryptionShares( const LSType::LabelType& label,
00340 unsigned int server ) const;
00341
00343 const LSType::LabelType& defaultDecryptionLabel() const;
00344
00346 const ThresholdDecryptionType& thresholdDecryption() const;
00347
00352 template< class T > const LSType& shareTemplate(
00353 const LSType::LabelType& label,
00354 unsigned int server) const;
00355
00360 template< class T > const LSType::LabelType& labelTemplate() const;
00361
00366 template< class T > const T& thresholdTemplate() const;
00367
00373 unsigned int ppkSecurityParam() const { return m_ppkSecurityParam; }
00374
00391 SynchronyState synchronize(const char* fname, bool force_read=false);
00392
00393
00394 protected :
00396 StateInfo();
00397
00399 virtual ~StateInfo();
00400
00402 static StateInfo* m_instance;
00403
00404 private :
00405
00406 long m_clientPort;
00407
00408 ClientMap m_clientMap;
00409 RequestMap m_requestMap;
00410 KeyMap m_keyMap;
00411
00412 unsigned int m_ppkSecurityParam;
00413
00414 unsigned char m_messageDomain;
00415 unsigned char m_delegationDomain;
00416 };
00417
00418 template<>
00419 const StateInfo::LSType&
00420 StateInfo::shareTemplate< CODEX_Ciphers::RSACipherText >(
00421 const LSType::LabelType& label,
00422 unsigned int server) const;
00423
00424 template<>
00425 const StateInfo::LSType&
00426 StateInfo::shareTemplate< CODEX_Ciphers::ElGamalCipherText >(
00427 const LSType::LabelType& label,
00428 unsigned int server) const;
00429
00430 template<>
00431 const StateInfo::LSType&
00432 StateInfo::shareTemplate< CODEX_Ciphers::VarRSACipherText >(
00433 const LSType::LabelType& label,
00434 unsigned int server) const;
00435
00436
00437 template<>
00438 const StateInfo::LSType::LabelType&
00439 StateInfo::labelTemplate< CODEX_Ciphers::RSACipherText >() const;
00440
00441 template<>
00442 const StateInfo::LSType::LabelType&
00443 StateInfo::labelTemplate< CODEX_Ciphers::ElGamalCipherText >() const;
00444
00445 template<>
00446 const StateInfo::LSType::LabelType&
00447 StateInfo::labelTemplate< CODEX_Ciphers::VarRSACipherText >() const;
00448
00449
00450 template<>
00451 const CODEX_Server::ServerState::ThresholdRSAType&
00452 StateInfo::thresholdTemplate< CODEX_Server::ServerState::ThresholdRSAType >() const;
00453
00454 template<>
00455 const CODEX_Server::ServerState::ThresholdElGamalType&
00456 StateInfo::thresholdTemplate< CODEX_Server::ServerState::ThresholdElGamalType >() const;
00457
00458 template<>
00459 const CODEX_Server::ServerState::ThresholdVarRSAType&
00460 StateInfo::thresholdTemplate< CODEX_Server::ServerState::ThresholdVarRSAType >() const;
00461
00462 }
00463
00464 #endif