mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			943 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			943 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const utils = require('./utils');
 | 
						|
 | 
						|
function setDataKey(req, decryptedDataKey) {
 | 
						|
    req.session.decryptedDataKey = Array.from(decryptedDataKey); // can't store buffer in session
 | 
						|
    req.session.protectedSessionId = utils.randomSecureToken(32);
 | 
						|
 | 
						|
    return req.session.protectedSessionId;
 | 
						|
}
 | 
						|
 | 
						|
function getProtectedSessionId(req) {
 | 
						|
    return req.headers['x-protected-session-id'];
 | 
						|
}
 | 
						|
 | 
						|
function getDataKey(req) {
 | 
						|
    const protectedSessionId = getProtectedSessionId(req);
 | 
						|
 | 
						|
    if (protectedSessionId && req.session.protectedSessionId === protectedSessionId) {
 | 
						|
        return req.session.decryptedDataKey;
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        return null;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function isProtectedSessionAvailable(req) {
 | 
						|
    const protectedSessionId = getProtectedSessionId(req);
 | 
						|
 | 
						|
    return protectedSessionId && req.session.protectedSessionId === protectedSessionId;
 | 
						|
}
 | 
						|
 | 
						|
module.exports = {
 | 
						|
    setDataKey,
 | 
						|
    getDataKey,
 | 
						|
    isProtectedSessionAvailable
 | 
						|
}; |