This commit is contained in:
cheney
2023-08-09 13:58:15 +08:00
parent dd6405ff4d
commit f42de135d5
2250 changed files with 0 additions and 314928 deletions
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
-65
View File
@@ -1,65 +0,0 @@
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function hexToStr(hex,encoding) {
var trimedStr = hex.trim();
var rawStr = trimedStr.substr(0, 2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr;
var len = rawStr.length;
if (len % 2 !== 0) {
alert("Illegal Format ASCII Code!");
return "";
}
var curCharCode;
var resultStr = [];
for (var i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16);
resultStr.push(curCharCode);
}
// encoding为空时默认为utf-8
var bytesView = new Uint8Array(resultStr);
var str = new TextDecoder(encoding).decode(bytesView);
return str;
}
/**
* 输入 json 格式的授信信息
* 返回 hex 格式的登录信息
*/
function auth( info ){
var str = "";
var manufactor = info.manufactor + " ";
manufactor.substr(0, 8);
var system = info.system + " ";
system.substr(0, 8);
var customer = info.customer;
str = manufactor + system + customer
return stringToHex( str )
}
// 测试
var test = {
"manufactor": "sunyard",
"system": "hsm",
"customer": "ICBC"
}
console.log( auth(test) )
console.log("hexToStr=" + hexToStr("73756e796172642068736d202020202049434243", "UTF-8"))
// 73756e79617264202020202020202068736d202020202020202049434243
// 73756e796172642068736d202020202049434243
-460
View File
@@ -1,460 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>U 盾维护工具</title>
<style>
:root {
--mainColor: salmon;
}
html, body {
margin: 0;
width: 100%;
height: 100%;
}
.title {
color: var(--mainColor);
}
.container {
margin: 2rem auto;
border: var(--mainColor) solid 2px;
border-radius: 10px;
width: 80%;
height: 80%;
text-align: left;
}
.group {
padding: 1rem;
margin: 1rem;
}
.form input {
display: block;
margin: 0.5rem 0;
}
</style>
<link rel="stylesheet" type="text/css" href="tabs.css">
<link rel="stylesheet" type="text/css" href="layx.min.css">
</head>
<body>
<div style="width: 100%; text-align: center;">
<h2 class="title">信雅达 UKey 发行工具</h2>
</div>
<div class="container">
<div class="group" style="width: 100%; ">
<select id="ukeys" style="height: 1.5rem; width: 308px">
</select>
<button id="btn_refresh" style="margin-right: 1rem">刷&emsp;&emsp;新</button>
</div>
<div class="group" style="width: 100%;">
<input id="pwd1" style="width: 300px;height: 1.06rem" type="password" maxlength="8" placeholder="口令,8 个数字">
<button id="login" style="margin-right: 1rem">登&emsp;&emsp;录</button>
<button id="login_def" style="margin-right: 1rem">默认口令</button>
</div>
<div class="group" style="height: 10rem">
<ul class="tabs">
<li>
<a href="#" name="tab_public">UKey 发行</a>
</li>
<li>
<a href="#" name="tab_file">文件操作</a>
</li>
<li>
<a href="#" name="tab_sign">签名</a>
</li>
<li>
<a href="#" name="tab_pin">PIN 管理</a>
</li>
<li>
<a href="#" name="tab_active">驱动程序</a>
</li>
</ul>
<div class="tabs-content">
<div class="tab tab_public">
<div class="form">
<input id="manufactor" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="厂家标记">
<input id="system" style="width: 300px; height: 1.06rem" type="text" value="" placeholder="系统信息">
<input id="customer" style="width: 300px; height: 1.06rem" type="text" value="" placeholder="客户信息">
</div>
<div style="margin: 1rem 0 ">
<button id="btn_nameplate_clear" style="margin-right: 1rem">清空</button>
<button id="btn_nameplate_tmp_save" style="margin-right: 1rem">临存</button>
<button id="btn_nameplate_tmp_load" style="margin-right: 1rem">临取</button>
<button id="btn_nameplate_read" style="margin-right: 1rem">返显</button>
</div>
<button id="btn_nameplate_release" style="margin-right: 1rem">发&emsp;&emsp;行</button>
</div>
<div class="tab tab_file">
<input id="path" style="width: 300px; height: 1.06rem" type="text" value="\root\mana"
placeholder="文件目录">
<button id="btn_list_path" style="margin-right: 1rem">枚&emsp;&emsp;举</button>
<textarea id="ta_files" style="display: block; margin: 1rem 0; width: 375px; height: 100px;"
readonly></textarea>
<input id="filepath" style="width: 260px; height: 1.06rem" type="text" value="\root\mana\name"
placeholder="文件">
<button id="btn_read" style="margin-right: 0.5rem">读</button>
<button id="btn_write" style="margin-right: 0.5rem">写</button>
<button id="btn_delete" style="margin-right: 0.5rem">删</button>
<textarea id="ta_txt" style="display: block; margin: 1rem 0; width: 375px; height: 100px;"
></textarea>
</div>
<div class="tab tab_sign">
<textarea id="inData" style="display: block; margin: 1rem 0; width: 375px; height: 100px;" placeholder="输入签名文本"></textarea>
<button id="btn_sign" style="margin-right: 1rem">签&emsp;&emsp;名</button>
<textarea id="outData" style="display: block; margin: 1rem 0; width: 375px; height: 100px;" readonly></textarea>
</div>
<div class="tab tab_pin">
<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 个数字">
<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"
placeholder="重复新口令,8 个数字">
<button id="update1" style="margin-right: 1rem">修改操作员 PIN</button>
<button id="update2" style="margin-right: 1rem">修改管理员 PIN</button>
<button id="reset" style="margin-right: 1rem">解锁操作员 PIN</button>
</div>
</div>
<div class="tab tab_active" style="padding-top: 1rem">
<ul>
<li>
<h4 style="color: var(--mainColor);"><span>【2023年01月01日】</span> V1.0.1 <a href="./Setup_V1.0.1.exe" style="text-decoration:none; font-size: 0.5rem; font-weight: normal; cursor: pointer">(点击下载)</a> </h4>
<p>渔翁 UKey</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- UKey 支持, 共 3 个 js-->
<!-- jquery -->
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./fiseckey.js"></script>
<script type="text/javascript" src="./ukey.js"></script>
<script type="application/javascript" src="./gmhelper.js"></script>
<!-- 演示程序 -->
<script type="text/javascript" src="./tabs.js"></script>
<script type="application/javascript" src="layx.min.js"></script>
<script type="application/javascript" src="tools.js"></script>
<script type="application/javascript">
$(function () {
function refresh() {
var list = window.UKey.enumDevByArray()
if (list) {
var ll = list.split("|");
var options = ""
for (var i = 0; i < ll.length; i++) {
var value = ll[i].split(",")[0]
options += "<option value =\"" + value + "\">" + ll[i] + "</option>"
}
$("#ukeys").html(options);
}
}
refresh();
$("#btn_refresh").click(function () {
refresh()
success("刷新成功")
})
$("#btn_list_path").click(function () {
var path = $("#path").val();
try {
var ret = window.UKey.enumDir(path)
var out = ""
for (var i = 0; i < ret.folders.length; i++) {
out += "文件夹:\t" + ret.folders[i] + "\r\n"
}
for (var i = 0; i < ret.files.length; i++) {
out += "文件:\t" + ret.files[i] + "\r\n"
}
$("#ta_files").text(out)
success("枚举成功")
} catch (e) {
alert("枚举失败:" + e.message)
}
})
$("#login2").click(function () {
var pwd2 = $("#pwd2").val();
check(pwd2, /\d{8}/, "口令输入错误")
var ukey = $("#ukeys").val();
try {
window.UKey.admin(ukey, pwd2)
success("登录成功")
} catch (e) {
alert("登录失败:" + e.message)
}
})
$("#login2_def").click(function () {
$("#pwd2").val("12345678");
$("#login2").click()
})
$("#login").click(function () {
var pwd1 = $("#pwd1").val();
check(pwd1, /\d{8}/, "口令输入错误")
var ukey = $("#ukeys").val();
try {
window.UKey.login(ukey, pwd1)
success("登录成功")
} catch (e) {
alert("登录失败:" + e.message)
}
})
$("#login_def").click(function () {
$("#pwd1").val("12345678");
$("#login").click()
})
$("#btn_nameplate_clear").click(function () {
$("#manufactor").val("");
$("#system").val("");
$("#customer").val("");
})
$("#btn_read").click(function () {
try {
var filepath = $("#filepath").val()
var idx = filepath.lastIndexOf("\\")
var folder = filepath.substr(0, idx)
var file = filepath.substr(idx + 1)
var txt = window.UKey.readFile(folder, file);
txt = JSON.stringify(txt, null, 4)
$("#ta_txt").val( txt )
success("读取成功")
} catch (e) {
alert("读取失败:" + e.message)
}
})
$("#btn_write").click(function () {
// alert("暂不开放")
try {
var filepath = $("#filepath").val()
var idx = filepath.lastIndexOf("\\")
var folder = filepath.substr(0, idx)
var file = filepath.substr(idx + 1)
var txt = $("#ta_txt").val();
window.UKey.writeFile(folder, file, txt);
success("写入成功")
} catch (e) {
alert("写入失败:" + e.message)
}
})
$("#btn_delete").click(function () {
// alert("暂不开放")
try {
var filepath = $("#filepath").val()
var idx = filepath.lastIndexOf("\\")
var folder = filepath.substr(0, idx)
var file = filepath.substr(idx + 1)
window.UKey.deleteFile(folder, file);
success("删除成功")
} catch (e) {
alert("删除失败:" + e.message)
}
})
$("#btn_nameplate_tmp_load").click(function () {
var def = {
manufactor: "sunyard",
system: "hsm",
customer: "ICBC"
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_read").click(function () {
try {
var txt = window.UKey.catRelease();
var def = Object.assign({
manufactor: "",
system: "",
customer: ""
}, txt)
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
success("返显成功")
} catch (e) {
alert("返显失败:" + e.message)
}
})
$("#btn_nameplate_tmp_load").click(function () {
var json = localStorage.getItem("tmp")
var def = {
manufactor: "sunyard",
system: "hsm",
customer: "ICBC"
}
try {
def = JSON.parse(json)
} catch (e) {
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_tmp_save").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
localStorage.setItem("tmp", JSON.stringify(def))
})
$("#btn_nameplate_release").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
check(def.manufactor, /\w+/, "厂家标记填写错误")
check(def.system, /\w+/, "系统信息填写错误")
check(def.customer, /\w+/, "客户信息填写错误")
try {
window.UKey.release(def)
success("发行成功")
} catch (e) {
alert("发行失败:" + e.message)
}
})
$("#btn_sign").click(function () {
var inData = $("#inData").val()
// 公钥
var pk = window.UKey.exportPk();
var s = window.gmhelper.getHashAsBase64( inData, pk )
var outData = pk
outData += "\r\n\r\nz=" + s.z
outData += "\r\n\r\nhash=" + s.hashHex
var sign = window.UKey.sign( s.hashBase64 )
outData += "\r\n\r\nsign=" + sign
$("#outData").text(outData)
})
$("#reset").click(function () {
alert("暂不开放")
})
$("#update1").click(function () {
alert("暂不开放")
})
$("#update2").click(function () {
alert("暂不开放")
})
})
</script>
</body>
</html>
-4
View File
File diff suppressed because one or more lines are too long
-1
View File
File diff suppressed because one or more lines are too long
-5
View File
File diff suppressed because one or more lines are too long
-55
View File
@@ -1,55 +0,0 @@
.tabs {
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
}
.tabs li {
float: left;
margin: 0 -15px 0 0;
}
.tabs a {
float: left;
position: relative;
padding: 0 40px;
height: 0;
line-height: 30px;
text-transform: uppercase;
text-decoration: none;
color: #fff;
border-right: 30px solid transparent;
border-bottom: 30px solid var(--mainColor);
/*border-bottom-color: #777 \9;*/
opacity: .3;
filter: alpha(opacity=30);
}
.tabs a:hover {
border-bottom-color: var(--mainColor);
opacity: 0.5;
filter: alpha(opacity=50);
}
.tabs a:focus {
outline: 0;
}
.tabs .current {
z-index: 3;
border-bottom-color: var(--mainColor);
opacity: 1;
filter: alpha(opacity=100);
}
.tabs-content {
background: #fff;
border-top: 2px solid var(--mainColor);
padding: 1rem 0;
}
.tabs-content h2, #content h3, #content p {
margin: 0 0 15px 0;
}
-19
View File
@@ -1,19 +0,0 @@
$(function (){
var $e = $(".tabs a").first();
$e.addClass("current")
showHideBlock( $e )
function showHideBlock($e){
$(".tabs-content .tab").hide()
var block = ".tabs-content .tab" + "." + $e.attr("name")
$(block).show()
}
$(".tabs a").click(function (){
$(".tabs a").removeClass("current")
$(this).addClass("current")
showHideBlock( $(this) )
})
})
-1597
View File
File diff suppressed because it is too large Load Diff
-45
View File
@@ -1,45 +0,0 @@
// 覆盖默认行为
function success(msg){
layx.notice({
title: '成功',
type: 'success',
message: msg
});
}
// 覆盖默认行为
function warning(msg){
layx.notice({
title: '警告',
type: 'warning',
message: msg
});
}
// 覆盖默认行为
function alert(msg){
layx.notice({
title: '错误',
type: 'error',
message: msg
});
}
function check(v, re, msg) {
if (!re.test(v)) {
alert("参数校验失败:" + msg)
throw "参数校验失败"
}
}
function getyyyyMMdd(){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
String(curr_month).length < 2 ? (curr_month = "0" + curr_month): curr_month;
String(curr_date).length < 2 ? (curr_date = "0" + curr_date): curr_date;
var yyyyMMdd = curr_year + "" + curr_month +""+ curr_date;
return yyyyMMdd;
}
-323
View File
@@ -1,323 +0,0 @@
(function( root ){
var DIR = "\\root\\mana"
var FISECKEY = root.FISECKEY;
var hDevice = undefined;
var fileSize = 4096;
if ( ! FISECKEY ) {
console.error("缺少 FISECKEY 支持 !!!")
}
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function hexToString(hex){
var arr = hex.split("")
var out = ""
for (var i = 0; i < arr.length / 2; i++) {
var tmp = "0x" + arr[i * 2] + arr[i * 2 + 1]
var charValue = String.fromCharCode(tmp);
out += charValue
}
return out
}
function admin( dev, pin ){
if ( ! hDevice ) {
hDevice = FISECKEY.OpenBySerial(dev, "4");
}
if ( ! hDevice ) {
throw new Error("设备打开失败")
}
FISECKEY.ADMIN_Login(hDevice, pin);
return hDevice;
}
function login( dev, pin ){
hDevice = FISECKEY.OpenBySerial(dev, "4");
if ( ! hDevice ) {
throw new Error("设备打开失败")
}
FISECKEY.USER_Login(hDevice, pin);
return hDevice;
}
function logout(){
FISECKEY.USER_Logout(hDevice, 0);
FISECKEY.CloseDevice(hDevice);
hDevice = undefined
}
function sumHash(data){
var sum = 0;
for (var i =0 ; i < data.length; i++) {
sum += data.charCodeAt(i)
}
sum += "";
return sum.substr( sum.length -4 );
}
function release( info ){
if ( ! hDevice ) {
throw new Error("设备未登录")
}
FISECKEY.FILE_Init(hDevice);
FISECKEY.FILE_CreateDir(hDevice, DIR, 0);
FISECKEY.FILE_CreateFile(hDevice, DIR, "name", fileSize, 0);
FISECKEY.GenECCKeypair(hDevice, 0, 256, 1);
var data = JSON.stringify(info)
writeFile(DIR, "name", data)
readFile(DIR, "name")
}
function deleteFile(dir, file){
if ( ! hDevice ) {
throw new Error("设备未登录")
}
FISECKEY.FILE_DeleteFile(hDevice, dir, file);
}
function readFile(dir, file) {
if ( ! hDevice ) {
throw new Error("设备未登录")
}
var len = FISECKEY.FILE_ReadFile(hDevice, dir, file, 0, 2);
len = parseInt( len, 10 );
var data = FISECKEY.FILE_ReadFile(hDevice, dir, file, 2, len);
var sum = sumHash(data);
var hash = FISECKEY.FILE_ReadFile(hDevice, dir, file, 2 + len, 2);
if ( sum === hash ) {
var str = hexToString(data);
console.log( "read", data )
return JSON.parse(str);
}
throw new Error("文件读取失败")
}
function writeData(hDevice, dir, file, idx, len, data){
if ( len <= 400 ) {
FISECKEY.FILE_WriteFile(hDevice, dir, file, idx, len, data);
} else {
// 先写入 400
FISECKEY.FILE_WriteFile(hDevice, dir, file, idx, 400, data.substr(0, 800 ));
writeData( hDevice, dir, file, idx + 400, len - 400, data.substr(800) )
}
}
function writeFile(dir, file, data){
if ( ! hDevice ) {
throw new Error("设备未登录")
}
try {
FISECKEY.FILE_DeleteFile(hDevice, dir, file);
}catch (e) {
}
FISECKEY.FILE_CreateFile(hDevice, dir, file, fileSize, 0);
console.log( "write", data )
console.log( "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)
// console.log( "writeFile=" + len )
// console.log( "writeFile=" + data )
// console.log( "writeFile=" + data.length )
console.log("w2")
var hash = sumHash(data);
// console.log( "writeFile hash=" + hash )
FISECKEY.FILE_WriteFile(hDevice, dir, file, 2 + (data.length/2), 2, hash);
}
// 枚举序列号与名称
function enumDevByArray() {
return FISECKEY.EnumByArray();
}
function enumDir( path ){
if ( ! hDevice ) {
throw new Error("设备未登录")
}
var folders = FISECKEY.FILE_EnmuDir(hDevice, path);
var fos = folders.split("|")
folders = []
for ( var i = 0 ; i < fos.length ; i++ ) {
if ( fos[i] ) {
folders.push( path + "\\" + fos[i] );
}
}
var files = FISECKEY.FILE_EnmuFile(hDevice, path);
var fs = files.split("|")
files = []
for ( var i = 0 ; i < fs.length ; i++ ) {
if ( fs[i] ) {
files.push( path + "\\" + fs[i] );
}
}
return {
folders : folders,
files : files
}
}
function loadLMK(){
return readFile(DIR, "lmk")
}
/**
*
* @param no 1/2/3
* @param mkey HEX(48 字节)
*/
function saveLMK(no, lmk, pk, sk) {
if ( ! hDevice ) {
throw new Error("设备未登录")
}
var info = {
pk : pk , sk : sk
}
switch ( no ) {
case 1: {
info = Object.assign( info, {
no : no,
lmk1 : lmk.substr(0, 32),
lmk2 : lmk.substr(32, 64)
})
break;
}
case 2: {
// 0 16 32 48
// 0 32 64 96
info = Object.assign( info, {
no : no,
lmk2 : lmk.substr(32, 64),
lmk3 : lmk.substr(64, 96)
})
break;
}
case 3: {
info = Object.assign( info, {
no : no,
lmk3 : lmk.substr(64, 96),
lmk1 : lmk.substr(0, 32)
})
break;
}
default :
throw new Error("不支持的分量")
}
var data = JSON.stringify(info)
FISECKEY.FILE_DeleteFile(hDevice, DIR, "lmk");
FISECKEY.FILE_CreateFile(hDevice, DIR, "lmk", fileSize, 0);
writeFile( DIR, "lmk" , data);
var auth = {
uid : no,
rid : no
}
FISECKEY.FILE_DeleteFile(hDevice, DIR, "auth");
FISECKEY.FILE_CreateFile(hDevice, DIR, "auth", fileSize, 0);
writeFile( DIR, "auth" , auth);
}
function saveAuth(uid, rid){
var auth = {
uid : no,
rid : no
}
FISECKEY.FILE_DeleteFile(hDevice, DIR, "auth");
FISECKEY.FILE_CreateFile(hDevice, DIR, "auth", fileSize, 0);
writeFile( DIR, "auth" , auth);
}
function loadAuth(){
return readFile(DIR, "auth")
}
function catRelease(){
return readFile(DIR, "name")
}
/**
* 修改口令
*/
function updatePin(oldpin, newpin){
FISECKEY.USER_ChangePin(hDevice, 1, oldpin, newpin);
}
function exportPk(){
return FISECKEY.ExportECCKeypair(hDevice, 1);
}
function sign(vInbuf){
return FISECKEY.ECCSign(hDevice, 1, 1, vInbuf);
}
root.UKey = {
release: release,
catRelease : catRelease,
readFile: readFile,
writeFile : writeFile,
deleteFile : deleteFile,
login : login,
logout : logout,
updatePin : updatePin,
admin : admin,
enumDevByArray : enumDevByArray,
enumDir: enumDir,
saveLMK : saveLMK,
loadLMK : loadLMK,
saveAuth : saveAuth,
loadAuth : loadAuth,
exportPk : exportPk,
sign : sign
}
})( window )