loudmouth/lm-ssl-openssl.c
author Frank Zschockelt <lm@freakysoft.de>
Thu, 11 Feb 2016 21:00:41 +0100
changeset 702 75866de0e731
parent 690 7ccf2113ec5f
child 704 d682ae8d7d3a
permissions -rw-r--r--
Load system certs only if user doesn't specify trusted certs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     2
/*
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     3
 * Copyright (C) 2006 Imendio AB
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
     4
 * Copyright (C) 2006 Nokia Corporation. All rights reserved.
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     5
 *
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     7
 * modify it under the terms of the GNU Lesser General Public License as
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     8
 * published by the Free Software Foundation; either version 2 of the
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
     9
 * License, or (at your option) any later version.
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    10
 *
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful,
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    14
 * Lesser General Public License for more details.
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    15
 *
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    16
 * You should have received a copy of the GNU Lesser General Public
690
7ccf2113ec5f Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents: 689
diff changeset
    17
 * License along with this program; if not, see <https://www.gnu.org/licenses>
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    18
 */
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    19
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    20
#include <config.h>
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    21
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    22
#include <stdio.h>
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    23
#include <string.h>
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
    24
#include <sys/types.h>
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
    25
#include <sys/stat.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    26
#include <unistd.h>
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    27
#include <glib.h>
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    28
213
27567fb5d37b Use g_warning and g_log for warnings and debug printouts in OpenSSL backend.
Mikael Hallendal <micke@imendio.com>
parents: 209
diff changeset
    29
#include "lm-debug.h"
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    30
#include "lm-error.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    31
#include "lm-ssl-base.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    32
#include "lm-ssl-internals.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    33
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    34
#ifdef HAVE_OPENSSL
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    35
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    36
#include <openssl/ssl.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    37
#include <openssl/err.h>
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
    38
#include <openssl/x509v3.h>
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
    39
#include <openssl/asn1.h>
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
    40
#include <openssl/safestack.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    41
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    42
#define LM_SSL_CN_MAX       63
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    43
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    44
struct _LmSSL {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    45
    LmSSLBase base;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    46
628
1ac0534623ef Fix compilation warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents: 618
diff changeset
    47
    const SSL_METHOD *ssl_method;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
    SSL_CTX *ssl_ctx;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    49
    SSL *ssl;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    50
    /*BIO *bio;*/
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    51
};
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    52
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    53
int ssl_verify_cb (int preverify_ok, X509_STORE_CTX *x509_ctx);
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    54
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    55
static gboolean ssl_verify_certificate (LmSSL *ssl, const gchar *server);
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    56
static GIOStatus ssl_io_status_from_return (LmSSL *ssl, gint error);
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    57
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    58
/*static char _ssl_error_code[11];*/
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    59
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    60
static void
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    61
ssl_print_state (LmSSL *ssl, const char *func, int val)
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    62
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    63
    unsigned long errid;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    64
    const char *errmsg;
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    65
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    66
    switch (SSL_get_error(ssl->ssl, val)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    67
    case SSL_ERROR_NONE:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    68
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "%s(): %i / SSL_ERROR_NONE",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    69
                   func, val);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    70
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    71
    case SSL_ERROR_ZERO_RETURN:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    72
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    73
                   "%s(): %i / SSL_ERROR_ZERO_RETURN", func, val);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    74
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    75
    case SSL_ERROR_WANT_READ:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    76
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    77
                   "%s(): %i / SSL_ERROR_WANT_READ", func, val);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    78
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    79
    case SSL_ERROR_WANT_WRITE:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    80
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    81
                   "%s(): %i / SSL_ERROR_WANT_WRITE", func, val);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    82
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    83
    case SSL_ERROR_WANT_X509_LOOKUP:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    84
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    85
                   "%s(): %i / SSL_ERROR_WANT_X509_LOOKUP", func, val);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    86
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    87
    case SSL_ERROR_SYSCALL:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    88
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    89
                   "%s(): %i / SSL_ERROR_SYSCALL", func, val);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    90
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    91
    case SSL_ERROR_SSL:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    92
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    93
                   "%s(): %i / SSL_ERROR_SSL", func, val);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    94
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    95
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    96
    do {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    97
        errid = ERR_get_error();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    98
        if (errid) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    99
            errmsg = ERR_error_string(errid, NULL);
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   100
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "\t%s", errmsg);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   101
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   102
    } while (errid != 0);
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   103
}
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   104
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   105
/*static const char *
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   106
  ssl_get_x509_err (long verify_res)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   107
  {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   108
  sprintf(_ssl_error_code, "%ld", verify_res);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   109
  return _ssl_error_code;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   110
  }*/
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   111
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   112
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   113
int
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   114
ssl_verify_cb (int preverify_ok, X509_STORE_CTX *x509_ctx)
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   115
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   116
    /* As this callback doesn't get auxiliary pointer parameter we
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   117
     * cannot really use this. However, we can retrieve results later. */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   118
    return 1;
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   119
}
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   120
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   121
/* side effect: fills the ssl->fingerprint buffer */
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   122
static gboolean
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   123
ssl_verify_certificate (LmSSL *ssl, const gchar *server)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   124
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   125
    gboolean retval = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   126
    LmSSLBase *base;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   127
    long verify_res;
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   128
    int rc;
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   129
    const EVP_MD *digest = EVP_md5();
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   130
    unsigned int digest_len;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   131
    X509 *srv_crt;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   132
    gchar *cn;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   133
    X509_NAME *crt_subj;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   134
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   135
    base = LM_SSL_BASE(ssl);
