Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ServerState.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: ServerState.h,v 1.5 2005/01/21 19:44:18 mmarsh Exp $
00008 //
00009 // $Log: ServerState.h,v $
00010 // Revision 1.5  2005/01/21 19:44:18  mmarsh
00011 // Updated for compatibility with Doxygen 1.4.1
00012 //
00013 // Revision 1.4  2004/05/19 15:56:59  mmarsh
00014 // *** empty log message ***
00015 //
00016 // Revision 1.3  2003/11/04 22:19:55  mmarsh
00017 // The ElGamal public key is handled here, not in CODEX_Client.  All
00018 // black magic relating to switching between cryptosystems used for
00019 // key service decryption has been moved to CODEX_KeyService, where
00020 // it belongs.  This package is no longer dependent on CODEX_Client.
00021 //
00022 //
00023 
00024 #ifndef __CODEX_SERVER_SERVERSTATE_H__
00025 #define __CODEX_SERVER_SERVERSTATE_H__
00026 
00027 #include <map>
00028 #include <list>
00029 
00030 #include <openssl/conf.h>
00031 
00032 #include "CODEX_Quorum/StaticByzantineQuorumSystem.h"
00033 #include "CODEX_Quorum/SocketBuilder.h"
00034 #include "CODEX_Quorum/LoopbackSocket.h"
00035 #include "CODEX_SSL/SSLSocket.h"
00036 
00037 #include "CODEX_ASN1/Base.h"
00038 #include "CODEX_ASN1/OctetString.h"
00039 #include "CODEX_ASN1/Certificate.h"
00040 
00041 #include "CODEX_Events/Activity.h"
00042 #include "CODEX_Quorum/LocalServer.h"
00043 
00044 #include "CODEX_Ciphers/SHA1HashFunction.h"
00045 #include "CODEX_Ciphers/RSA.h"
00046 #include "CODEX_Ciphers/ElGamal.h"
00047 
00048 #include "CODEX_ThresholdCrypto/CombinatoricThresholdRSA.h"
00049 #include "CODEX_ThresholdCrypto/CombinatoricThresholdElGamal.h"
00050 #include "CODEX_ThresholdCrypto/CombinatoricThresholdVarRSA.h"
00051 #include "CODEX_VSS/Combinatoric.h"
00052 #include "CODEX_VSS/CombinatoricFeldman.h"
00053 #include "ShareCallback.h"
00054 
00055 #include "AugmentedEGPublicKey.h"
00056 
00065 namespace CODEX_Server
00066 {
00067    class ShareLabelChallenge;
00068 
00081    class ServerState
00082    {
00083          //==========================================================
00084          // CONFIGURATION
00085          //==========================================================
00086 
00087       public :
00089          static const unsigned int  nServers = 4;
00091          static const unsigned int  nFaults = 1;
00092 
00094          static const size_t  nSID = 1;
00096          static const size_t  nMID = 8;
00097 
00099          static const unsigned char  OutgoingMask = 0x80;
00100 
00102          static const unsigned int  RSAKeyNum = 0;
00103 
00105          static const unsigned int  EGKeyNum = 1;
00106 
00107       private :
00108          typedef
00109          CODEX_Quorum::StaticByzantineQuorumSystem< nServers, nFaults >
00110          QSType;
00111 
00112          typedef CODEX_Ciphers::SHA1HashFunction HashType;
00113 
00114          typedef CODEX_Quorum::SocketBuilder ClientSocketBuilderType;
00115          typedef CODEX_SSL::SSLSocketBuilder ServerSocketBuilderType;
00116 
00117       public :
00118 
00119          //==========================================================
00120          // TYPEDEFs
00121          //==========================================================
00122 
00124          typedef list< CODEX_Quorum::LocalServer* > ServerList;
00125 
00127          typedef CODEX_VSS::Combinatoric< nServers , nFaults+1 >  ShareType;
00128 
00130          typedef CODEX_VSS::ModExpFunctional  OneWay;
00131 
00133          typedef CODEX_VSS::LabeledShare< ShareType , OneWay >  LSType;
00134 
00136          typedef CODEX_VSS::SecretWitness< ShareType , OneWay >  WitnessType;
00137 
00139          typedef CODEX_VSS::ShareSet< ShareType >  ShareSetType;
00140 
00142          typedef CODEX_ThresholdCrypto::ThresholdRSACrypto< ShareType >
00143          ThresholdRSAType;
00144 
00146          typedef CODEX_ThresholdCrypto::ThresholdElGamalCrypto< ShareType >
00147          ThresholdElGamalType;
00148 
00150          typedef CODEX_ThresholdCrypto::ThresholdVarRSACrypto< ShareType >
00151          ThresholdVarRSAType;
00152 
00154          typedef ThresholdRSAType  ThresholdSignatureType;
00155 
00157          typedef ShareCallbackBase< ShareType , OneWay >  ShareCallback;
00158 
00160          typedef vector< ShareLabelChallenge* >  ChallengeVector;
00161 
00163          typedef map< const unsigned char* ,
00164             ChallengeVector ,
00165             CODEX_Quorum::memless< CODEX_Server::ServerState::nMID > >
00166          ChallengeMap;
00167 
00168          //==========================================================
00169          // UNIQUE INSTANCE
00170          //==========================================================
00171          
00173          static ServerState* instance();
00174 
00176          static void destroy();
00177 
00179          const CODEX_Ciphers::HashFunction& hashFunc() const
00180          {
00181             return m_hashFunc;
00182          }
00183 
00184 
00185          //==========================================================
00186          // SERVER CONFIGURATION
00187          //==========================================================
00188 
00190          void configure( const CONF* conf,
00191                          const char* sec,
00192                          const string& fname );
00193 
00194 
00195          //==========================================================
00196          // LOCAL SERVERS
00197          //==========================================================
00198 
00200          void addServer( CODEX_Quorum::LocalServer* server );
00201 
00203          void removeServer( CODEX_Quorum::LocalServer* server );
00204 
00206          ServerList::const_iterator serverListBegin()
00207          {
00208             return m_serverList.begin();
00209          }
00210 
00212          ServerList::const_iterator serverListEnd()
00213          {
00214             return m_serverList.end();
00215          }
00216 
00218          int serverListSize() { return m_serverList.size(); }
00219 
00221          void cleanServer( CODEX_Quorum::LocalServer* server );
00222 
00224          void garbageCollectServers();
00225 
00226 
00227          //==========================================================
00228          // SERVER KEYS
00229          //==========================================================
00230 
00232          const CODEX_ASN1::Certificate& serverCert() const
00233          {
00234             return m_serverCerts[m_hostNum];
00235          }
00236 
00238          const CODEX_ASN1::Certificate& serverCert( unsigned int i ) const;
00239 
00241          const CODEX_Ciphers::RSAPublicKey& publicKey();
00242 
00244          const CODEX_Ciphers::RSAPublicKey& publicKey( unsigned int i );
00245 
00247          const CODEX_Ciphers::RSAPrivateKey& privateKey() const
00248          {
00249             return m_privateKey;
00250          }
00251 
00252 
00253          //==========================================================
00254          // CERTIFICATION AUTHORITY
00255          //==========================================================
00256 
00258          const CODEX_ASN1::Certificate& caCert() const { return m_caCert; }
00259 
00261          const EVP_PKEY* caKey();
00262 
00263 
00264          //==========================================================
00265          // SERVICE KEYS
00266          //==========================================================
00267 
00269          const CODEX_Ciphers::RSAPublicKey& serviceKey();
00270 
00272          const CODEX_Ciphers::ElGamalPublicKey& publicEGKey() const
00273          {
00274             return m_signedEGKey.key().key();
00275          }
00276 
00278          const CODEX_ASN1::BigNumber& h() const {
00279             return m_signedEGKey.key().h();
00280          }
00281 
00283          const SignedAugmentedEGPublicKey& signedEGKey() const
00284          {
00285             return m_signedEGKey;
00286          }
00287 
00288 
00295          const LSType& rsaShares( const LSType::LabelType& label,
00296                                   unsigned int server ) const;
00297 
00299          const LSType::LabelType& defaultRSALabel() const;
00300 
00302          void setRSAShareCallback( const ShareCallback* cb )
00303          {
00304             // Setting the callback should clear the default shares.
00305             if ( m_rsaShares.initialized() )
00306             {
00307                m_rsaShares = LSType();
00308             }
00309             m_rsaShareCallback = cb;
00310          }
00311 
00313          void setRSADefaultLabel( const LSType::LabelType* label )
00314          {
00315             m_rsaDefaultLabel = label;
00316          }
00317 
00319          const ThresholdRSAType& thresholdRSA() const
00320          {
00321             return m_thresholdRSA;
00322          }
00323 
00325          const ThresholdVarRSAType& thresholdVarRSA() const
00326          {
00327             return m_thresholdVarRSA;
00328          }
00329 
00331          const WitnessType& rsaWitness() const
00332          {
00333             return m_rsaWitness;
00334          }
00335 
00336 
00343          const LSType& elgamalShares( const LSType::LabelType& label,
00344                                       unsigned int server ) const;
00345 
00347          const LSType::LabelType& defaultEGLabel() const;
00348 
00350          void setEGShareCallback( const ShareCallback* cb )
00351          {
00352             // Setting the callback should clear the default shares.
00353             if ( m_elgamalShares.initialized() )
00354             {
00355                m_elgamalShares = LSType();
00356             }
00357             m_egShareCallback = cb;
00358          }
00359 
00361          void setEGDefaultLabel( const LSType::LabelType* label )
00362          {
00363             m_egDefaultLabel = label;
00364          }
00365 
00367          const ThresholdElGamalType& thresholdEG() const
00368          {
00369             return m_thresholdEG;
00370          }
00371 
00373          const WitnessType& egWitness() const
00374          {
00375             return m_egWitness;
00376          }
00377 
00378 
00385          const LSType::LabelType& defaultLabel( unsigned int num ) const;
00386 
00392          void setShareCallback( unsigned int num, const ShareCallback* cb );
00393 
00400          void setDefaultLabel( const LSType::LabelType* label );
00401 
00402 
00412          const LSType& signatureShares( const LSType::LabelType& label,
00413                                         unsigned int server ) const
00414          {
00415             return rsaShares( label, server );
00416          }
00417 
00419          const LSType::LabelType& defaultSignatureLabel() const
00420          {
00421             return defaultRSALabel();
00422          }
00423 
00425          const ThresholdSignatureType& thresholdSignature() const;
00426 
00437          void rationalizeSharings( const vector< ShareType* >& sharings,
00438                                    ShareSetType& result ) const;
00439 
00448          BIGNUM* thresholdOperation( const vector< ShareType* >& sharings,
00449                                      const BIGNUM * operand ) const;
00450 
00451 
00452          //==========================================================
00453          // SEQUENCE NUMBERS
00454          //==========================================================
00455 
00471          unsigned char* newSequenceNumber();
00472 
00486          void addChallenge( const unsigned char* request,
00487                             ShareLabelChallenge* challenge );
00488 
00490          const ServerState::ChallengeMap& challengeMap()
00491          {
00492             return m_challengeMap;
00493          }
00494 
00501          void removeChallenge( const unsigned char* request );
00502 
00503 
00504          //==========================================================
00505          // QUORUM SYSTEM MANAGEMENT
00506          //==========================================================
00507 
00509          CODEX_Quorum::QuorumSystem* quorumSystem() const
00510          {
00511             return m_quorumSystem;
00512          }
00513 
00515          long hostNum() const { return m_hostNum; }
00516 
00518          const string& hostName( long i );
00519 
00521          long serverPort() const { return m_serverPorts[ m_hostNum ]; }
00522 
00524          long serverPort( long i );
00525          
00536          bool addQuorumServer(
00537             int host,
00538             CODEX_Quorum::AsynchronousRemoteServer* server );
00539 
00541          const CODEX_Quorum::RemoteServer* getQuorumServer( int host );
00542 
00544          bool haveQuorumServer( int host ) const;
00545 
00546 
00547          //==========================================================
00548          // MISCELLANEOUS
00549          //==========================================================
00550 
00552          const CODEX_Quorum::SocketBuilder& clientSocketBuilder() const
00553          {
00554             return m_clientSocketBuilder;
00555          }
00556 
00558          const CODEX_Quorum::SocketBuilder& serverOutSocketBuilder() const
00559          {
00560             //return m_clientSocketBuilder;
00561             return *m_serverOutSocketBuilder;
00562          }
00563 
00565          const CODEX_Quorum::SocketBuilder& serverInSocketBuilder() const
00566          {
00567             //return m_clientSocketBuilder;
00568             return *m_serverInSocketBuilder;
00569          }
00570 
00571 
00572       protected :
00574          ServerState();
00575 
00577          virtual ~ServerState();
00578 
00580          static ServerState* m_instance;
00581 
00583          void readPrivateKey( const char* fname, const char* passwd=NULL );
00584 
00586          void readCACert( const char* fname );
00587 
00589          void readServiceCert( const char* fname );
00590 
00592          void readPublicEGKey( const char* fname );
00593 
00595          void readRSAShares( const char* fname );
00596 
00598          void readElGamalShares( const char* fname );
00599 
00600       private :
00601 
00602          QSType*  m_quorumSystem;
00603 
00604          ClientSocketBuilderType              m_clientSocketBuilder;
00605          ServerSocketBuilderType*             m_serverOutSocketBuilder;
00606          ServerSocketBuilderType*             m_serverInSocketBuilder;
00607          CODEX_Quorum::LoopbackSocketBuilder  m_loopbackSocketBuilder;
00608 
00609          unsigned char  m_seqNum[nMID];
00610          ChallengeMap   m_challengeMap;
00611 
00612          long                     m_hostNum;
00613          string                   m_hostnames[nServers];
00614          long                     m_serverPorts[nServers];
00615          CODEX_ASN1::Certificate  m_serverCerts[nServers];
00616 
00617          HashType  m_hashFunc;
00618 
00619          // Server key information.
00620          CODEX_Ciphers::RSAPublicKey   m_publicKeys[nServers];
00621          RSA*                          m_rsa;
00622          CODEX_Ciphers::RSAPrivateKey  m_privateKey;
00623          LSType                        m_rsaShares;
00624          ThresholdRSAType              m_thresholdRSA;
00625          ThresholdVarRSAType           m_thresholdVarRSA;
00626          ShareCallback*                m_defaultRSAShareCB;
00627          const ShareCallback*          m_rsaShareCallback;
00628          const LSType::LabelType*      m_rsaDefaultLabel;
00629          LSType::LabelType             m_rsaInitialLabel;
00630          WitnessType                   m_rsaWitness;
00631          LSType                        m_elgamalShares;
00632          ThresholdElGamalType          m_thresholdEG;
00633          ShareCallback*                m_defaultEGShareCB;
00634          const ShareCallback*          m_egShareCallback;
00635          const LSType::LabelType*      m_egDefaultLabel;
00636          LSType::LabelType             m_egInitialLabel;
00637          WitnessType                   m_egWitness;
00638 
00639          ServerList  m_serverList;
00640          ServerList  m_deadServerList;
00641 
00642          CODEX_ASN1::Certificate  m_caCert;
00643          EVP_PKEY *               m_caKey;
00644 
00645          CODEX_ASN1::Certificate      m_serviceCert;
00646          CODEX_Ciphers::RSAPublicKey  m_serviceKey;
00647 
00648          SignedAugmentedEGPublicKey  m_signedEGKey;
00649    };
00650 
00651 }
00652 
00653 #endif /* __CODEX_SERVER_SERVERSTATE_H__ */

Generated on Fri May 6 17:41:15 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1