mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29:26 +00:00
Major update, devices view and components
The view for devices is functional now. It is possible to view, link and unlink devices and possible to gain access to authenticated endpoints with a key encrypted by a one time pin.
This commit is contained in:
parent
b598a090bc
commit
a01e026aa1
12 changed files with 1282 additions and 673 deletions
|
|
@ -3,11 +3,13 @@ import { defineStore } from 'pinia'
|
|||
import axios from 'axios'
|
||||
import { appUrl, encrypt } from '@/services/ApiService'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { encryptAES, getDateStr } from '@/services/EncryptService'
|
||||
|
||||
export const useDeviceStore = defineStore('device', () => {
|
||||
// Properties - State values
|
||||
const current = ref({
|
||||
uuid: false,
|
||||
key: false,
|
||||
})
|
||||
|
||||
const remote = ref([])
|
||||
|
|
@ -31,6 +33,23 @@ export const useDeviceStore = defineStore('device', () => {
|
|||
return uuid
|
||||
}
|
||||
|
||||
const key = () => {
|
||||
if (!current.value.key && localStorage.getItem('deviceKey')) {
|
||||
current.value.key = localStorage.getItem('deviceKey')
|
||||
}
|
||||
return current.value.key
|
||||
}
|
||||
|
||||
const setDeviceKey = (key) => {
|
||||
current.value.key = key
|
||||
localStorage.setItem('deviceKey', key)
|
||||
}
|
||||
|
||||
const removeDeviceKey = () => {
|
||||
current.value.key = false
|
||||
localStorage.removeItem('deviceKey')
|
||||
}
|
||||
|
||||
// Server application
|
||||
const serverGetRemotes = async (remoteUuid) => {
|
||||
axios.post(appUrl() + '/device/list', { uuid: remoteUuid }).then((data) => {
|
||||
|
|
@ -71,13 +90,14 @@ export const useDeviceStore = defineStore('device', () => {
|
|||
}, 1000)
|
||||
}
|
||||
|
||||
const remoteHandshake = async (pin) => {
|
||||
// send encrypt(uuid + pin)
|
||||
// then decrypt data with pin = key
|
||||
|
||||
axios.post(appUrl() + '/device/handshake', { shake: pin }).then((data) => {
|
||||
console.log(data)
|
||||
const remoteHandshake = async (key) => {
|
||||
const handshake = await axios.post(appUrl() + '/device/handshake', {
|
||||
uuid: uuid(),
|
||||
shake: encryptAES(key, getDateStr()),
|
||||
})
|
||||
console.log(handshake)
|
||||
|
||||
return handshake.data
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -85,6 +105,9 @@ export const useDeviceStore = defineStore('device', () => {
|
|||
server,
|
||||
uuid,
|
||||
setDeviceId,
|
||||
key,
|
||||
setDeviceKey,
|
||||
removeDeviceKey,
|
||||
serverGetRemotes,
|
||||
serverStartLink,
|
||||
remoteCheckServerAccess,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue