Added save file tempering "protection"

This commit is contained in:
Renan LE CARO 2025-03-17 19:02:19 +01:00
parent 659d79bcd0
commit efa634cd8f
2 changed files with 3773 additions and 3 deletions

3763
dist/index.html vendored

File diff suppressed because one or more lines are too long

View file

@ -51,6 +51,7 @@ import {
closeModal,
} from "./asyncAlert";
import { isOptionOn, options, toggleOption } from "./options";
import {hashCode} from "./getLevelBackground";
export function play() {
if (gameState.running) return;
@ -662,6 +663,7 @@ async function openSettingsPanel() {
localStorageContent[key] = value;
}
const signedPayload=JSON.stringify(localStorageContent)
const dlLink = document.createElement("a");
dlLink.setAttribute(
@ -671,7 +673,8 @@ async function openSettingsPanel() {
JSON.stringify({
fileType: "B71-save-file",
appVersion,
localStorageContent,
signedPayload,
key: hashCode('Security by obscurity, but really the game is oss so eh'+signedPayload)
}),
),
);
@ -722,7 +725,7 @@ async function openSettingsPanel() {
const {
fileType,
appVersion: fileVersion,
localStorageContent,
signedPayload,key
} = JSON.parse(content);
if (fileType !== "B71-save-file")
throw new Error("Not a B71 save file");
@ -732,6 +735,12 @@ async function openSettingsPanel() {
fileVersion +
" or newer.",
);
if(key!== hashCode('Security by obscurity, but really the game is oss so eh'+signedPayload)){
throw new Error("Key does not match content.")
}
const localStorageContent=JSON.parse(signedPayload)
localStorage.clear();
for (let key in localStorageContent) {
localStorage.setItem(key, localStorageContent[key]);