diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-03-19 10:33:25 -0400 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-01 17:32:53 -0400 |
| commit | 655eacf345a108247ba6ea506721395571108912 (patch) | |
| tree | 01c5658eb2d221a49ecd9d47c2d7e7b6094a69af | |
| parent | 4e97804fc1b8b47667ec1d8b8f3c473d31c8bb29 (diff) | |
| download | luarocks-655eacf345a108247ba6ea506721395571108912.tar.gz luarocks-655eacf345a108247ba6ea506721395571108912.tar.bz2 luarocks-655eacf345a108247ba6ea506721395571108912.zip | |
Add --sign option to `luarocks pack`
* Introduce a new module, `luarocks.signing`
* Add `--sign` option to `luarocks pack`, which produces a
detached GPG signature
* Includes a basic test, along with some fixtures with
a password-less GPG key
| -rw-r--r-- | .travis.yml | 4 | ||||
| -rw-r--r-- | spec/fixtures/gpg/private-keys-v1.d/5D2D3F97B88B18604D819EA9DF5B730C75D71B60.key | bin | 0 -> 977 bytes | |||
| -rw-r--r-- | spec/fixtures/gpg/private-keys-v1.d/B71C36B4EDEB72A047FED1C01BCFF4D08837E3B1.key | bin | 0 -> 978 bytes | |||
| -rw-r--r-- | spec/fixtures/gpg/pubring.kbx | bin | 0 -> 1494 bytes | |||
| -rw-r--r-- | spec/fixtures/gpg/trustdb.gpg | bin | 0 -> 1240 bytes | |||
| -rw-r--r-- | spec/pack_spec.lua | 10 | ||||
| -rw-r--r-- | spec/util/test_env.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/cmd/pack.lua | 14 | ||||
| -rw-r--r-- | src/luarocks/core/cfg.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/signing.lua | 22 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 1 |
11 files changed, 53 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml index 67eec990..70fe9ee6 100644 --- a/.travis.yml +++ b/.travis.yml | |||
| @@ -22,8 +22,8 @@ integration_script: &integration_script | |||
| 22 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then shellcheck ./configure; fi | 22 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then shellcheck ./configure; fi |
| 23 | - ./configure --with-lua=lua_install | 23 | - ./configure --with-lua=lua_install |
| 24 | - ./makedist dev | 24 | - ./makedist dev |
| 25 | - busted -o gtest --exclude-tags=git,unit --verbose -Xhelper "lua_dir=$PWD/lua_install,travis" | 25 | - busted -o gtest --exclude-tags=gpg,git,unit --verbose -Xhelper "lua_dir=$PWD/lua_install,travis" |
| 26 | - busted -o gtest --exclude-tags=git,unit --verbose -Xhelper "lua_dir=$PWD/lua_install,travis,env=full" | 26 | - busted -o gtest --exclude-tags=gpg,git,unit --verbose -Xhelper "lua_dir=$PWD/lua_install,travis,env=full" |
| 27 | 27 | ||
| 28 | jobs: | 28 | jobs: |
| 29 | include: | 29 | include: |
diff --git a/spec/fixtures/gpg/private-keys-v1.d/5D2D3F97B88B18604D819EA9DF5B730C75D71B60.key b/spec/fixtures/gpg/private-keys-v1.d/5D2D3F97B88B18604D819EA9DF5B730C75D71B60.key new file mode 100644 index 00000000..26240f5a --- /dev/null +++ b/spec/fixtures/gpg/private-keys-v1.d/5D2D3F97B88B18604D819EA9DF5B730C75D71B60.key | |||
| Binary files differ | |||
diff --git a/spec/fixtures/gpg/private-keys-v1.d/B71C36B4EDEB72A047FED1C01BCFF4D08837E3B1.key b/spec/fixtures/gpg/private-keys-v1.d/B71C36B4EDEB72A047FED1C01BCFF4D08837E3B1.key new file mode 100644 index 00000000..e75a2eb4 --- /dev/null +++ b/spec/fixtures/gpg/private-keys-v1.d/B71C36B4EDEB72A047FED1C01BCFF4D08837E3B1.key | |||
| Binary files differ | |||
diff --git a/spec/fixtures/gpg/pubring.kbx b/spec/fixtures/gpg/pubring.kbx new file mode 100644 index 00000000..fc63cbc6 --- /dev/null +++ b/spec/fixtures/gpg/pubring.kbx | |||
| Binary files differ | |||
diff --git a/spec/fixtures/gpg/trustdb.gpg b/spec/fixtures/gpg/trustdb.gpg new file mode 100644 index 00000000..cabca669 --- /dev/null +++ b/spec/fixtures/gpg/trustdb.gpg | |||
| Binary files differ | |||
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 08647cfb..8b3612db 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua | |||
| @@ -50,6 +50,16 @@ describe("LuaRocks pack #integration", function() | |||
| 50 | assert(test_env.remove_files(lfs.currentdir(), "say%-")) | 50 | assert(test_env.remove_files(lfs.currentdir(), "say%-")) |
| 51 | end) | 51 | end) |
| 52 | 52 | ||
| 53 | pending("#gpg --sign", function() | ||
| 54 | assert(run.luarocks_bool("install say 1.2")) | ||
| 55 | assert(run.luarocks_bool("install luassert")) | ||
| 56 | assert(run.luarocks_bool("install say 1.0")) | ||
| 57 | assert(run.luarocks_bool("pack say --sign")) | ||
| 58 | assert.is_truthy(lfs.attributes("say-1.2-1.all.rock")) | ||
| 59 | assert.is_truthy(lfs.attributes("say-1.2-1.all.rock.asc")) | ||
| 60 | assert(test_env.remove_files(lfs.currentdir(), "say%-")) | ||
| 61 | end) | ||
| 62 | |||
| 53 | describe("#mock", function() | 63 | describe("#mock", function() |
| 54 | 64 | ||
| 55 | setup(function() | 65 | setup(function() |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 6850214f..9337c396 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
| @@ -436,6 +436,7 @@ local function create_env(testing_paths) | |||
| 436 | end | 436 | end |
| 437 | 437 | ||
| 438 | local env_variables = {} | 438 | local env_variables = {} |
| 439 | env_variables.GNUPGHOME = testing_paths.gpg_dir | ||
| 439 | env_variables.LUA_VERSION = luaversion_short | 440 | env_variables.LUA_VERSION = luaversion_short |
| 440 | env_variables.LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config.lua" | 441 | env_variables.LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config.lua" |
| 441 | if test_env.TEST_TARGET_OS == "windows" then | 442 | if test_env.TEST_TARGET_OS == "windows" then |
| @@ -593,6 +594,7 @@ local function create_paths(luaversion_full) | |||
| 593 | end | 594 | end |
| 594 | 595 | ||
| 595 | testing_paths.fixtures_dir = base_dir .. "/spec/fixtures" | 596 | testing_paths.fixtures_dir = base_dir .. "/spec/fixtures" |
| 597 | testing_paths.gpg_dir = testing_paths.fixtures_dir .. "/gpg" | ||
| 596 | testing_paths.fixtures_repo_dir = base_dir .. "/spec/fixtures/a_repo" | 598 | testing_paths.fixtures_repo_dir = base_dir .. "/spec/fixtures/a_repo" |
| 597 | testing_paths.util_dir = base_dir .. "/spec/util" | 599 | testing_paths.util_dir = base_dir .. "/spec/util" |
| 598 | testing_paths.testrun_dir = base_dir .. "/testrun" | 600 | testing_paths.testrun_dir = base_dir .. "/testrun" |
diff --git a/src/luarocks/cmd/pack.lua b/src/luarocks/cmd/pack.lua index 52b2fbca..02e554d9 100644 --- a/src/luarocks/cmd/pack.lua +++ b/src/luarocks/cmd/pack.lua | |||
| @@ -5,11 +5,14 @@ local cmd_pack = {} | |||
| 5 | 5 | ||
| 6 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
| 7 | local pack = require("luarocks.pack") | 7 | local pack = require("luarocks.pack") |
| 8 | local signing = require("luarocks.signing") | ||
| 8 | local queries = require("luarocks.queries") | 9 | local queries = require("luarocks.queries") |
| 9 | 10 | ||
| 10 | cmd_pack.help_summary = "Create a rock, packing sources or binaries." | 11 | cmd_pack.help_summary = "Create a rock, packing sources or binaries." |
| 11 | cmd_pack.help_arguments = "{<rockspec>|<name> [<version>]}" | 12 | cmd_pack.help_arguments = "{<rockspec>|<name> [<version>]}" |
| 12 | cmd_pack.help = [[ | 13 | cmd_pack.help = [[ |
| 14 | --sign Produce a signature file as well. | ||
| 15 | |||
| 13 | Argument may be a rockspec file, for creating a source rock, | 16 | Argument may be a rockspec file, for creating a source rock, |
| 14 | or the name of an installed package, for creating a binary rock. | 17 | or the name of an installed package, for creating a binary rock. |
| 15 | In the latter case, the app version may be given as a second | 18 | In the latter case, the app version may be given as a second |
| @@ -40,7 +43,18 @@ function cmd_pack.command(flags, arg, version) | |||
| 40 | if err then | 43 | if err then |
| 41 | return nil, err | 44 | return nil, err |
| 42 | else | 45 | else |
| 46 | local sigfile | ||
| 47 | if flags["sign"] then | ||
| 48 | sigfile, err = signing.sign_file(file) | ||
| 49 | util.printout() | ||
| 50 | end | ||
| 43 | util.printout("Packed: "..file) | 51 | util.printout("Packed: "..file) |
| 52 | if sigfile then | ||
| 53 | util.printout("Sigature stored in: "..sigfile) | ||
| 54 | end | ||
| 55 | if err then | ||
| 56 | return nil, err | ||
| 57 | end | ||
| 44 | return true | 58 | return true |
| 45 | end | 59 | end |
| 46 | end | 60 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 5b9dec2f..c6824153 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -230,6 +230,8 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
| 230 | SVN = "svn", | 230 | SVN = "svn", |
| 231 | HG = "hg", | 231 | HG = "hg", |
| 232 | 232 | ||
| 233 | GPG = "gpg", | ||
| 234 | |||
| 233 | RSYNC = "rsync", | 235 | RSYNC = "rsync", |
| 234 | WGET = "wget", | 236 | WGET = "wget", |
| 235 | SCP = "scp", | 237 | SCP = "scp", |
diff --git a/src/luarocks/signing.lua b/src/luarocks/signing.lua new file mode 100644 index 00000000..7503768e --- /dev/null +++ b/src/luarocks/signing.lua | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | local signing = {} | ||
| 2 | |||
| 3 | local cfg = require("luarocks.core.cfg") | ||
| 4 | local fs = require("luarocks.fs") | ||
| 5 | |||
| 6 | function signing.sign_file(file) | ||
| 7 | local vars = cfg.variables | ||
| 8 | local gpg_ok, err = fs.is_tool_available(vars.GPG, "gpg") | ||
| 9 | if not gpg_ok then | ||
| 10 | return nil, err | ||
| 11 | end | ||
| 12 | local gpg = vars.GPG | ||
| 13 | |||
| 14 | local sigfile = file .. ".asc" | ||
| 15 | if fs.execute(gpg, "--armor", "--output", sigfile, "--detach-sign", file) then | ||
| 16 | return sigfile | ||
| 17 | else | ||
| 18 | return nil, "failed running " .. gpg .. " to sign " .. file | ||
| 19 | end | ||
| 20 | end | ||
| 21 | |||
| 22 | return signing | ||
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 25c521ea..bba39457 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -149,6 +149,7 @@ local supported_flags = { | |||
| 149 | ["rockspec"] = true, | 149 | ["rockspec"] = true, |
| 150 | ["rockspec-format"] = "<ver>", | 150 | ["rockspec-format"] = "<ver>", |
| 151 | ["server"] = "<server>", | 151 | ["server"] = "<server>", |
| 152 | ["sign"] = true, | ||
| 152 | ["skip-pack"] = true, | 153 | ["skip-pack"] = true, |
| 153 | ["source"] = true, | 154 | ["source"] = true, |
| 154 | ["summary"] = "\"<text>\"", | 155 | ["summary"] = "\"<text>\"", |
