Fully end to end encrypted anonymous chat program. Server only stores public key lookup for users and the encrypted messages. No credentials are transfered to the server, but kept in local browser storage. This allows 100% safe chatting.
https://safechat.ch
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.6 KiB
129 lines
3.6 KiB
8 years ago
|
#!/usr/bin/env nodejs
|
||
|
|
||
|
var safechat = function(keyserver) {
|
||
|
var hkp = new openpgp.HKP(keyserver)
|
||
|
return {
|
||
|
client: {
|
||
|
user: null,
|
||
|
createUser: function(name, host, password, success, fail) {
|
||
|
openpgp.generateKey({
|
||
|
numBits: 4096,
|
||
|
userIds: [{name: name, email: name+'@'+host}],
|
||
|
passphrase: password
|
||
|
}).then(function(keyPair) {
|
||
|
user = {
|
||
|
name: name,
|
||
|
email: name+'@'+host,
|
||
|
numBits: 4096,
|
||
|
key: {
|
||
|
pub: keyPair.publicKeyArmored,
|
||
|
priv: keyPair.privateKeyArmored
|
||
|
}
|
||
|
}
|
||
|
hkp.upload(user.key.pub).then(function() {
|
||
|
success(user)
|
||
|
}).catch(function(e) {
|
||
|
fail('upload key failed', e)
|
||
|
})
|
||
|
}).catch(function(e) {
|
||
|
fail('generating key pairs failed', e)
|
||
|
})
|
||
|
},
|
||
|
setUser: function() {
|
||
|
|
||
|
}
|
||
|
},
|
||
|
server: {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
|
||
|
var package = require(__dirname+'/../package.json')
|
||
|
var config = require(package.path.config)
|
||
|
var io = require('socket.io-client')
|
||
|
var program = require('commander')
|
||
|
var openpgp = require('openpgp')
|
||
|
var fs = require('fs');
|
||
|
|
||
|
program
|
||
|
.version(package.version)
|
||
|
.description('command line client for SafeChat, see https://safechat.ch')
|
||
|
.option('-u, --url <url>', 'url to safechat server [http://localhost:8888]', 'http://localhost:8888')
|
||
|
.option('-n, --name <name>', 'username [test]', 'test')
|
||
|
.option('-H, --host <host>', 'user\'s SafeChat host, mail is <name>@<host> [safechat.ch]', 'safechat.ch')
|
||
|
.option('-K, --keyserver <host>', 'pgp key server [https://safechat.ch]', 'https://safechat.ch')
|
||
|
.option('-p, --password <pwd>', 'password [ert456]', 'ert456')
|
||
|
.option('-k, --key <file>', 'pgp key file [key.pgp]', 'key.pgp')
|
||
|
.parse(process.argv)
|
||
|
|
||
|
openpgp.initWorker()
|
||
|
openpgp.config.aead_protect = true
|
||
|
var client = safechat(program.keyserver).client;
|
||
|
|
||
|
fs.stat(program.key, function(err, stats) {
|
||
|
if (err) {
|
||
|
console.log('generate keys')
|
||
|
client.createUser(program.name, program.host, program.password,
|
||
|
function(user) {
|
||
|
fs.writeFileSync(program.key, JSON.stringify(user))
|
||
|
console.log('new user credentials created')
|
||
|
},
|
||
|
function(msg, e) {
|
||
|
console.log("**** ERRROR:", msg, e)
|
||
|
})
|
||
|
} else if (stats.isFile()) {
|
||
|
client.user = JSON.parse(fs.readFileSync(program.key))
|
||
|
console.log("user:", client.user.name)
|
||
|
} else {
|
||
|
console.log('**** ERROR: cannot read file', program.key)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
/*
|
||
|
console.log('connecting to:', program.url)
|
||
|
|
||
|
var socket = io(program.url)
|
||
|
socket
|
||
|
.on('connect', function() {
|
||
|
console.log('connect')
|
||
|
socket.emit('login', {name: 'test', })
|
||
|
})
|
||
|
.on("login", function() {
|
||
|
console.log('loggedin')
|
||
|
})
|
||
|
.on("fail", function() {
|
||
|
console.log('fail')
|
||
|
})
|
||
|
.on("user", function() {
|
||
|
console.log('user')
|
||
|
})
|
||
|
.on("users", function() {
|
||
|
console.log('users')
|
||
|
})
|
||
|
.on("message", function() {
|
||
|
console.log('message')
|
||
|
})
|
||
|
.on("messages", function() {
|
||
|
console.log('messages')
|
||
|
})
|
||
|
.io
|
||
|
.on("connect", function() {
|
||
|
console.log('io.connect')
|
||
|
})
|
||
|
.on("reconnect", function() {
|
||
|
console.log('io.reconnect')
|
||
|
})
|
||
|
.on("disconnect", function() {
|
||
|
console.log('io.disconnect')
|
||
|
})
|
||
|
.on("error", function() {
|
||
|
console.log('io.disconnect')
|
||
|
})
|
||
|
*/
|
||
|
|
||
|
} catch (e) {
|
||
|
console.log('**** ERROR:', e.stack)
|
||
|
}
|