irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irods_ssl_object.cpp
Go to the documentation of this file.
1 // =-=-=-=-=-=-=-
2 #include "irods_ssl_object.hpp"
4 
5 #include "rodsKeyWdDef.h"
6 #include "rcMisc.h"
7 
8 extern int ProcessType;
9 
10 namespace irods {
11 // =-=-=-=-=-=-=-
12 // public - ctor
14  ssl_ctx_( 0 ),
15  ssl_( 0 ),
16  key_size_( 0 ),
17  salt_size_( 0 ),
18  num_hash_rounds_( 0 ) {
19 
20  } // ctor
21 
22 // =-=-=-=-=-=-=-
23 // public - ctor
25  const rcComm_t& _comm ) :
26  network_object( _comm ),
27  ssl_ctx_( _comm.ssl_ctx ),
28  ssl_( _comm.ssl ),
29  host_( _comm.host ),
30  key_size_( _comm.key_size ),
31  salt_size_( _comm.salt_size ),
32  num_hash_rounds_( _comm.num_hash_rounds ),
33  encryption_algorithm_( _comm.encryption_algorithm ) {
34  } // ctor
35 
36 // =-=-=-=-=-=-=-
37 // public - ctor
39  const rsComm_t& _comm ) :
40  network_object( _comm ),
41  ssl_ctx_( _comm.ssl_ctx ),
42  ssl_( _comm.ssl ),
43  host_( "" ),
44  key_size_( _comm.key_size ),
45  salt_size_( _comm.salt_size ),
46  num_hash_rounds_( _comm.num_hash_rounds ),
47  encryption_algorithm_( _comm.encryption_algorithm ) {
48  } // ctor
49 
50 // =-=-=-=-=-=-=-
51 // public - cctor
53  const ssl_object& _rhs ) :
54  network_object( _rhs ),
55  ssl_ctx_( _rhs.ssl_ctx() ),
56  ssl_( _rhs.ssl() ),
57  host_( _rhs.host() ),
58  key_size_( _rhs.key_size() ),
59  salt_size_( _rhs.salt_size() ),
60  num_hash_rounds_( _rhs.num_hash_rounds() ),
61  encryption_algorithm_( _rhs.encryption_algorithm() ) {
62  } // cctor
63 
64 // =-=-=-=-=-=-=-
65 // public - dtor
67  } // dtor
68 
69 // =-=-=-=-=-=-=-
70 // public - assignment operator
72  const ssl_object& _rhs ) {
74  ssl_ctx_ = _rhs.ssl_ctx();
75  ssl_ = _rhs.ssl();
76  host_ = _rhs.host();
77  key_size_ = _rhs.key_size();
78  salt_size_ = _rhs.salt_size();
81 
82  return *this;
83 
84  } // operator=
85 
86 // =-=-=-=-=-=-=-
87 // public - equality operator
89  const ssl_object& _rhs ) const {
90 
91  bool ret = network_object::operator==( _rhs );
92 
93  ret &= ( ssl_ctx_ == _rhs.ssl_ctx() );
94  ret &= ( ssl_ == _rhs.ssl() );
95  ret &= ( host_ == _rhs.host() );
96  ret &= ( key_size_ == _rhs.key_size() );
97  ret &= ( salt_size_ == _rhs.salt_size() );
98  ret &= ( num_hash_rounds_ == _rhs.num_hash_rounds() );
99  ret &= ( encryption_algorithm_ == _rhs.encryption_algorithm() );
100 
101  return ret;
102 
103  } // operator==
104 
105 // =-=-=-=-=-=-=-
106 // public - resolver for ssl_manager
108  const std::string& _interface,
109  plugin_ptr& _ptr ) {
110  // =-=-=-=-=-=-=-
111  // check the interface type and error out if it
112  // isnt a network interface
113  if ( NETWORK_INTERFACE != _interface ) {
114  std::stringstream msg;
115  msg << "ssl_object does not support a [";
116  msg << _interface;
117  msg << "] plugin interface";
118  return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
119 
120  }
121 
122  // =-=-=-=-=-=-=-
123  // ask the network manager for a SSL resource
124  network_ptr net_ptr;
125  error ret = netwk_mgr.resolve( SSL_NETWORK_PLUGIN, net_ptr );
126  if ( !ret.ok() ) {
127  // =-=-=-=-=-=-=-
128  // attempt to load the plugin, in this case the type,
129  // instance name, key etc are all ssl as there is only
130  // the need for one instance of a ssl object, etc.
131  std::string empty_context( "" );
133  ProcessType,
137  empty_context,
138  net_ptr );
139  if ( !ret.ok() ) {
140  return PASS( ret );
141 
142  }
143  else {
144  // =-=-=-=-=-=-=-
145  // upcast for out variable
146  _ptr = boost::dynamic_pointer_cast< plugin_base >( net_ptr );
147  return SUCCESS();
148 
149  }
150 
151  } // if !ok
152 
153  // =-=-=-=-=-=-=-
154  // upcast for out variable
155  _ptr = boost::dynamic_pointer_cast< plugin_base >( net_ptr );
156 
157  return SUCCESS();
158 
159  } // resolve
160 
161 // =-=-=-=-=-=-=-
162 // accessor for rule engine variables
164  rule_engine_vars_t& _kvp ) {
166 
167  _kvp[SSL_HOST_KW] = host_.c_str();
168 
169  // =-=-=-=-=-=-=-
170  // since the shared secret is random and unsigned it needs
171  // a bit of sanitizaiton until we can copy it to the kvp
172  std::stringstream key_sz;
173  key_sz << key_size_;
174  _kvp[SSL_KEY_SIZE_KW] = key_sz.str().c_str();
175 
176  std::stringstream salt_sz;
177  salt_sz << salt_size_;
178  _kvp[SSL_SALT_SIZE_KW] = salt_sz.str().c_str();
179 
180  std::stringstream hash_rnds;
181  hash_rnds << num_hash_rounds_;
182  _kvp[SSL_NUM_HASH_ROUNDS_KW] = hash_rnds.str().c_str();
183 
184  _kvp[SSL_ALGORITHM_KW] = encryption_algorithm_.c_str();
185 
186  return SUCCESS();
187 
188  } // get_re_vars
189 
190 // =-=-=-=-=-=-=-
191 // conversion to client comm ptr
193  if ( !_comm ) {
194  return ERROR( SYS_INVALID_INPUT_PARAM, "null comm ptr" );
195  }
196 
197  network_object::to_client( _comm );
198 
199  _comm->ssl = ssl_;
200  _comm->ssl_ctx = ssl_ctx_;
201  std::copy(
202  shared_secret_.begin(),
203  shared_secret_.end(),
204  &_comm->shared_secret[0] );
205  _comm->key_size = key_size_;
206  _comm->salt_size = salt_size_;
208  snprintf( _comm->encryption_algorithm, sizeof( _comm->encryption_algorithm ),
209  "%s", encryption_algorithm_.c_str() );
210 
211  return SUCCESS();
212 
213  } // to_client
214 
215 // =-=-=-=-=-=-=-
216 // convertion to client comm ptr
218  if ( !_comm ) {
219  return ERROR( SYS_INVALID_INPUT_PARAM, "null comm ptr" );
220  }
221 
222  network_object::to_server( _comm );
223 
224  _comm->ssl = ssl_;
225  _comm->ssl_ctx = ssl_ctx_;
226  std::copy(
227  shared_secret_.begin(),
228  shared_secret_.end(),
229  &_comm->shared_secret[0] );
230  _comm->key_size = key_size_;
231  _comm->salt_size = salt_size_;
233  snprintf( _comm->encryption_algorithm, sizeof( _comm->encryption_algorithm ),
234  "%s", encryption_algorithm_.c_str() );
235 
236 
237  return SUCCESS();
238 
239  } // to_server
240 
241 
242 }; // namespace irods
243 
244 
245 
rodsKeyWdDef.h
irods::plugin_ptr
boost::shared_ptr< plugin_base > plugin_ptr
Definition: irods_first_class_object.hpp:18
rcComm_t
Definition: rcConnect.h:95
irods::ssl_object
Definition: irods_ssl_object.hpp:20
rsComm_t
Definition: rcConnect.h:145
SSL_KEY_SIZE_KW
#define SSL_KEY_SIZE_KW
Definition: rodsKeyWdDef.h:240
irods::ssl_object::get_re_vars
virtual error get_re_vars(rule_engine_vars_t &)
Definition: irods_ssl_object.cpp:163
irods::ssl_object::encryption_algorithm_
std::string encryption_algorithm_
Definition: irods_ssl_object.hpp:123
SSL_NUM_HASH_ROUNDS_KW
#define SSL_NUM_HASH_ROUNDS_KW
Definition: rodsKeyWdDef.h:242
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
irods_ssl_object.hpp
rcComm_t::num_hash_rounds
int num_hash_rounds
Definition: rcConnect.h:123
rcMisc.h
rsComm_t::salt_size
int salt_size
Definition: rcConnect.h:189
irods::ssl_object::salt_size_
int salt_size_
Definition: irods_ssl_object.hpp:121
irods::NETWORK_INTERFACE
const std::string NETWORK_INTERFACE("irods_network_interface")
irods::netwk_mgr
network_manager netwk_mgr
Definition: irods_network_manager.cpp:8
rsComm_t::num_hash_rounds
int num_hash_rounds
Definition: rcConnect.h:190
irods::ssl_object::to_client
virtual error to_client(rcComm_t *)
Definition: irods_ssl_object.cpp:192
irods::ssl_object::~ssl_object
virtual ~ssl_object()
Definition: irods_ssl_object.cpp:66
irods::ssl_object::host
virtual std::string host() const
Definition: irods_ssl_object.hpp:66
irods::ssl_object::to_server
virtual error to_server(rsComm_t *)
Definition: irods_ssl_object.cpp:217
irods_network_manager.hpp
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
irods::ssl_object::salt_size
virtual int salt_size() const
Definition: irods_ssl_object.hpp:76
irods::network_manager::init_from_type
error init_from_type(const int &, const std::string &, const std::string &, const std::string &, const std::string &, network_ptr &)
Definition: irods_network_manager.cpp:83
ProcessType
int ProcessType
Definition: rcGlobal.cpp:16
irods::ssl_object::ssl
virtual SSL * ssl() const
Definition: irods_ssl_object.hpp:63
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::ssl_object::encryption_algorithm
virtual std::string encryption_algorithm() const
Definition: irods_ssl_object.hpp:82
irods::ssl_object::num_hash_rounds
virtual int num_hash_rounds() const
Definition: irods_ssl_object.hpp:79
irods::ssl_object::ssl_ctx_
SSL_CTX * ssl_ctx_
Definition: irods_ssl_object.hpp:115
irods
Definition: apiHandler.hpp:35
irods::ssl_object::ssl_ctx
virtual SSL_CTX * ssl_ctx() const
Definition: irods_ssl_object.hpp:60
irods::experimental::filesystem::client::copy
auto copy(rcComm_t &_comm, const path &_from, const path &_to, copy_options _options=copy_options::none) -> void
Definition: filesystem.cpp:370
irods::network_ptr
boost::shared_ptr< network > network_ptr
Definition: irods_network_types.hpp:19
rcComm_t::encryption_algorithm
char encryption_algorithm[64]
Definition: rcConnect.h:124
irods::network_object::operator=
virtual network_object & operator=(const network_object &)
Definition: irods_network_object.cpp:49
irods::SSL_NETWORK_PLUGIN
const std::string SSL_NETWORK_PLUGIN("ssl")
rsComm_t::ssl
SSL * ssl
Definition: rcConnect.h:181
rsComm_t::ssl_ctx
SSL_CTX * ssl_ctx
Definition: rcConnect.h:180
rcComm_t::ssl
SSL * ssl
Definition: rcConnect.h:130
rsComm_t::key_size
int key_size
Definition: rcConnect.h:188
rcComm_t::ssl_ctx
SSL_CTX * ssl_ctx
Definition: rcConnect.h:129
irods::ssl_object::resolve
virtual error resolve(const std::string &, plugin_ptr &)
Definition: irods_ssl_object.cpp:107
rsComm_t::shared_secret
unsigned char shared_secret[64]
Definition: rcConnect.h:186
irods::ssl_object::ssl_
SSL * ssl_
Definition: irods_ssl_object.hpp:116
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods::network_object::to_server
virtual error to_server(rsComm_t *)
Definition: irods_network_object.cpp:91
irods::ssl_object::ssl_object
ssl_object()
Definition: irods_ssl_object.cpp:13
SSL_SALT_SIZE_KW
#define SSL_SALT_SIZE_KW
Definition: rodsKeyWdDef.h:241
irods::ssl_object::host_
std::string host_
Definition: irods_ssl_object.hpp:117
irods::ssl_object::operator=
virtual ssl_object & operator=(const ssl_object &)
Definition: irods_ssl_object.cpp:71
irods::network_object::operator==
virtual bool operator==(const network_object &_rhs) const
Definition: irods_network_object.cpp:58
irods::network_manager::resolve
error resolve(std::string, network_ptr &)
Definition: irods_network_manager.cpp:31
generate_iadmin_commands_for_41_to_42_upgrade.host
host
Definition: generate_iadmin_commands_for_41_to_42_upgrade.py:23
irods::network_object
Definition: irods_network_object.hpp:18
irods::network_object::get_re_vars
virtual error get_re_vars(rule_engine_vars_t &)
Definition: irods_network_object.cpp:66
rcComm_t::shared_secret
unsigned char shared_secret[64]
Definition: rcConnect.h:126
irods::ssl_object::num_hash_rounds_
int num_hash_rounds_
Definition: irods_ssl_object.hpp:122
irods::ssl_object::key_size_
int key_size_
Definition: irods_ssl_object.hpp:120
rsComm_t::encryption_algorithm
char encryption_algorithm[64]
Definition: rcConnect.h:191
irods::ssl_object::shared_secret_
buffer_crypt::array_t shared_secret_
Definition: irods_ssl_object.hpp:118
SSL_HOST_KW
#define SSL_HOST_KW
Definition: rodsKeyWdDef.h:238
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
rcComm_t::key_size
int key_size
Definition: rcConnect.h:121
SSL_ALGORITHM_KW
#define SSL_ALGORITHM_KW
Definition: rodsKeyWdDef.h:243
irods::ssl_object::operator==
virtual bool operator==(const ssl_object &_rhs) const
Definition: irods_ssl_object.cpp:88
irods::ssl_object::key_size
virtual int key_size() const
Definition: irods_ssl_object.hpp:73
rcComm_t::salt_size
int salt_size
Definition: rcConnect.h:122
irods::rule_engine_vars_t
std::map< std::string, std::string > rule_engine_vars_t
Definition: irods_first_class_object.hpp:20
irods::network_object::to_client
virtual error to_client(rcComm_t *)
Definition: irods_network_object.cpp:78