lm_ssl.c
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 16 Mar 2016 01:53:56 +0200
changeset 66 a40beb82130c
parent 62 d92358eafead
permissions -rw-r--r--
node: Use new loudmouth feature - public attribute list (v0.9.7)
23
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     1
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
     2
/* Copyright 2009-2016 Myhailo Danylenko
23
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     3
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     4
This file is part of lua-lm.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     5
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     6
lua-lm is free software: you can redistribute it and/or modify
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     7
it under the terms of the GNU General Public License as published by
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     8
the Free Software Foundation, either version 2 of the License, or
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     9
(at your option) any later version.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    10
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    11
This program is distributed in the hope that it will be useful,
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    14
GNU General Public License for more details.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    15
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    16
You should have received a copy of the GNU General Public License
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    17
along with this program.  If not, see <http://www.gnu.org/licenses/>. */
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    18
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    19
#include <lua.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    20
#include <lauxlib.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    21
#include <glib.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
#include <loudmouth/loudmouth.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
#include <stdio.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    25
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
#include "util.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
#include "lm_types.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
/// lm.ssl
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
/// Object, containing information about ssl abilities for connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
/// Create, set parameters, and attach to connection with 'ssl' method.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
/// ssl status
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    34
/// String, representing what problem have current ssl session.
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    35
/// G:
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
    36
