loudmouth/lm-ssl-openssl.c
author Mikael Berthe <mikael@lilotux.net>
Mon, 25 Jan 2016 18:35:10 +0100
changeset 685 dfa02c1c7fda
parent 682 4a092b834996
child 689 031cb4db953f
permissions -rw-r--r--
Bumped version to 1.5.2
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
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    17
 * License along with this program; if not, write to the
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    18
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    19
 * Boston, MA 02111-1307, USA.
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    20
 */
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    21
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    22
#include <config.h>
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    23
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    24
#include <stdio.h>
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    25
#include <string.h>
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
    26
#include <sys/types.h>
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
    27
#include <sys/stat.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    28
#include <unistd.h>
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    29
#include <glib.h>
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    30
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
    31
#include "lm-debug.h"
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    32
#include "lm-error.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    33
#include "lm-ssl-base.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    34
#include "lm-ssl-internals.h"
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
#ifdef HAVE_OPENSSL
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    37
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    38
#include <openssl/ssl.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    39
#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
    40
#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
    41
#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
    42
#include <openssl/safestack.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    43
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
    44
#define LM_SSL_CN_MAX       63
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    45
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    46
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
    47
    LmSSLBase base;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    48
628
1ac0534623ef Fix compilation warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents: 618
diff changeset
    49
    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
    50
    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
    51
    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
    52
    /*BIO *bio;*/
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    53
};
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    54
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    55
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
    56
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    57
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
    58
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
    59
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    60
/*static char _ssl_error_code[11];*/
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    61
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    62
static void
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    63
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
    64
{
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
    65
    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
    66
    const char *errmsg;
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    67
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
    68
    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
    69
    case SSL_ERROR_NONE:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    70
        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
    71
                   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
    72
        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
    73
    case SSL_ERROR_ZERO_RETURN:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    74
        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
    75
                   "%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
    76
        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
    77
    case SSL_ERROR_WANT_READ:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    78
        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
    79
                   "%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
    80
        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
    81
    case SSL_ERROR_WANT_WRITE:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    82
        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
    83
                   "%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
    84
        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
    85
    case SSL_ERROR_WANT_X509_LOOKUP:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    86
        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
    87
                   "%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
    88
        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
    89
    case SSL_ERROR_SYSCALL:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    90
        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
    91
                   "%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
    92
        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
    93
    case SSL_ERROR_SSL:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
    94
        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
    95
                   "%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
    96
        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
    97
    }
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
    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
    99
        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
   100
        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
   101
            errmsg = ERR_error_string(errid, NULL);
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   102
            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
   103
        }
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
   104
    } while (errid != 0);
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   105
}
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   106
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   107
/*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
   108
  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
   109
  {
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
  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
   111
  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
   112
  }*/
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   113
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   114
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   115
int
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   116
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
   117
{
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
   118
    /* 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
   119
     * 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
   120
    return 1;
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   121
}
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   122
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   123
/* side effect: fills the ssl->fingerprint buffer */
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   124
static gboolean
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   125
ssl_verify_certificate (LmSSL *ssl, const gchar *server)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   126
{
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
   127
    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
   128
    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
   129
    long verify_res;
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   130
    int rc;
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   131
    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
   132
    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
   133
    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
   134
    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
   135
    X509_NAME *crt_subj;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
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
    base = LM_SSL_BASE(ssl);
169
10bcf8e0e443 2006-09-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   138
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
   139
    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
   140
           "%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
   141
           __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
   142
           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
   143
           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
   144
           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
   145
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
   146
    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
   147
    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
   148
    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
   149
                     &digest_len);
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   150
    if ((rc > 0) && (digest_len == EVP_MD_size(digest))) {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   151
        if (base->expected_fingerprint != NULL) {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   152
            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
   153
                   digest_len) != 0) {
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   154
                if (base->func(ssl,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   155
                               LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   156
                               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
   157
                    return FALSE;
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   158
                }
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
   159
            }
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
   160
        }
682
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   161
    } else {
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   162
      if (base->func(ssl,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   163
                     LM_SSL_STATUS_GENERIC_ERROR,
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   164
                     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
   165
          return FALSE;
4a092b834996 openssl: always fill the fingerprint field of LmSSL
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
   166
      }
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
   167
    }
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
    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
   169
           "%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
   170
           __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
   171
           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
   172
    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
   173
    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
   174
        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
   175
    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
   176
    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
   177
        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
   178
                       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
   179
                       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
   180
            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
   181
        }
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
   182
        break;
