summaryrefslogtreecommitdiff
path: root/xmake/modules/utils
diff options
context:
space:
mode:
authorruki <[email protected]>2018-05-26 23:24:13 +0800
committerruki <[email protected]>2018-05-26 23:24:13 +0800
commit26038ac60976706764745d0a6fd93febb10765f9 (patch)
tree82f7a2d862900b2b363c388d63e050386599684b /xmake/modules/utils
parentcbd06bb6936b3257faf907d6d5ff3708861f1119 (diff)
impl testcert
Diffstat (limited to 'xmake/modules/utils')
-rw-r--r--xmake/modules/utils/wdk/testcert.lua127
1 files changed, 127 insertions, 0 deletions
diff --git a/xmake/modules/utils/wdk/testcert.lua b/xmake/modules/utils/wdk/testcert.lua
new file mode 100644
index 000000000..045d2045a
--- /dev/null
+++ b/xmake/modules/utils/wdk/testcert.lua
@@ -0,0 +1,127 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file testcert.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.global")
+import("core.project.config")
+import("detect.sdks.find_wdk")
+
+-- get tool
+function _get_tool(wdk, name)
+
+ -- init cache
+ _g.tools = _g.tools or {}
+
+ -- get it from the cache
+ local tool = _g.tools[name]
+ if not tool then
+
+ -- get arch
+ local arch = config.arch() or os.arch()
+
+ -- get tool
+ tool = path.join(wdk.bindir, arch, name .. ".exe")
+ if not os.isexec(tool) then
+ tool = path.join(wdk.bindir, wdk.sdkver, arch, name .. ".exe")
+ end
+ assert(os.isexec(tool), name .. " not found!")
+ _g.tools[name] = tool
+ end
+ return tool
+end
+
+-- install test certificate
+function _install(wdk)
+
+ -- get signtool
+ local signtool = _get_tool(wdk, "signtool")
+
+ -- check test certificate first
+ local ok = try
+ {
+ function ()
+ local tmpfile = os.tmpfile(os.programfile())
+ if not os.isfile(tmpfile) then
+ os.cp(os.programfile(), tmpfile)
+ end
+ os.vrunv(signtool, {"sign", "/v", "/a", "/s", "PrivateCertStore", "/n", "tboox.org(test)", tmpfile})
+ return true
+ end
+ }
+ if ok then
+ return
+ end
+
+ -- get makecert
+ local makecert = _get_tool(wdk, "makecert")
+
+ -- get certmgr
+ local certmgr = _get_tool(wdk, "certmgr")
+
+ -- get a test certificate
+ local testcer = path.join(global.directory(), "sign", "test.cer")
+ local company = "tboox.org(test)"
+
+ -- make a new test certificate @note need re-generate certificate when reinstalling
+ local signdir = path.directory(testcer)
+ if not os.isdir(signdir) then
+ os.mkdir(signdir)
+ end
+ os.vrunv(makecert, {"-r", "-pe", "-ss", "PrivateCertStore", "-n", "CN=" .. company, testcer})
+
+ -- register this test certificate
+ try
+ {
+ function ()
+ os.vrunv(certmgr, {"/add", testcer, "/s", "/r", "localMachine", "root"})
+ os.vrunv(certmgr, {"/add", testcer, "/s", "/r", "localMachine", "trustedpublisher"})
+ end,
+ catch
+ {
+ function (errors)
+ os.tryrm(testcer)
+ raise(errors)
+ end
+ }
+ }
+
+ -- trace
+ print("install test certificate ok!")
+ print(" - company: %s", company)
+ print(" - cerfile: %s", testcer)
+end
+
+-- entry function
+function main(action)
+
+ -- find wdk envirnoment first
+ local wdk = find_wdk()
+ assert(wdk, "wdk not found!")
+
+ -- install or uninstall test certificate
+ if action == "install" then
+ _install(wdk)
+ end
+end