mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-20 21:59:23 -04:00
Signed-off-by: wangchun17 <chunn.wang@huawei.com> Change-Id: Ia53b238db2fc7d574304950e5692460bc2eee30f
This commit is contained in:
@@ -8,19 +8,17 @@ ace_loader_lib_dir =
|
||||
get_label_info(":build_ace_loader_library", "target_out_dir") + "/lib"
|
||||
|
||||
action("build_ace_loader_library") {
|
||||
script = "//foundation/ace/huawei_proprietary/tools/ace-loader/build_ace_loader_library.py"
|
||||
script = "//developtools/ace-js2bundle/build_ace_loader_library.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
outputs = [ ace_loader_lib_dir ]
|
||||
|
||||
_ace_loader_dir =
|
||||
"//foundation/ace/huawei_proprietary/tools/ace-loader/ace-loader"
|
||||
_ace_toolkit_dir = "//prebuilts/ace-toolkit/ace-loader/linux-x64"
|
||||
_ace_loader_dir = "//developtools/ace-js2bundle/ace-loader"
|
||||
|
||||
_module_source_js = _ace_loader_dir + "/module-source.js"
|
||||
|
||||
_babel_js = _ace_toolkit_dir + "/node_modules/@babel/cli/bin/babel.js"
|
||||
_babel_config_js = _ace_toolkit_dir + "/babel.config.js"
|
||||
_uglify_source_js = _ace_toolkit_dir + "/uglify-source.js"
|
||||
_babel_js = _ace_loader_dir + "/node_modules/@babel/cli/bin/babel.js"
|
||||
_babel_config_js = _ace_loader_dir + "/babel.config.js"
|
||||
_uglify_source_js = _ace_loader_dir + "/uglify-source.js"
|
||||
|
||||
inputs = [
|
||||
_babel_config_js,
|
||||
@@ -32,10 +30,9 @@ action("build_ace_loader_library") {
|
||||
# different host platform nodejs tool directory
|
||||
if (host_os == "linux") {
|
||||
nodejs_path =
|
||||
"//prebuilts/ace-toolkit/nodejs/node-v12.18.4-linux-x64/bin/node"
|
||||
"//prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin/node"
|
||||
} else if (host_os == "mac") {
|
||||
nodejs_path =
|
||||
"//prebuilts/ace-toolkit/nodejs/node-v12.18.4-darwin-x64/bin/node"
|
||||
nodejs_path = "//prebuilts/build-tools/common/nodejs/node-v12.18.4-darwin-x64/bin/node"
|
||||
} else {
|
||||
assert(false, "Unsupported host_os: $host_os")
|
||||
}
|
||||
@@ -48,8 +45,7 @@ action("build_ace_loader_library") {
|
||||
"--babel-js",
|
||||
rebase_path(_babel_js, root_build_dir),
|
||||
"--weex-loader-src-dir",
|
||||
rebase_path(_ace_loader_dir + "/third_party/weex-loader/src",
|
||||
root_build_dir),
|
||||
rebase_path("//third_party/weex-loader/src", root_build_dir),
|
||||
"--ace-loader-src-dir",
|
||||
rebase_path(_ace_loader_dir + "/src", root_build_dir),
|
||||
"--babel-config-js",
|
||||
@@ -72,11 +68,9 @@ ohos_copy("ace_loader") {
|
||||
"ace-loader/npm-install.js",
|
||||
"ace-loader/package-lock.json",
|
||||
"ace-loader/package.json",
|
||||
"ace-loader/router",
|
||||
"ace-loader/sample",
|
||||
"ace-loader/webpack.lite.config.js",
|
||||
"ace-loader/webpack.rich.config.js",
|
||||
"ace-loader/webpack.router.config.js",
|
||||
]
|
||||
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
|
||||
module_source_dir = target_out_dir + "/$target_name/"
|
||||
|
||||
@@ -68,6 +68,6 @@ function copyResource(src, dist) {
|
||||
copyResource(path.resolve(__dirname, './plugin/templater'), process.argv[2] + '/templater');
|
||||
copyResource(path.resolve(__dirname, './plugin/theme'), process.argv[2] + '/theme');
|
||||
copyResource(path.resolve(__dirname, './plugin/codegen'), process.argv[2] + '/codegen');
|
||||
copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-scripter'), process.argv[2] + '/scripter');
|
||||
copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-styler'), process.argv[2] + '/styler');
|
||||
copyResource(path.resolve(__dirname, '../../../../../../third_party/parse5/packages/parse5/lib'), process.argv[2] + '/parse');
|
||||
copyResource(path.resolve(__dirname, '../../../third_party/weex-loader/deps/weex-scripter'), process.argv[2] + '/scripter');
|
||||
copyResource(path.resolve(__dirname, '../../../third_party/weex-loader/deps/weex-styler'), process.argv[2] + '/styler');
|
||||
copyResource(path.resolve(__dirname, '../../../third_party/parse5/packages/parse5/lib'), process.argv[2] + '/parse');
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
const os = require("os")
|
||||
const http = require("http");
|
||||
const crypto = require('crypto');
|
||||
|
||||
const localHost = '127.0.0.1'
|
||||
const uri = '/api/system/deviceinfo'
|
||||
const timeout = 300
|
||||
const IPv4 = 'IPv4'
|
||||
const SHA256 = 'SHA256'
|
||||
const hex = 'hex'
|
||||
|
||||
function fliterAlias(alias) {
|
||||
return alias.family === IPv4 && alias.address !== localHost && !alias.internal
|
||||
}
|
||||
|
||||
function getIP() {
|
||||
let IPAdress = [];
|
||||
Object.values(os.networkInterfaces()).forEach(
|
||||
iface => iface.filter(fliterAlias).forEach(
|
||||
alias => {
|
||||
ip = alias.address.replace(/\.\d+$/, '.1')
|
||||
!IPAdress.includes(ip) && IPAdress.push(ip)
|
||||
}
|
||||
)
|
||||
);
|
||||
return IPAdress;
|
||||
}
|
||||
|
||||
async function getName(ip) {
|
||||
return await new Promise(resolve => {
|
||||
let req = http.get(`http://${ip}${uri}`, { timeout: timeout }, resp => {
|
||||
if (resp.statusCode != 200) {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
|
||||
resp.setEncoding('utf8');
|
||||
let ret = "";
|
||||
resp.on('data', chunk => ret += chunk);
|
||||
resp.on('end', () => {
|
||||
try {
|
||||
const parsedData = JSON.parse(ret)
|
||||
resolve({ ip, name: parsedData.FriendlyName, udid: crypto.createHash(SHA256).update(parsedData.uuid).digest(hex) });
|
||||
} catch (error) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
req.on("error", () => {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
}).on("timeout", () => {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let ipArr = getIP();
|
||||
let ret = [];
|
||||
for (let i = 0; i < ipArr.length; i++) {
|
||||
let route = await getName(ipArr[i]);
|
||||
route && ret.push(route)
|
||||
}
|
||||
console.info("resp : 200");
|
||||
console.info(JSON.stringify(ret));
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
let aceModuleRoot = process.env.aceModuleRoot;
|
||||
const buildPath = process.env.aceModuleBuild;
|
||||
|
||||
const config = path.join(aceModuleRoot, "../../config.json");
|
||||
const appJSPath = path.join(aceModuleRoot, "app.js");
|
||||
let pluginInfo = {};
|
||||
|
||||
loadEntryObj();
|
||||
|
||||
function loadEntryObj() {
|
||||
const red = "\u001b[31m";
|
||||
const reset = "\u001b[39m";
|
||||
|
||||
if (!fs.existsSync(config)) {
|
||||
throw Error(red + "ERROR: missing config" + reset).message;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(appJSPath)) {
|
||||
throw Error(red + "ERROR: missing app.js" + reset).message;
|
||||
}
|
||||
|
||||
pluginInfo = JSON.parse(fs.readFileSync(config, {
|
||||
encoding: "utf-8"
|
||||
}));
|
||||
|
||||
if (!(pluginInfo && pluginInfo.app && pluginInfo.app.bundleName && pluginInfo.app.version.name)) {
|
||||
throw Error(red + "ERROR: mainfest context invalid" + JSON.stringify(pluginInfo)).message;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
appJSPath,
|
||||
pluginInfo,
|
||||
buildPath: buildPath,
|
||||
projectPath: aceModuleRoot,
|
||||
manifestFilePath: config,
|
||||
pkgName: pluginInfo.app.bundleName,
|
||||
hapName: pluginInfo.app.bundleName + "-" + pluginInfo.app.version.name + "_unsigned",
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
module.exports = function (context) {
|
||||
if (this.query == undefined || this.query.pkgName == undefined) {
|
||||
throw Error("custom loader haven't recv the pkgName");
|
||||
}
|
||||
return context.replace(
|
||||
/import (\w+) from [\'\"]{1}@system\.(\w+)[\'\"]{1}/g,
|
||||
`var $1 = requireNative('${this.query.pkgName}','$2')`
|
||||
);
|
||||
};
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const http = require("http");
|
||||
const os = require("os");
|
||||
const { login, GET, POST, decryptStr2Str } = require("./pushHelper");
|
||||
|
||||
let localIp = undefined;
|
||||
let argv = getArgv();
|
||||
|
||||
checkArgv();
|
||||
|
||||
let pwd = decryptStr2Str(argv.metePath, argv.session);
|
||||
if (pwd == undefined) {
|
||||
finish(12, "incorrect password.");
|
||||
}
|
||||
|
||||
function constainsKey(array, key) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i].pkgName === key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
let cnt = 0;
|
||||
function getErr(data) {
|
||||
if (cnt == 20) {
|
||||
POST(`http://${argv.ip}/api/system/user_logout`);
|
||||
finish(41, "install timeout");
|
||||
}
|
||||
cnt++;
|
||||
|
||||
GET(`http://${argv.ip}/api/hap/all_infos`).then(
|
||||
allInfos => {
|
||||
if (constainsKey(allInfos.installedHap, data.pkgName)) {
|
||||
POST(`http://${argv.ip}/api/system/user_logout`);
|
||||
finish(31, "install success.");
|
||||
}
|
||||
if (constainsKey(allInfos.installingHap, data.pkgName)) {
|
||||
return;
|
||||
}
|
||||
return POST(`http://${argv.ip}/api/acelite/get_err`, data);
|
||||
}
|
||||
).then(
|
||||
errInfo => {
|
||||
POST(`http://${argv.ip}/api/system/user_logout`);
|
||||
if (errInfo.errCode == 404) {
|
||||
finish(30, "no interface.");
|
||||
}
|
||||
finish(errInfo.errCode, "install fail");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
login(argv.ip, pwd).then(res => {
|
||||
if (res == undefined) {
|
||||
finish(10, "internal error.");
|
||||
};
|
||||
|
||||
if (res.err == 0) {
|
||||
let port = createListen(argv.file);
|
||||
if (port == null) {
|
||||
finish(8, "create the file server failed.");
|
||||
}
|
||||
|
||||
let data = {
|
||||
pkgName: argv.pkgName,
|
||||
name: argv.name,
|
||||
versionName: argv.versionName || "1.0.0",
|
||||
versionCode: parseInt(argv.versionCode) || 1,
|
||||
appId: argv.appId || "C" + new Date().getTime(),
|
||||
downloadUrl: `http://${localIp}:${port}/signed.hap`,
|
||||
iconUrl: "https://appimg.dbankcdn.com/application/icon144/a02cb676dfdf49ccad87471b421a5276.png",
|
||||
isDebug: 1,
|
||||
};
|
||||
|
||||
POST(`http://${argv.ip}/api/acelite/hap_delete`, data).then(
|
||||
() => {
|
||||
return POST(`http://${argv.ip}/api/acelite/hap_debug`, data);
|
||||
}
|
||||
).then(
|
||||
res => {
|
||||
if (res.errcode != 0) {
|
||||
finish(14, "push fail.");
|
||||
}
|
||||
setInterval(()=>getErr(data), 3000);
|
||||
}
|
||||
);
|
||||
} else if ((res.err == 4784230 || res.err == 4784231) && res.waitTime) {
|
||||
finish(13, "too many errors. Please try again later.");
|
||||
} else {
|
||||
finish(9, "login failed.");
|
||||
}
|
||||
}).catch(err => {
|
||||
finish(10, "internal error.");
|
||||
});
|
||||
|
||||
if (!argv.file) {
|
||||
finish(2, "Path is null")
|
||||
}
|
||||
|
||||
function checkArgv() {
|
||||
if (!argv.ip || !(localIp = getLocalIp(argv.ip))) {
|
||||
finish(1, "ip error")
|
||||
}
|
||||
if (!argv.file || !fs.existsSync(argv.file)) {
|
||||
finish(2, "file error.")
|
||||
}
|
||||
if (!argv.metePath || !fs.statSync(argv.metePath).isDirectory()) {
|
||||
finish(3, "metePath error.")
|
||||
}
|
||||
if (!argv.session) {
|
||||
finish(4, "session error.")
|
||||
}
|
||||
if (!argv.pkgName) {
|
||||
finish(5, "pkgName error.")
|
||||
}
|
||||
if (!argv.name) {
|
||||
finish(6, "name error.")
|
||||
}
|
||||
}
|
||||
|
||||
function finish(code, msg) {
|
||||
process.exit(code)
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to external download requirements on random port from 9000 to 9100.
|
||||
* @param {String} hapPath hap file path.
|
||||
* @return {Number} service port.
|
||||
*/
|
||||
function createListen(hapPath) {
|
||||
/* Generate a random number 9000~9100. randomBytes() return number is 0~255. */
|
||||
let port = 9000 + Math.round(new Uint8Array(crypto.randomBytes(1))[0] * 100 / 255);
|
||||
|
||||
let server = http.createServer(function (req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Disposition': 'attachment; filename=' + path.basename(hapPath),
|
||||
"Content-Length": fs.statSync(hapPath).size
|
||||
});
|
||||
fs.createReadStream(hapPath).pipe(res);
|
||||
server.close();
|
||||
}).listen(port);
|
||||
|
||||
server.on("error", () => {
|
||||
finish(8, "create the file server failed.");
|
||||
})
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parameter from command.
|
||||
* @return {Object} Object of parameter
|
||||
*/
|
||||
function getArgv() {
|
||||
let ret = {};
|
||||
process.argv.splice(2).forEach((value, index, array) => {
|
||||
if (/^--[a-zA-Z]+/.test(value)) {
|
||||
if (index < array.length - 1 && /[^-]+/.test(array[index + 1])) {
|
||||
ret[value.substr(2)] = array[index + 1];
|
||||
} else {
|
||||
ret[value.substr(2)] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getLocalIp(ip) {
|
||||
let localIp = undefined;
|
||||
Object.values(os.networkInterfaces()).forEach(
|
||||
iface => {
|
||||
iface.forEach(
|
||||
alias => {
|
||||
if (alias.address.replace(/\.\d+$/, '.1') == ip) {
|
||||
localIp = alias.address;
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (localIp) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
return localIp;
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
var http = require("http");
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
let ip = undefined;
|
||||
let pwd = undefined;
|
||||
let csrf = {};
|
||||
let globalCookie = '';
|
||||
|
||||
const defaultHeader = {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
Accept: 'application/json, text/javascript, */*; q=0.01',
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
}
|
||||
|
||||
module.exports = { decryptStr2Str, login, GET, POST };
|
||||
|
||||
function login(ipParam, pwdParam) {
|
||||
return new Promise(async resolve => {
|
||||
if (!ipParam || pwdParam == undefined) {
|
||||
resolve();
|
||||
}
|
||||
ip = ipParam;
|
||||
pwd = pwdParam;
|
||||
|
||||
await GET(`http://${ip}/api/system/deviceinfo`);
|
||||
|
||||
let count = 0;
|
||||
let proofData = undefined;
|
||||
do {
|
||||
let firstNonce = crypto.createHash('sha256').update(crypto.randomBytes(8)).digest("hex");
|
||||
let res = await POST(`http://${ip}/api/system/user_login_nonce`, { username: 'admin', firstnonce: firstNonce })
|
||||
|
||||
if (res.err != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
proofData = getProofData(res, firstNonce);
|
||||
} while (!proofData && ++count < 5);
|
||||
|
||||
if (proofData == undefined) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
res = await POST(`http://${ip}/api/system/user_login_proof`, proofData)
|
||||
resolve(res);
|
||||
});
|
||||
};
|
||||
|
||||
function getProofData(res, firstNonce) {
|
||||
if (!res || res.err != 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let iter = res.iterations;
|
||||
let finalNonce = res.servernonce;
|
||||
let salt = res.salt;
|
||||
if (!iter || !finalNonce || !salt) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let authMsg = firstNonce + "," + finalNonce + "," + finalNonce;
|
||||
let saltPwd = crypto.pbkdf2Sync(Buffer.from(stringToByte(pwd)), hexStringToByte(salt), iter, 32, "sha256");
|
||||
let clientKey = crypto.createHmac("sha256", "Client Key").update(saltPwd).digest();
|
||||
let storekey = crypto.createHash("sha256").update(clientKey).digest();
|
||||
let clientsignature = crypto.createHmac("sha256", authMsg).update(storekey).digest();
|
||||
let len = clientKey.byteLength;
|
||||
let clientproof = Buffer.alloc(len);
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
clientproof.writeUInt8(clientKey.readUInt8(i) ^ clientsignature.readUInt8(i), i);
|
||||
}
|
||||
|
||||
clientproof = clientproof.toString("hex")
|
||||
|
||||
return {
|
||||
clientproof: clientproof,
|
||||
finalnonce: finalNonce
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function refreshSession(header, ret) {
|
||||
let cookie = header && header["set-cookie"] && header["set-cookie"][0];
|
||||
|
||||
cookie && (globalCookie = (cookie.substring(0, cookie.indexOf(";"))));
|
||||
ret.csrf_param && (csrf.csrf_param = ret.csrf_param);
|
||||
ret.csrf_token && (csrf.csrf_token = ret.csrf_token);
|
||||
}
|
||||
|
||||
function POST(url, data) {
|
||||
return new Promise(resolve => {
|
||||
let req = http.request(url, {
|
||||
method: "post",
|
||||
timeout: 300,
|
||||
headers: {
|
||||
...defaultHeader,
|
||||
Cookie: globalCookie
|
||||
}
|
||||
}, resp => {
|
||||
if (resp.statusCode != 200) {
|
||||
resolve({errCode: 404});
|
||||
return;
|
||||
}
|
||||
|
||||
let ret = "";
|
||||
resp.on('data', chunk => ret += chunk);
|
||||
resp.on('end', () => {
|
||||
try{
|
||||
ret = JSON.parse(ret);
|
||||
}catch(err) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
refreshSession(resp.headers, ret);
|
||||
resolve(ret);
|
||||
});
|
||||
});
|
||||
|
||||
req.write(JSON.stringify({
|
||||
data,
|
||||
csrf,
|
||||
}));
|
||||
req.end();
|
||||
|
||||
req.on("error", () => {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
}).on("timeout", () => {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function GET(url) {
|
||||
return new Promise(resolve => {
|
||||
let req = http.get(url, {
|
||||
timeout: 300, headers: {
|
||||
...defaultHeader,
|
||||
Cookie: globalCookie
|
||||
}
|
||||
}, resp => {
|
||||
let ret = "";
|
||||
resp.on('data', chunk => ret += chunk);
|
||||
resp.on('end', () => {
|
||||
ret = JSON.parse(ret);
|
||||
refreshSession(resp.headers, ret);
|
||||
resolve(ret);
|
||||
});
|
||||
});
|
||||
|
||||
req.on("error", () => {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
}).on("timeout", () => {
|
||||
req.destroy();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fd Root key component directory.
|
||||
* ac Directory for storing the salt used to generate the final root key in iteration mode.
|
||||
* ce work key material directory
|
||||
*/
|
||||
const comDirs = ["fd", "ac", "ce"];
|
||||
|
||||
/**
|
||||
* Root path of key materials. All materials are stored in this path.
|
||||
*/
|
||||
const meteDir = "material";
|
||||
|
||||
/**
|
||||
* A part of the root key component. It must work with other components to form a root key.
|
||||
* For details, see the Key Management Security Specifications V1.3.
|
||||
*/
|
||||
let COMPONENT = Array.from(new Int8Array([
|
||||
0x31, 0xf3, 0x09, 0x73, 0xd6, 0xaf, 0x5b, 0xb8,
|
||||
0xd3, 0xbe, 0xb1, 0x58, 0x65, 0x83, 0xc0, 0x77
|
||||
]));
|
||||
|
||||
function decryptStr2Str(rootPath, input) {
|
||||
let metePath = path.resolve(rootPath, meteDir);
|
||||
let components = readComponents(metePath);
|
||||
let saltDir = path.resolve(metePath, comDirs[1]);
|
||||
let salt = readDirBytes(saltDir);
|
||||
let rootKey = deriveRootKey(components, salt);
|
||||
let workMeteDir = path.resolve(metePath, comDirs[2]);
|
||||
let workMete = readDirBytes(workMeteDir);
|
||||
let key = decrypt(rootKey, workMete);
|
||||
let bts = hexStringToByte(input);
|
||||
|
||||
let output = decrypt(key, bts);
|
||||
return (Buffer.from(output).toString("utf-8"));
|
||||
}
|
||||
|
||||
function hexStringToByte(str) {
|
||||
if (!str) {
|
||||
return new Uint8Array();
|
||||
}
|
||||
|
||||
var a = [];
|
||||
for (var i = 0, len = str.length; i < len; i += 2) {
|
||||
a.push(parseInt(str.substr(i, 2), 16));
|
||||
}
|
||||
|
||||
return new Int8Array(a);
|
||||
}
|
||||
|
||||
function decrypt(rootKey, workMete) {
|
||||
if (workMete.length < 32) {
|
||||
return null;
|
||||
}
|
||||
let bodyLength = ((workMete[0] & 0xFF) << 24) | ((workMete[1] & 0xFF) << 16) | ((workMete[2] & 0xFF) <<
|
||||
8) | ((workMete[3] & 0xFF));
|
||||
|
||||
let iv = workMete.slice(4, workMete.length - bodyLength);
|
||||
|
||||
let cipher = crypto.createCipheriv("aes-128-gcm", new Int8Array(rootKey), new Int8Array(iv), {
|
||||
authTagLength: 16
|
||||
});
|
||||
let encrypted = cipher.update(new Int8Array(workMete.slice(workMete.length - bodyLength)))
|
||||
cipher.final();
|
||||
return new Int8Array(encrypted).slice(0, bodyLength - 16);
|
||||
|
||||
}
|
||||
|
||||
function deriveRootKey(components, salt) {
|
||||
let fullComponents = components;
|
||||
fullComponents.push(COMPONENT);
|
||||
let finalComponent = sortFullComponent(fullComponents);
|
||||
let key = Array.from(new Int8Array(crypto.pbkdf2Sync(finalComponent, new Int8Array(salt), 10000, 16, "sha256")));
|
||||
return key;
|
||||
}
|
||||
|
||||
function sortFullComponent(fullComponents) {
|
||||
let ret = fullComponents[0];
|
||||
for (let i = 1; i < fullComponents.length; i++) {
|
||||
ret = xor(ret, fullComponents[i]);
|
||||
}
|
||||
return new Int8Array(stringToByte(Buffer.from(ret).toString("utf-8")));
|
||||
}
|
||||
|
||||
function stringToByte(str) {
|
||||
var bytes = new Array();
|
||||
var len, c;
|
||||
len = str.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
c = str.charCodeAt(i);
|
||||
if (c >= 0x010000 && c <= 0x10FFFF) {
|
||||
bytes.push(((c >> 18) & 0x07) | 0xF0);
|
||||
bytes.push(((c >> 12) & 0x3F) | 0x80);
|
||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else if (c >= 0x000800 && c <= 0x00FFFF) {
|
||||
bytes.push(((c >> 12) & 0x0F) | 0xE0);
|
||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else if (c >= 0x000080 && c <= 0x0007FF) {
|
||||
bytes.push(((c >> 6) & 0x1F) | 0xC0);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else {
|
||||
bytes.push(c & 0xFF);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
function xor(arr1, arr2) {
|
||||
if (!arr1 || !arr2 || arr1.length != arr2.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let ret = [];
|
||||
for (let i = 0; i < arr1.length; i++) {
|
||||
ret.push(arr1[i] ^ arr2[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function readDirBytes(dir) {
|
||||
let files = fs.readdirSync(dir);
|
||||
if (files.length != 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Array.from(new Int8Array(fs.readFileSync(path.resolve(dir, files[0]))));
|
||||
}
|
||||
|
||||
function readComponents(dir) {
|
||||
let files = fs.readdirSync(path.resolve(dir, comDirs[0]));
|
||||
if (files == null || files.length != 3) {
|
||||
return null;
|
||||
}
|
||||
let ret = [];
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
ret.push(readDirBytes(path.resolve(dir, comDirs[0], files[i])));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
const main = require("./router/main.product.router.js");
|
||||
const path = require("path");
|
||||
|
||||
module.exports = {
|
||||
entry: main.appJSPath,
|
||||
output: {
|
||||
path: main.buildPath,
|
||||
filename: "app.js",
|
||||
libraryTarget: "this",
|
||||
library: main.pkgName,
|
||||
libraryExport: "default",
|
||||
},
|
||||
target: "node",
|
||||
mode: "production",
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.js$/,
|
||||
use: [{
|
||||
loader: path.resolve(__dirname, "node_modules/babel-loader"),
|
||||
options: {
|
||||
presets: [
|
||||
path.resolve(__dirname, "node_modules/@babel/preset-env"),
|
||||
],
|
||||
configFile: false
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: path.resolve(__dirname, "router/module-scipt-router.js"),
|
||||
options: {
|
||||
pkgName: main.pkgName,
|
||||
},
|
||||
},
|
||||
],
|
||||
}],
|
||||
},
|
||||
};
|
||||
Regular → Executable
+2
-3
@@ -19,9 +19,8 @@ import subprocess
|
||||
import argparse
|
||||
|
||||
sys.path.append(
|
||||
os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir,
|
||||
os.pardir, os.pardir, 'build'))
|
||||
from maple.java.util import build_utils # noqa: E402
|
||||
os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'build'))
|
||||
from scripts.util import build_utils # noqa: E402
|
||||
|
||||
|
||||
def parse_args():
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
module.exports = function(api) {
|
||||
api.cache(true);
|
||||
|
||||
const presets = ['@babel/preset-env'];
|
||||
const plugins = [
|
||||
'@babel/plugin-transform-modules-commonjs',
|
||||
'@babel/plugin-proposal-class-properties',
|
||||
'@babel/plugin-transform-runtime',
|
||||
[
|
||||
'@babel/plugin-transform-arrow-functions',
|
||||
{
|
||||
spec: true,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
return {
|
||||
presets,
|
||||
plugins,
|
||||
};
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const uglifyJS = require('uglify-es')
|
||||
|
||||
readCode(process.argv[2])
|
||||
|
||||
function readCode(inputPath) {
|
||||
if (fs.existsSync(inputPath)) {
|
||||
const files = fs.readdirSync(inputPath)
|
||||
files.forEach(function(file) {
|
||||
const filePath = path.join(inputPath, file)
|
||||
if (fs.existsSync(filePath)) {
|
||||
const fileStat = fs.statSync(filePath)
|
||||
if (fileStat.isFile()) {
|
||||
const code = fs.readFileSync(filePath, 'utf-8')
|
||||
uglifyCode(code,filePath)
|
||||
}
|
||||
if (fileStat.isDirectory()) {
|
||||
readCode(filePath)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function uglifyCode(code, outPath) {
|
||||
const uglifyCode = uglifyJS.minify(code).code
|
||||
fs.writeFileSync(outPath, uglifyCode)
|
||||
}
|
||||
Reference in New Issue
Block a user