loudmouth/lm-ssl-openssl.c
author Mikael Hallendal <micke@imendio.com>
Wed, 22 Oct 2008 14:08:45 +0200
changeset 539 4e387d919a46
parent 518 cdd6a0c5b439
child 565 87a57a62be8c
permissions -rw-r--r--
Made type property on LmResolver settable after creation. Currently the type of the resolver is changed after doing the initial SRV lookup so the property can't be creation only.
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>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    26
#include <unistd.h>
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    27
#include <glib.h>
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    28
213
27567fb5d37b Use g_warning and g_log for warnings and debug printouts in OpenSSL backend.
Mikael Hallendal <micke@imendio.com>
parents: 209
diff changeset
    29
#include "lm-debug.h"
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    30
#include "lm-error.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    31
#include "lm-ssl-base.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    32
#include "lm-ssl-internals.h"
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    33
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    34
#ifdef HAVE_OPENSSL
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    35
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    36
#include <openssl/ssl.h>
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    37
#include <openssl/err.h>
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    38
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
    39
#define LM_SSL_CN_MAX       63
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    40
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    41
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
    42
    LmSSLBase base;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
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
    SSL_METHOD *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
    45
    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
    46
    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
    47
    /*BIO *bio;*/
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    48
};
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
    49
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    50
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
    51
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    52
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
    53
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
    54
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    55
/*static char _ssl_error_code[11];*/
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 void
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    58
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
    59
{
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
    60
    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
    61
    const char *errmsg;
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
    62
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    63
    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
    64
    case SSL_ERROR_NONE:
cdd6a0c5b439 Went 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
        g_warning ("%s(): %i / SSL_ERROR_NONE",
cdd6a0c5b439 Went 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
                   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
    67
        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
    68
    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
    69
        g_warning ("%s(): %i / 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
    70
                   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
    71
        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
    72
    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
    73
        g_warning ("%s(): %i / 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
    74
                   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
    75
        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
    76
    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
    77
        g_warning ("%s(): %i / 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
    78
                   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
    79
        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
    80
    case SSL_ERROR_WANT_X509_LOOKUP:
cdd6a0c5b439 Went 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
        g_warning ("%s(): %i / SSL_ERROR_WANT_X509_LOOKUP",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    82
                   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
    83
        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
    84
    case SSL_ERROR_SYSCALL:
cdd6a0c5b439 Went 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
        g_warning ("%s(): %i / SSL_ERROR_SYSCALL",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    86
                   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
    87
        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
    88
    case SSL_ERROR_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
    89
        g_warning ("%s(): %i / SSL_ERROR_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
    90
                   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
    91
        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
    92
    }
cdd6a0c5b439 Went 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
    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
    94
        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
    95
        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
    96
            errmsg = ERR_error_string(errid, 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
    97
            g_warning ("\t%s", errmsg);
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went 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
    } while (errid != 0);
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   100
}
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   101
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   102
/*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
   103
  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
   104
  {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   105
  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
   106
  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
   107
  }*/
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   108
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
   109
    
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   110
int
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   111
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
   112
{
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
   113
    /* 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
   114
     * 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
   115
    return 1;
209
1fd5e3004816 Added SSL changes from Senko on SSL branch
Mikael Hallendal <micke@imendio.com>
parents: 169
diff changeset
   116
}
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   117
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   118
static gboolean
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   119
ssl_verify_certificate (LmSSL *ssl, const gchar *server)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   120
{
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
   121
    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
   122
    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
   123
    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
   124
    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
   125
    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
   126
    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
   127
    X509_NAME *crt_subj;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   128
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
   129
    base = LM_SSL_BASE(ssl);
169
10bcf8e0e443 2006-09-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   130
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
   131
    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
   132
           "%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
   133
           __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
   134
           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
   135
           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
   136
           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
   137
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
   138
    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
   139
    srv_crt = SSL_get_peer_certificate(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
   140
    if (base->expected_fingerprint != 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
   141
        X509_digest(srv_crt, EVP_md5(), (guchar *) base->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
   142
                    &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
   143
        if (memcmp(base->expected_fingerprint, base->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
   144
                   digest_len) != 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
   145
            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
   146
                           LM_SSL_STATUS_CERT_FINGERPRINT_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
   147
                           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
   148
                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
   149
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   150
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   151
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   152
    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
   153
           "%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
   154
           __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
   155
           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
   156
    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
   157
    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
   158
        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
   159
    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_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
   160
        /* special case for self signed certificates? */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   161
    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
   162
    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
   163
    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   164
        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
   165
                       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
   166
                       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
   167
            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
   168
        }
cdd6a0c5b439 Went 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
        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
   170
    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
   171
    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
   172
    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
   173
        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
   174
                       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
   175
                       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
   176
            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
   177
        }
cdd6a0c5b439 Went 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
        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
   179
    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
   180
    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
   181
        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
   182
                       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
   183
                       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
   184
            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
   185
        }
cdd6a0c5b439 Went 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
        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
   187
    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
   188
    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
   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_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
   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
    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
   196
        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
   197
                       base->func_data) != LM_SSL_RESPONSE_CONTINUE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   198
            retval = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   199
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   200
    }
cdd6a0c5b439 Went 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
    /*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
   202
      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
   203
      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
   204
      }*/
cdd6a0c5b439 Went 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
    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
   206
    cn = (gchar *) g_malloc0(LM_SSL_CN_MAX + 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
   207
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   208
    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
   209
        gchar *domain = cn;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   210
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
   211
        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
   212
               "%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
   213
               __FILE__, server, 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
   214
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   215
        if ((cn[0] == '*') && (cn[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
   216
            domain = strstr (cn, 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
   217
        }
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   218
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
   219
        if ((domain == NULL) || (strncmp (server, domain, 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
   220
            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
   221
                            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
   222
                            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
   223
                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
   224
            }
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went 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
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   227
        g_warning ("X509_NAME_get_text_by_NID() failed");
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 269
diff changeset
   228
    }
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
   229
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
   230
    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
   231
           "%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
   232
           __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
   233
           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
   234
           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
   235
           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
   236
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
   237
    g_free(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
   238
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   239
    return retval;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   240
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   241
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   242
static GIOStatus
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   243
ssl_io_status_from_return (LmSSL *ssl, gint ret)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   244
{
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
   245
    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
   246
    GIOStatus status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   247
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
   248
    if (ret > 0) return G_IO_STATUS_NORMAL;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   249
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
   250
    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
   251
    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
   252
    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
   253
    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
   254
        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
   255
        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
   256
    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
   257
        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
   258
        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
   259
    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
   260
        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
   261
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   262
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
   263
    return status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   264
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   265
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   266
/* From lm-ssl-protected.h */
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   267
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   268
LmSSL *
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   269
_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
   270
             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
   271
             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
   272
             GDestroyNotify  notify)
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   273
{
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
   274
    LmSSL *ssl;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   275
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
   276
    ssl = g_new0 (LmSSL, 1);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   277
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
   278
    _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
   279
                       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
   280
                       ssl_function, user_data, notify);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   281
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
   282
    return ssl;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   283
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   284
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   285
void
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   286
_lm_ssl_initialize (LmSSL *ssl) 
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   287
{
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
   288
    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
   289
    /*const char *cert_file = NULL;*/
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   290
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
    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
   292
        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
   293
        /* 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
   294
        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
   295
        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
   296
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   297
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
   298
    ssl->ssl_method = TLSv1_client_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
   299
    if (ssl->ssl_method == 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
   300
        g_warning ("TLSv1_client_method() == 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
   301
        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
   302
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   303
    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
   304
    if (ssl->ssl_ctx == 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
   305
        g_warning ("SSL_CTX_new() == 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
   306
        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
   307
    }
cdd6a0c5b439 Went 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 (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
   309
      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
   310
      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
   311
      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
   312
      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
   313
      }*/
cdd6a0c5b439 Went 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
    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
   315
    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
   316
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   317
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   318
gboolean
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   319
_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
   320
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   321
    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
   322
    GIOStatus status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   323
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
   324
    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
   325
        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
   326
                     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
   327
                     "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
   328
        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
   329
    }
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
   330
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
   331
    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
   332
    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
   333
        g_warning ("SSL_new() == 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
   334
        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
   335
                    "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
   336
        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
   337
    }
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
   338
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
   339
    if (!SSL_set_fd (ssl->ssl, 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
   340
        g_warning ("SSL_set_fd() 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
   341
        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
   342
                    "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
   343
        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
   344
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   345
    /*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
   346
      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
   347
      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
   348
      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
   349
      "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
   350
      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
   351
      }
cdd6a0c5b439 Went 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_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
   353
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
   354
    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
   355
        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
   356
        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
   357
            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
   358
            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
   359
                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
   360
                                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
   361
                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
   362
                            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
   363
                            "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
   364
                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
   365
            }
139
2d0dcbb757b3 2006-04-18 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 138
diff changeset
   366
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
   367
        }
cdd6a0c5b439 Went 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
    } while (ssl_ret <= 0);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   369
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
    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
   371
        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
   372
                     "*** 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
   373
        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
   374
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   375
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   376
    return TRUE; 
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   377
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   378
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   379
GIOStatus
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   380
_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
   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
    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
   383
    gint ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   384
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
   385
    *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
   386
    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
   387
    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
   388
    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
   389
        *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
   390
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   391
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   392
    return status;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   393
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   394
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   395
gint
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   396
_lm_ssl_send (LmSSL *ssl, const gchar *str, gint len)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   397
{
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
   398
    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
   399
    gint ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   400
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
   401
    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
   402
        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
   403
        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
   404
            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
   405
            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
   406
                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
   407
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   408
    } while (ssl_ret <= 0);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   409
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
   410
    return ssl_ret;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   411
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   412
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   413
void 
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   414
_lm_ssl_close (LmSSL *ssl)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   415
{
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
   416
    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
   417
        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
   418
        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
   419
        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
   420
    }
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   421
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   422
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   423
void
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   424
_lm_ssl_free (LmSSL *ssl)
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   425
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   426
    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
   427
    ssl->ssl_ctx = NULL;
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   428
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
    _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
   430
    g_free (ssl);
138
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   431
}
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   432
210cf8993393 2006-04-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
diff changeset
   433
#endif /* HAVE_GNUTLS */