169
10bcf8e0e443 2006-09-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   136
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   137
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   138
           "%s: Cipher: %s/%s/%i\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   139
           __FILE__,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   140
           SSL_get_cipher_version(ssl->ssl),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   141
           SSL_get_cipher_name(ssl->ssl),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   142
           SSL_get_cipher_bits(ssl->ssl, NULL));
213
27567fb5d37b Use g_warning and g_log for warnings and debug printouts in OpenSSL backend.
Mikael Hallendal <micke@imendio.com>
parents: 209
diff changeset
   143
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   144
    verify_res = SSL_get_verify_result(ssl->ssl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   145
    srv_crt = SSL_get_peer_certificate(ssl->ssl);
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   146
    rc = X509_digest(srv_crt, digest, (guchar *) base->fingerprint,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   147
                     &digest_len);
689
031cb4db953f be as precise as possible when handling return values
Frank Zschockelt <lm@freakysoft.de>
parents: 682
diff changeset
   148
    if ((rc != 0) && (digest_len == EVP_MD_size(digest))) {
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   149
        if (base->expected_fingerprint != NULL) {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   150
            if (memcmp(base->expected_fingerprint, base->fingerprint,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   151
                   digest_len) != 0) {
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   152
                if (base->func(ssl,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   153
                               LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   154
                               base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   155
                    return FALSE;
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   156
                }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   157
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   158
        }
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   159
    } else {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   160
      if (base->func(ssl,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   161
                     LM_SSL_STATUS_GENERIC_ERROR,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   162
                     base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   163
          return FALSE;
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   164
      }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   165
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   166
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   167
           "%s: SSL_get_verify_result() = %ld\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   168
           __FILE__,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   169
           verify_res);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   170
    switch (verify_res) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   171
    case X509_V_OK:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   172
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   173
    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   174
    case X509_V_ERR_UNABLE_TO_GET_CRL:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   175
        if (base->func(ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   176
                       LM_SSL_STATUS_NO_CERT_FOUND,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   177
                       base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   178
            retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   179
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   180
        break;
645
b6f59df1fbaa Change mapping of openssl errors to lm ssl errors
Myhailo Danylenko <isbear@ukrpost.net>
parents: 628
diff changeset
   181
    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
b6f59df1fbaa Change mapping of openssl errors to lm ssl errors
Myhailo Danylenko <isbear@ukrpost.net>
parents: 628
diff changeset
   182
        /* special case for self signed certificates? */
b6f59df1fbaa Change mapping of openssl errors to lm ssl errors
Myhailo Danylenko <isbear@ukrpost.net>
parents: 628
diff changeset
   183
    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   184
    case X509_V_ERR_INVALID_CA:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   185
    case X509_V_ERR_CERT_UNTRUSTED:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   186
    case X509_V_ERR_CERT_REVOKED:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   187
        if (base->func(ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   188
                       LM_SSL_STATUS_UNTRUSTED_CERT,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   189
                       base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   190
            retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   191
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   192
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   193
    case X509_V_ERR_CERT_NOT_YET_VALID:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   194
    case X509_V_ERR_CRL_NOT_YET_VALID:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   195
        if (base->func(ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   196
                       LM_SSL_STATUS_CERT_NOT_ACTIVATED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   197
                       base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   198
            retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   199
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   200
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   201
    case X509_V_ERR_CERT_HAS_EXPIRED:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   202
    case X509_V_ERR_CRL_HAS_EXPIRED:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   203
        if (base->func(ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   204
                       LM_SSL_STATUS_CERT_EXPIRED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   205
                       base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   206
            retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   207
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   208
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   209
    default:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   210
        if (base->func(ssl, LM_SSL_STATUS_GENERIC_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   211
                       base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   212
            retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   213
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   214
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   215
    /*if (retval == FALSE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   216
      g_set_error (error, LM_ERROR, LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   217
      ssl_get_x509_err(verify_res), NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   218
      }*/
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   219
    crt_subj = X509_get_subject_name(srv_crt);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   220
    cn = (gchar *) g_malloc0(LM_SSL_CN_MAX + 1);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   221
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   222
    /* FWB: deprecated call, can only get first entry */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   223
    if (X509_NAME_get_text_by_NID(crt_subj, NID_commonName, cn, LM_SSL_CN_MAX) > 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   224
        gchar *domain = cn;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   225
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   226
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   227
               "%s: server = '%s', cn = '%s'\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   228
               __FILE__, server, cn);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   229
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   230
        if (domain != NULL) {
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   231
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   232
            if ((cn[0] == '*') && (cn[1] == '.')) {
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   233
                /*
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   234
                 * FWB: huh? ever tested?
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   235
                 * server="sub.domain.tld";
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   236
                 * cn="*.domain.tld";
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   237
                 * domain=strstr(cn, server); ???
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   238
                 */
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   239
                /* domain = strstr (cn, server); */
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   240
                server = strchr(server, '.') + 1;
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   241
                domain = cn + 2;
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   242
            }
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   243
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   244
            if (strncasecmp (server, domain, LM_SSL_CN_MAX) != 0) {
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   245
                /* FWB: CN doesn't match, try SANs */
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   246
                int subject_alt_names_nb = -1;
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   247
                int san_result = 0;
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   248
                int san_counter;
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   249
                STACK_OF(GENERAL_NAME) *subject_alt_names = NULL;
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   250
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   251
                /* g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "%s: CN does not match server name\n", __FILE__); */
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   252
                // Try to extract the names within the SAN extension from the certificate
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   253
                subject_alt_names = X509_get_ext_d2i((X509 *) srv_crt, NID_subject_alt_name, NULL, NULL);
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   254
                if (subject_alt_names != NULL) {
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   255
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   256
                    // Check each name within the extension
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   257
                    subject_alt_names_nb = sk_GENERAL_NAME_num(subject_alt_names);
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   258
                    for (san_counter=0; san_counter<subject_alt_names_nb; san_counter++) {
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   259
                        const GENERAL_NAME *current_name = sk_GENERAL_NAME_value(subject_alt_names, san_counter);
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   260
                        if (current_name->type == GEN_DNS) {
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   261
                            // Current name is a DNS name, let's check it, it's ASCII
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   262
                            if (strcasecmp(server, (char *)current_name->d.dNSName->data) == 0) {
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   263
                                g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "%s: found SAN '%s' - MATCH\n", __FILE__, current_name->d.dNSName->data);
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   264
                                san_result = 1; /* break; */
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   265
                            } else {
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   266
                                g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "%s: found SAN '%s'\n", __FILE__, current_name->d.dNSName->data);
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   267
                            }
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   268
                        }
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   269
                    }
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   270
661
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   271
                }
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   272
                sk_GENERAL_NAME_pop_free(subject_alt_names, GENERAL_NAME_free);
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   273
                if (!san_result) goto cn_and_san_mismatch;
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   274
            } /* SAN */
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   275
        } else {
22492003e3f7 CERTs: added checking of SAN(s) when CN does not match; fix CN wildcard handling
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 660
diff changeset
   276
            cn_and_san_mismatch:
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   277
            if (base->func (ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   278
                            LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   279
                            base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   280
                retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   281
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   282
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   283
    } else {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   284
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   285
               "X509_NAME_get_text_by_NID() failed");
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   286
    }
213
27567fb5d37b Use g_warning and g_log for warnings and debug printouts in OpenSSL backend.
Mikael Hallendal <micke@imendio.com>
parents: 209
diff changeset
   287
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   288
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   289
           "%s:\n\tIssuer: %s\n\tSubject: %s\n\tFor: %s\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   290
           __FILE__,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   291
           X509_NAME_oneline(X509_get_issuer_name(srv_crt), NULL, 0),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   292
           X509_NAME_oneline(X509_get_subject_name(srv_crt), NULL, 0),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   293
           cn);
213
27567fb5d37b Use g_warning and g_log for warnings and debug printouts in OpenSSL backend.
Mikael Hallendal <micke@imendio.com>
parents: 209
diff changeset
   294
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   295
    g_free(cn);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   296
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   297
    return retval;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   298
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   299
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   300
static GIOStatus
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   301
ssl_io_status_from_return (LmSSL *ssl, gint ret)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   302
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   303
    gint      error;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   304
    GIOStatus status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   305
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   306
    if (ret > 0) return G_IO_STATUS_NORMAL;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   307
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   308
    error = SSL_get_error(ssl->ssl, ret);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   309
    switch (error) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   310
    case SSL_ERROR_WANT_READ:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   311
    case SSL_ERROR_WANT_WRITE:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   312
        status = G_IO_STATUS_AGAIN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   313
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   314
    case SSL_ERROR_ZERO_RETURN:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   315
        status = G_IO_STATUS_EOF;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   316
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   317
    default:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   318
        status = G_IO_STATUS_ERROR;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   319
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   320
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   321
    return status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   322
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   323
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   324
/* From lm-ssl-protected.h */
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   325
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   326
LmSSL *
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   327
_lm_ssl_new (const gchar    *expected_fingerprint,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   328
             LmSSLFunction   ssl_function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   329
             gpointer        user_data,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   330
             GDestroyNotify  notify)
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   331
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   332
    LmSSL *ssl;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   333
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   334
    ssl = g_new0 (LmSSL, 1);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   335
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   336
    _lm_ssl_base_init ((LmSSLBase *) ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   337
                       expected_fingerprint,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   338
                       ssl_function, user_data, notify);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   339
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   340
    return ssl;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   341
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   342
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   343
void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   344
_lm_ssl_initialize (LmSSL *ssl)
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   345
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   346
    static gboolean initialized = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   347
    /*const char *cert_file = NULL;*/
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   348
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   349
    if (!initialized) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   350
        SSL_library_init();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   351
        /* FIXME: Is this needed when we are not in debug? */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   352
        SSL_load_error_strings();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   353
        initialized = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   354
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   355
660
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   356
    /* don't use TLSv1_client_method() because otherwise we don't get
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   357
     * connections to TLS1_1 and TLS1_2 only servers
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   358
     */
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   359
    ssl->ssl_method = SSLv23_client_method();
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   360
    if (ssl->ssl_method == NULL) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   361
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
660
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   362
               "SSLv23_client_method() == NULL");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   363
        abort();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   364
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   365
    ssl->ssl_ctx = SSL_CTX_new(ssl->ssl_method);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   366
    if (ssl->ssl_ctx == NULL) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   367
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "SSL_CTX_new() == NULL");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   368
        abort();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   369
    }
565
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   370
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   371
    /* Set the NO_TICKET option on the context to allow for talk to Google Talk
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   372
     * which apparently seems to be having a problem handling empty session
565
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   373
     * tickets due to a bug in Java.
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   374
     *
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   375
     * See http://twistedmatrix.com/trac/ticket/3463 and
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   376
     * Loudmouth [#28].
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   377
     */
660
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   378
    SSL_CTX_set_options (ssl->ssl_ctx, (SSL_OP_NO_TICKET | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3));
565
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   379
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   380
    /*if (access("/etc/ssl/cert.pem", R_OK) == 0)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   381
      cert_file = "/etc/ssl/cert.pem";
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   382
      if (!SSL_CTX_load_verify_locations(ssl->ssl_ctx,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   383
      cert_file, "/etc/ssl/certs")) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   384
      g_warning("SSL_CTX_load_verify_locations() failed");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   385
      }*/
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   386
    SSL_CTX_set_verify (ssl->ssl_ctx, SSL_VERIFY_PEER, ssl_verify_cb);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   387
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   388
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   389
gboolean
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   390
_lm_ssl_set_ca (LmSSL       *ssl,
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   391
                const gchar *ca_path)
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   392
{
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   393
    struct stat target;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   394
    int success = 0;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   395
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   396
    if (stat (ca_path, &target) != 0) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   397
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   398
               "ca_path '%s': no such file or directory", ca_path);
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   399
        return FALSE;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   400
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   401
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   402
    if (S_ISDIR (target.st_mode)) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   403
        success = SSL_CTX_load_verify_locations(ssl->ssl_ctx, NULL, ca_path);
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   404
    } else if (S_ISREG (target.st_mode)) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   405
        success = SSL_CTX_load_verify_locations(ssl->ssl_ctx, ca_path, NULL);
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   406
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   407
    if (success == 0) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   408
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   409
               "Loading of ca_path '%s' failed: %s",
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   410
               ca_path,
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   411
               ERR_error_string(ERR_peek_last_error(), NULL));
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   412
        return FALSE;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   413
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   414
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   415
    return TRUE;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   416
}
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   417
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   418
gboolean
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   419
_lm_ssl_begin (LmSSL *ssl, gint fd, const gchar *server, GError **error)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   420
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   421
    gint ssl_ret;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   422
    GIOStatus status;
650
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   423
    LmSSLBase *base;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   424
650
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   425
    base = LM_SSL_BASE(ssl);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   426
    if (!ssl->ssl_ctx) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   427
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   428
                     LM_ERROR, LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   429
                     "No SSL Context for OpenSSL");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   430
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   431
    }
309
329900413057 Check to see that the OpenSSL session is setup correctly. Fixes LM-88.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 301
diff changeset
   432
650
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   433
    if (base->cipher_list) {
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   434
        SSL_CTX_set_cipher_list(ssl->ssl_ctx, base->cipher_list);
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   435
    }
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   436
    if (base->ca_path) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   437
        _lm_ssl_set_ca (ssl, base->ca_path);
702
75866de0e731 Load system certs only if user doesn't specify trusted certs
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   438
    } else {
75866de0e731 Load system certs only if user doesn't specify trusted certs
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   439
        SSL_CTX_set_default_verify_paths (ssl->ssl_ctx);
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   440
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   441
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   442
    ssl->ssl = SSL_new(ssl->ssl_ctx);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   443
    if (ssl->ssl == NULL) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   444
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "SSL_new() == NULL");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   445
        g_set_error(error, LM_ERROR, LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   446
                    "SSL_new()");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   447
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   448
    }
213
27567fb5d37b Use g_warning and g_log for warnings and debug printouts in OpenSSL backend.
Mikael Hallendal <micke@imendio.com>
parents: 209
diff changeset
   449
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   450
    if (!SSL_set_fd (ssl->ssl, fd)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   451
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL, "SSL_set_fd() failed");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   452
        g_set_error(error, LM_ERROR, LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   453
                    "SSL_set_fd()");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   454
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   455
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   456
    /*ssl->bio = BIO_new_socket (fd, BIO_NOCLOSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   457
      if (ssl->bio == NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   458
      g_warning("BIO_new_socket() failed");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   459
      g_set_error(error, LM_ERROR, LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   460
      "BIO_new_socket()");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   461
      return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   462
      }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   463
      SSL_set_bio(ssl->ssl, ssl->bio, ssl->bio);*/
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   464
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   465
    do {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   466
        ssl_ret = SSL_connect(ssl->ssl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   467
        if (ssl_ret <= 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   468
            status = ssl_io_status_from_return(ssl, ssl_ret);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   469
            if (status != G_IO_STATUS_AGAIN) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   470
                ssl_print_state(ssl, "SSL_connect",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   471
                                ssl_ret);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   472
                g_set_error(error, LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   473
                            LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   474
                            "SSL_connect()");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   475
                return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   476
            }
139
2d0dcbb757b3 2006-04-18 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 138
diff changeset
   477
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   478
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   479
    } while (ssl_ret <= 0);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   480
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   481
    if (!ssl_verify_certificate (ssl, server)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   482
        g_set_error (error, LM_ERROR, LM_ERROR_CONNECTION_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   483
                     "*** SSL certificate verification failed");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   484
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   485
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   486
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   487
    return TRUE;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   488
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   489
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   490
GIOStatus
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   491
_lm_ssl_read (LmSSL *ssl, gchar *buf, gint len, gsize *bytes_read)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   492
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   493
    GIOStatus status;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   494
    gint ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   495
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   496
    *bytes_read = 0;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   497
    ssl_ret = SSL_read(ssl->ssl, buf, len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   498
    status = ssl_io_status_from_return(ssl, ssl_ret);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   499
    if (status == G_IO_STATUS_NORMAL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   500
        *bytes_read = ssl_ret;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   501
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   502
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   503
    return status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   504
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   505
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   506
gint
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   507
_lm_ssl_send (LmSSL *ssl, const gchar *str, gint len)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   508
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   509
    GIOStatus status;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   510
    gint ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   511
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   512
    do {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   513
        ssl_ret = SSL_write(ssl->ssl, str, len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   514
        if (ssl_ret <= 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   515
            status = ssl_io_status_from_return(ssl, ssl_ret);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   516
            if (status != G_IO_STATUS_AGAIN)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   517
                return -1;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   518
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   519
    } while (ssl_ret <= 0);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   520
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   521
    return ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   522
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   523
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   524
void
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   525
_lm_ssl_close (LmSSL *ssl)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   526
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   527
    if (ssl->ssl != NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   528
        SSL_shutdown(ssl->ssl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   529
        SSL_free(ssl->ssl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   530
        ssl->ssl = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   531
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   532
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   533
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   534
void
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   535
_lm_ssl_free (LmSSL *ssl)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   536
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   537
    SSL_CTX_free(ssl->ssl_ctx);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   538
    ssl->ssl_ctx = NULL;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   539
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   540
    _lm_ssl_base_free_fields (LM_SSL_BASE(ssl));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   541
    g_free (ssl);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   542
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   543
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   544
#endif /* HAVE_GNUTLS */