const string2enum_t status_lm_ssl[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    37
	{ "no cert found",             LM_SSL_STATUS_NO_CERT_FOUND             },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
	{ "untrusted cert",            LM_SSL_STATUS_UNTRUSTED_CERT            },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
	{ "cert expired",              LM_SSL_STATUS_CERT_EXPIRED              },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
	{ "cert not activated",        LM_SSL_STATUS_CERT_NOT_ACTIVATED        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
	{ "cert hostname mismatch",    LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH    },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
	{ "cert fingerprint mismatch", LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
	{ "generic error",             LM_SSL_STATUS_GENERIC_ERROR             },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    44
	{ NULL,                        0                                       }, // XXX
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
/// ssl callback function
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
/// User function, called when ssl error happens.
42
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
    49
/// A: userdata (lm ssl object), argument enum field (ssl status)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
/// R: boolean (false if connection process should be terminated)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
    51
LmSSLResponse callback_lm_ssl (LmSSL *ssl, LmSSLStatus status, llm_callback_t *cb)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    53
	int ret;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    54
	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
    55
	bless_lm_ssl (cb->L, ssl);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    56
	// XXX lm_ssl_unref (ssl);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
    57
	luaL_pushenum (cb->L, status, status_lm_ssl);
42
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
    58
	if (lua_pcall (cb->L, 2, 1, 0)) {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    59
		W ("SSL callback error: %s", lua_tostring (cb->L, -1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
		lua_pop (cb->L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
		return LM_SSL_RESPONSE_CONTINUE;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
	ret = lua_toboolean (cb->L, -1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
	lua_pop (cb->L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65
	if (ret)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
		return LM_SSL_RESPONSE_CONTINUE;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    67
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    68
		return LM_SSL_RESPONSE_STOP;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    69
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    70
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    71
#ifndef HAVE_LM_SHA256_FINGERPRINTS
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
static void string2fingerprint (const char *string, char *buffer)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
	int i;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    75
	for (i = 0; i < 16; i++) {
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    76
		int h = g_ascii_xdigit_value ((char)string[i*3]);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
		int l = g_ascii_xdigit_value ((char)string[i*3+1]);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
		buffer[i] = (char) ((h >= 0 && l >= 0) ? h*16 + l : 0);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    79
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    80
}
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    81
#endif
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    82
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    83
/// lm.ssl.new
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    84
/// Creates new ssl object for use with connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    85
/// You can specify server key fingerprint, callback function for error handling,
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    86
/// both, or neither. Though, fingerprint should go before callback function.
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    87
/// SSL fingerprint is a string like 'SHA256:ABCDEF123456...' (or
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    88
/// '01:23:45:67:89:AB:CD:EF:FE:DC:BA:98:76:54:32:10' for LM versions, older than 1.5.3).
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
/// A: string (optional ssl fingerprint), ssl callback function (optional)
42
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
    90
/// R: userdata (lm ssl object)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
    91
static int new_lm_ssl (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    93
	int args = lua_gettop (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    94
	LmSSL *ssl;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    95
	if (args == 0)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    96
		ssl = lm_ssl_new (NULL, NULL, NULL, NULL);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    97
	else if (args == 1 && !lua_isfunction (L, 1)) {
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    98
		const char *fingerprint = luaL_checkstring (L, 1);
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    99
#ifndef HAVE_LM_SHA256_FINGERPRINTS
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   100
		gchar buffer[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   101
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   102
		if (lua_rawlen (L, 1) > 46) {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   103
			string2fingerprint (fingerprint, buffer);
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   104
			fingerprint = buffer;
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   105
		} else
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   106
			fingerprint = NULL;
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   107
#endif
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   108
		ssl = lm_ssl_new (fingerprint, NULL, NULL, NULL);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
	} else {
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   110
		llm_callback_t *cb;
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   111
		const char *fingerprint = NULL;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   112
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   113
		if (args > 1) {
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   114
			fingerprint = luaL_checkstring (L, 1);
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   115
#ifndef HAVE_LM_SHA256_FINGERPRINTS
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   116
			gchar buffer[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   117
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   118
			if (lua_rawlen (L, 1) > 46) {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   119
				string2fingerprint (fingerprint, buffer);
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   120
				fingerprint = buffer;
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   121
			} else
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   122
				fingerprint = NULL;
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   123
#endif
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   124
			luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   125
		} else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   126
			luaL_argcheck (L, lua_isfunction (L, 1), 1, "function expected");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   127
		
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   128
		cb = luaL_malloc (L, sizeof (llm_callback_t));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   129
		cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   130
		cb->L = L;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   131
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   132
		ssl = lm_ssl_new (fingerprint, (LmSSLFunction)callback_lm_ssl,
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   133
							cb, (GDestroyNotify)llm_callback_destroy);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   134
	}
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   135
	bless_lm_ssl (L, ssl);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   136
	lm_ssl_unref (ssl); // XXX
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   137
	D ("SSL %p created", ssl);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   138
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   139
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   140
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   141
/// lm.ssl.bless
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   142
/// Blesses given pointer to lm ssl object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   143
/// A: lightuserdata (C lm ssl object)
42
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   144
/// R: userdata (lm ssl object)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   145
static int bless_lua_lm_ssl (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   146
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   147
	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "lm ssl lightuserdata expected");
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   148
	bless_lm_ssl (L, lua_touserdata (L, 1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   149
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   150
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   151
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   152
/// lm.ssl.supported
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   153
/// Indicates if SSL is supported by loudmouth library and what kind of
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   154
/// ssl fingerprint is used.
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   155
/// R: nil or string ("MD5" or "SHA256")
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   156
static int supported_lm_ssl (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   157
{
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   158
	if (lm_ssl_is_supported ()) {
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   159
#ifdef HAVE_LM_SHA256_FINGERPRINTS
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   160
		lua_pushliteral (L, "SHA256");
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   161
#else
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   162
		lua_pushliteral (L, "MD5");
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   163
#endif
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   164
	} else {
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   165
		lua_pushnil (L);
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   166
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   167
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   168
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   169
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   170
#ifdef HAVE_LM_SSL_SET_CA
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   171
/// ssl:ca_path
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   172
/// Set path to trusted ssl certificates. Argument must be a name of a PEM file
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   173
/// or a name of directory with hashed certificates.
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   174
/// A: string (path)
62
d92358eafead ssl: Return object from cipher/ca methods for chain initialization
Myhailo Danylenko <isbear@ukrpost.net>
parents: 59
diff changeset
   175
/// R: lm ssl object
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   176
static int ca_path_lm_ssl (lua_State *L)
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   177
{
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   178
	llm_ssl_t *object = luaL_checklm_ssl (L, 1);
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   179
	const gchar *path = luaL_checkstring (L, 2);
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   180
	lm_ssl_set_ca (object -> ssl, path);
62
d92358eafead ssl: Return object from cipher/ca methods for chain initialization
Myhailo Danylenko <isbear@ukrpost.net>
parents: 59
diff changeset
   181
	lua_pop (L, 1);
d92358eafead ssl: Return object from cipher/ca methods for chain initialization
Myhailo Danylenko <isbear@ukrpost.net>
parents: 59
diff changeset
   182
	return 1;
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   183
}
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   184
#endif
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   185
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   186
#ifdef HAVE_LM_SSL_SET_CIPHER_LIST
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   187
/// ssl:cipher_list
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   188
/// Set list of allowed ciphers (colon-separated). Names may vary depending on ssl
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   189
/// implementation in use.
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   190
/// A: string (cipher list)
62
d92358eafead ssl: Return object from cipher/ca methods for chain initialization
Myhailo Danylenko <isbear@ukrpost.net>
parents: 59
diff changeset
   191
/// R: lm ssl object
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   192
static int cipher_list_lm_ssl (lua_State *L)
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   193
{
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   194
	llm_ssl_t *object = luaL_checklm_ssl (L, 1);
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   195
	const gchar *list = luaL_checkstring (L, 2);
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   196
	lm_ssl_set_cipher_list (object -> ssl, list);
62
d92358eafead ssl: Return object from cipher/ca methods for chain initialization
Myhailo Danylenko <isbear@ukrpost.net>
parents: 59
diff changeset
   197
	lua_pop (L, 1);
d92358eafead ssl: Return object from cipher/ca methods for chain initialization
Myhailo Danylenko <isbear@ukrpost.net>
parents: 59
diff changeset
   198
	return 1;
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   199
}
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   200
#endif
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   201
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   202
/// ssl:fingerprint
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   203
/// Returns fingerprint of remote server.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   204
/// R: string or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   205
static int fingerprint_lm_ssl (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   206
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   207
	llm_ssl_t *object = luaL_checklm_ssl (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   208
	const gchar *fingerprint = lm_ssl_get_fingerprint (object->ssl);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   209
	if (fingerprint == NULL)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   210
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   211
	else {
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   212
#ifdef HAVE_LM_SHA256_FINGERPRINTS
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   213
		lua_pushstring (L, fingerprint);
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   214
#else
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   215
		char buffer[48];
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   216
		snprintf (buffer, 48,
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   217
			  "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   218
			  "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX",
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   219
			  fingerprint[0], fingerprint[1], fingerprint[2], fingerprint[3],
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   220
			  fingerprint[4], fingerprint[5], fingerprint[6], fingerprint[7],
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   221
			  fingerprint[8], fingerprint[9], fingerprint[10], fingerprint[11],
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   222
			  fingerprint[12], fingerprint[13], fingerprint[14], fingerprint[15]);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   223
		lua_pushlstring (L, buffer, 47);
57
37ed3c7ac1b6 ssl: Support for SHA256 fingerprints (v0.9.3)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   224
#endif
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   225
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   226
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   227
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   228
42
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   229
/// ssl:tls
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   230
/// Sets or returns use of starttls by this ssl object.
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   231
/// A: boolean (use starttls), boolean (require starttls)
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   232
/// or
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   233
/// R: boolean (use starttls), boolean (require starttls)
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   234
static int tls_lm_ssl (lua_State *L)
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   235
{
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   236
	llm_ssl_t *object = luaL_checklm_ssl (L, 1);
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   237
	if (lua_gettop (L) > 1) {
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   238
		gboolean use     = lua_toboolean (L, 2);
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   239
		gboolean require = lua_toboolean (L, 3);
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   240
		lm_ssl_use_starttls (object -> ssl, use, require);
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   241
		return 0;
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   242
	} else {
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   243
		lua_pushboolean (L, lm_ssl_get_use_starttls (object -> ssl));
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   244
		lua_pushboolean (L, lm_ssl_get_require_starttls (object -> ssl));
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   245
		return 2;
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   246
	}
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   247
}
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   248
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   249
/// ssl:pointer
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   250
/// Returns pointer to underlying C structure.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   251
/// R: lightuserdata
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   252
static int pointer_lm_ssl (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   253
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   254
	llm_ssl_t *object = luaL_checklm_ssl (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   255
	lua_pushlightuserdata (L, object->ssl);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   256
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   257
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   258
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   259
static int gc_lm_ssl (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   260
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   261
	llm_ssl_t *object = luaL_checklm_ssl (L, 1);
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   262
	D ("SSL %p gc called", object);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   263
	lm_ssl_unref (object->ssl);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   264
	return 0;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   265
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   266
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   267
const static luaL_Reg reg_f_lm_ssl[] = {
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   268
	{ "new",       new_lm_ssl       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   269
	{ "bless",     bless_lua_lm_ssl },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   270
	{ "supported", supported_lm_ssl },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   271
	{ NULL,        NULL             },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   272
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   273
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   274
const static luaL_Reg reg_m_lm_ssl[] = {
59
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   275
#ifdef HAVE_LM_SSL_SET_CA
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   276
	{ "ca_path",     ca_path_lm_ssl     },
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   277
#endif
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   278
#ifdef HAVE_LM_SSL_SET_CIPHER_LIST
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   279
	{ "cipher_list", cipher_list_lm_ssl },
19cfaceda6bb ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 57
diff changeset
   280
#endif
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   281
	{ "fingerprint", fingerprint_lm_ssl },
42
61d0ab29f17f Add ssl:tls method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   282
	{ "tls",         tls_lm_ssl         },
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   283
	{ "pointer",     pointer_lm_ssl     },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   284
	{ "__gc",        gc_lm_ssl          },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   285
	{ NULL,          NULL               },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   286
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   287
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   288
int luaopen_lm_ssl (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   289
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   290
	luaL_newmetatable (L, "loudmouth.ssl");
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   291
	lua_pushvalue (L, -1);
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   292
	lua_setfield (L, -2, "__index");
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 42
diff changeset
   293
	luaL_setfuncs (L, reg_m_lm_ssl, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   294
	lua_pop (L, 1);
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   295
	lua_newtable (L); // XXX we can specify here exact amount of fields
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 42
diff changeset
   296
	luaL_setfuncs (L, reg_f_lm_ssl, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   297
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   298
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   299