Commit f22f1112 by 周海峰

密钥管理

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