From fad14d0a300f07cc14e7cd90df8b0b0907faca41 Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 24 Jun 2020 13:14:56 +0100 Subject: [PATCH] secure trip --- .gitignore | 1 + package.json | 2 +- server/server.js | 2 +- tripcode.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tripcode.js diff --git a/.gitignore b/.gitignore index c2a3db1..fb4cde2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ www/favicon.ico stage/ homepage/ +*~ *.node *.pid diff --git a/package.json b/package.json index 340f9d9..b1cf691 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "formidable": "1.0.17", "hashloli": "git+ssh://public@flanchan.moe:hashloli.git", "jsoncompress": "^0.1.3", - "kana-hash": "file:../home/flandre/work/libkhash/node", + "kana-hash": "file:../kana-hash/node", "minimist": "1.2.0", "nan": "^2.14.0", "recaptcha2": "^1.3.2", diff --git a/server/server.js b/server/server.js index fe5e331..afaf417 100644 --- a/server/server.js +++ b/server/server.js @@ -23,7 +23,7 @@ var _ = require('../lib/underscore'), render = require('./render'), request = require('request'), STATE = require('./state'), - tripcode = {hash:function(a,b){return new khash.Kana(0, this.salt).once(a);}, setSalt:function(a){if(a) this.salt = new khash.Salt(a); else this.salt = khash.Salt.Default; return this.salt;}}, //require('./../tripcode/tripcode'), + tripcode = require('../tripcode').make(),//{hash:function(a,b){return new khash.Kana(0, this.salt).once(a);}, setSalt:function(a){if(a) this.salt = new khash.Salt(a); else this.salt = khash.Salt.Default; return this.salt;}}, //require('./../tripcode/tripcode'), urlParse = require('url').parse, web = require('./web'), winston = require('winston'); diff --git a/tripcode.js b/tripcode.js new file mode 100644 index 0000000..6e2226a --- /dev/null +++ b/tripcode.js @@ -0,0 +1,46 @@ +const hash = require('kana-hash'); + +function Tripcode(algo, salt) +{ + this.algo = algo || hash.Kana.ALGO_DEFAULT; + this.salt = salt ? new hash.Kana(salt) : hash.Salt.Default; +} + +Tripcode.Algorithm = { + Default: hash.Kana.ALGO_DEFAULT, + Crc32: hash.Kana.ALGO_CRC32, + Crc64: hash.Kana.ALGO_CRC64, + Sha256: hash.Kana.ALGO_SHA256, + Sha256T: hash.Kana.ALGO_SHA256_TRUNCATED, +}; +Tripcode.make = (algo, salt) => { + return new Tripcode(algo,salt);b +}; +Object.freeze(Tripcode.Algorithm); + +const TC = Tripcode.prototype; + +TC.hash = function(a, b, c) { + console.log("what are these?:"); + + if (a) { + // Insecure + return "!" +new hash.Kana(this.algo, hash.Salt.Default).once(a); + } else if (b) { + // Secure + return "!!" +new hash.Kana(this.algo, this.salt).once(b); + } +}; + +TC.setSalt = function(salt) { + if (salt) + this.salt = new hash.Salt(salt); + else if(salt === true) + this.salt = hash.Salt.Default; + else if (salt === false) + this.salt = hash.Salt.None; + + return this.salt; +}; + +module.exports = Tripcode;