mirror of
https://github.com/balzack/databag.git
synced 2025-04-24 02:25:26 +00:00
fix parsing of decrypted content
This commit is contained in:
parent
0315ccc464
commit
b8abef126a
@ -85,9 +85,10 @@ export class NativeCrypto implements Crypto {
|
||||
|
||||
// decrypt data with private rsa key
|
||||
public async rsaDecrypt(encryptedDataB64: string, privateKeyB64: string): Promise<{data: string}> {
|
||||
const crypto = new JSEncrypt();
|
||||
crypto.setPrivateKey(privateKeyB64);
|
||||
const data = await RSA.decrypt(encryptedDataB64, privateKeyB64);
|
||||
const begin = '-----BEGIN RSA PRIVATE KEY-----\n';
|
||||
const end = '\n-----END RSA PRIVATE KEY-----';
|
||||
const key = `${begin}${privateKeyB64}${end}`;
|
||||
const data = await RSA.decrypt(encryptedDataB64, key);
|
||||
if (!data) {
|
||||
throw new Error('rsaDecrypt failed');
|
||||
}
|
||||
|
@ -95,9 +95,32 @@ export function useContent() {
|
||||
}
|
||||
};
|
||||
|
||||
const getMessage = () => {
|
||||
if (!lastTopic) {
|
||||
return '';
|
||||
}
|
||||
if (lastTopic.dataType === 'superbasictopic') {
|
||||
if (lastTopic.data?.text) {
|
||||
return lastTopic.data.text;
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
} else if (lastTopic.dataType === 'sealedtopic') {
|
||||
if (lastTopic.data) {
|
||||
if (lastTopic.data.message?.text) {
|
||||
return lastTopic.data.message.text;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const hosted = cardId == null;
|
||||
const subject = data?.subject ? [data.subject] : buildSubject();
|
||||
const message = lastTopic ? (lastTopic.data ? lastTopic.data.text : null) : '';
|
||||
const message = getMessage();
|
||||
const imageUrl = selectImage();
|
||||
|
||||
return {cardId, channelId, sealed, hosted, unread, imageUrl, subject, message};
|
||||
|
@ -447,6 +447,7 @@ export class ContactModule implements Contact {
|
||||
this.log.warn(err);
|
||||
}
|
||||
}
|
||||
this.emitChannels(cardId);
|
||||
}
|
||||
this.unsealAll = false;
|
||||
}
|
||||
@ -985,8 +986,7 @@ export class ContactModule implements Contact {
|
||||
}
|
||||
if (item.channelKey) {
|
||||
const { data } = await this.crypto.aesDecrypt(subjectEncrypted, subjectIv, item.channelKey);
|
||||
const { subject } = JSON.parse(data);
|
||||
item.unsealedDetail = subject;
|
||||
item.unsealedDetail = data;
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
@ -1006,8 +1006,7 @@ export class ContactModule implements Contact {
|
||||
if (item.channelKey) {
|
||||
const { messageEncrypted, messageIv } = JSON.parse(item.summary.data);
|
||||
const { data } = await this.crypto.aesDecrypt(messageEncrypted, messageIv, item.channelKey);
|
||||
const { message } = JSON.parse(data);
|
||||
item.unsealedSummary = message;
|
||||
item.unsealedSummary = data;
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -95,7 +95,7 @@ export class StreamModule {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (err) {
|
||||
console.log('invalid channel data');
|
||||
this.log.warn('invalid channel data');
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -204,6 +204,7 @@ export class StreamModule {
|
||||
}
|
||||
}
|
||||
this.unsealAll = false;
|
||||
this.emitChannels();
|
||||
}
|
||||
|
||||
this.syncing = false;
|
||||
@ -498,8 +499,7 @@ export class StreamModule {
|
||||
}
|
||||
if (item.channelKey) {
|
||||
const { data } = await this.crypto.aesDecrypt(subjectEncrypted, subjectIv, item.channelKey);
|
||||
const { subject } = JSON.parse(data);
|
||||
item.unsealedDetail = subject;
|
||||
item.unsealedDetail = data;
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
@ -519,8 +519,7 @@ export class StreamModule {
|
||||
if (item.channelKey) {
|
||||
const { messageEncrypted, messageIv } = JSON.parse(item.summary.data);
|
||||
const { data } = await this.crypto.aesDecrypt(messageEncrypted, messageIv, item.channelKey);
|
||||
const { message } = JSON.parse(data);
|
||||
item.unsealedSummary = message;
|
||||
item.unsealedSummary = data;
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user