forge icon indicating copy to clipboard operation
forge copied to clipboard

tag is not works.

Open misha-marinenko opened this issue 8 years ago • 2 comments

TypeError: Cannot read property 'tag' of undefined
    at /home/wh0ami/WebstormProjects/fsociety/index.js:24:32
    at Layer.handle [as handle_request] (/home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/layer.js:95:5)
    at /home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/index.js:335:12)
    at next (/home/wh0ami/WebstormProjects/fsociety/node_modules/express/lib/router/index.js:275:10)
    at SendStream.error (/home/wh0ami/WebstormProjects/fsociety/node_modules/serve-static/index.js:121:7)
    at emitOne (events.js:77:13)

const otplib = require('otplib').default;
const forge = require('node-forge');
const fs = require("fs");
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
var defaultKey = otplib.authenticator.generate("mysomekey") + otplib.authenticator.generate("mysomekey") + otplib.authenticator.generate("mysomekey");
var jsonfile = require('jsonfile');
jsonfile.spaces = 4
app.use("/", express.static('public'));


app.listen(port, function () {
    console.log('App listening on port ' + port + "!");
});

app.get('/api/genUser', function(req, res) {
    const userSecret = otplib.authenticator.generateSecret();
    var ivgenUsr = "֙A”™G|";
    var ciphergenUsr = forge.rc2.createEncryptionCipher(defaultKey);
    ciphergenUsr.start(ivgenUsr);
    ciphergenUsr.update(forge.util.createBuffer(userSecret));
    var encryptedgenUSer = ciphergenUsr.output;
    var tag = ciphergenUsr.mode.tag;
    res.send("['" + encryptedgenUSer.toHex() + "', '" + tag + "']");
    var encryptedgenUSer = "";
    ciphergenUsr.output = "";

    jsonfile.writeFileSync("users.json", {user: userSecret}, {flag: 'a'});
});

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>fsociety</title>
    <script src="forge.min.js"></script>
    <script src="otplib_common0.js"></script>
    <script src="otplib.js"></script>

    <script>
        var defaultKey = otplib.authenticator.generate("mysomekey") + otplib.authenticator.generate("mysomekey") + otplib.authenticator.generate("mysomekey");

        function getXmlHttp(){
            var xmlhttp;
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    xmlhttp = false;
                }
            }
            if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest();
            }
            return xmlhttp;
        }

        var xmlhttp = getXmlHttp()
        function register(){
            document.getElementById('register').style = 'display: block;'
        xmlhttp.open('GET', '/api/genUser', false);
        xmlhttp.send(null);
        if(xmlhttp.status == 200) {
            var decipher = forge.cipher.createDecipher('AES-GCM', defaultKey);
            decipher.start({
                iv: "֙A”™G|",
                tag: xmlhttp.responseText[1] // authentication tag from encryption
            });
            decipher.update(xmlhttp.responseText[0]);
            var pass = decipher.finish();
            if(pass) {

                   document.getElementById("registeruser").innerHTML = decipher.output.toHex();
            }else{
                document.getElementById("registeruser").innerHTML = "Cannot UnEnCrypt";
            }

        }else{
            document.getElementById("registeruser").innerHTML = "Cannot load new UserCode";
        }
        }
        var ivgenUsr = forge.random.getBytesSync(8);
        var ciphergenUsr = forge.rc2.createEncryptionCipher(defaultKey);

    </script>
</head>
<body>
<button value="Register" onclick="register();">Register</button>

<div id="register" style="display: none;">
Your UserCode: (Do not say it another people! Enter it in your Google Autheficator app or in another 2FA app.):<br /> <div id="registeruser"></div> <br />
</div>

<div id="login" style="display: none;">
<input type="text" id="loginuser" />
    <input type="password" id="loginpass" />
</div>

<div id="main" style="display: none;">
<div id="currentusername"></div>
</div>

</body>
</html>

misha-marinenko avatar Jun 10 '17 10:06 misha-marinenko

Who can help me???

misha-marinenko avatar Jun 10 '17 10:06 misha-marinenko

If you have figured out the fix, then please share it. Thanks

Goutham0110 avatar Oct 19 '23 07:10 Goutham0110