00001 // ---------------------------------------------------------------------------- 00002 // CERTI - HLA RunTime Infrastructure 00003 // Copyright (C) 2002-2005 ONERA 00004 // 00005 // This program is free software ; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation ; either version 2 of 00008 // the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, but 00011 // WITHOUT ANY WARRANTY ; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this program ; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00018 // USA 00019 // 00020 // $Id: SecureTCPSocket.hh,v 3.9 2008/10/13 11:27:51 gotthardp Exp $ 00021 // ---------------------------------------------------------------------------- 00022 00023 #ifndef CERTI_SECURE_TCP_SOCKET_HH 00024 #define CERTI_SECURE_TCP_SOCKET_HH 00025 00026 #include "SocketTCP.hh" 00027 #include "GSSAPIHandler.hh" 00028 #include "certi.hh" 00029 00030 #ifndef _WIN32 00031 #include <unistd.h> 00032 #include <pwd.h> 00033 #endif 00034 00035 namespace certi { 00036 00037 // ============================================================================ 00040 class CERTI_EXPORT SecureTCPSocket : public SocketTCP 00041 { 00042 public: 00043 SecureTCPSocket(); 00044 virtual ~SecureTCPSocket(); 00045 00046 virtual void send(const unsigned char *, size_t) 00047 throw (NetworkError, NetworkSignal); 00048 virtual void receive(void *Buffer, unsigned long Size) 00049 throw (NetworkError, NetworkSignal); 00050 00051 // FIXME: Peut-etre devrait-on regarder si un message est pret en interne, 00052 // et balancer une exception dans ce cas la. 00053 virtual bool isDataReady() const { return SocketTCP::isDataReady(); } 00054 00055 // Return Peer's principal name. Must not be freed ! Principal name is 00056 // without any network address part(starting with a '@'). 00057 const char *getPeerName(); 00058 00059 private: 00060 #ifdef WITH_GSSAPI 00061 // Initial Token exchange to open the GSS API session. The client send the 00062 // initial token to a server principal whose name is fixed. 00063 void sendInitialToken(); 00064 void receiveInitialToken(); 00065 00066 // Input/Output methods. Parameters of SendMessage are unscrambled 00067 // messages. GetMessage read an incoming message from the TCP 00068 // socket, decrypt and verify it, and then store it in 00069 // InternalBuffer. Call GetMessagePart to retrieve it. 00070 void sendMessage(void *Buffer, unsigned long Size); 00071 void getMessage(); 00072 00073 // Copy a part of an already received and decrypted message to buffer. 00074 // The copied part is(Size) bytes long. If(Size) bytes are not available, 00075 // an exception is raised. 00076 void getMessagePart(void *Buffer, unsigned long Size); 00077 00078 bool SessionInitialized ; 00079 bool DecryptedMessageReady ; 00080 00081 GSSAPIHandler *GSSHandler ; 00082 00083 // GSSAPI buffer for incming messages. Memory is allocated by GSSHandler 00084 // but deleted locally after use. Base offset is zero. 00085 gss_buffer_desc IncomingBuffer ; 00086 unsigned long CurrentOffset ; // Current offset in buffer. 00087 00088 #endif // WITH_GSSAPI 00089 00090 char *PeerName ; 00091 }; 00092 00093 } // namespace certi 00094 00095 #endif // CERTI_SECURE_TCP_SOCKET_HH 00096 00097 // $Id: SecureTCPSocket.hh,v 3.9 2008/10/13 11:27:51 gotthardp Exp $ 00098