diff options
| author | William Ahern <william@williams-air.cudanet.local> | 2014-07-16 12:56:43 -0700 |
|---|---|---|
| committer | William Ahern <william@williams-air.cudanet.local> | 2014-07-16 12:56:43 -0700 |
| commit | 836e49289448c1827b118152e361605f1d569415 (patch) | |
| tree | a1acfa09ef3734ef326094098621f57acfe18977 /src | |
| parent | 2a655b72b6013994432313c8799037fa598eb5c5 (diff) | |
| parent | 934e32e0416ae1da69aa1295837b93369c9f7aca (diff) | |
| download | luaossl-836e49289448c1827b118152e361605f1d569415.tar.gz luaossl-836e49289448c1827b118152e361605f1d569415.tar.bz2 luaossl-836e49289448c1827b118152e361605f1d569415.zip | |
Merge branch 'custom-ext' of https://github.com/kunkku/luaossl into kunkku-custom-ext
Diffstat (limited to 'src')
| -rw-r--r-- | src/GNUmakefile | 1 | ||||
| -rw-r--r-- | src/openssl.c | 108 | ||||
| -rw-r--r-- | src/openssl.x509.extension.lua | 1 |
3 files changed, 110 insertions, 0 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile index 240a773..f988855 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile | |||
| @@ -95,6 +95,7 @@ MODS$(1)_$(d) = \ | |||
| 95 | $$(DESTDIR)$(3)/openssl/x509/altname.lua \ | 95 | $$(DESTDIR)$(3)/openssl/x509/altname.lua \ |
| 96 | $$(DESTDIR)$(3)/openssl/x509/chain.lua \ | 96 | $$(DESTDIR)$(3)/openssl/x509/chain.lua \ |
| 97 | $$(DESTDIR)$(3)/openssl/x509/crl.lua \ | 97 | $$(DESTDIR)$(3)/openssl/x509/crl.lua \ |
| 98 | $$(DESTDIR)$(3)/openssl/x509/extension.lua \ | ||
| 98 | $$(DESTDIR)$(3)/openssl/x509/store.lua \ | 99 | $$(DESTDIR)$(3)/openssl/x509/store.lua \ |
| 99 | $$(DESTDIR)$(3)/openssl/pkcs12.lua \ | 100 | $$(DESTDIR)$(3)/openssl/pkcs12.lua \ |
| 100 | $$(DESTDIR)$(3)/openssl/ssl/context.lua \ | 101 | $$(DESTDIR)$(3)/openssl/ssl/context.lua \ |
diff --git a/src/openssl.c b/src/openssl.c index ee1fd89..7bd9c61 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -84,6 +84,7 @@ | |||
| 84 | #define PKEY_CLASS "EVP_PKEY*" | 84 | #define PKEY_CLASS "EVP_PKEY*" |
| 85 | #define X509_NAME_CLASS "X509_NAME*" | 85 | #define X509_NAME_CLASS "X509_NAME*" |
| 86 | #define X509_GENS_CLASS "GENERAL_NAMES*" | 86 | #define X509_GENS_CLASS "GENERAL_NAMES*" |
| 87 | #define X509_EXT_CLASS "X509_EXTENSION*" | ||
| 87 | #define X509_CERT_CLASS "X509*" | 88 | #define X509_CERT_CLASS "X509*" |
| 88 | #define X509_CHAIN_CLASS "STACK_OF(X509)*" | 89 | #define X509_CHAIN_CLASS "STACK_OF(X509)*" |
| 89 | #define X509_CSR_CLASS "X509_REQ*" | 90 | #define X509_CSR_CLASS "X509_REQ*" |
| @@ -1819,6 +1820,98 @@ int luaopen__openssl_x509_altname(lua_State *L) { | |||
| 1819 | 1820 | ||
| 1820 | 1821 | ||
| 1821 | /* | 1822 | /* |
| 1823 | * X509_EXTENSION - openssl.x509.extension | ||
| 1824 | * | ||
| 1825 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
| 1826 | |||
| 1827 | static int xe_new(lua_State *L) { | ||
| 1828 | lua_settop(L, 3); | ||
| 1829 | |||
| 1830 | X509_EXTENSION **ud = prepsimple(L, X509_EXT_CLASS); | ||
| 1831 | |||
| 1832 | char *name = (char *) luaL_checkstring(L, 1); | ||
| 1833 | char *value = (char *) luaL_checkstring(L, 2); | ||
| 1834 | |||
| 1835 | CONF *conf = NULL; | ||
| 1836 | X509V3_CTX *ctx = NULL; | ||
| 1837 | X509_EXTENSION *ext = NULL; | ||
| 1838 | |||
| 1839 | if (!lua_isnil(L, 3)) { | ||
| 1840 | char *cdata = (char *) luaL_checkstring(L, 3); | ||
| 1841 | BIO *bio = getbio(L); | ||
| 1842 | if (BIO_puts(bio, cdata) < 0) | ||
| 1843 | goto error; | ||
| 1844 | |||
| 1845 | if (!(conf = NCONF_new(NULL))) | ||
| 1846 | goto error; | ||
| 1847 | if (!NCONF_load_bio(conf, bio, NULL)) | ||
| 1848 | goto error; | ||
| 1849 | |||
| 1850 | ctx = (X509V3_CTX *) malloc(sizeof (X509V3_CTX)); | ||
| 1851 | X509V3_set_nconf(ctx, conf); | ||
| 1852 | } | ||
| 1853 | |||
| 1854 | if (!(*ud = X509V3_EXT_nconf(conf, ctx, name, value))) | ||
| 1855 | goto error; | ||
| 1856 | |||
| 1857 | if (conf) { | ||
| 1858 | free(ctx); | ||
| 1859 | NCONF_free(conf); | ||
| 1860 | } | ||
| 1861 | |||
| 1862 | return 1; | ||
| 1863 | |||
| 1864 | error: | ||
| 1865 | if (ctx) | ||
| 1866 | free(ctx); | ||
| 1867 | if (conf) | ||
| 1868 | NCONF_free(conf); | ||
| 1869 | |||
| 1870 | return throwssl(L, "x509.extension.new"); | ||
| 1871 | } /* xe_new() */ | ||
| 1872 | |||
| 1873 | |||
| 1874 | static int xe_interpose(lua_State *L) { | ||
| 1875 | return interpose(L, X509_EXT_CLASS); | ||
| 1876 | } /* xe_interpose() */ | ||
| 1877 | |||
| 1878 | |||
| 1879 | static int xe__gc(lua_State *L) { | ||
| 1880 | X509_EXTENSION **ud = luaL_checkudata(L, 1, X509_EXT_CLASS); | ||
| 1881 | |||
| 1882 | X509_EXTENSION_free(*ud); | ||
| 1883 | *ud = NULL; | ||
| 1884 | |||
| 1885 | return 0; | ||
| 1886 | } /* xe__gc() */ | ||
| 1887 | |||
| 1888 | |||
| 1889 | static const luaL_Reg xe_methods[] = { | ||
| 1890 | { NULL, NULL }, | ||
| 1891 | }; | ||
| 1892 | |||
| 1893 | static const luaL_Reg xe_metatable[] = { | ||
| 1894 | { "__gc", &xe__gc }, | ||
| 1895 | { NULL, NULL }, | ||
| 1896 | }; | ||
| 1897 | |||
| 1898 | |||
| 1899 | static const luaL_Reg xe_globals[] = { | ||
| 1900 | { "new", &xe_new }, | ||
| 1901 | { "interpose", &xe_interpose }, | ||
| 1902 | { NULL, NULL }, | ||
| 1903 | }; | ||
| 1904 | |||
| 1905 | int luaopen__openssl_x509_extension(lua_State *L) { | ||
| 1906 | initall(L); | ||
| 1907 | |||
| 1908 | luaL_newlib(L, xe_globals); | ||
| 1909 | |||
| 1910 | return 1; | ||
| 1911 | } /* luaopen__openssl_x509_extension() */ | ||
| 1912 | |||
| 1913 | |||
| 1914 | /* | ||
| 1822 | * X509 - openssl.x509.cert | 1915 | * X509 - openssl.x509.cert |
| 1823 | * | 1916 | * |
| 1824 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 1917 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| @@ -2511,6 +2604,19 @@ static int xc_setBasicConstraintsCritical(lua_State *L) { | |||
| 2511 | } /* xc_setBasicConstraintsCritical() */ | 2604 | } /* xc_setBasicConstraintsCritical() */ |
| 2512 | 2605 | ||
| 2513 | 2606 | ||
| 2607 | static int xc_addExtension(lua_State *L) { | ||
| 2608 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); | ||
| 2609 | X509_EXTENSION *ext = checksimple(L, 2, X509_EXT_CLASS); | ||
| 2610 | |||
| 2611 | if (!X509_add_ext(crt, ext, -1)) | ||
| 2612 | throwssl(L, "x509.cert:addExtension"); | ||
| 2613 | |||
| 2614 | lua_pushboolean(L, 1); | ||
| 2615 | |||
| 2616 | return 1; | ||
| 2617 | } /* xc_addExtension() */ | ||
| 2618 | |||
| 2619 | |||
| 2514 | static int xc_isIssuedBy(lua_State *L) { | 2620 | static int xc_isIssuedBy(lua_State *L) { |
| 2515 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); | 2621 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); |
| 2516 | X509 *issuer = checksimple(L, 2, X509_CERT_CLASS); | 2622 | X509 *issuer = checksimple(L, 2, X509_CERT_CLASS); |
| @@ -2726,6 +2832,7 @@ static const luaL_Reg xc_methods[] = { | |||
| 2726 | { "setBasicConstraint", &xc_setBasicConstraint }, | 2832 | { "setBasicConstraint", &xc_setBasicConstraint }, |
| 2727 | { "getBasicConstraintsCritical", &xc_getBasicConstraintsCritical }, | 2833 | { "getBasicConstraintsCritical", &xc_getBasicConstraintsCritical }, |
| 2728 | { "setBasicConstraintsCritical", &xc_setBasicConstraintsCritical }, | 2834 | { "setBasicConstraintsCritical", &xc_setBasicConstraintsCritical }, |
| 2835 | { "addExtension", &xc_addExtension }, | ||
| 2729 | { "isIssuedBy", &xc_isIssuedBy }, | 2836 | { "isIssuedBy", &xc_isIssuedBy }, |
| 2730 | { "getPublicKey", &xc_getPublicKey }, | 2837 | { "getPublicKey", &xc_getPublicKey }, |
| 2731 | { "setPublicKey", &xc_setPublicKey }, | 2838 | { "setPublicKey", &xc_setPublicKey }, |
| @@ -4967,6 +5074,7 @@ static void initall(lua_State *L) { | |||
| 4967 | addclass(L, PKEY_CLASS, pk_methods, pk_metatable); | 5074 | addclass(L, PKEY_CLASS, pk_methods, pk_metatable); |
| 4968 | addclass(L, X509_NAME_CLASS, xn_methods, xn_metatable); | 5075 | addclass(L, X509_NAME_CLASS, xn_methods, xn_metatable); |
| 4969 | addclass(L, X509_GENS_CLASS, gn_methods, gn_metatable); | 5076 | addclass(L, X509_GENS_CLASS, gn_methods, gn_metatable); |
| 5077 | addclass(L, X509_EXT_CLASS, xe_methods, xe_metatable); | ||
| 4970 | addclass(L, X509_CERT_CLASS, xc_methods, xc_metatable); | 5078 | addclass(L, X509_CERT_CLASS, xc_methods, xc_metatable); |
| 4971 | addclass(L, X509_CSR_CLASS, xr_methods, xr_metatable); | 5079 | addclass(L, X509_CSR_CLASS, xr_methods, xr_metatable); |
| 4972 | addclass(L, X509_CRL_CLASS, xx_methods, xx_metatable); | 5080 | addclass(L, X509_CRL_CLASS, xx_methods, xx_metatable); |
diff --git a/src/openssl.x509.extension.lua b/src/openssl.x509.extension.lua new file mode 100644 index 0000000..7043f45 --- /dev/null +++ b/src/openssl.x509.extension.lua | |||
| @@ -0,0 +1 @@ | |||
| return require('_openssl.x509.extension') | |||
