Skip to content

Commit 2fe68ac

Browse files
committed
adding signature verification
1 parent 78d7fe0 commit 2fe68ac

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

server/Routes/api.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,28 @@ exports.get_post = async function (req, res) {
8989
return;
9090
}
9191
const privateKey = await encrypt.getUserPrivateKey(username);
92-
for (const post of posts) {
93-
post.text = encrypt.decryptMessage(privateKey, post.text).message;
92+
const verifiedPosts = [];
93+
for (let post of posts) {
94+
const decrypted = encrypt.decryptMessage(privateKey, post.text);
95+
let verified = false;
96+
if (decrypted.signature) {
97+
const issuerPublicKey = await encrypt.getUserPublicKey(post.user);
98+
verified = encrypt.verifySignature(
99+
issuerPublicKey,
100+
decrypted.signature,
101+
decrypted.message,
102+
);
103+
}
104+
verifiedPosts.push({
105+
user: post.user,
106+
group: post.group,
107+
text: decrypted.message,
108+
postedAt: post.postedAt,
109+
verified: verified,
110+
});
94111
}
95-
res.status(200).json(posts);
112+
113+
res.status(200).json(verifiedPosts);
96114
return;
97115
}
98116

server/encryption.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ exports.decryptMessage = function decryptMessage(privateKey, encrypted) {
6565
exports.getSignature = function getSignature(privateKey, message) {
6666
return crypt.signature(privateKey, message);
6767
}
68+
69+
exports.verifySignature = function verifySignature(publicKey, signature, message) {
70+
return crypt.verify(
71+
publicKey,
72+
signature,
73+
message,
74+
);
75+
}

0 commit comments

Comments
 (0)