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

1. 优化登录验证api,使之可以更灵活地支持多种验证方式

2. 增加上海市证书中心(uca)验证方式
上级 e659321d
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
}, },
"dependencies": { "dependencies": {
"antd": "^2.13.0", "antd": "^2.13.0",
"axo": "0.0.2",
"babel-plugin-import": "^1.2.1", "babel-plugin-import": "^1.2.1",
"babel-runtime": "^6.9.2", "babel-runtime": "^6.9.2",
"bowser": "^1.8.1",
"bundle-loader": "^0.5.5", "bundle-loader": "^0.5.5",
"dva": "^1.2.1", "dva": "^1.2.1",
"dva-loading": "^0.2.1", "dva-loading": "^0.2.1",
......
import { routerRedux } from 'dva/router'; import { routerRedux } from 'dva/router';
import { login, userInfo } from '../services/login'; import { login, userInfo } from '../services/login';
import { validate } from '../services/login/password';
import { fullPath } from '../utils/helper'; import { fullPath } from '../utils/helper';
import { setToken, setUser, setDomain, histories } from '../utils/auth'; import { setToken, setUser, setDomain, histories } from '../utils/auth';
import { switchDomain, currentDomain } from '../services/domain'; import { switchDomain, currentDomain } from '../services/domain';
...@@ -15,12 +16,7 @@ export default { ...@@ -15,12 +16,7 @@ export default {
const loginRequest = { const loginRequest = {
type: 'userName', type: 'userName',
data: payload.userName, data: payload.userName,
authRequest: { authRequest: yield call(validate, payload.password),
type: 'password',
parameters: {
cipher: payload.password,
},
},
}; };
const result = yield call(login, loginRequest); const result = yield call(login, loginRequest);
const { tokenId, authResponse, remainedAuthRequirements } = result; const { tokenId, authResponse, remainedAuthRequirements } = result;
......
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
/** @module services/login */ /** @module services/login */
import { getDeviceId } from '../utils/device'; import { getDeviceId } from '../../utils/device';
import post from '../utils/post'; import post from '../../utils/post';
import request from '../utils/request'; import request from '../../utils/request';
import { encrypt } from '../utils/helper'; import { encrypt } from '../../utils/helper';
import { getToken } from '../utils/auth'; import { getToken } from '../../utils/auth';
import config from '../utils/config'; import config from '../../utils/config';
/** /**
* @typedef {Object} TokenInfo * @typedef {Object} TokenInfo
......
import { addToken } from './utils';
export const validate = async (password, token) => {
const request = {
type: 'password',
parameters: {
cipher: password,
},
};
await addToken(request, token);
return request;
};
import { addToken } from './utils';
export const requestCode = async (token) => {
const request = {
type: 'uca',
parameters: {
action: 'request',
},
};
await addToken(request, token);
return request;
};
export const validate = async (signed, token) => {
const request = {
type: 'uca',
parameters: {
action: 'validate',
response: signed,
},
};
await addToken(request, token);
return request;
};
import { getToken } from '../../utils/auth';
export const addToken = async (request, token) => {
if (token) {
// eslint-disable-next-line no-param-reassign
request.tkId = token;
} else {
const localToken = await getToken();
if (localToken) {
// eslint-disable-next-line no-param-reassign
request.tkId = localToken;
}
}
return request;
};
import AXO from 'axo';
import bowser from 'bowser';
/**
* 初始化
* @return {number} 0: success; 1: blocked by the browser; 2: driver not installed
*/
export const init = () => {
if (bowser.msie || bowser.msedge) {
try {
const se = new AXO('SafeEngineCOM.SafeEngineCtl');
if (se) {
return 0;
} else {
return 2;
}
} catch (err) {
return 1;
}
} else {
return 3;
}
};
/**
* 签名
* @param password usb的密钥
* @param data 需要签名的数据,从服务端获取
* @return {{deadTime: number, signed: string}}
*/
export const sign = (password, data) => {
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 = {};
const deadTime = safeEngine.SEH_GetCertValidDate(cert);
res.deadTime = parseInt(deadTime, 10);
const signed = safeEngine.SEH_SignData(data, 3);
if (safeEngine.ErrorCode !== 0) {
throw new Error(`数字签名失败,错误代码为:${safeEngine.ErrorCode}。`);
}
res.signed = signed;
return res;
} finally {
safeEngine.SEH_ClearSession();
}
} else {
throw new Error('当前浏览器不支持activeX控件,请切换ie或edge或带ie内核的360之类的浏览器。');
}
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论