~vcs-imports/irssi/old-svn

« back to all changes in this revision

Viewing changes to src/core/network-openssl.c

  • Committer: ahf
  • Date: 2013-06-23 23:50:26 UTC
  • Revision ID: svn-v4:dbcabf3a-b0e7-0310-adc4-f8d773084564:irssi/trunk:5219
Pass SERVER_REC directly to net_connect_ip_ssl

This patch refactors how we are passing connection information for SSL
connections. This will allow us to emit signals with a SERVER_REC as
parameter during SSL handshake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "module.h"
22
22
#include "network.h"
23
23
#include "misc.h"
 
24
#include "servers.h"
24
25
 
25
26
#ifdef HAVE_OPENSSL
26
27
 
45
46
        SSL *ssl;
46
47
        SSL_CTX *ctx;
47
48
        unsigned int verify:1;
48
 
        const char *hostname;
 
49
        SERVER_REC *server;
49
50
        int port;
50
51
} GIOSSLChannel;
51
52
 
428
429
 
429
430
}
430
431
 
431
 
static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *hostname, int port, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify)
 
432
static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_REC *server)
432
433
{
433
434
        GIOSSLChannel *chan;
434
435
        GIOChannel *gchan;
436
437
        SSL *ssl;
437
438
        SSL_CTX *ctx = NULL;
438
439
 
 
440
        const char *mycert = server->connrec->ssl_cert;
 
441
        const char *mypkey = server->connrec->ssl_pkey;
 
442
        const char *cafile = server->connrec->ssl_cafile;
 
443
        const char *capath = server->connrec->ssl_capath;
 
444
        gboolean verify = server->connrec->ssl_verify;
 
445
 
439
446
        g_return_val_if_fail(handle != NULL, NULL);
440
447
 
441
448
        if(!ssl_inited && !irssi_ssl_init())
511
518
        chan->giochan = handle;
512
519
        chan->ssl = ssl;
513
520
        chan->ctx = ctx;
 
521
        chan->server = server;
 
522
        chan->port = port;
514
523
        chan->verify = verify;
515
 
        chan->hostname = hostname;
516
 
        chan->port = port;
517
524
 
518
525
        gchan = (GIOChannel *)chan;
519
526
        gchan->funcs = &irssi_ssl_channel_funcs;
524
531
        return gchan;
525
532
}
526
533
 
527
 
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
 
534
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server)
528
535
{
529
536
        GIOChannel *handle, *ssl_handle;
530
537
 
531
538
        handle = net_connect_ip(ip, port, my_ip);
532
539
        if (handle == NULL)
533
540
                return NULL;
534
 
        ssl_handle  = irssi_ssl_get_iochannel(handle, hostname, port, cert, pkey, cafile, capath, verify);
 
541
        ssl_handle  = irssi_ssl_get_iochannel(handle, port, server);
535
542
        if (ssl_handle == NULL)
536
543
                g_io_channel_unref(handle);
537
544
        return ssl_handle;
573
580
                g_warning("SSL server supplied no certificate");
574
581
                return -1;
575
582
        }
576
 
        ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->hostname, chan->port, cert);
 
583
        ret = !chan->verify || irssi_ssl_verify(chan->ssl, chan->ctx, chan->server->connrec->address, chan->port, cert);
577
584
        X509_free(cert);
578
585
        return ret ? 0 : -1;
579
586
}
580
587
 
581
588
#else /* HAVE_OPENSSL */
582
589
 
583
 
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, const char* hostname, IPADDR *my_ip, const char *cert, const char *pkey, const char *cafile, const char *capath, gboolean verify)
 
590
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server)
584
591
{
585
592
        g_warning("Connection failed: SSL support not enabled in this build.");
586
593
        errno = ENOSYS;