Actually fixed Access Token decryption

This commit is contained in:
CaramelKat
2021-10-17 11:21:10 -05:00
committed by CaramelKat
parent 2457829f05
commit fd3031b4ed
6 changed files with 88 additions and 12 deletions

View File

@@ -112,12 +112,12 @@ let methods = {
}
catch(e)
{
console.log(e)
return null;
}
},
decryptToken: function(token) {
// Access and refresh tokens use a different format since they must be much smaller
// Assume a small length means access or refresh token
if (token.length <= 32) {
@@ -133,6 +133,7 @@ let methods = {
return decryptedBody;
}
const cryptoPath = `${__dirname}/certs/access`;
const cryptoOptions = {
@@ -170,7 +171,7 @@ let methods = {
const hmac = crypto.createHmac('sha1', cryptoOptions.hmac_secret).update(decryptedBody);
const calculatedSignature = hmac.digest();
if (calculatedSignature !== signature) {
if (Buffer.compare(calculatedSignature, signature) !== 0) {
console.log('Token signature did not match');
return null;
}
@@ -222,9 +223,7 @@ let methods = {
Buffer.from('\x02\x65\x43\x46'),
Buffer.from(password)
]);
const hashed = crypto.createHash('sha256').update(unpacked).digest().toString('hex');
return hashed;
return crypto.createHash('sha256').update(unpacked).digest().toString('hex');
},
getCommunityHash: function() {
return communityMap;

View File

@@ -5,6 +5,7 @@ const { ENDPOINT } = require('./models/endpoint');
const { COMMUNITY } = require('./models/communities');
const { POST } = require('./models/post');
const { USER } = require('./models/user');
const { CONVERSATION } = require('./models/conversation');
const { uri, database, options } = mongooseConfig;
let connection;
@@ -303,6 +304,23 @@ async function getNewsFeedAfterTimestamp(user, numberOfPosts, post) {
}).limit(numberOfPosts).sort({ created_at: -1});
}
async function getConversations(pid) {
verifyConnected();
return CONVERSATION.find({
pids: pid
});
}
async function getConversation(pid, pid2) {
verifyConnected();
return CONVERSATION.find({
$and: [
{pids: pid},
{pids: pid2}
],
});
}
module.exports = {
connect,
getCommunities,
@@ -337,5 +355,7 @@ module.exports = {
getNewsFeed,
getNewsFeedAfterTimestamp,
getFollowingUsers,
getFollowedUsers
getFollowedUsers,
getConversations,
getConversation,
};

View File

@@ -0,0 +1,32 @@
const { Schema, model } = require('mongoose');
const ConversationSchema = new Schema({
created_at: {
type: Date,
default: new Date(),
},
id: {
type: String,
default: 0
},
pids: [Number],
});
ConversationSchema.methods.addUser = async function(pid) {
const conversation = this.get('pids');
conversation.addToSet(pid);
await this.save();
}
ConversationSchema.methods.removeUser = async function(pid) {
const conversation = this.get('pids');
conversation.pull(pid);
await this.save();
}
const CONVERSATION = model('CONVERSATION', ConversationSchema);
module.exports = {
ConversationSchema: ConversationSchema,
CONVERSATION: CONVERSATION
};

View File

@@ -1,5 +1,5 @@
const { Schema, model } = require('mongoose');
//just testing pull requests
const PostSchema = new Schema({
title_id: String,
screen_name: String,
@@ -23,8 +23,8 @@ const PostSchema = new Schema({
feeling_id: Number,
id: String,
is_autopost: {
type: Number,
default: 0
type: Number,
default: 0
},
is_community_private_autopost: {
type: Number,
@@ -67,6 +67,10 @@ const PostSchema = new Schema({
parent: {
type: String,
default: null
},
message_to_pid: {
type: String,
default: null
}
});

View File

@@ -8,17 +8,19 @@ var router = express.Router();
router.get('/', async function (req, res) {
let user = await database.getUserByPID(req.pid);
let conversations = await database.getConversations(user.pid)
res.render(req.directory + '/messages.ejs', {
moment: moment,
user: user,
conversations: conversations,
cdnURL: config.CDN_domain,
lang: req.lang,
mii_image_CDN: config.mii_image_CDN
});
user.notification_list.filter(noti => noti.read === false).forEach(function(notification) {
/*user.notification_list.filter(noti => noti.read === false).forEach(function(notification) {
notification.read = true;
});
user.markModified('notification_list');
user.markModified('notification_list');*/
user.save();
});

View File

@@ -21,7 +21,26 @@
<div id="main">
<h1 id="title" class="page-header"><%= lang.global.messages %></h1>
<div class="community-page-posts-wrapper">
<p class="no-posts-text"><%= lang.messages.coming_soon %></p>
<table cellspacing="0">
<tbody id="messages-list">
<tr class="message-wrapper" onclick="showMessage(' + notificationObj.messages[i].id + ')">
<td class="messages-unread-badge-wrapper">
<div class="unread-badge"></div>
</td>
<td>
<%if(true) {%>
<img class="community-page-post-user-icon verified" >
<span class="community-page-verified-user-badge community-page-verified" style=""></span>
<%} else {%>
<img class="community-page-post-user-icon" >
<span class="community-page-verified-user-badge community-page-verified" style="display: none;"></span>
<%}%>
<h2 class="community-page-post-username" >UserName</h2>
<h4 class="community-page-post-time-stamp"><%= moment(new Date()).fromNow() %></h4>
</td>
</tr>
</tbody>
</table>
</div>
<img src="" onerror="wiiuBrowser.showLoadingIcon(!1);window.scroll(0, 0);">
</div>