Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes
Arc::PayloadTLSStream Class Reference

Implemetation of PayloadStreamInterface for SSL handle. More...

#include <PayloadTLSStream.h>

Inheritance diagram for Arc::PayloadTLSStream:
Inheritance graph
[legend]
Collaboration diagram for Arc::PayloadTLSStream:
Collaboration graph
[legend]

List of all members.

Public Types

typedef signed long long int Size_t

Public Member Functions

 PayloadTLSStream (Logger &logger, SSL *ssl=NULL)
 Constructor.
 PayloadTLSStream (PayloadTLSStream &stream)
virtual ~PayloadTLSStream (void)
 Destructor.
void HandleError (int code=SSL_ERROR_NONE)
virtual bool Get (char *buf, int &size)
 Extracts information from stream up to 'size' bytes.
virtual bool Get (std::string &buf)
 Read as many as possible (sane amount) of bytes into buf.
virtual std::string Get (void)
 Read as many as possible (sane amount) of bytes.
virtual bool Put (const char *buf, Size_t size)
 Push 'size' bytes from 'buf' into stream.
virtual bool Put (const std::string &buf)
 Push information from 'buf' into stream.
virtual bool Put (const char *buf)
 Push null terminated information from 'buf' into stream.
virtual operator bool (void)
 Returns true if stream is valid.
virtual bool operator! (void)
 Returns true if stream is invalid.
virtual int Timeout (void) const
 Query current timeout for Get() and Put() operations.
virtual void Timeout (int to)
 Set current timeout for Get() and Put() operations.
virtual Size_t Pos (void) const
 Returns current position in stream if supported.
virtual Size_t Size (void) const
 Returns size of underlying object if supported.
virtual Size_t Limit (void) const
 Returns position at which stream reading will stop if supported.
X509 * GetPeerCert (void)
 Get peer certificate from the established ssl.
 STACK_OF (X509)*GetPeerChain(void)
 Get chain of peer certificates from the established ssl.
X509 * GetCert (void)
 Get local certificate from associated ssl.

Static Public Member Functions

static void HandleError (Logger &logger, int code=SSL_ERROR_NONE)
static void ClearError (void)

Protected Attributes

int timeout_
SSL * ssl_
 Timeout for read/write operations.
Loggerlogger_

Detailed Description

Implemetation of PayloadStreamInterface for SSL handle.

Definition at line 16 of file PayloadTLSStream.h.


Member Typedef Documentation

typedef signed long long int Arc::PayloadStreamInterface::Size_t [inherited]

Definition at line 18 of file PayloadStream.h.


Constructor & Destructor Documentation

Arc::PayloadTLSStream::PayloadTLSStream ( Logger logger,
SSL *  ssl = NULL 
)

Constructor.

Attaches to already open handle. Handle is not managed by this class and must be closed by external code.

Definition at line 56 of file PayloadTLSStream.cpp.

                                                         :ssl_(ssl),logger_(logger) {
  //initialize something
  return;
}

Definition at line 61 of file PayloadTLSStream.cpp.

                                                          :timeout_(stream.timeout_),ssl_(stream.ssl_),logger_(stream.logger_) {
}

Destructor.

Definition at line 64 of file PayloadTLSStream.cpp.

                                        {
  ClearError();
}

Here is the call graph for this function:


Member Function Documentation

void Arc::PayloadTLSStream::ClearError ( void  ) [static]

Definition at line 49 of file PayloadTLSStream.cpp.

                                      {
  int e = ERR_get_error();
  while(e != 0) {
    e = ERR_get_error();
  }
}

Here is the caller graph for this function:

bool Arc::PayloadTLSStream::Get ( char *  buf,
int &  size 
) [virtual]

Extracts information from stream up to 'size' bytes.

'size' contains number of read bytes on exit. Returns true in case of success.

Implements Arc::PayloadStreamInterface.

Definition at line 68 of file PayloadTLSStream.cpp.

                                              {
  if(ssl_ == NULL) return false;
  //ssl read
  ssize_t l=size;
  size=0;
  l=SSL_read(ssl_,buf,l);
  if(l <= 0){
     HandleError(SSL_get_error(ssl_,l));
     return false;
  }
  size=l;
  return true;
}

Here is the call graph for this function:

bool Arc::PayloadTLSStream::Get ( std::string &  buf) [virtual]

Read as many as possible (sane amount) of bytes into buf.

Implements Arc::PayloadStreamInterface.

Definition at line 82 of file PayloadTLSStream.cpp.

                                         {
  char tbuf[1024];
  int l = sizeof(tbuf);
  bool result = Get(tbuf,l);
  buf.assign(tbuf,l);
  return result;
}

Here is the call graph for this function:

virtual std::string Arc::PayloadTLSStream::Get ( void  ) [inline, virtual]

Read as many as possible (sane amount) of bytes.

Implements Arc::PayloadStreamInterface.

Definition at line 35 of file PayloadTLSStream.h.

{ std::string buf; Get(buf); return buf; };

Here is the call graph for this function:

Here is the caller graph for this function:

X509 * Arc::PayloadTLSStream::GetCert ( void  )

Get local certificate from associated ssl.

Obtained X509 object is owned by this instance and becomes invalid after destruction.

