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

CODEX_Client/Message.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: Message.h,v 1.6 2005/01/21 19:44:16 mmarsh Exp $
00008 //
00009 // $Log: Message.h,v $
00010 // Revision 1.6  2005/01/21 19:44:16  mmarsh
00011 // Updated for compatibility with Doxygen 1.4.1
00012 //
00013 // Revision 1.5  2004/05/19 15:56:48  mmarsh
00014 // *** empty log message ***
00015 //
00016 // Revision 1.4  2003/11/06 21:46:23  mmarsh
00017 // Use the RSA variant by default.
00018 //
00019 // Revision 1.3  2003/11/04 22:09:57  mmarsh
00020 // The signed ElGamal public key for the service was moved into CODEX_Server.
00021 //
00022 //
00023 
00024 #ifndef __CODEX_CLIENT_MESSAGE_H__
00025 #define __CODEX_CLIENT_MESSAGE_H__
00026 
00027 #include "CODEX_ASN1/OctetString.h"
00028 #include "CODEX_ASN1/BigNumber.h"
00029 #include "CODEX_ASN1/Certificate.h"
00030 #include "CODEX_Ciphers/ElGamal.h"
00031 #include "CODEX_Ciphers/RSA.h"
00032 #include "CODEX_Ciphers/VarRSA.h"
00033 #include "CODEX_Ciphers/Policy.h"
00034 #include "CODEX_Ciphers/Credentials.h"
00035 #include "CODEX_Ciphers/TranslationCertificate.h"
00036 #include "CODEX_Ciphers/RSAPlaintextPK.h"
00037 #include "CODEX_Ciphers/HashFunction.h"
00038 #include "CODEX_Server/AugmentedEGPublicKey.h"
00039 
00040 /* #define ELGAMAL */
00041 
00049 namespace CODEX_Client
00050 {
00051 
00052 #ifndef ELGAMAL
00053 
00054    typedef CODEX_Ciphers::VarRSACipherText          CipherTextType;
00056    typedef CipherTextType                           RequestCipherTextType;
00058    typedef CODEX_Ciphers::RSACipherText             BlindingCipherTextType;
00060    typedef CODEX_Ciphers::VarRSABlindCipherText     BlindCipherTextType;
00062    typedef CODEX_Ciphers::VarRSABlindPlainText      BlindPlainTextType;
00063 #else
00064 
00065    typedef CODEX_Ciphers::ElGamalCipherText         CipherTextType;
00067    typedef CODEX_Ciphers::ElGamalSchnorrCipherText  RequestCipherTextType;
00069    typedef RequestCipherTextType                    BlindingCipherTextType;
00071    typedef CipherTextType                           BlindCipherTextType;
00073    typedef CODEX_ASN1::BigNumber                    BlindPlainTextType;
00074 #endif
00075 
00079    class Message : public CODEX_ASN1::Base
00080    {
00081       public :
00083          Message( bool initialized ) :
00084             Base( initialized )
00085          {}
00086 
00088          virtual ~Message() {}
00089 
00091          BIGNUM * digest( const CODEX_Ciphers::HashFunction& hf ) const;
00092    };
00093 
00100    template< class MT, class ST >
00101    class SignedMessage : public Message
00102    {
00103       public :
00105          SignedMessage() : Message( false ) {}
00106 
00108          SignedMessage( const MT& message, ST signature ) :
00109             Message( true ),
00110             m_message( message ),
00111             m_signature( signature )
00112          {}
00113 
00115          SignedMessage( const SignedMessage& aMessage ) :
00116             Message( aMessage.m_initialized ),
00117             m_message( aMessage.m_message ),
00118             m_signature( aMessage.m_signature )
00119          {}
00120 
00122          virtual ~SignedMessage() {}
00123 
00125          void operator=( const SignedMessage& aMessage )
00126          {
00127             m_initialized = aMessage.m_initialized;
00128             m_message     = aMessage.m_message;
00129             m_signature   = aMessage.m_signature;
00130          }
00131 
00133          const MT&  message()   const { return m_message; }
00135          const ST&  signature() const { return m_signature; }
00136 
00138          int marshal( unsigned char ** pp ) const
00139          {
00140             int r=0;
00141             int ret=0;
00142             unsigned char * p;
00143 
00144             ret += m_message.marshal(0);
00145             ret += m_signature.marshal(0);
00146             M_ASN1_I2D_seq_total();
00147             m_message.marshal(&p);
00148             m_signature.marshal(&p);
00149             M_ASN1_I2D_finish();
00150          }
00151 
00153          void* unmarshal( void* bogus,
00154                           unsigned char ** pp,
00155                           long length )
00156          {
00157             if ( m_initialized )
00158             {
00159                return NULL;
00160             }
00161             if ( (NULL == pp) || (NULL == *pp) )
00162             {
00163                return NULL;
00164             }
00165             ASN1_CTX c;
00166             c.pp = pp;
00167             c.q = *pp;
00168             c.error = ERR_R_NESTED_ASN1_ERROR;
00169             int i;
00170 
00171             M_ASN1_D2I_Init();
00172             M_ASN1_D2I_start_sequence();
00173             M_ASN1_D2I_get(i, m_message.unmarshal);
00174             M_ASN1_D2I_get(i, m_signature.unmarshal);
00175             if ( !asn1_Finish(&c) )
00176             {
00177                return NULL;
00178             }
00179             *pp=c.p;
00180             m_initialized = true;
00181             return this;
00182            err: // needed by ASN.1 macros
00183             return NULL;
00184          }
00185 
00186       private :
00187          MT  m_message;
00188          ST  m_signature;
00189    };
00190 
00195    class RequestKeyMsg : public Message
00196    {
00197       public :
00199          RequestKeyMsg() : Message( true ) {}
00200 
00202          virtual ~RequestKeyMsg() {}
00203 
00205          void operator=( const RequestKeyMsg& aMsg ) {}
00206 
00208          int marshal( unsigned char ** pp ) const { return 0; }
00210          void* unmarshal( void* bogus, unsigned char ** pp, long length )
00211          {
00212             return this;
00213          }
00214    };
00215 
00216 
00218    typedef CODEX_Server::SignedAugmentedEGPublicKey SignedPublicKeyMsg;
00219 
00235    class CreateKeyMsg : public Message
00236    {
00237       public :
00239          CreateKeyMsg();
00240 
00242          CreateKeyMsg( const CODEX_ASN1::OctetString& name,
00243                        const CODEX_ASN1::Certificate& owner,
00244                        const CODEX_Ciphers::Policy& readP,
00245                        const CODEX_Ciphers::Policy& writeP );
00246 
00248          CreateKeyMsg( const CreateKeyMsg& aCKM );
00249 
00251          virtual ~CreateKeyMsg() {}
00252 
00254          void operator=( const CreateKeyMsg& aCKM );
00255 
00257          const CODEX_ASN1::OctetString& name() const { return m_name; }
00258 
00260          const CODEX_ASN1::Certificate& owner() const { return m_owner; }
00261 
00263          const CODEX_Ciphers::Policy& readP() const { return m_readP; }
00264 
00266          const CODEX_Ciphers::Policy& writeP() const { return m_writeP; }
00267 
00269          int marshal( unsigned char ** pp ) const;
00271          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00272 
00273       private :
00274          CODEX_ASN1::OctetString  m_name;
00275          CODEX_ASN1::Certificate  m_owner;
00276          CODEX_Ciphers::Policy    m_readP;
00277          CODEX_Ciphers::Policy    m_writeP;
00278    };
00279 
00281    typedef SignedMessage< CreateKeyMsg, CODEX_Ciphers::RSASignature >
00282    SignedCreateKeyMsg;
00283 
00293    class BoundNameMsg : public Message
00294    {
00295       public :
00297          BoundNameMsg();
00298 
00300          BoundNameMsg( const CODEX_ASN1::OctetString& name,
00301                        const SignedCreateKeyMsg& request );
00302 
00304          BoundNameMsg( const BoundNameMsg& aBNM );
00305 
00307          virtual ~BoundNameMsg() {}
00308 
00310          void operator=( const BoundNameMsg& aBNM );
00311 
00313          const CODEX_ASN1::OctetString& name() const { return m_name; }
00314 
00316          const SignedCreateKeyMsg& request() const { return m_request; }
00317 
00319          int marshal( unsigned char ** pp ) const;
00321          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00322 
00323       private :
00324          CODEX_ASN1::OctetString  m_name;
00325          SignedCreateKeyMsg       m_request;
00326    };
00327 
00329    typedef SignedMessage< BoundNameMsg, CODEX_Ciphers::RSASignature >
00330    SignedBoundNameMsg;
00331 
00345    class WriteKeyMsg : public Message
00346    {
00347       public :
00349          WriteKeyMsg();
00350 
00352          WriteKeyMsg( const CODEX_ASN1::OctetString& name,
00353                       const RequestCipherTextType& encryption,
00354 #ifndef ELGAMAL
00355                       const CODEX_Ciphers::RSAPlaintextPK& proof,
00356 #endif
00357                       const CODEX_Ciphers::Credentials& credentials,
00358                       const SignedBoundNameMsg& binding );
00359 
00361          WriteKeyMsg( const WriteKeyMsg& aWKM );
00362 
00364          virtual ~WriteKeyMsg() {}
00365 
00367          void operator=( const WriteKeyMsg& aWKM );
00368 
00370          const CODEX_ASN1::OctetString& name() const { return m_name; }
00371 
00373          const RequestCipherTextType& encryption() const
00374          {
00375             return m_encryption;
00376          }
00377 
00378 #ifndef ELGAMAL
00379 
00380          const CODEX_Ciphers::RSAPlaintextPK& proof() const
00381          {
00382             return m_proof;
00383          }
00384 #endif
00385 
00387          const CODEX_Ciphers::Credentials& credentials() const
00388          {
00389             return m_credentials;
00390          }
00391 
00393          const SignedBoundNameMsg& binding() const { return m_binding; }
00394 
00396          int marshal( unsigned char ** pp ) const;
00398          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00399 
00400       private :
00401          CODEX_ASN1::OctetString        m_name;
00402          RequestCipherTextType            m_encryption;
00403 #ifndef ELGAMAL
00404          CODEX_Ciphers::RSAPlaintextPK  m_proof;
00405 #endif
00406          CODEX_Ciphers::Credentials     m_credentials;
00407          SignedBoundNameMsg             m_binding;
00408    };
00409 
00411    typedef SignedMessage< WriteKeyMsg, CODEX_Ciphers::RSASignature >
00412    SignedWriteKeyMsg;
00413 
00424    class KeyStoredMsg : public Message
00425    {
00426       public :
00428          KeyStoredMsg();
00429 
00431          KeyStoredMsg( const CODEX_ASN1::OctetString& name,
00432                        const CODEX_Ciphers::RSASignature& requestSignature );
00433 
00435          KeyStoredMsg( const KeyStoredMsg& aKSM );
00436 
00438          virtual ~KeyStoredMsg() {}
00439 
00441          void operator=( const KeyStoredMsg& aKSM );
00442 
00444          const CODEX_ASN1::OctetString& name() const { return m_name; }
00445 
00447          const CODEX_Ciphers::RSASignature& requestSignature() const
00448          {
00449             return m_requestSignature;
00450          }
00451 
00453          int marshal( unsigned char ** pp ) const;
00455          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00456 
00457       private :
00458          CODEX_ASN1::OctetString      m_name;
00459          CODEX_Ciphers::RSASignature  m_requestSignature;
00460    };
00461 
00463    typedef SignedMessage< KeyStoredMsg, CODEX_Ciphers::RSASignature >
00464    SignedKeyStoredMsg;
00465 
00474    class ReadKeyMsg : public Message
00475    {
00476       public :
00478          ReadKeyMsg();
00479 
00481          ReadKeyMsg( const CODEX_ASN1::OctetString& name,
00482                      const BlindingCipherTextType& blinding,
00483 #ifndef ELGAMAL
00484                      const CODEX_Ciphers::RSAPlaintextPK& proof,
00485 #endif
00486                      const CODEX_Ciphers::Credentials& credentials );
00487 
00489          ReadKeyMsg( const ReadKeyMsg& aRKM );
00490 
00492          virtual ~ReadKeyMsg() {}
00493 
00495          void operator=( const ReadKeyMsg& aRKM );
00496 
00498          const CODEX_ASN1::OctetString& name() const { return m_name; }
00499 
00501          const BlindingCipherTextType& blinding() const
00502          {
00503             return m_blinding;
00504          }
00505 
00506 #ifndef ELGAMAL
00507 
00508          const CODEX_Ciphers::RSAPlaintextPK& proof() const
00509          {
00510             return m_proof;
00511          }
00512 #endif
00513 
00515          const CODEX_Ciphers::Credentials& credentials() const
00516          {
00517             return m_credentials;
00518          }
00519 
00521          int marshal( unsigned char ** pp ) const;
00523          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00524 
00525       private :
00526          CODEX_ASN1::OctetString        m_name;
00527          BlindingCipherTextType         m_blinding;
00528 #ifndef ELGAMAL
00529          CODEX_Ciphers::RSAPlaintextPK  m_proof;
00530 #endif
00531          CODEX_Ciphers::Credentials     m_credentials;
00532    };
00533 
00535    typedef SignedMessage< ReadKeyMsg, CODEX_Ciphers::RSASignature >
00536    SignedReadKeyMsg;
00537 
00548    class BlindKeyMsg : public Message
00549    {
00550       public :
00552          BlindKeyMsg();
00553 
00555          BlindKeyMsg( const CODEX_ASN1::OctetString& name,
00556                       const BlindPlainTextType& blindedKey,
00557                       const CODEX_Ciphers::RSASignature& requestSignature );
00558 
00560          BlindKeyMsg( const BlindKeyMsg& aBKM );
00561 
00563          virtual ~BlindKeyMsg() {}
00564 
00566          void operator=( const BlindKeyMsg& aBKM );
00567 
00569          const CODEX_ASN1::OctetString& name() const { return m_name; }
00570 
00572          const BlindPlainTextType& blindedKey() const
00573          {
00574             return m_blindedKey;
00575          }
00576 
00578          const CODEX_Ciphers::RSASignature& requestSignature() const
00579          {
00580             return m_requestSignature;
00581          }
00582 
00584          int marshal( unsigned char ** pp ) const;
00586          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00587 
00588       private :
00589          CODEX_ASN1::OctetString      m_name;
00590          BlindPlainTextType           m_blindedKey;
00591          CODEX_Ciphers::RSASignature  m_requestSignature;
00592    };
00593 
00595    typedef SignedMessage< BlindKeyMsg, CODEX_Ciphers::RSASignature >
00596    SignedBlindKeyMsg;
00597 
00605    enum MessageType
00606    {
00607       kRequestKeyMsg,
00608       kPublicKeyMsg,
00609       kCreateKeyMsg,
00610       kBoundNameMsg,
00611       kWriteKeyMsg,
00612       kKeyStoredMsg,
00613       kReadKeyMsg,
00614       kBlindKeyMsg
00615    };
00616 
00621    const unsigned char SignatureMask = 0x80;
00622 }
00623 
00624 #endif /* __CODEX_CLIENT_MESSAGE_H__ */

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