mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-24 05:50:06 +00:00
perf: 修改使用 rsa 加密数据
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
"install": "^0.13.0",
|
||||
"jquery": "^3.5.0",
|
||||
"js-cookie": "2.2.0",
|
||||
"jsencrypt": "^3.2.1",
|
||||
"krry-transfer": "^1.7.3",
|
||||
"less": "^3.10.3",
|
||||
"less-loader": "^5.0.0",
|
||||
|
||||
40
src/components/FormFields/EncryptedPassword.vue
Normal file
40
src/components/FormFields/EncryptedPassword.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<PasswordInput
|
||||
:value="value"
|
||||
:attrs="attrs"
|
||||
@input="handleInput"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import PasswordInput from './PasswordInput'
|
||||
import { encryptPassword } from '@/utils/jms'
|
||||
|
||||
export default {
|
||||
name: 'EncryptedPassword',
|
||||
components: { PasswordInput },
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
attrs: {
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
},
|
||||
methods: {
|
||||
handleInput(value) {
|
||||
const cipher = encryptPassword(value)
|
||||
this.$emit('input', cipher)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<password
|
||||
<Password
|
||||
:value="value"
|
||||
v-bind="iAttrs"
|
||||
class="el-input password-input"
|
||||
@@ -32,7 +32,8 @@ export default {
|
||||
const defaultAttrs = {
|
||||
secureLength: 7,
|
||||
defaultClass: 'el-input__inner',
|
||||
toggle: true
|
||||
toggle: true,
|
||||
showStrengthMeter: false
|
||||
}
|
||||
return Object.assign(defaultAttrs, this.attrs)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
attrs: {
|
||||
showStrengthMeter: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import DatetimeRangePicker from './DatetimeRangePicker'
|
||||
import Link from './Link'
|
||||
import PasswordInput from './PasswordInput'
|
||||
import EncryptedPassword from './EncryptedPassword'
|
||||
import Select2 from './Select2'
|
||||
import Swicher from './Swicher'
|
||||
import UploadField from './UploadField'
|
||||
@@ -23,7 +24,8 @@ export default {
|
||||
WeekCronSelect,
|
||||
UpdateToken,
|
||||
JsonEditor,
|
||||
Text
|
||||
Text,
|
||||
EncryptedPassword
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -38,5 +40,6 @@ export {
|
||||
WeekCronSelect,
|
||||
UpdateToken,
|
||||
JsonEditor,
|
||||
Text
|
||||
Text,
|
||||
EncryptedPassword
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
<script>
|
||||
import AutoDataForm from '@/components/AutoDataForm'
|
||||
import { getUpdateObjURL } from '@/utils/common'
|
||||
import { encryptPassword } from '@/utils/jms'
|
||||
|
||||
export default {
|
||||
name: 'GenericCreateUpdateForm',
|
||||
components: {
|
||||
@@ -218,6 +220,10 @@ export default {
|
||||
hasDetailInMsg: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
encryptedFields: {
|
||||
type: Array,
|
||||
default: () => ['password', 'token']
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@@ -265,10 +271,23 @@ export default {
|
||||
isUpdateMethod() {
|
||||
return ['put', 'patch'].indexOf(this.method.toLowerCase()) > -1
|
||||
},
|
||||
encryptFields(values) {
|
||||
values = { ...values }
|
||||
for (const field of this.encryptedFields) {
|
||||
let value = values[field]
|
||||
if (!value || typeof value !== 'string') {
|
||||
continue
|
||||
}
|
||||
value = encryptPassword(value)
|
||||
values[field] = value
|
||||
}
|
||||
return values
|
||||
},
|
||||
handleSubmit(values, formName, addContinue) {
|
||||
let handler = this.onSubmit || this.defaultOnSubmit
|
||||
handler = handler.bind(this)
|
||||
values = this.cleanFormValue(values)
|
||||
values = this.encryptFields(values)
|
||||
return handler(values, formName, addContinue)
|
||||
},
|
||||
defaultOnSubmit(validValues, formName, addContinue) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import store from '@/store'
|
||||
import { constantRoutes } from '@/router'
|
||||
import { JSEncrypt } from 'jsencrypt'
|
||||
import VueCookie from 'vue-cookie'
|
||||
|
||||
export function openTaskPage(taskId) {
|
||||
window.open(`/#/ops/celery/task/${taskId}/log/`, '', 'width=900,height=600')
|
||||
@@ -132,3 +134,16 @@ export function getConstRouteName() {
|
||||
addRoutes(names, constRoutes)
|
||||
return names
|
||||
}
|
||||
|
||||
export function encryptPassword(password) {
|
||||
if (!password) {
|
||||
return ''
|
||||
}
|
||||
var rsaPublicKeyText = VueCookie.get('jms_public_key')
|
||||
.replaceAll('"', '')
|
||||
var rsaPublicKey = atob(rsaPublicKeyText)
|
||||
var jsencrypt = new JSEncrypt()
|
||||
jsencrypt.setPublicKey(rsaPublicKey)
|
||||
var value = jsencrypt.encrypt(password)
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ export default {
|
||||
props: {
|
||||
tree: {
|
||||
type: Object,
|
||||
require: true
|
||||
require: true,
|
||||
default: () => ({})
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
||||
@@ -29,6 +29,7 @@ export default {
|
||||
[this.$t('common.Command filter'), ['cmd_filters']],
|
||||
[this.$t('common.Other'), ['priority', 'comment']]
|
||||
],
|
||||
encryptedFields: ['password'],
|
||||
fieldsMeta: {
|
||||
login_mode: fields.login_mode,
|
||||
username: fields.username,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<IBox>
|
||||
<GenericCreateUpdateForm
|
||||
:fields="fields"
|
||||
:encrypted-fields="encryptedFields"
|
||||
:fields-meta="fieldsMeta"
|
||||
:initial="object"
|
||||
:url="url"
|
||||
@@ -17,6 +18,7 @@ import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm
|
||||
import UserPassword from '@/components/FormFields/UserPassword'
|
||||
import { IBox } from '@/components'
|
||||
import rules from '@/components/DataForm/rules'
|
||||
import { PasswordInput } from '@/components/FormFields'
|
||||
|
||||
export default {
|
||||
name: 'PasswordUpdate',
|
||||
@@ -34,12 +36,11 @@ export default {
|
||||
return {
|
||||
url: '/api/v1/users/profile/password/',
|
||||
fields: ['old_password', 'new_password', 'new_password_again'],
|
||||
encryptedFields: ['old_password', 'new_password', 'new_password_again'],
|
||||
fieldsMeta: {
|
||||
old_password: {
|
||||
label: this.$t('users.OldPassword'),
|
||||
el: {
|
||||
type: 'password'
|
||||
}
|
||||
component: PasswordInput
|
||||
},
|
||||
new_password: {
|
||||
label: this.$t('users.NewPassword'),
|
||||
@@ -48,9 +49,7 @@ export default {
|
||||
},
|
||||
new_password_again: {
|
||||
label: this.$t('users.ConfirmPassword'),
|
||||
el: {
|
||||
type: 'password'
|
||||
}
|
||||
component: PasswordInput
|
||||
}
|
||||
},
|
||||
updateSuccessNextRoute: {
|
||||
|
||||
@@ -6338,6 +6338,11 @@ jsdom@^11.5.1:
|
||||
ws "^5.2.0"
|
||||
xml-name-validator "^3.0.0"
|
||||
|
||||
jsencrypt@^3.2.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.npmmirror.com/jsencrypt/-/jsencrypt-3.2.1.tgz#09766983cc760088ff26b12fe7e574252af97727"
|
||||
integrity sha512-k1sD5QV0KPn+D8uG9AdGzTQuamt82QZ3A3l6f7TRwMU6Oi2Vg0BsL+wZIQBONcraO1pc78ExMdvmBBJ8WhNYUA==
|
||||
|
||||
jsesc@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b"
|
||||
|
||||
Reference in New Issue
Block a user