Definition at line 123 of file PayloadTLSStream.cpp.

                                   {
  X509* cert;
  if(ssl_ == NULL) return NULL;
  cert=SSL_get_certificate (ssl_);
  if(cert!=NULL) return cert;
  logger_.msg(WARNING,"Certificate cannot be extracted, make sure it is the case where client side authentication is turned off");
  HandleError();
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get peer certificate from the established ssl.

Obtained X509 object is owned by this instance and becomes invalid after destruction. Still obtained has to be freed at end of usage.

Definition at line 105 of file PayloadTLSStream.cpp.

                                       {
  X509* peercert;
  int err;
  if(ssl_ == NULL) return NULL;
  if((err=SSL_get_verify_result(ssl_)) == X509_V_OK){
    peercert=SSL_get_peer_certificate (ssl_);
    if(peercert!=NULL) return peercert;
    logger_.msg(ERROR,"Peer certificate cannot be extracted");
    HandleError();
  }
  else{
    logger_.msg(ERROR,"Peer cert verification fail");
    logger_.msg(ERROR,"%s",X509_verify_cert_error_string(err));
    HandleError(err);
  }
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::PayloadTLSStream::HandleError ( int  code = SSL_ERROR_NONE)

Definition at line 25 of file PayloadTLSStream.cpp.

                                           {
   HandleError(logger_,code);
}

Here is the caller graph for this function:

void Arc::PayloadTLSStream::HandleError ( Logger logger,
int  code = SSL_ERROR_NONE 
) [static]

Definition at line 29 of file PayloadTLSStream.cpp.

                                                          {
  unsigned long e = (code==SSL_ERROR_NONE)?ERR_get_error():code;
  while(e != SSL_ERROR_NONE) {
    if(e == SSL_ERROR_SYSCALL) {
      // Hiding system errors
      //logger.msg(ERROR, "SSL error: %d - system call failed",e); 
    } else {
      const char* lib = ERR_lib_error_string(e);
      const char* func = ERR_func_error_string(e);
      const char* reason = ERR_reason_error_string(e);
      logger.msg(ERROR, "SSL error: %d - %s:%s:%s", 
                        e, 
                        lib?lib:"",
                        func?func:"",
                        reason?reason:"");
    };
    e = ERR_get_error();
  }
}

Here is the call graph for this function:

virtual Size_t Arc::PayloadTLSStream::Limit ( void  ) const [inline, virtual]

Returns position at which stream reading will stop if supported.

That may be not same as Size() if instance is meant to provide access to only part of underlying obejct.

Implements Arc::PayloadStreamInterface.

Definition at line 45 of file PayloadTLSStream.h.

{ return 0; };
virtual Arc::PayloadTLSStream::operator bool ( void  ) [inline, virtual]

Returns true if stream is valid.

Implements Arc::PayloadStreamInterface.

Definition at line 39 of file PayloadTLSStream.h.

{ return (ssl_ != NULL); };
virtual bool Arc::PayloadTLSStream::operator! ( void  ) [inline, virtual]

Returns true if stream is invalid.

Implements Arc::PayloadStreamInterface.

Definition at line 40 of file PayloadTLSStream.h.

{ return (ssl_ == NULL); };
virtual Size_t Arc::PayloadTLSStream::Pos ( void  ) const [inline, virtual]

Returns current position in stream if supported.

Implements Arc::PayloadStreamInterface.

Definition at line 43 of file PayloadTLSStream.h.

{ return 0; };
bool Arc::PayloadTLSStream::Put ( const char *  buf,
Size_t  size 
) [virtual]

Push 'size' bytes from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 90 of file PayloadTLSStream.cpp.

                                                      {
  //ssl write
  ssize_t l;
  if(ssl_ == NULL) return false;
  for(;size;){
     l=SSL_write(ssl_,buf,size);
     if(l <= 0){
        HandleError(SSL_get_error(ssl_,l));
        return false;
     }
     buf+=l; size-=l;
  }
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool Arc::PayloadTLSStream::Put ( const std::string &  buf) [inline, virtual]

Push information from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 37 of file PayloadTLSStream.h.

{ return Put(buf.c_str(),buf.length()); };

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool Arc::PayloadTLSStream::Put ( const char *  buf) [inline, virtual]

Push null terminated information from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 38 of file PayloadTLSStream.h.

{ return Put(buf,buf?strlen(buf):0); };

Here is the call graph for this function:

Here is the caller graph for this function:

virtual Size_t Arc::PayloadTLSStream::Size ( void  ) const [inline, virtual]

Returns size of underlying object if supported.

Implements Arc::PayloadStreamInterface.

Definition at line 44 of file PayloadTLSStream.h.

{ return 0; };

Get chain of peer certificates from the established ssl.

Obtained X509 object is owned by this instance and becomes invalid after destruction.

virtual int Arc::PayloadTLSStream::Timeout ( void  ) const [inline, virtual]

Query current timeout for Get() and Put() operations.

Implements Arc::PayloadStreamInterface.

Definition at line 41 of file PayloadTLSStream.h.

{ return timeout_; };
virtual void Arc::PayloadTLSStream::Timeout ( int  to) [inline, virtual]

Set current timeout for Get() and Put() operations.

Implements Arc::PayloadStreamInterface.

Definition at line 42 of file PayloadTLSStream.h.

{ timeout_=to; };

Member Data Documentation

Definition at line 20 of file PayloadTLSStream.h.

SSL* Arc::PayloadTLSStream::ssl_ [protected]

Timeout for read/write operations.

Definition at line 19 of file PayloadTLSStream.h.

Definition at line 18 of file PayloadTLSStream.h.


The documentation for this class was generated from the following files: