Marc Wäckerlin 8 years ago
parent cc4f5d6619
commit d2a6a0f518
  1. 39
      nodejs/public/javascripts/safechat.js

@ -46,7 +46,7 @@ function SafeChat() {
/// @class Crypto cryptographic functions /// @class Crypto cryptographic functions
/** @param view is of class SafeChat.View */ /** @param view is of class SafeChat.View */
function Crypto(view) { function Crypto(controller) {
/// cache client's key from local strorage /// cache client's key from local strorage
var k = null var k = null
@ -72,18 +72,18 @@ function SafeChat() {
/// create New User /// create New User
function createuser(user, email, pwd) { function createuser(user, email, pwd) {
view.notice("generating keys") controller.notice("generating keys")
openpgp.generateKey({ openpgp.generateKey({
numBits: 4096, numBits: 4096,
userIds: [{name: user, email: email}], userIds: [{name: user, email: email}],
passphrase: pwd passphrase: pwd
}).then(function(keyPair) { }).then(function(keyPair) {
view.success("keys generated") controller.success("keys generated")
localStorage.key = keyPair.privateKeyArmored localStorage.key = keyPair.privateKeyArmored
k = keyPair.key k = keyPair.key
}).catch(function(e) { }).catch(function(e) {
console.log(e) console.log(e)
view.fatal("generating key pairs failed") controller.fatal("generating key pairs failed")
}) })
} }
@ -409,8 +409,22 @@ function SafeChat() {
function Controller(view) { function Controller(view) {
var db = new Database() var db = new Database()
var crypto = new Crypto(this)
var communication = new Communication(this) var communication = new Communication(this)
var users = new Users() var users = new Users()
/// @name error handling
/// @{
this.fatal = view.fatal
this.error = view.error
this.warning = view.warning
this.notice = view.notice
/// @}
/// @name signals from server
/// @{
function fail(msg) { function fail(msg) {
console.log('rcv-> fail('+msg+')') console.log('rcv-> fail('+msg+')')
@ -445,12 +459,7 @@ function SafeChat() {
this.disconnect = view.disconnected this.disconnect = view.disconnected
this.error = view.disconnected this.error = view.disconnected
function login() { // @}
}
function user(usr) {
if (usr.exists) db.adduser
}
function initBrowser() { function initBrowser() {
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB
@ -460,7 +469,17 @@ function SafeChat() {
return window.indexedDB && window.crypto.getRandomValues && Storage return window.indexedDB && window.crypto.getRandomValues && Storage
} }
function register() {
}
function login() {
if (!crypto.key()) register()
else password()
}
function run() { function run() {
login()
} }
function start() { function start() {

Loading…
Cancel
Save