diff options
author | William Ahern <william@server.local> | 2012-10-15 11:52:41 -0700 |
---|---|---|
committer | William Ahern <william@server.local> | 2012-10-15 11:52:41 -0700 |
commit | 3575f08d8eb9f6b2cb1b334c5108af1e00699acf (patch) | |
tree | 0165f7683f580df45d7b332b12cd669f55d9f487 | |
parent | b641ef683a81cb9241b35f408aacb0a9a78d0667 (diff) | |
download | luaossl-3575f08d8eb9f6b2cb1b334c5108af1e00699acf.tar.gz luaossl-3575f08d8eb9f6b2cb1b334c5108af1e00699acf.tar.bz2 luaossl-3575f08d8eb9f6b2cb1b334c5108af1e00699acf.zip |
-n
wrap so_checktls
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | openssl.c | 123 |
2 files changed, 127 insertions, 2 deletions
@@ -48,7 +48,7 @@ install: $(lua52cpath)/_openssl.so $(lua52path)/openssl/bignum.lua \ | |||
48 | $(lua52path)/openssl/pubkey.lua $(lua52path)/openssl/x509.lua \ | 48 | $(lua52path)/openssl/pubkey.lua $(lua52path)/openssl/x509.lua \ |
49 | $(lua52path)/openssl/x509/name.lua $(lua52path)/openssl/x509/altname.lua \ | 49 | $(lua52path)/openssl/x509/name.lua $(lua52path)/openssl/x509/altname.lua \ |
50 | $(lua52path)/openssl/x509/chain.lua $(lua52path)/openssl/x509/store.lua \ | 50 | $(lua52path)/openssl/x509/chain.lua $(lua52path)/openssl/x509/store.lua \ |
51 | $(lua52path)/openssl/ssl/context.lua | 51 | $(lua52path)/openssl/ssl/context.lua $(lua52path)/openssl/ssl.lua |
52 | 52 | ||
53 | $(lua52cpath)/_openssl.so: openssl.so | 53 | $(lua52cpath)/_openssl.so: openssl.so |
54 | mkdir -p $(@D) | 54 | mkdir -p $(@D) |
@@ -86,6 +86,10 @@ $(lua52path)/openssl/ssl/context.lua: openssl.ssl.context.lua | |||
86 | mkdir -p $(@D) | 86 | mkdir -p $(@D) |
87 | cp -p $< $@ | 87 | cp -p $< $@ |
88 | 88 | ||
89 | $(lua52path)/openssl/ssl.lua: openssl.ssl.lua | ||
90 | mkdir -p $(@D) | ||
91 | cp -p $< $@ | ||
92 | |||
89 | 93 | ||
90 | .PHONY: clean clean~ | 94 | .PHONY: clean clean~ |
91 | 95 | ||
@@ -67,6 +67,7 @@ | |||
67 | #define X509_STORE_CLASS "OpenSSL X.509 Store" | 67 | #define X509_STORE_CLASS "OpenSSL X.509 Store" |
68 | #define X509_STCTX_CLASS "OpenSSL X.509 Store Context" | 68 | #define X509_STCTX_CLASS "OpenSSL X.509 Store Context" |
69 | #define SSL_CTX_CLASS "OpenSSL SSL Context" | 69 | #define SSL_CTX_CLASS "OpenSSL SSL Context" |
70 | #define SSL_CLASS "OpenSSL SSL" | ||
70 | 71 | ||
71 | 72 | ||
72 | #define countof(a) (sizeof (a) / sizeof *(a)) | 73 | #define countof(a) (sizeof (a) / sizeof *(a)) |
@@ -2594,6 +2595,48 @@ int luaopen__openssl_x509_csr(lua_State *L) { | |||
2594 | * | 2595 | * |
2595 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 2596 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
2596 | 2597 | ||
2598 | static void xl_dup(lua_State *L, STACK_OF(X509) *src, _Bool copy) { | ||
2599 | STACK_OF(X509) **dst = prepsimple(L, X509_CHAIN_CLASS); | ||
2600 | X509 *crt; | ||
2601 | int i, n; | ||
2602 | |||
2603 | if (copy) { | ||
2604 | if (!(*dst = sk_X509_new_null())) | ||
2605 | goto error; | ||
2606 | |||
2607 | n = sk_X509_num(src); | ||
2608 | |||
2609 | for (i = 0; i < n; i++) { | ||
2610 | if (!(crt = sk_X509_value(src, i))) | ||
2611 | continue; | ||
2612 | |||
2613 | if (!(crt = X509_dup(crt))) | ||
2614 | goto error; | ||
2615 | |||
2616 | if (!sk_X509_push(*dst, crt)) { | ||
2617 | X509_free(crt); | ||
2618 | goto error; | ||
2619 | } | ||
2620 | } | ||
2621 | } else { | ||
2622 | if (!(*dst = sk_X509_dup(src))) | ||
2623 | goto error; | ||
2624 | |||
2625 | n = sk_X509_num(*dst); | ||
2626 | |||
2627 | for (i = 0; i < n; i++) { | ||
2628 | if (!(crt = sk_X509_value(*dst, i))) | ||
2629 | continue; | ||
2630 | CRYPTO_add(&crt->references, 1, CRYPTO_LOCK_X509); | ||
2631 | } | ||
2632 | } | ||
2633 | |||
2634 | return; | ||
2635 | error: | ||
2636 | throwssl(L, "sk_X509_dup"); | ||
2637 | } /* xl_dup() */ | ||
2638 | |||
2639 | |||
2597 | static int xl_new(lua_State *L) { | 2640 | static int xl_new(lua_State *L) { |
2598 | STACK_OF(X509) **chain = prepsimple(L, X509_CHAIN_CLASS); | 2641 | STACK_OF(X509) **chain = prepsimple(L, X509_CHAIN_CLASS); |
2599 | 2642 | ||
@@ -2778,7 +2821,8 @@ static int xs_verify(lua_State *L) { | |||
2778 | X509 *elm; | 2821 | X509 *elm; |
2779 | int i, n; | 2822 | int i, n; |
2780 | 2823 | ||
2781 | chain = sk_X509_dup(checksimple(L, 3, X509_CHAIN_CLASS)); | 2824 | if (!(chain = sk_X509_dup(checksimple(L, 3, X509_CHAIN_CLASS)))) |
2825 | return throwssl(L, "x509.store:verify"); | ||
2782 | 2826 | ||
2783 | n = sk_X509_num(chain); | 2827 | n = sk_X509_num(chain); |
2784 | 2828 | ||
@@ -3108,6 +3152,82 @@ int luaopen__openssl_ssl_context(lua_State *L) { | |||
3108 | } /* luaopen__openssl_ssl_context() */ | 3152 | } /* luaopen__openssl_ssl_context() */ |
3109 | 3153 | ||
3110 | 3154 | ||
3155 | /* | ||
3156 | * SSL - openssl.ssl | ||
3157 | * | ||
3158 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
3159 | |||
3160 | static int ssl_new(lua_State *L) { | ||
3161 | lua_pushnil(L); | ||
3162 | |||
3163 | return 1; | ||
3164 | } /* ssl_new() */ | ||
3165 | |||
3166 | |||
3167 | static int ssl_interpose(lua_State *L) { | ||
3168 | return interpose(L, SSL_CLASS); | ||
3169 | } /* ssl_interpose() */ | ||
3170 | |||
3171 | |||
3172 | static int ssl_getPeerCertificate(lua_State *L) { | ||
3173 | SSL *ssl = checksimple(L, 1, SSL_CLASS); | ||
3174 | X509 **x509 = prepsimple(L, X509_CERT_CLASS); | ||
3175 | |||
3176 | if (!(*x509 = SSL_get_peer_certificate(ssl))) | ||
3177 | return 0; | ||
3178 | |||
3179 | return 1; | ||
3180 | } /* ssl_getPeerCertificate() */ | ||
3181 | |||
3182 | |||
3183 | static int ssl_getPeerChain(lua_State *L) { | ||
3184 | SSL *ssl = checksimple(L, 1, SSL_CLASS); | ||
3185 | STACK_OF(X509) *chain; | ||
3186 | |||
3187 | if (!(chain = SSL_get_peer_cert_chain(ssl))) | ||
3188 | return 0; | ||
3189 | |||
3190 | xl_dup(L, chain, 0); | ||
3191 | |||
3192 | return 1; | ||
3193 | } /* ssl_getPeerChain() */ | ||
3194 | |||
3195 | |||
3196 | static int ssl__gc(lua_State *L) { | ||
3197 | SSL **ud = luaL_checkudata(L, 1, SSL_CLASS); | ||
3198 | |||
3199 | SSL_free(*ud); | ||
3200 | *ud = NULL; | ||
3201 | |||
3202 | return 0; | ||
3203 | } /* ssl__gc() */ | ||
3204 | |||
3205 | |||
3206 | static const luaL_Reg ssl_methods[] = { | ||
3207 | { "getPeerCertificate", &ssl_getPeerCertificate }, | ||
3208 | { "getPeerChain", &ssl_getPeerChain }, | ||
3209 | { NULL, NULL }, | ||
3210 | }; | ||
3211 | |||
3212 | static const luaL_Reg ssl_metatable[] = { | ||
3213 | { "__gc", &ssl__gc }, | ||
3214 | { NULL, NULL }, | ||
3215 | }; | ||
3216 | |||
3217 | static const luaL_Reg ssl_globals[] = { | ||
3218 | { "new", &ssl_new }, | ||
3219 | { "interpose", &ssl_interpose }, | ||
3220 | { NULL, NULL }, | ||
3221 | }; | ||
3222 | |||
3223 | int luaopen__openssl_ssl(lua_State *L) { | ||
3224 | initall(L); | ||
3225 | |||
3226 | luaL_newlib(L, ssl_globals); | ||
3227 | |||
3228 | return 1; | ||
3229 | } /* luaopen__openssl_ssl() */ | ||
3230 | |||
3111 | 3231 | ||
3112 | static void initall(lua_State *L) { | 3232 | static void initall(lua_State *L) { |
3113 | ERR_load_crypto_strings(); | 3233 | ERR_load_crypto_strings(); |
@@ -3122,6 +3242,7 @@ static void initall(lua_State *L) { | |||
3122 | addclass(L, X509_CHAIN_CLASS, xl_methods, xl_metatable); | 3242 | addclass(L, X509_CHAIN_CLASS, xl_methods, xl_metatable); |
3123 | addclass(L, X509_STORE_CLASS, xs_methods, xs_metatable); | 3243 | addclass(L, X509_STORE_CLASS, xs_methods, xs_metatable); |
3124 | addclass(L, SSL_CTX_CLASS, sx_methods, sx_metatable); | 3244 | addclass(L, SSL_CTX_CLASS, sx_methods, sx_metatable); |
3245 | addclass(L, SSL_CLASS, ssl_methods, ssl_metatable); | ||
3125 | } /* initall() */ | 3246 | } /* initall() */ |
3126 | 3247 | ||
3127 | 3248 | ||