提交 f0c86e58 authored 作者: vipcxj's avatar vipcxj

uca验证支持

上级 b1b0526e
...@@ -16,7 +16,7 @@ export const validate = async (signed, token) => { ...@@ -16,7 +16,7 @@ export const validate = async (signed, token) => {
type: 'uca', type: 'uca',
parameters: { parameters: {
action: 'validate', action: 'validate',
response: signed, response: encodeURIComponent(signed),
}, },
}; };
await addToken(request, token); await addToken(request, token);
......
import post from '../utils/post';
import config from '../utils/config';
export const bindCert = async (uid, cert) => {
return post(`${config.apiContextPath}/api/uca/admin/cert`, { uid, cert: encodeURIComponent(cert) });
};
...@@ -22,9 +22,43 @@ export const init = () => { ...@@ -22,9 +22,43 @@ export const init = () => {
} }
}; };
/**
* 获取证书
* @param password usb-key的密钥
* @return {{cert: string, deadTime: number}}
*/
export const getCert = (password) => {
if (bowser.msie || bowser.msedge) {
const safeEngine = new AXO('SafeEngineCOM.SafeEngineCtl');
if (!safeEngine) {
throw new Error('未安装USB证书控件。');
}
safeEngine.SEH_InitialSession(27, 'com1', password, 100, 2, '', '');
if (safeEngine.ErrorCode !== 0) {
throw new Error('USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。');
}
try {
const cert = safeEngine.SEH_GetSelfCertificate(27, 'com1', '');
if (safeEngine.ErrorCode !== 0) {
throw new Error(`获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`);
}
const res = {
cert,
};
const deadTime = safeEngine.SEH_GetCertValidDate(cert);
res.deadTime = parseInt(deadTime, 10);
return res;
} finally {
safeEngine.SEH_ClearSession();
}
} else {
throw new Error('当前浏览器不支持activeX控件,请切换ie或edge或带ie内核的360之类的浏览器。');
}
};
/** /**
* 签名 * 签名
* @param password usb的密钥 * @param password usb-key的密钥
* @param data 需要签名的数据,从服务端获取 * @param data 需要签名的数据,从服务端获取
* @return {{deadTime: number, signed: string}} * @return {{deadTime: number, signed: string}}
*/ */
...@@ -32,7 +66,7 @@ export const sign = (password, data) => { ...@@ -32,7 +66,7 @@ export const sign = (password, data) => {
if (bowser.msie || bowser.msedge) { if (bowser.msie || bowser.msedge) {
const safeEngine = new AXO('SafeEngineCOM.SafeEngineCtl'); const safeEngine = new AXO('SafeEngineCOM.SafeEngineCtl');
if (!safeEngine) { if (!safeEngine) {
throw new Error('未安装USB证书驱动。'); throw new Error('未安装USB证书控件。');
} }
safeEngine.SEH_InitialSession(27, 'com1', password, 100, 2, '', ''); safeEngine.SEH_InitialSession(27, 'com1', password, 100, 2, '', '');
if (safeEngine.ErrorCode !== 0) { if (safeEngine.ErrorCode !== 0) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论