Commit f22f1112 by 周海峰

密钥管理

parent 48edd2a2
...@@ -127,7 +127,7 @@ export function downloadSanWeiConfig(query) { ...@@ -127,7 +127,7 @@ export function downloadSanWeiConfig(query) {
}) })
} }
/** * 上传三密管配置 /** * 上传三密管配置
* @description 该方法用于上传三维密管配置文件,通常用于测试或配置验证 * @description 该方法用于上传三维密管配置文件,通常用于测试或配置验证
* @param {Object} formData - 包含文件数据的FormData对象 * @param {Object} formData - 包含文件数据的FormData对象
* @returns {Promise} - 返回一个Promise对象, 表示上传操作的结果 * @returns {Promise} - 返回一个Promise对象, 表示上传操作的结果
......
...@@ -3,14 +3,14 @@ export const testData = { ...@@ -3,14 +3,14 @@ export const testData = {
machine: { machine: {
sdkkeyid: '110', sdkkeyid: '110',
sdkpassword: 'pass', sdkpassword: 'pass',
hsmfiledir: '/Users/zhouhaifeng/Desktop' hsmfiledir: '/Users/zhouhaifeng/Desktop/'
}, },
cloud: { cloud: {
sdkkeyid: '110', sdkkeyid: '110',
sdkpassword: 'pass', sdkpassword: 'pass',
hsmfiledir: '/home/ghca/data/', hsmfiledir: '/Users/zhouhaifeng/Desktop/',
keystoredir: '/home/ghca/data/', keystoredir: '/Users/zhouhaifeng/Desktop/',
truststoredir: '/home/ghca/data/' truststoredir: '/Users/zhouhaifeng/Desktop/'
}, },
card: { card: {
cphpwd: '', cphpwd: '',
...@@ -41,8 +41,8 @@ export const testData = { ...@@ -41,8 +41,8 @@ export const testData = {
thport: '', thport: '',
appid: '', appid: '',
keyid: '', keyid: '',
keystoredir: '', keystoredir: '/Users/zhouhaifeng/Desktop/',
truststoredir: '' truststoredir: '/Users/zhouhaifeng/Desktop/'
}, },
dean: { dean: {
ip: '', ip: '',
...@@ -52,10 +52,10 @@ export const testData = { ...@@ -52,10 +52,10 @@ export const testData = {
keynum: '' keynum: ''
}, },
star: { star: {
zdxlzjcedir: '', zdxlzjcedir: '/Users/zhouhaifeng/Desktop/',
certspem: '', certspem: '/Users/zhouhaifeng/Desktop/',
sigkeypem: '', sigkeypem: '/Users/zhouhaifeng/Desktop/',
cacrtpem: '' cacrtpem: '/Users/zhouhaifeng/Desktop/'
}, },
threeTerm: {} threeTerm: {}
}; };
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.keystoredir" placeholder="" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.keystoredir" placeholder="" style="width: 300px" :disabled="!editable" />
<div class="button-group"> <div class="button-group">
<el-button type="primary" @click="uploadCert('client')">上传证书</el-button> <el-button type="primary" @click="uploadCert('cloud-client')">上传证书</el-button>
</div> </div>
<div class="tip-text">* KeyStore: 类似client.p12客户端证书上传,此处上传路径应和配置文件中客户端证书路径保持一致</div> <div class="tip-text">* KeyStore: 类似client.p12客户端证书上传,此处上传路径应和配置文件中客户端证书路径保持一致</div>
</div> </div>
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.truststoredir" placeholder="" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.truststoredir" placeholder="" style="width: 300px" :disabled="!editable" />
<div class="button-group"> <div class="button-group">
<el-button type="primary" @click="uploadCert('ca')">上传证书</el-button> <el-button type="primary" @click="uploadCert('cloud-ca')">上传证书</el-button>
</div> </div>
<div class="tip-text">* TrustStore: 类似ca.cer CA证书上传,此处上传路径应和配置文件里的证书路径保持一致</div> <div class="tip-text">* TrustStore: 类似ca.cer CA证书上传,此处上传路径应和配置文件里的证书路径保持一致</div>
</div> </div>
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
<el-form-item label="私钥证书" required> <el-form-item label="私钥证书" required>
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.keystoredir" placeholder="" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.keystoredir" placeholder="" style="width: 300px" :disabled="!editable" />
<el-button type="primary" @click="uploadCert('sm2')">上传证书</el-button> <el-button type="primary" @click="uploadCert('thkms-sm2')">上传证书</el-button>
<div class="tip-text">* 类似sm2pri.pkcs8.der 证书上传</div> <div class="tip-text">* 类似sm2pri.pkcs8.der 证书上传</div>
</div> </div>
</el-form-item> </el-form-item>
...@@ -281,7 +281,7 @@ ...@@ -281,7 +281,7 @@
<el-form-item label="公钥证书" required> <el-form-item label="公钥证书" required>
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.truststoredir" placeholder="" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.truststoredir" placeholder="" style="width: 300px" :disabled="!editable" />
<el-button type="primary" @click="uploadCert('sm2pub')">上传证书</el-button> <el-button type="primary" @click="uploadCert('thkms-sm2pub')">上传证书</el-button>
<div class="tip-text">* 类似sm2pub.cer 证书上传</div> <div class="tip-text">* 类似sm2pub.cer 证书上传</div>
</div> </div>
</el-form-item> </el-form-item>
...@@ -342,7 +342,7 @@ ...@@ -342,7 +342,7 @@
<el-form-item label="用户证书路径"> <el-form-item label="用户证书路径">
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.certspem" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.certspem" style="width: 300px" :disabled="!editable" />
<el-button type="primary" @click="uploadCert('certs')">上传证书</el-button> <el-button type="primary" @click="uploadCert('star-certs')">上传证书</el-button>
<div class="tip-text">* certs.pem</div> <div class="tip-text">* certs.pem</div>
</div> </div>
</el-form-item> </el-form-item>
...@@ -350,7 +350,7 @@ ...@@ -350,7 +350,7 @@
<el-form-item label="用户密钥路径"> <el-form-item label="用户密钥路径">
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.sigkeypem" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.sigkeypem" style="width: 300px" :disabled="!editable" />
<el-button type="primary" @click="uploadCert('sigkey')">上传证书</el-button> <el-button type="primary" @click="uploadCert('star-sigkey')">上传证书</el-button>
<div class="tip-text">* sig.key.pem</div> <div class="tip-text">* sig.key.pem</div>
</div> </div>
</el-form-item> </el-form-item>
...@@ -358,7 +358,7 @@ ...@@ -358,7 +358,7 @@
<el-form-item label="服务端CA证书路径"> <el-form-item label="服务端CA证书路径">
<div class="input-group"> <div class="input-group">
<el-input v-model="modelValue.cacrtpem" style="width: 300px" :disabled="!editable" /> <el-input v-model="modelValue.cacrtpem" style="width: 300px" :disabled="!editable" />
<el-button type="primary" @click="uploadCert('ca')">上传证书</el-button> <el-button type="primary" @click="uploadCert('star-ca')">上传证书</el-button>
<div class="tip-text">* ca.crt.pem</div> <div class="tip-text">* ca.crt.pem</div>
</div> </div>
</el-form-item> </el-form-item>
......
<template>
<el-dialog
:title="title"
:model-value="visible"
width="500px"
:close-on-click-modal="false"
:close-on-press-escape="false"
@close="handleCancel"
@update:model-value="val => emit('update:visible', val)"
>
<div style="padding: 10px 0;">
<el-upload
drag
action=""
:auto-upload="false"
:file-list="fileList"
:on-change="handleFileChange"
:show-file-list="true"
:limit="1"
>
<i class="el-icon-upload" style="font-size:48px;color:#409EFF;"></i>
<div class="el-upload__text" style="font-size:16px;color:#909399;">点击或拖拽文件到此处进行上传</div>
</el-upload>
</div>
<div style="text-align:center;margin-top:20px;">
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" :loading="loading" @click="handleConfirm">确定</el-button>
</div>
</el-dialog>
</template>
<script setup>
import { ref, watch, defineProps, defineEmits } from 'vue';
const props = defineProps({
visible: Boolean,
title: {
type: String,
default: '上传'
},
loading: Boolean,
fileList: {
type: Array,
default: () => []
}
});
const emit = defineEmits(['update:visible', 'file-change', 'confirm', 'cancel']);
const handleFileChange = (file, fileList) => {
emit('file-change', file, fileList);
};
const handleConfirm = () => {
emit('confirm');
};
const handleCancel = () => {
emit('cancel');
emit('update:visible', false);
};
watch(() => props.visible, (val) => {
if (!val) emit('cancel');
});
</script>
<style scoped>
</style>
...@@ -61,42 +61,36 @@ ...@@ -61,42 +61,36 @@
</template> </template>
</div> </div>
</div> </div>
<!-- 上传配置文件弹层 --> <!-- 上传配置文件弹层组件 -->
<el-dialog <UploadDialog
title="上传配置文件" v-model:visible="uploadDialogVisible"
v-model="uploadDialogVisible" :title="'上传配置文件'"
width="500px" :loading="uploadLoading"
:close-on-click-modal="false" :fileList="uploadFileList"
:close-on-press-escape="false" @file-change="handleFileChange"
@close="handleUploadCancel" @confirm="handleUploadConfirm"
> @cancel="handleUploadCancel"
<div style="padding: 10px 0;"> />
<el-upload
drag <!-- 上传证书弹层组件 -->
action="" <UploadDialog
:auto-upload="false" v-model:visible="uploadCertDialogVisible"
:file-list="uploadFileList" :title="'上传证书'"
:on-change="handleFileChange" :loading="uploadCertLoading"
:show-file-list="true" :fileList="uploadCertFileList"
:limit="1" @file-change="handleCertFileChange"
> @confirm="handleCertUploadConfirm"
<i class="el-icon-upload" style="font-size:48px;color:#409EFF;"></i> @cancel="handleCertUploadCancel"
<div class="el-upload__text" style="font-size:16px;color:#909399;">点击或拖拽文件到此处进行上传</div> />
</el-upload>
</div>
<div style="text-align:center;margin-top:20px;">
<el-button @click="handleUploadCancel">取消</el-button>
<el-button type="primary" :loading="uploadLoading" @click="handleUploadConfirm">确定</el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, computed, onMounted } from 'vue'; import { ref, reactive, computed, onMounted } from 'vue';
import { queryKeys, showKeyParams, editIsUse, testCallKey, saveKeyParams, uploadHsmConfig, createParam, import { queryKeys, showKeyParams, editIsUse, testCallKey, saveKeyParams, uploadHsmConfig, createParam,
downloadHsmConfig, downloadCloudHsmConfig, downloadSanWeiConfig, downloadZdxlzjceConfig } from '@/api/ruleConfig/keyManagement.js'; downloadHsmConfig, downloadCloudHsmConfig, downloadSanWeiConfig, downloadZdxlzjceConfig, uploadSanWeiConfig } from '@/api/ruleConfig/keyManagement.js';
import ParamsConfig from './components/ParamsConfig.vue'; import ParamsConfig from './components/ParamsConfig.vue';
import UploadDialog from './components/UploadDialog.vue';
import { testData } from '@/constants/keyConfigDefaultData.js'; import { testData } from '@/constants/keyConfigDefaultData.js';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
const keyManageType = ref(''); const keyManageType = ref('');
...@@ -108,6 +102,11 @@ const uploadDialogVisible = ref(false); ...@@ -108,6 +102,11 @@ const uploadDialogVisible = ref(false);
const uploadFile = ref(null); const uploadFile = ref(null);
const uploadFileList = ref([]); const uploadFileList = ref([]);
const uploadLoading = ref(false); const uploadLoading = ref(false);
const uploadCertDialogVisible = ref(false);
const uploadCertFile = ref(null);
const uploadCertFileList = ref([]);
const uploadCertLoading = ref(false);
let currentCertType = '';
const getConfigType = computed(() => { const getConfigType = computed(() => {
const typeMap = { const typeMap = {
...@@ -141,6 +140,10 @@ const getKeyManageOptions = async () => { ...@@ -141,6 +140,10 @@ const getKeyManageOptions = async () => {
} }
}; };
/**
* 处理密管方式变化
* @param newVal
*/
const handleKeyManageChange = async (newVal) => { const handleKeyManageChange = async (newVal) => {
const selectedOption = keyManageData.value.find(item => item.typeid === newVal); const selectedOption = keyManageData.value.find(item => item.typeid === newVal);
isEnabled.value = selectedOption ? selectedOption.isuse === '1' : false; isEnabled.value = selectedOption ? selectedOption.isuse === '1' : false;
...@@ -172,6 +175,10 @@ const handleKeyManageChange = async (newVal) => { ...@@ -172,6 +175,10 @@ const handleKeyManageChange = async (newVal) => {
} }
}; };
/**
* 是否启用
* @param newVal
*/
const handleEnableChange = async (newVal) => { const handleEnableChange = async (newVal) => {
if (!keyManageType.value) { if (!keyManageType.value) {
ElMessageBox.alert('请先选择密管方式', '提示', { ElMessageBox.alert('请先选择密管方式', '提示', {
...@@ -205,6 +212,9 @@ const handleCancel = () => { ...@@ -205,6 +212,9 @@ const handleCancel = () => {
isEditing.value = false; isEditing.value = false;
}; };
/**
* 执行测试
*/
const handleTest = async () => { const handleTest = async () => {
try { try {
const res = await testCallKey({ typeid: keyManageType.value }); const res = await testCallKey({ typeid: keyManageType.value });
...@@ -227,6 +237,9 @@ const handleTest = async () => { ...@@ -227,6 +237,9 @@ const handleTest = async () => {
} }
}; };
/**
* 保存参数配置
*/
const handleConfirm = async () => { const handleConfirm = async () => {
try { try {
const res = await saveKeyParams({ ...configParams.value, typeid: keyManageType.value }); const res = await saveKeyParams({ ...configParams.value, typeid: keyManageType.value });
...@@ -264,6 +277,9 @@ const handleUploadCancel = () => { ...@@ -264,6 +277,9 @@ const handleUploadCancel = () => {
uploadFileList.value = []; uploadFileList.value = [];
}; };
/**
* 上传配置文件-执行后台调用
*/
const handleUploadConfirm = async () => { const handleUploadConfirm = async () => {
if (!uploadFile.value) { if (!uploadFile.value) {
ElMessageBox.alert('请先选择文件', '提示', { ElMessageBox.alert('请先选择文件', '提示', {
...@@ -276,41 +292,31 @@ const handleUploadConfirm = async () => { ...@@ -276,41 +292,31 @@ const handleUploadConfirm = async () => {
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append('file', uploadFile.value); formData.append('file', uploadFile.value);
const res = await uploadHsmConfig(formData); // 如果是三未密管配置
if (res.code === 'POP_00014') { if (keyManageType.value === '8') {
ElMessageBox.alert('上传成功', '提示', { const res = await uploadSanWeiConfig(formData);
confirmButtonText: '确定', if (res.code === 'POP_00014') {
type: 'success' ElMessageBox.alert('上传成功', '提示', {
}); confirmButtonText: '确定',
uploadDialogVisible.value = false; type: 'success'
} else { });
ElMessageBox.alert(res.msg || '上传失败', '提示', { uploadDialogVisible.value = false;
confirmButtonText: '确定', } else {
type: 'error' ElMessageBox.alert(res.msg || '上传失败', '提示', {
}); confirmButtonText: '确定',
type: 'error'
});
}
return
} }
} catch (error) {
ElMessageBox.alert('上传异常', '提示', {
confirmButtonText: '确定',
type: 'error'
});
} finally {
uploadLoading.value = false;
}
};
const handleUploadConfig = async () => { //如果量子加密机配置
if (!uploadFile.value) { if (keyManageType.value === '9'){
ElMessageBox.alert('请先选择文件', '提示', { formData.append('filePath', configParams.value.zdxlzjcedir);
confirmButtonText: '确定', }else{
type: 'warning' // 如果是其他类型的密管配置
}); formData.append('filePath', configParams.value.hsmfiledir);
return; }
}
uploadLoading.value = true;
try {
const formData = new FormData();
formData.append('file', uploadFile.value);
const res = await uploadHsmConfig(formData); const res = await uploadHsmConfig(formData);
if (res.code === 'POP_00014') { if (res.code === 'POP_00014') {
ElMessageBox.alert('上传成功', '提示', { ElMessageBox.alert('上传成功', '提示', {
...@@ -325,7 +331,6 @@ const handleUploadConfig = async () => { ...@@ -325,7 +331,6 @@ const handleUploadConfig = async () => {
}); });
} }
} catch (error) { } catch (error) {
console.error('上传配置文件失败:', error);
ElMessageBox.alert('上传异常', '提示', { ElMessageBox.alert('上传异常', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
type: 'error' type: 'error'
...@@ -335,42 +340,16 @@ const handleUploadConfig = async () => { ...@@ -335,42 +340,16 @@ const handleUploadConfig = async () => {
} }
}; };
const handleUploadCert = async (type) => { /**
if (!uploadFile.value) { * 上传配置回调方法。触发弹层
ElMessageBox.alert('请先选择证书文件', '提示', { */
confirmButtonText: '确定', const handleUploadConfig = async () => {
type: 'warning' uploadDialogVisible.value = true
});
return;
}
uploadLoading.value = true;
try {
const formData = new FormData();
formData.append('file', uploadFile.value);
formData.append('type', type);
const res = await uploadHsmConfig(formData);
if (res.code === 'POP_00014') {
ElMessageBox.alert('证书上传成功', '提示', {
confirmButtonText: '确定',
type: 'success'
});
uploadDialogVisible.value = false;
} else {
ElMessageBox.alert(res.msg || '证书上传失败', '提示', {
confirmButtonText: '确定',
type: 'error'
});
}
} catch (error) {
ElMessageBox.alert('证书上传异常', '提示', {
confirmButtonText: '确定',
type: 'error'
});
} finally {
uploadLoading.value = false;
}
}; };
/**
* 生成国芯加密卡参数
*/
const generateParams = () => { const generateParams = () => {
ElMessageBox.alert('开始生成国芯加密卡参数', '提示', { ElMessageBox.alert('开始生成国芯加密卡参数', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
...@@ -395,8 +374,10 @@ const generateParams = () => { ...@@ -395,8 +374,10 @@ const generateParams = () => {
}); });
}); });
}; };
/**
const handleDownloadTemplate = async () => { * 下载配置
*/
const handleDownloadTemplate = async () => {
try { try {
if (!keyManageType.value) { if (!keyManageType.value) {
ElMessageBox.alert('请先选择密管方式', '提示', { ElMessageBox.alert('请先选择密管方式', '提示', {
...@@ -466,6 +447,86 @@ const handleDownloadTemplate = async () => { ...@@ -466,6 +447,86 @@ const handleDownloadTemplate = async () => {
} }
}; };
const handleUploadCert = (type) => {
currentCertType = type;
uploadCertDialogVisible.value = true;
uploadCertFile.value = null;
uploadCertFileList.value = [];
};
const handleCertFileChange = (file, fileList) => {
uploadCertFile.value = file.raw;
uploadCertFileList.value = fileList;
};
const handleCertUploadCancel = () => {
uploadCertDialogVisible.value = false;
uploadCertFile.value = null;
uploadCertFileList.value = [];
};
const handleCertUploadConfirm = async () => {
if (!uploadCertFile.value) {
ElMessageBox.alert('请先选择证书文件', '提示', {
confirmButtonText: '确定',
type: 'warning'
});
return;
}
uploadCertLoading.value = true;
try {
const formData = new FormData();
let certPath = '';
switch (currentCertType) {
case 'cloud-client':
certPath = configParams.value.keystoredir;
break;
case 'cloud-ca':
certPath = configParams.value.truststoredir;
break;
case 'thkms-sm2':
certPath = configParams.value.keystoredir;
break;
case 'thkms-sm2pub':
certPath = configParams.value.truststoredir;
break;
case 'star-certs':
certPath = configParams.value.certspem;
break;
case 'star-sigkey':
certPath = configParams.value.sigkeypem;
break;
case 'star-ca':
certPath = configParams.value.cacrtpem;
break;
default:
certPath = '';
}
formData.append('filePath', certPath);
formData.append('file', uploadCertFile.value);
formData.append('type', currentCertType);
const res = await uploadHsmConfig(formData);
if (res.code === 'POP_00014') {
ElMessageBox.alert('证书上传成功', '提示', {
confirmButtonText: '确定',
type: 'success'
});
uploadCertDialogVisible.value = false;
} else {
ElMessageBox.alert(res.msg || '证书上传失败', '提示', {
confirmButtonText: '确定',
type: 'error'
});
}
} catch (error) {
ElMessageBox.alert('证书上传异常', '提示', {
confirmButtonText: '确定',
type: 'error'
});
} finally {
uploadCertLoading.value = false;
}
};
onMounted(() => { onMounted(() => {
getKeyManageOptions(); getKeyManageOptions();
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论