Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

StateInfo.h

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: StateInfo.h,v 1.3 2004/05/19 15:56:53 mmarsh Exp $
00008 //
00009 // $Log: StateInfo.h,v $
00010 // Revision 1.3  2004/05/19 15:56:53  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:15:00  mmarsh
00014 // General code cleanup and reorganization.  The signed ElGamal public key
00015 // was moved to CODEX_Server, decoupling that package from CODEX_Client.
00016 // Since CODEX_Server no longer knows about the cryptosystem used by
00017 // the client, switching between cryptosystems is handled locally by
00018 // CODEX_KeyService.
00019 //
00020 //
00021 
00022 #ifndef __CODEX_KEYSERVICE_STATEINFO_H__
00023 #define __CODEX_KEYSERVICE_STATEINFO_H__
00024 
00025 #include <map>
00026 #include <list>
00027 
00028 #include "CODEX_ASN1/Base.h"
00029 #include "CODEX_ASN1/OctetString.h"
00030 #include "CODEX_Events/Activity.h"
00031 #include "CODEX_Client/Message.h"
00032 #include "CODEX_Server/ServerState.h"
00033 
00037 namespace CODEX_KeyService
00038 {
00039    class ClientActivity;
00040 
00044    class KeyInfo : public CODEX_ASN1::Base
00045    {
00046       public :
00048          KeyInfo();
00050          KeyInfo( const CODEX_Client::BoundNameMsg& binding );
00052          KeyInfo( const CODEX_Client::BoundNameMsg& binding,
00053                   const CODEX_Ciphers::RSASignature& signature );
00055          KeyInfo( const CODEX_Client::SignedBoundNameMsg& binding );
00057          KeyInfo( const CODEX_Client::BoundNameMsg& binding,
00058                   const CODEX_Ciphers::RSASignature& signature,
00059                   const CODEX_Client::RequestCipherTextType& keyValue );
00061          KeyInfo( const CODEX_Client::SignedBoundNameMsg& binding,
00062                   const CODEX_Client::RequestCipherTextType& keyValue );
00064          KeyInfo( const KeyInfo& aKI );
00066          virtual ~KeyInfo();
00067 
00069          void operator=( const KeyInfo& aKI );
00070 
00072          void setBinding( const CODEX_Client::BoundNameMsg& binding );
00073 
00075          void setSignature( const CODEX_Ciphers::RSASignature& signature );
00076 
00078          void setKeyValue(
00079             const CODEX_Client::RequestCipherTextType& keyValue );
00080 
00082          void setVerified() { m_verified = true; }
00083 
00085          const CODEX_Client::BoundNameMsg& binding() const
00086          {
00087             return m_binding;
00088          }
00089 
00091          const CODEX_Ciphers::RSASignature& signature() const
00092          {
00093             return m_signature;
00094          }
00095 
00097          const CODEX_Client::RequestCipherTextType& keyValue() const
00098          {
00099             return m_keyValue;
00100          }
00101 
00103          bool verified() const { return m_verified; }
00104 
00106          int marshal( unsigned char ** pp ) const;
00108          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00109 
00110       private :
00111          CODEX_Client::BoundNameMsg           m_binding;
00112          CODEX_Ciphers::RSASignature          m_signature;
00113          CODEX_Client::RequestCipherTextType  m_keyValue;
00114          bool                                 m_verified;
00115    };
00116 
00117 
00119    template< class CT , class ST > class CryptoSystem;
00120 
00122    template< class ST >
00123    class CryptoSystem< CODEX_Ciphers::RSACipherText , ST >
00124    {
00125       public :
00127          typedef CODEX_ThresholdCrypto::ThresholdRSACrypto< ST > ThresholdType;
00128    };
00129 
00131    template< class ST >
00132    class CryptoSystem< CODEX_Ciphers::ElGamalCipherText , ST >
00133    {
00134       public :
00136          typedef CODEX_ThresholdCrypto::ThresholdElGamalCrypto< ST >
00137          ThresholdType;
00138    };
00139 
00141    template< class ST >
00142    class CryptoSystem< CODEX_Ciphers::VarRSACipherText , ST >
00143    {
00144       public :
00146          typedef CODEX_ThresholdCrypto::ThresholdVarRSACrypto< ST >
00147          ThresholdType;
00148    };
00149 
00150 
00166    class StateInfo
00167    {
00168          //==========================================================
00169          // CONFIGURATION
00170          //==========================================================
00171 
00172       public :
00173 
00175          enum SynchronyState
00176          {
00177             kFailed,
00178             kWrote,
00179             kRead
00180          };
00181 
00182 
00183          //==========================================================
00184          // TYPEDEFs
00185          //==========================================================
00186 
00188          typedef map< CODEX_Events::Activity* , ClientActivity* > ClientMap;
00189 
00191          typedef map< const unsigned char* ,
00192             CODEX_Events::Activity* ,
00193             CODEX_Quorum::memless< CODEX_Server::ServerState::nMID > >
00194          RequestMap;
00195 
00197          typedef map< CODEX_ASN1::ustring , KeyInfo* > KeyMap;
00198 
00200          typedef CODEX_Server::ServerState::ShareType  ShareType;
00201 
00203          typedef CODEX_Server::ServerState::LSType  LSType;
00204 
00206          typedef CryptoSystem< CODEX_Client::CipherTextType, ShareType >
00207          CryptoSystemType;
00208 
00210          typedef
00211          CryptoSystemType::ThresholdType  ThresholdDecryptionType;
00212 
00213 
00214          //==========================================================
00215          // UNIQUE INSTANCE
00216          //==========================================================
00217          
00219          static StateInfo* instance();
00220 
00222          static void destroy();
00223 
00224 
00225          //==========================================================
00226          // KEY SERVICE CONFIGURATION
00227          //==========================================================
00228 
00230          void configure( const CONF* conf,
00231                          const char* sec,
00232                          const string& fname );
00233 
00235          void setMessageDomain( unsigned char d ) {m_messageDomain = d;}
00236 
00238          void setDelegationDomain( unsigned char d ) {m_delegationDomain = d;}
00239 
00241          unsigned char messageDomain() { return m_messageDomain; }
00242 
00244          unsigned char delegationDomain() { return m_delegationDomain; }
00245 
00246 
00247          //==========================================================
00248          // CLIENT MANAGEMENT
00249          //==========================================================
00250 
00252          long clientPort() const { return m_clientPort; }
00253 
00259          bool addClient( ClientActivity* clientAct );
00260 
00262          ClientActivity*
00263          getClient( CODEX_Events::Activity* clientAct ) const;
00264 
00266          bool removeClient( CODEX_Events::Activity* clientAct );
00267 
00272          bool registerSequenceNumber( const unsigned char* seqNum,
00273                                       CODEX_Events::Activity* clientAct );
00274 
00281          CODEX_Events::Activity* getActFromSeqNum(
00282             const unsigned char* seqNum ) const;
00283 
00287          bool removeSequenceNumber( const unsigned char* seqNum );
00288 
00289 
00290          //==========================================================
00291          // STORED KEYS
00292          //==========================================================
00293 
00295          bool addKeyName( const CODEX_ASN1::ustring& name,
00296                           const CODEX_Client::SignedBoundNameMsg& binding );
00297 
00299          bool addKeyName( const CODEX_ASN1::ustring& name,
00300                           const CODEX_Client::BoundNameMsg& binding );
00301 
00303          const KeyInfo* getKeyInfo( const CODEX_ASN1::ustring& name ) const;
00304 
00306          bool addKeySignature( const CODEX_ASN1::ustring& name,
00307                                const CODEX_Ciphers::RSASignature& signature );
00308 
00310          bool replaceKeyBinding(
00311             const CODEX_ASN1::ustring& name,
00312             const CODEX_Client::SignedBoundNameMsg& binding );
00313 
00315          bool addKeyValue(
00316             const CODEX_ASN1::ustring& name,
00317             const CODEX_Client::RequestCipherTextType& keyValue );
00318 
00320          bool verifyKeyValue( const CODEX_ASN1::ustring& name );
00321 
00322 
00323          //==========================================================
00324          // MISCELLANEOUS
00325          //==========================================================
00326 
00336          const LSType& decryptionShares( const LSType::LabelType& label,
00337                                          unsigned int server ) const;
00338 
00340          const LSType::LabelType& defaultDecryptionLabel() const;
00341 
00343          const ThresholdDecryptionType& thresholdDecryption() const;
00344 
00349          template< class T > const LSType& shareTemplate(
00350             const LSType::LabelType& label,
00351             unsigned int server) const;
00352 
00357          template< class T > const LSType::LabelType& labelTemplate() const;
00358 
00363          template< class T > const T& thresholdTemplate() const;
00364 
00370          unsigned int ppkSecurityParam() const { return m_ppkSecurityParam; }
00371 
00388          SynchronyState synchronize(const char* fname, bool force_read=false);
00389 
00390 
00391       protected :
00393          StateInfo();
00394 
00396          virtual ~StateInfo();
00397 
00399          static StateInfo* m_instance;
00400 
00401       private :
00402 
00403          long                     m_clientPort;
00404 
00405          ClientMap   m_clientMap;
00406          RequestMap  m_requestMap;
00407          KeyMap      m_keyMap; // to stable storage
00408 
00409          unsigned int  m_ppkSecurityParam;
00410 
00411          unsigned char  m_messageDomain;
00412          unsigned char  m_delegationDomain;
00413    };
00414 
00415    template<>
00416    const StateInfo::LSType&
00417    StateInfo::shareTemplate< CODEX_Ciphers::RSACipherText >(
00418       const LSType::LabelType& label,
00419       unsigned int server) const;
00420 
00421    template<>
00422    const StateInfo::LSType&
00423    StateInfo::shareTemplate< CODEX_Ciphers::ElGamalCipherText >(
00424       const LSType::LabelType& label,
00425       unsigned int server) const;
00426 
00427    template<>
00428    const StateInfo::LSType&
00429    StateInfo::shareTemplate< CODEX_Ciphers::VarRSACipherText >(
00430       const LSType::LabelType& label,
00431       unsigned int server) const;
00432 
00433 
00434    template<>
00435    const StateInfo::LSType::LabelType&
00436    StateInfo::labelTemplate< CODEX_Ciphers::RSACipherText >() const;
00437 
00438    template<>
00439    const StateInfo::LSType::LabelType&
00440    StateInfo::labelTemplate< CODEX_Ciphers::ElGamalCipherText >() const;
00441 
00442    template<>
00443    const StateInfo::LSType::LabelType&
00444    StateInfo::labelTemplate< CODEX_Ciphers::VarRSACipherText >() const;
00445 
00446 
00447    template<>
00448    const CODEX_Server::ServerState::ThresholdRSAType&
00449    StateInfo::thresholdTemplate< CODEX_Server::ServerState::ThresholdRSAType >() const;
00450 
00451    template<>
00452    const CODEX_Server::ServerState::ThresholdElGamalType&
00453    StateInfo::thresholdTemplate< CODEX_Server::ServerState::ThresholdElGamalType >() const;
00454 
00455    template<>
00456    const CODEX_Server::ServerState::ThresholdVarRSAType&
00457    StateInfo::thresholdTemplate< CODEX_Server::ServerState::ThresholdVarRSAType >() const;
00458 
00459 }
00460 
00461 #endif /* __CODEX_KEYSERVICE_STATEINFO_H__ */

Generated on Wed Jun 2 16:32:56 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18