645
b6f59df1fbaa Change mapping of openssl errors to lm ssl errors
Myhailo Danylenko <isbear@ukrpost.net>
parents: 628
diff changeset
   183
    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
   184
        /* 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
   185
    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
   186
    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
   187
    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
   188
    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
   189
        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
   190
                       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
   191
                       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
   192
            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
   193
        }
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
        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
   195
    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
   196
    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
   197
        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
   198
                       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
   199
                       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
   200
            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
   201
        }
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
        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
   203
    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
   204
    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
   205
        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
   206
                       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
   207
                       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
   208
            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
   209
        }
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
        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
   211
    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
   212
        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
   213
                       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
   214
            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
   215
        }
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
    }
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
    /*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
   218
      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
   219
      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
   220
      }*/
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
   221
    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
   222
    cn = (gchar *) g_malloc0(LM_SSL_CN_MAX + 1);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   223
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
   224
    /* 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
   225
    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
   226
        gchar *domain = cn;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   227
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
   228
        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
   229
               "%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
   230
               __FILE__, server, cn);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
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 (domain != NULL) {
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
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
            if ((cn[0] == '*') && (cn[1] == '.')) {
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   235
                /*
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
   236
                 * 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
   237
                 * 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
   238
                 * 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
   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
                 */
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 = 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
   242
                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
   243
                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
   244
            }
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   245
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
   246
            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
   247
                /* 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
   248
                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
   249
                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
   250
                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
   251
                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
   252
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
   253
                /* 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
   254
                // 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
   255
                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
   256
                if (subject_alt_names != NULL) {
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   257
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
   258
                    // 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
   259
                    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
   260
                    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
   261
                        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
   262
                        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
   263
                            // 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
   264
                            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
   265
                                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
   266
                                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
   267
                            } 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
   268
                                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
   269
                            }
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
   270
                        }
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
                    }
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   272
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
   273
                }
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
                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
   275
                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
   276
            } /* 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
   277
        } 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
   278
            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
   279
            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
   280
                            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
   281
                            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
   282
                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
   283
            }
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
   284
        }
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
   285
    } else {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   286
        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
   287
               "X509_NAME_get_text_by_NID() failed");
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   288
    }
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
   289
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   290
    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
   291
           "%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
   292
           __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
   293
           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
   294
           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
   295
           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
   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
    g_free(cn);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   298
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
   299
    return retval;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   300
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   301
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   302
static GIOStatus
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   303
ssl_io_status_from_return (LmSSL *ssl, gint ret)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   304
{
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
   305
    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
   306
    GIOStatus status;
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
    if (ret > 0) return G_IO_STATUS_NORMAL;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   309
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
   310
    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
   311
    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
   312
    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
   313
    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
   314
        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
   315
        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
   316
    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
   317
        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
   318
        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
   319
    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
   320
        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
   321
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   322
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
   323
    return status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   324
}
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
/* From lm-ssl-protected.h */
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   327
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   328
LmSSL *
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   329
_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
   330
             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
   331
             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
   332
             GDestroyNotify  notify)
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
    LmSSL *ssl;
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
    ssl = g_new0 (LmSSL, 1);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   337
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
   338
    _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
   339
                       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
   340
                       ssl_function, user_data, notify);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   341
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
   342
    return ssl;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   343
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   344
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   345
void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   346
_lm_ssl_initialize (LmSSL *ssl)
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   347
{
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
   348
    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
   349
    /*const char *cert_file = NULL;*/
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   350
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
   351
    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
   352
        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
   353
        /* 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
   354
        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
   355
        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
   356
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   357
660
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   358
    /* 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
   359
     * 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
   360
     */
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   361
    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
   362
    if (ssl->ssl_method == NULL) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   363
        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
   364
               "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
   365
        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
   366
    }
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
   367
    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
   368
    if (ssl->ssl_ctx == NULL) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   369
        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
   370
        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
   371
    }
