fixes, encryption sharing key, copy

This commit is contained in:
PhilReact 2025-01-08 17:50:47 +02:00
parent c3d300e80b
commit 24a1a0eebf
3 changed files with 14 additions and 11 deletions

View File

@ -33,6 +33,7 @@ const allowedParams= ["name", "service", "identifier", "mimeType", "fileName", "
.join("&"); // Join with `&` .join("&"); // Join with `&`
}; };
export const createAndCopyEmbedLink = async (data) => { export const createAndCopyEmbedLink = async (data) => {
const requiredFields = [ const requiredFields = [
"type", "type",
]; ];
@ -239,7 +240,7 @@ const UIQortalRequests = [
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE', 'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER', 'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', 'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER',
'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA' 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY'
]; ];
@ -615,7 +616,7 @@ isDOMContentLoaded: false
} else if(event?.data?.action === 'CREATE_AND_COPY_EMBED_LINK'){ } else if(event?.data?.action === 'CREATE_AND_COPY_EMBED_LINK'){
try { try {
const link = await createAndCopyEmbedLink(event?.data?.payload) const link = await createAndCopyEmbedLink(event?.data)
event.ports[0].postMessage({ event.ports[0].postMessage({
result: link, result: link,
error: null, error: null,

View File

@ -65,7 +65,7 @@ export const createSymmetricKeyAndNonce = () => {
}; };
export const encryptDataGroup = ({ data64, publicKeys, privateKey, userPublicKey }: any) => { export const encryptDataGroup = ({ data64, publicKeys, privateKey, userPublicKey, customSymmetricKey }: any) => {
let combinedPublicKeys = [...publicKeys, userPublicKey] let combinedPublicKeys = [...publicKeys, userPublicKey]
const decodedPrivateKey = Base58.decode(privateKey) const decodedPrivateKey = Base58.decode(privateKey)
@ -76,9 +76,16 @@ export const encryptDataGroup = ({ data64, publicKeys, privateKey, userPublicKey
throw new Error("The Uint8ArrayData you've submitted is invalid") throw new Error("The Uint8ArrayData you've submitted is invalid")
} }
try { try {
// Generate a random symmetric key for the message. let messageKey
const messageKey = new Uint8Array(32) if(customSymmetricKey){
messageKey = base64ToUint8Array(customSymmetricKey)
} else {
messageKey = new Uint8Array(32)
crypto.getRandomValues(messageKey) crypto.getRandomValues(messageKey)
}
if(!messageKey) throw new Error('Cannot create symmetric key')
const nonce = new Uint8Array(24) const nonce = new Uint8Array(24)
crypto.getRandomValues(nonce) crypto.getRandomValues(nonce)
// Encrypt the data with the symmetric key. // Encrypt the data with the symmetric key.
@ -461,7 +468,6 @@ export function decryptDeprecatedSingle(uint8Array, publicKey, privateKey) {
} }
export const decryptGroupEncryptionWithSharingKey = async ({ data64EncryptedData, key }: any) => { export const decryptGroupEncryptionWithSharingKey = async ({ data64EncryptedData, key }: any) => {
const allCombined = base64ToUint8Array(data64EncryptedData) const allCombined = base64ToUint8Array(data64EncryptedData)
const str = "qortalGroupEncryptedData" const str = "qortalGroupEncryptedData"
const strEncoder = new TextEncoder() const strEncoder = new TextEncoder()
@ -487,7 +493,6 @@ export const decryptGroupEncryptionWithSharingKey = async ({ data64EncryptedData
const encryptedDataEndPosition = allCombined.length - ((count * (32 + 16)) + 4) const encryptedDataEndPosition = allCombined.length - ((count * (32 + 16)) + 4)
const encryptedData = allCombined.slice(encryptedDataStartPosition, encryptedDataEndPosition) const encryptedData = allCombined.slice(encryptedDataStartPosition, encryptedDataEndPosition)
const symmetricKey = base64ToUint8Array(key); const symmetricKey = base64ToUint8Array(key);
// Decrypt the data using the nonce and messageKey // Decrypt the data using the nonce and messageKey
const decryptedData = nacl.secretbox.open(encryptedData, nonce, symmetricKey) const decryptedData = nacl.secretbox.open(encryptedData, nonce, symmetricKey)

View File

@ -841,9 +841,7 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
) { ) {
throw new Error("Encrypting data requires public keys"); throw new Error("Encrypting data requires public keys");
} }
if (!data.encrypt && data.service.endsWith("_PRIVATE")) {
throw new Error("Only encrypted data can go into private services");
}
if (data.fileId) { if (data.fileId) {
data64 = await getFileFromContentScript(data.fileId, sender); data64 = await getFileFromContentScript(data.fileId, sender);
} }
@ -3353,7 +3351,6 @@ export const encryptDataWithSharingKey = async (data, sender) => {
export const decryptDataWithSharingKey = async (data, sender) => { export const decryptDataWithSharingKey = async (data, sender) => {
const { encryptedData, key } = data; const { encryptedData, key } = data;
if (!encryptedData) { if (!encryptedData) {
throw new Error("Please include data to decrypt"); throw new Error("Please include data to decrypt");