summaryrefslogtreecommitdiffstats
path: root/plugins/netutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 9539a7f..e3fbb3a 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -234,6 +234,54 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
234 } 234 }
235} 235}
236 236
237#ifdef HAVE_SSL
238static SSL_CTX *c=NULL;
239static SSL *s=NULL;
240
241int np_net_ssl_init (int sd){
242 SSL_METHOD *m=NULL;
243 /* Initialize SSL context */
244 SSLeay_add_ssl_algorithms ();
245 m = SSLv23_client_method ();
246 SSL_load_error_strings ();
247 OpenSSL_add_all_algorithms();
248 if ((c = SSL_CTX_new (m)) == NULL) {
249 printf (_("CRITICAL - Cannot create SSL context.\n"));
250 return STATE_CRITICAL;
251 }
252 if ((s = SSL_new (c)) != NULL){
253 SSL_set_fd (s, sd);
254 if (SSL_connect(s) == 1){
255 return OK;
256 } else {
257 printf (_("CRITICAL - Cannot make SSL connection "));
258#ifdef USE_OPENSSL /* XXX look into ERR_error_string */
259 ERR_print_errors_fp (stdout);
260#endif /* USE_OPENSSL */
261 }
262 } else {
263 printf (_("CRITICAL - Cannot initiate SSL handshake.\n"));
264 }
265 return STATE_CRITICAL;
266}
267
268void np_net_ssl_cleanup (){
269 if(s){
270 SSL_shutdown (s);
271 SSL_free (s);
272 if(c) SSL_CTX_free (c);
273 }
274}
275
276int np_net_ssl_write(const void *buf, int num){
277 return SSL_write(s, buf, num);
278}
279
280int np_net_ssl_read(void *buf, int num){
281 return SSL_read(s, buf, num);
282}
283
284#endif /* HAVE_SSL */
237 285
238int 286int
239send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size) 287send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size)