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

修正关于uca登录的bug

上级 aa0a8707
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Input, Spin } from 'antd';
import { debounce } from 'lodash';
import { getCert, init, sign } from '../../utils/uca';
class UCA extends Component {
......@@ -34,23 +33,30 @@ class UCA extends Component {
onChange = (value) => {
if (this.state.ready && this.props.onChange) {
if (value) {
if (this.props.data) {
this.props.onChange(sign(value, this.props.data));
} else {
this.props.onChange(getCert(value));
}
}
this.props.onChange(this.valueToObj(value));
}
};
objToValue = (obj) => {
return obj ? obj.input : '';
};
valueToObj = (value) => {
if (!value) {
return value;
}
if (this.props.data) {
return sign(value, this.props.data);
} else {
return getCert(value);
}
};
render() {
const onChange = (e) => {
return debounce(this.onChange, 300)(e.target.value);
return this.onChange(e.target.value);
};
const { loading, ...rest } = this.props;
const { loading, value, ...rest } = this.props;
return (
<Spin spinning={!this.state.ready && loading} size="small">
<Input {...rest} onChange={onChange} type="password" />
<Spin spinning={!this.state.ready || loading} size="small">
<Input {...rest} disabled={!this.state.ready || loading} value={this.objToValue(value)} onChange={onChange} />
</Spin>
);
}
......
......@@ -111,8 +111,8 @@ export default {
yield put({ type: 'setStatus', payload: 'auth' });
},
*requestUCACode(ignored, { call, put }) {
const code = yield call(authorize, yield call(requestCode, encrypt(tkId)));
yield put({ type: 'setUCACode', payload: code });
const { data } = yield call(authorize, yield call(requestCode, encrypt(tkId)));
yield put({ type: 'setUCACode', payload: data });
},
*auth({ payload: { password, uca } }, { call }) {
let response;
......@@ -122,9 +122,9 @@ export default {
response = yield call(authorize, yield call(ucaValidate, uca, encrypt(tkId)));
}
if (response) {
const { status, remainedAuthRequirements } = response;
const { status, remainedAuthRequirements, data } = response;
if (status !== 'authed' && status !== 'skipped') {
throw errors.authFailed();
throw errors.authFailed(data);
}
if (remainedAuthRequirements.requirements.length === 0) {
yield call(successAuthed, tkId);
......
......@@ -2,5 +2,5 @@ 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) });
return post(`${config.apiContextPath}/api/uca/admin/cert`, { uid, cert });
};
......@@ -84,9 +84,9 @@ export const errors = {
code: errorCodes.wrong_password,
msg: '密码错误!',
}),
authFailed: () => createError({
authFailed: msg => createError({
code: errorCodes.auth_failed,
msg: '登录验证失败!',
msg: `登录验证失败!${msg}`,
}),
unsupportedAuthType: (...types) => createError({
code: errorCodes.unsupported_auth_type,
......
......@@ -37,6 +37,7 @@ export const getCert = (password) => {
if (!safeEngine) {
return {
status: 1,
input: password,
error: '未安装USB证书控件。',
};
}
......@@ -44,6 +45,7 @@ export const getCert = (password) => {
if (safeEngine.ErrorCode !== 0) {
return {
status: safeEngine.ErrorCode,
input: password,
error: 'USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。',
};
}
......@@ -52,12 +54,14 @@ export const getCert = (password) => {
if (safeEngine.ErrorCode !== 0) {
return {
status: safeEngine.ErrorCode,
input: password,
error: `获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`,
};
}
const res = {
status: 0,
cert,
input: password,
};
const deadTime = safeEngine.SEH_GetCertValidDate(cert);
res.deadTime = parseInt(deadTime, 10);
......@@ -77,7 +81,7 @@ export const getCert = (password) => {
* 签名
* @param password usb-key的密钥
* @param data 需要签名的数据,从服务端获取
* @return {{[cert]: string, [deadTime]: number, [signed]: string, status: number, [error]: string}}
* @return {{input: string, [cert]: string, [deadTime]: number, [signed]: string, status: number, [error]: string}}
*/
export const sign = (password, data) => {
if (bowser.msie || bowser.msedge) {
......@@ -85,6 +89,7 @@ export const sign = (password, data) => {
if (!safeEngine) {
return {
status: 1,
input: password,
error: '未安装USB证书控件。',
};
}
......@@ -92,6 +97,7 @@ export const sign = (password, data) => {
if (safeEngine.ErrorCode !== 0) {
return {
status: safeEngine.ErrorCode,
input: password,
error: 'USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。',
};
}
......@@ -100,16 +106,18 @@ export const sign = (password, data) => {
if (safeEngine.ErrorCode !== 0) {
return {
status: safeEngine.ErrorCode,
input: password,
error: `获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`,
};
}
const res = { cert, status: 0 };
const res = { cert, status: 0, input: password };
const deadTime = safeEngine.SEH_GetCertValidDate(cert);
res.deadTime = parseInt(deadTime, 10);
const signed = safeEngine.SEH_SignData(data, 3);
if (safeEngine.ErrorCode !== 0) {
return {
status: safeEngine.ErrorCode,
input: password,
error: `数字签名失败,错误代码为:${safeEngine.ErrorCode}。`,
};
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论