565
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   372
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   373
    /* 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
   374
     * 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
   375
     * tickets due to a bug in Java.
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   376
     *
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   377
     * 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
   378
     * Loudmouth [#28].
87a57a62be8c Use option NO_TICKET for OpenSSL [#28]
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   379
     */
660
1da5ff42dc1f activate TLS 1.1 and 1.2; deactivate SSL 2 and 3
Frank W. Bergmann <loudmouth@tuxad.com>
parents: 651
diff changeset
   380
    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
   381
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
   382
    /*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
   383
      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
   384
      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
   385
      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
   386
      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
   387
      }*/
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
   388
    SSL_CTX_set_default_verify_paths (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
   389
    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
   390
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   391
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   392
gboolean
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   393
_lm_ssl_set_ca (LmSSL       *ssl,
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   394
                const gchar *ca_path)
651
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
    struct stat target;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   397
    int success = 0;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   398
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   399
    if (stat (ca_path, &target) != 0) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   400
        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
   401
               "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
   402
        return FALSE;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   403
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   404
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   405
    if (S_ISDIR (target.st_mode)) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   406
        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
   407
    } else if (S_ISREG (target.st_mode)) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   408
        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
   409
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   410
    if (success == 0) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   411
        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
   412
               "Loading of ca_path '%s' failed: %s",
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   413
               ca_path,
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 661
diff changeset
   414
               ERR_error_string(ERR_peek_last_error(), NULL));
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   415
        return FALSE;
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
    return TRUE;
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   419
}
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   420
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   421
gboolean
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   422
_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
   423
{
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
   424
    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
   425
    GIOStatus status;
650
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   426
    LmSSLBase *base;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   427
650
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   428
    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
   429
    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
   430
        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
   431
                     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
   432
                     "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
   433
        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
   434
    }
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
   435
650
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   436
    if (base->cipher_list) {
a51209f570b6 Implemented lm_ssl_set_cipher_list
Frank Zschockelt <lm@freakysoft.de>
parents: 645
diff changeset
   437
        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
   438
    }
651
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   439
    if (base->ca_path) {
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   440
        _lm_ssl_set_ca (ssl, base->ca_path);
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   441
    }
2990ee03cfa3 Implemented lm_ssl_set_ca
Frank Zschockelt <lm@freakysoft.de>
parents: 650
diff changeset
   442
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
   443
    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
   444
    if (ssl->ssl == NULL) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   445
        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
   446
        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
   447
                    "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
   448
        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
   449
    }
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
   450
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
   451
    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
   452
        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
   453
        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
   454
                    "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
   455
        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
   456
    }
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
    /*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
   458
      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
   459
      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
   460
      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
   461
      "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
   462
      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
   463
      }
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
   464
      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
   465
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
   466
    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
   467
        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
   468
        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
   469
            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
   470
            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
   471
                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
   472
                                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
   473
                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
   474
                            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
   475
                            "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
   476
                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
   477
            }
139
2d0dcbb757b3 2006-04-18 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 138
diff changeset
   478
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
   479
        }
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
   480
    } while (ssl_ret <= 0);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   481
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
   482
    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
   483
        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
   484
                     "*** 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
   485
        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
   486
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   487
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   488
    return TRUE;
138
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
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   491
GIOStatus
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   492
_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
   493
{
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
   494
    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
   495
    gint ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   496
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
   497
    *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
   498
    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
   499
    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
   500
    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
   501
        *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
   502
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   503
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
   504
    return status;
138
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
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   507
gint
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   508
_lm_ssl_send (LmSSL *ssl, const gchar *str, gint len)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   509
{
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
   510
    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
   511
    gint ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   512
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
   513
    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
   514
        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
   515
        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
   516
            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
   517
            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
   518
                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
   519
        }
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
   520
    } while (ssl_ret <= 0);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   521
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
   522
    return ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   523
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   524
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 565
diff changeset
   525
void
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   526
_lm_ssl_close (LmSSL *ssl)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   527
{
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
   528
    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
   529
        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
   530
        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
   531
        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
   532
    }
138
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
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   535
void
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   536
_lm_ssl_free (LmSSL *ssl)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   537
{
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
   538
    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
   539
    ssl->ssl_ctx = NULL;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   540
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
   541
    _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
   542
    g_free (ssl);
138
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
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   545
#endif /* HAVE_GNUTLS */