sipxportlib  Version 3.3
OsSSLConnectionSocket.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef _OsSSLConnectionSocket_h_
12 #define _OsSSLConnectionSocket_h_
13 
14 #ifdef HAVE_SSL
15 
16 // SYSTEM INCLUDES
17 //#include <...>
18 
19 // APPLICATION INCLUDES
20 #include <utl/UtlSList.h>
21 #include <utl/UtlString.h>
22 #include <os/OsConnectionSocket.h>
23 
24 #include <openssl/crypto.h>
25 #include <openssl/x509.h>
26 #include <openssl/pem.h>
27 #include <openssl/ssl.h>
28 #include <openssl/err.h>
29 
30 // DEFINES
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 // STRUCTS
36 // TYPEDEFS
37 // FORWARD DECLARATIONS
38 
40 class OsSSLConnectionSocket : public OsConnectionSocket
41 {
42 /* //////////////////////////// PUBLIC //////////////////////////////////// */
43 public:
44 
45 /* ============================ CREATORS ================================== */
46 
47  OsSSLConnectionSocket(int remoteHostPort,
48  const char* remoteHostName,
49  long timeoutInSecs = 0
50  );
51 
52  OsSSLConnectionSocket(int connectedSocketDescriptor, long timeoutInSecs = 0);
53 
54  OsSSLConnectionSocket(SSL *s, int connectedSocketDescriptor);
55 
56  virtual
57  ~OsSSLConnectionSocket();
58  //:Destructor
59 
60 /* ============================ MANIPULATORS ============================== */
61 
62  virtual UtlBoolean reconnect();
63  //: Sets up the connection again, assuming the connection failed
64 
65  virtual int write(const char* buffer, int bufferLength);
66  //:Blocking write to the socket
67  // Write the characters in the given buffer to the socket.
68  // This method will block until all of the bytes are written.
74 
75  virtual int write(const char* buffer, int bufferLength, long waitMilliseconds);
76  //:Non-blocking or limited blocking write to socket
77  // Same as blocking version except that this write will block
78  // for no more than the specified length of time.
80 
81  virtual int read(char* buffer, int bufferLength);
82  //:Blocking read from the socket
83  // Read bytes into the buffer from the socket up to a maximum of
84  // bufferLength bytes. This method will block until there is
85  // something to read from the socket.
89 
90  virtual int read(char* buffer, int bufferLength,
91  UtlString* ipAddress, int* port);
92  //:Blocking read from the socket
93  // Read bytes into the buffer from the socket up to a maximum of
94  // bufferLength bytes. This method will block until there is
95  // something to read from the socket.
101 
102  virtual int read(char* buffer, int bufferLength, long waitMilliseconds);
103  //: Non-blocking or limited blocking read from socket
104  // Same as blocking version except that this read will block
105  // for no more than the specified length of time.
107 
108 /* ============================ ACCESSORS ================================= */
109 
110  virtual void close();
111  //: Closes the SSL socket
112 
113 /* ============================ INQUIRY =================================== */
114 
116  //: Returns the protocol type of this socket
117 
119  virtual bool isEncrypted() const;
120 
122  virtual bool peerIdentity( UtlSList* altNames
125  ,UtlString* commonName
126  ) const;
137 /* //////////////////////////// PROTECTED ///////////////////////////////// */
138 protected:
139 
140 /* //////////////////////////// PRIVATE /////////////////////////////////// */
141 private:
142  SSL* mSSL;
143 
144  // cached copies of peer information - parsing the cert is expensive
145  mutable enum
146  {
147  NOT_IDENTIFIED,
148  TRUSTED,
149  UNTRUSTED
150  } mPeerIdentity;
151  mutable UtlSList mAltNames;
152  mutable UtlString mCommonName;
153 
154  UtlBoolean mbExternalSSLSocket;
155  //:Should this object clean up SSL when shutdown.
156  //:It shouldn't if SSL is managed by a parent class
157  void SSLInitSocket(int socket, long timeoutInSecs);
158 
159  OsSSLConnectionSocket(const OsSSLConnectionSocket& rOsSSLConnectionSocket);
160  //:Disable copy constructor
161 
162  OsSSLConnectionSocket();
163  //:Disable default constructor
164 
165  OsSSLConnectionSocket& operator=(const OsSSLConnectionSocket& rhs);
166  //:Disable Assignment operator
167 };
168 
169 /* ============================ INLINE METHODS ============================ */
170 
171 #endif // HAVE_SSL
172 
173 #endif // _OsSSLConnectionSocket_h_
174 
IpProtocolSocketType
Definition: OsSocket.h:92
virtual int write(const char *buffer, int bufferLength, const char *ipAddress, int port)
Definition: OsSocket.h:117
virtual int read(char *buffer, int bufferLength)
param: waitMilliseconds - The maximum number of milliseconds to block. This may be set to zero...
Definition: OsConnectionSocket.cpp:304
virtual void close()
param: waitMilliseconds - The maximum number of milliseconds to block. This may be set to zero in whi...
Definition: OsSocket.cpp:692
virtual bool isEncrypted() const
Is this connection encrypted using TLS/SSL?
Definition: OsConnectionSocket.cpp:347
virtual UtlBoolean reconnect()
Definition: OsConnectionSocket.cpp:295
Definition: UtlString.h:48
virtual OsSocket::IpProtocolSocketType getIpProtocol() const
param: waitMilliseconds - The maximum number of milliseconds to block. This may be set to zero in whi...
Definition: OsConnectionSocket.cpp:340
Definition: UtlSList.h:47
Definition: OsConnectionSocket.h:34
int UtlBoolean
Definition: UtlDefs.h:41
virtual bool peerIdentity(UtlSList *altNames=NULL, UtlString *commonName=NULL) const
Get any authenticated peer host names.
Definition: OsConnectionSocket.cpp:354