src/x509.c

Fri, 05 Nov 2010 21:25:13 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 05 Nov 2010 21:25:13 +0000
changeset 15
f1de983ff659
parent 14
1927b7b32faf
child 16
0cefcdd5b635
permissions
-rw-r--r--

src/x509.c: Fix compiler warning, return module table

14
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 /*--------------------------------------------------------------------------
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 * LuaSec 0.4
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2006-2009 Bruno Silvestre
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 *
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 *--------------------------------------------------------------------------*/
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 #include <string.h>
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 #include <openssl/ssl.h>
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 #include <openssl/x509v3.h>
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 #include <openssl/err.h>
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 #include <lua.h>
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 #include <lauxlib.h>
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 #include "io.h"
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 #include "buffer.h"
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 #include "timeout.h"
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 #include "socket.h"
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 #include "ssl.h"
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 #include "x509.h"
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 #define min(a, b) (a<b)?a:b
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 void luasec_push_x509(lua_State* L, X509 *cert)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 p_x509 cert_obj = (p_x509) lua_newuserdata(L, sizeof(t_x509));
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 cert_obj->cert = cert;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 luaL_getmetatable(L, "SSL:Certificate");
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 lua_setmetatable(L, -2);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 X509* luasec_to_x509(lua_State* L, int idx)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 return ((p_x509)luaL_checkudata(L, idx, "SSL:Certificate"))->cert;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 int meth_decode(lua_State* L)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 X509 *peer;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 X509_NAME *subject;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 int i, j, n_entries;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 peer = luasec_to_x509(L, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 lua_newtable(L); /* ret */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 subject = X509_get_subject_name(peer);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 n_entries = X509_NAME_entry_count(subject);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 lua_newtable(L); /* {} */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 lua_pushvalue(L, -1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 lua_setfield(L, -3, "subject"); /* ret.subject = {} */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 for(i = 0; i <= n_entries; i++)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 X509_NAME_ENTRY *entry;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 ASN1_OBJECT *object;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 entry = X509_NAME_get_entry(subject, i);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 object = X509_NAME_ENTRY_get_object(entry);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 luasec_push_asn1_objname(L, object, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 if(luasec_push_subtable(L, -2))
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 /* Get short/long name of the entry */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 luasec_push_asn1_objname(L, object, 0);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 lua_setfield(L, -2, "name");
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 luasec_push_asn1_string(L, X509_NAME_ENTRY_get_data(entry));
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 lua_rawseti(L, -2, lua_objlen(L, -2)+1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 lua_pop(L, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 lua_pop(L, 1); /* ret.subject */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 lua_newtable(L); /* {} */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 lua_pushvalue(L, -1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 lua_setfield(L, -3, "extensions"); /* ret.extensions = {} */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 i = -1;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 while((i = X509_get_ext_by_NID(peer, NID_subject_alt_name, i)) != -1)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 X509_EXTENSION *extension;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 STACK_OF(GENERAL_NAME) *values;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 int n_general_names;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 extension = X509_get_ext(peer, i);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 if(extension == NULL)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 break;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 values = X509V3_EXT_d2i(extension);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 if(values == NULL)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 break;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 /* Push ret.extensions[oid] */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 luasec_push_asn1_objname(L, extension->object, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 luasec_push_subtable(L, -2);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 /* Set ret.extensions[oid].name = name */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 luasec_push_asn1_objname(L, extension->object, 0);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 lua_setfield(L, -2, "name");
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 n_general_names = sk_GENERAL_NAME_num(values);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 for(j = 0; j < n_general_names; j++)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 GENERAL_NAME *general_name;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 general_name = sk_GENERAL_NAME_value(values, j);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 switch(general_name->type)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 case GEN_OTHERNAME:
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 OTHERNAME *otherName = general_name->d.otherName;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 luasec_push_asn1_objname(L, otherName->type_id, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 if(luasec_push_subtable(L, -2))
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 luasec_push_asn1_objname(L, otherName->type_id, 0);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 lua_setfield(L, -2, "name");
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 luasec_push_asn1_string(L, otherName->value->value.asn1_string);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 lua_rawseti(L, -2, lua_objlen(L, -2)+1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 lua_pop(L, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 break;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 case GEN_DNS:
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 lua_pushstring(L, "dNSName");
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 luasec_push_subtable(L, -2);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 luasec_push_asn1_string(L, general_name->d.dNSName);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 lua_rawseti(L, -2, lua_objlen(L, -2)+1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 lua_pop(L, 1);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 break;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 default:
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 break;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 lua_pop(L, 1); /* array */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 i++; /* Next extension */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 lua_pop(L, 1); /* ret.extensions */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 return 1;
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 }
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 /**
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 * Certificate metamethods
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 static luaL_Reg meta[] = {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 {"decode", meth_decode},
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 {NULL, NULL}
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 };
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 LUASEC_API int luaopen_ssl_x509(lua_State *L)
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 {
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 /* Register the functions and tables */
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 luaL_newmetatable(L, "SSL:Certificate");
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 lua_newtable(L);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 luaL_register(L, NULL, meta);
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 lua_setfield(L, -2, "__index");
15
f1de983ff659 src/x509.c: Fix compiler warning, return module table
Matthew Wild <mwild1@gmail.com>
parents: 14
diff changeset
169
f1de983ff659 src/x509.c: Fix compiler warning, return module table
Matthew Wild <mwild1@gmail.com>
parents: 14
diff changeset
170 lua_newtable(L);
f1de983ff659 src/x509.c: Fix compiler warning, return module table
Matthew Wild <mwild1@gmail.com>
parents: 14
diff changeset
171 return 1;
14
1927b7b32faf Split X509 decoding into a separate module, ssl.x509
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 }

mercurial