Skip to content

Commit

Permalink
[XrdCl] Set a message callback for TLS layer for logging purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal authored and osschar committed Oct 10, 2019
1 parent e7ce0be commit 1150293
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/XrdCl/XrdClConstants.hh
Expand Up @@ -39,6 +39,7 @@ namespace XrdCl
const uint64_t JobMgrMsg = 0x0000000000000400ULL;
const uint64_t PlugInMgrMsg = 0x0000000000000800ULL;
const uint64_t ExDbgMsg = 0x0000000000001000ULL; //special type debugging extra-hard problems
const uint64_t TlsMsg = 0x0000000000002000ULL;

//----------------------------------------------------------------------------
// Environment settings
Expand Down
1 change: 1 addition & 0 deletions src/XrdCl/XrdClDefaultEnv.cc
Expand Up @@ -827,6 +827,7 @@ namespace XrdCl
log->SetTopicName( JobMgrMsg, "JobMgr" );
log->SetTopicName( PlugInMgrMsg, "PlugInMgr" );
log->SetTopicName( ExDbgMsg, "ExDbgMsg" );
log->SetTopicName( TlsMsg, "TlsMsg" );
}

}
Expand Down
4 changes: 3 additions & 1 deletion src/XrdCl/XrdClSocket.cc
Expand Up @@ -755,7 +755,9 @@ namespace XrdCl
}
catch( std::exception& ex )
{
return Status( stError, errTlsError );
// the exception has been thrown when we tried to create
// the TLS context
return Status( stFatal, errTlsError );
}

return Status();
Expand Down
54 changes: 52 additions & 2 deletions src/XrdCl/XrdClTls.cc
Expand Up @@ -19,15 +19,58 @@
#include "XrdCl/XrdClTls.hh"
#include "XrdCl/XrdClPoller.hh"
#include "XrdCl/XrdClSocket.hh"
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClLog.hh"
#include "XrdCl/XrdClConstants.hh"

#include "XrdTls/XrdTls.hh"
#include "XrdTls/XrdTlsContext.hh"

namespace
{
//------------------------------------------------------------------------
// Helper class for setting the message callback for the TLS layer for
// logging purposes
//------------------------------------------------------------------------
struct SetTlsMsgCB
{
//----------------------------------------------------------------------
// The message callback
//----------------------------------------------------------------------
static void MsgCallBack(const char *tid, const char *msg, bool sslmsg)
{
XrdCl::Log *log = XrdCl::DefaultEnv::GetLog();
if( sslmsg )
log->Debug( XrdCl::TlsMsg, "[%s] %s", tid, msg );
else
log->Error( XrdCl::TlsMsg, "[%s] %s", tid, msg );
}

inline static void Once()
{
static SetTlsMsgCB instance;
}

private:

//--------------------------------------------------------------------
// Constructor. Sets the callback, there should be only one static
// instance
//--------------------------------------------------------------------
inline SetTlsMsgCB()
{
XrdTls::SetMsgCB( MsgCallBack );
}
};

//------------------------------------------------------------------------
// Helper function for setting the CA directory in TLS context
//------------------------------------------------------------------------
static const char* GetCaDir()
{
const char *envval = getenv("X509_CERT_DIR");
static const std::string cadir = envval ? envval : "/etc/grid-security/certificates";;
static const char *envval = getenv("X509_CERT_DIR");
static const std::string cadir = envval ? envval :
"/etc/grid-security/certificates";
return cadir.c_str();
}
}
Expand All @@ -39,6 +82,13 @@ namespace XrdCl
//------------------------------------------------------------------------
Tls::Tls( Socket *socket, AsyncSocketHandler *socketHandler ) : pSocket( socket ), pTlsHSRevert( None ), pSocketHandler( socketHandler )
{
//----------------------------------------------------------------------
// Set the message callback for TLS layer
//----------------------------------------------------------------------
SetTlsMsgCB::Once();
//----------------------------------------------------------------------
// we only need one instance of TLS
//----------------------------------------------------------------------
static XrdTlsContext tlsContext( 0, 0, GetCaDir(), 0, 0 );
//----------------------------------------------------------------------
// If the context is not valid throw an exception! We throw generic
Expand Down

0 comments on commit 1150293

Please sign in to comment.