更新 ukey 程序

This commit is contained in:
Cheney 2024-09-19 15:25:56 +08:00
parent 9dac075967
commit fd53c6a05c
8 changed files with 161 additions and 44 deletions

View File

@ -27,6 +27,33 @@
- taxonomy: 在线工具
icon: far fa-folder-open fa-lg
list:
- term: 基础设施
links:
- title: 网关
logo: nginx-proxy-manager.png
url: //www.fullstack.club:4081
description: 网关。
- title: 集群监控
logo: wg.png
url: //moniter.fullstack.club:9999/
description: 服务器集群监控。
- title: Kit
logo: anyway.png
url: //kit.fullstack.club
description: 手边的命令行脚本工具。
- title: Git
logo: gitea.png
url: //git.fullstack.club
description: Git Server & CICD。
- title: Nexus
logo: nexus.png
url: //nexus.fullstack.club:8081/
description: 内网 Maven 仓库。
# - title: TailBook
# logo: tailbook.ico
# url: //book.fullstack.club:8082/
# description: 私人图书管。
- term: 常用工具
links:
- title: 目标十字
@ -96,12 +123,6 @@
url: https://cn.vitejs.dev/
description: 下一代的前端工具链
- term: 开源
links:
- title: Kit
logo: anyway.png
url: http://kit.fullstack.club
description: 手边的命令行脚本工具。
# - term: 图标
# links:

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -24,6 +24,7 @@
border-radius: 10px;
width: 80%;
height: 80%;
min-height: 500px;
text-align: left;
}
@ -198,17 +199,17 @@
</div>
<div class="tab tab_pin" style="display: none">
<div class="group" style="width: 100%; ">
<input id="pwd2" style="width: 300px;height: 1.06rem" type="password" maxlength="8"
placeholder="口令8 个数字">
<button id="login2" style="margin-right: 1rem">&emsp;&emsp;</button>
<button id="login_def2" style="margin-right: 1rem">默认口令</button>
</div>
<!-- <div class="group" style="width: 100%; ">-->
<!-- <input id="pwd2" style="width: 300px;height: 1.06rem" type="password" maxlength="8"-->
<!-- placeholder="口令8 个数字">-->
<!-- <button id="login2" style="margin-right: 1rem">授&emsp;&emsp;权</button>-->
<!-- <button id="login_def2" style="margin-right: 1rem">默认口令</button>-->
<!-- </div>-->
<div class="form group">
<input id="old_pwd" style="width: 360px;height: 1.06rem" type="password" maxlength="8"
placeholder="口令8 个数字">
placeholder="口令8 个数字">
<input id="new_pwd1" style="width: 360px;height: 1.06rem" type="password" maxlength="8"
placeholder="新口令8 个数字">
<input id="new_pwd2" style="width: 360px;height: 1.06rem" type="password" maxlength="8"
@ -308,11 +309,22 @@
}
})
$("#login2_def").click(function () {
$("#pwd2").val("12345678");
$("#login2").click()
$("#login_def2").click(function () {
var pwd2 = "11111111"
$("#pwd2").val(pwd2);
var ukey = $("#ukeys").val();
try {
window.UKey.admin(ukey, pwd2)
success("登录成功")
} catch (e) {
alert("登录失败:" + e.message)
}
})
$("#login").click(function () {
var pwd1 = $("#pwd1").val();
check(pwd1, /\d{8}/, "口令输入错误")
@ -495,13 +507,52 @@
$("#reset").click(function () {
alert("暂不开放")
var ukey = $("#ukeys").val();
// 重置口令
var old_pwd = $("#old_pwd").val()
try {
window.UKey.admin(ukey, old_pwd)
success("授权成功")
} catch (e) {
alert("授权失败:" + e.message)
return
}
var new_pwd1 = $("#new_pwd1").val()
var new_pwd2 = $("#new_pwd2").val()
if ( new_pwd1 !== new_pwd2 ) {
alert("新口令两次不同")
} else {
window.UKey.updatePin(3, old_pwd, new_pwd1);
alert("执行成功")
}
})
$("#update1").click(function () {
alert("暂不开放")
var old_pwd = $("#old_pwd").val()
var new_pwd1 = $("#new_pwd1").val()
var new_pwd2 = $("#new_pwd2").val()
if ( new_pwd1 !== new_pwd2 ) {
alert("新口令两次不同")
} else {
window.UKey.updatePin(1, old_pwd, new_pwd1);
alert("执行成功")
}
})
$("#update2").click(function () {
alert("暂不开放")
var old_pwd = $("#old_pwd").val()
var new_pwd1 = $("#new_pwd1").val()
var new_pwd2 = $("#new_pwd2").val()
if ( new_pwd1 !== new_pwd2 ) {
alert("新口令两次不同")
} else {
window.UKey.updatePin(2, old_pwd, new_pwd1);
alert("执行成功")
}
})
})

View File

@ -3,7 +3,7 @@
var DIR = "\\root\\mana"
var FISECKEY = root.FISECKEY;
var hDevice = undefined;
var fileSize = 4096;
var fileSize = 4 * 1024;
if ( ! FISECKEY ) {
console.error("缺少 FISECKEY 支持 !!!")
@ -67,6 +67,10 @@
}
sum += "";
if ( sum.length < 4 ) {
sum = "0000" + sum
}
// 截取最后 2 字节
return sum.substr( sum.length -4 );
}
@ -76,15 +80,16 @@
}
FISECKEY.FILE_Init(hDevice);
FISECKEY.FILE_CreateDir(hDevice, DIR, 0);
FISECKEY.FILE_CreateFile(hDevice, DIR, "name", fileSize, 0);
FISECKEY.FILE_CreateDir(hDevice, DIR, 0);
FISECKEY.FILE_CreateFile(hDevice, DIR, "name", 1024, 0);
FISECKEY.GenECCKeypair(hDevice, 0, 256, 1);
var data = JSON.stringify(info)
writeFile(DIR, "name", data)
writeFile(DIR, "name", data, 1024)
readFile(DIR, "name")
@ -98,18 +103,52 @@
FISECKEY.FILE_DeleteFile(hDevice, dir, file);
}
function readData(hDevice, dir, file, off, len){
var data = "";
if ( len <= 1024 ) {
return FISECKEY.FILE_ReadFile(hDevice, dir, file, off, len);
}
else {
var curLen = 0;
while ( curLen < len ) {
var readLen = 1024;
if ( (len - curLen) <= 1024 ) {
// 剩余量小于= 1024
readLen = len - curLen;
} else {
// 剩余量大于 1024
readLen = 1024
}
data += FISECKEY.FILE_ReadFile(hDevice, dir, file, off + curLen, readLen);
curLen += readLen
}
return data;
}
}
function readFile(dir, file) {
if ( ! hDevice ) {
throw new Error("设备未登录")
}
var len = FISECKEY.FILE_ReadFile(hDevice, dir, file, 0, 2);
var len = FISECKEY.FILE_ReadFile(hDevice, dir, file, 0, 3);
console.log("read "+ file + " lenAsHex=", len, )
len = parseInt( len, 10 );
console.log("read "+ file + " len=", len)
var data = FISECKEY.FILE_ReadFile(hDevice, dir, file, 2, len);
var data = readData(hDevice, dir, file, 3, len);
console.log("read "+ file + " data=", data)
var sum = sumHash(data);
var hash = FISECKEY.FILE_ReadFile(hDevice, dir, file, 2 + len, 2);
var hash = FISECKEY.FILE_ReadFile(hDevice, dir, file, 3 + len, 2);
if ( sum === hash ) {
var str = hexToString(data);
@ -131,39 +170,45 @@
}
function writeFile(dir, file, data){
function writeFile(dir, file, data, keep, size){
if ( ! hDevice ) {
throw new Error("设备未登录")
}
if ( ! keep ) {
if ( !size ) {
size = fileSize
}
try {
FISECKEY.FILE_DeleteFile(hDevice, dir, file);
}catch (e) {
}
FISECKEY.FILE_CreateFile(hDevice, dir, file, size, 0);
}
FISECKEY.FILE_CreateFile(hDevice, dir, file, fileSize, 0);
console.log( "write", data )
console.log( "data.length" , data.length )
console.log( "write "+ file + " data=", data )
console.log( "write "+ file + " data.length" , data.length )
data = stringToHex( data ).toUpperCase()
var len = data.length / 2
len = "0000" + len;
len = len.substr( len.length -4 );
FISECKEY.FILE_WriteFile(hDevice, dir, file, 0, 2, len);
writeData(hDevice, dir, file, 2, data.length/2, data)
len = "000000" + len;
len = len.substr( len.length -6 );
console.log("write "+ file + " head=", len)
FISECKEY.FILE_WriteFile(hDevice, dir, file, 0, 3, len);
writeData(hDevice, dir, file, 3, data.length/2, data)
// console.log( "writeFile=" + len )
// console.log( "writeFile=" + data )
// console.log( "writeFile=" + data.length )
console.log("w2")
var hash = sumHash(data);
console.log("write "+ file + " hash=", hash)
// console.log( "writeFile hash=" + hash )
FISECKEY.FILE_WriteFile(hDevice, dir, file, 2 + (data.length/2), 2, hash);
FISECKEY.FILE_WriteFile(hDevice, dir, file, 3 + (data.length/2), 2, hash);
}
// 枚举序列号与名称
@ -289,8 +334,8 @@
/**
* 修改口令
*/
function updatePin(oldpin, newpin){
FISECKEY.USER_ChangePin(hDevice, 1, oldpin, newpin);
function updatePin(flag, oldpin, newpin){
FISECKEY.USER_ChangePin(hDevice, 3, oldpin, newpin);
}
function exportPk(){