diff --git a/doc/configuration.md b/doc/configuration.md index 4fc5e1fa0f24da3e40a50b200cfe24a9a604fb48..49a187d6e73d31cae5ec84ec6a4a6fdd557e66a6 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -22,6 +22,7 @@ angular.module("cesium.config", []) "initPhase": false, "expertMode": false, "decimalCount": 4, + "httpsMode": false, "helptip": { "enable": true, "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md" diff --git a/www/js/app.js b/www/js/app.js index 66f32d180f68d6caefd2020debd503dc65fdc1a3..8d7fa0e0d353b11343b11c2252f6a0b9d0d24fb2 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -327,8 +327,10 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht if (csConfig.httpsMode === 'clever') { $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { var href, hashIndex, rootPath ; + // Redirect to HTTP if view has preferHttp=true - if (next.data && next.data.preferHttp && $window.location.protocol == 'https:') { + if (next.data && next.data.preferHttp && + ($window.location.protocol == 'https:' || csConfig.httpsModeDebug)) { href = $window.location.href; hashIndex = href.indexOf('#'); rootPath = (hashIndex != -1) ? href.substr(0, hashIndex) : href; @@ -342,7 +344,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht } } // Redirect to HTTPS - else if((!next.data || !next.data.preferHttp) && $window.location.protocol != 'https:') { + else if((!next.data || !next.data.preferHttp) && + ($window.location.protocol != 'https:' || csConfig.httpsModeDebug)) { href = $window.location.href; hashIndex = href.indexOf('#'); rootPath = (hashIndex != -1) ? href.substr(0, hashIndex) : href; diff --git a/www/js/config.js b/www/js/config.js index 4fa090fe88fdcc29bd0c887dfa6f7b7ff0155a16..0b3a8289ed185914f998fef7b717d7a54e48c90d 100644 --- a/www/js/config.js +++ b/www/js/config.js @@ -21,7 +21,8 @@ angular.module("cesium.config", []) "initPhase": false, "expertMode": false, "decimalCount": 4, - "httpsMode": false, + "httpsMode": "clever", + "httpsModeDebug": true, "helptip": { "enable": true, "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md" @@ -49,4 +50,4 @@ angular.module("cesium.config", []) "newIssueUrl": "https://github.com/duniter/cesium/issues/new?labels=bug" }) -; \ No newline at end of file +; diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index 68f1dff13ee3c3c9afc20422bd3b2e8263110e50..6b1617543739507ed4a0e6412d2d25b4f917d3e0 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -63,6 +63,7 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi showUDHistory: true, showLoginSalt: false, initPhase: false, // For currency start (when block #0 not written) + httpsMode: false, expertMode: false, decimalCount: 4, forceNetworkViewToHttp: false, diff --git a/www/js/services/storage-services.js b/www/js/services/storage-services.js index f62040fc05b491cfd135db424fb03a7fe565a90c..482c7f6f94abcf39d7a98263207942b4a5810cee 100644 --- a/www/js/services/storage-services.js +++ b/www/js/services/storage-services.js @@ -1,35 +1,66 @@ -angular.module('cesium.storage.services', ['ngResource', 'cesium.device.services']) +angular.module('cesium.storage.services', ['ngResource', 'cesium.device.services', 'cesium.config']) -.factory('localStorage', function($window, $q, Device) { +.factory('localStorage', function($window, $q, $rootScope, Device, csConfig) { 'ngInject'; var appName = "Cesium", localStorage = $window.localStorage, exports = { - unsecure: { - put: function(key, value) { - localStorage[key] = value; - }, - get: function(key, defaultValue) { - return localStorage[key] || defaultValue; - }, - setObject: function(key, value) { - localStorage[key] = JSON.stringify(value); - }, - getObject: function(key) { - return JSON.parse(localStorage[key] || '{}'); - } + useHttpsFrame: false, + unsecure: {}, + https: { + frame: null, + domain: null }, secure: { storage: null } }; - function replaceSecureStorage() { - exports.secure = exports.unsecure; - exports.secure.storage = null; - } + /* -- default implementation (default browser storage) -- */ + + exports.unsecure.put = function(key, value) { + localStorage[key] = value; + }; + + exports.unsecure.get = function(key, defaultValue) { + return localStorage[key] || defaultValue; + }; + + exports.unsecure.setObject = function(key, value) { + localStorage[key] = JSON.stringify(value); + }; + + exports.unsecure.getObject = function(key) { + return JSON.parse(localStorage[key] || '{}'); + }; + + + /* -- HTTPS frame -- */ + + exports.https.put = function(key, value) { + console.log('TODO: setting [{0}] into https frame'.format(key)); + }; + + exports.https.get = function(key, defaultValue) { + exports.https.frame.postMessage(key, exports.https.domain); + console.log('TODO: getting [{0}] from https frame'.format(key)); + return localStorage[key] || defaultValue; + }; + + exports.https.setObject = function(key, value) { + console.log('TODO: setting object [{0}] into https frame'.format(key)); + }; + + exports.https.getObject = function(key) { + exports.https.frame.postMessage(key, exports.https.domain); + console.log('TODO: getting object [{0}] from https frame'.format(key)); + return JSON.parse(localStorage[key] || '{}'); + }; + + + /* -- Secure storage (device only, using a cordova plugin) -- */ // Set a value to the secure storage (or remove if value is not defined) exports.secure.put = function(key, value) { @@ -80,12 +111,42 @@ angular.module('cesium.storage.services', ['ngResource', 'cesium.device.services }); }; - // Copy unsecure function as root exports function - _.forEach(_.keys(exports.unsecure), function(key) { - exports[key] = exports.unsecure[key]; - }); + // Create a HTTPS frame to get local storage from HTTPS domaine + if (csConfig.httpsMode === 'clever' && $window.location.protocol !== 'https:') { + + var href = $window.location.href; + var hashIndex = href.indexOf('#'); + var rootPath = (hashIndex != -1) ? href.substr(0, hashIndex) : href; + var httpsFrame = (csConfig.httpsModeDebug ? 'http' : 'https') + rootPath.substr(4) + 'sync-storage.html'; + + console.debug('[storage] Adding HTTPS iframe [{0}]'.format(httpsFrame)); + angular.element(document.body).append('<iframe name="httpsFrame" style="display:none" src="'+httpsFrame+'"></iframe>'); + + + // Copy httpsFrame function as root exports function + _.forEach(_.keys(exports.https), function(key) { + exports[key] = exports.https[key]; + }); + + exports.https.domain = 'https' + rootPath.substr(4); + exports.https.frame = frames['httpsFrame']; + } + + else { + // Copy unsecure function as root exports function + _.forEach(_.keys(exports.unsecure), function(key) { + exports[key] = exports.unsecure[key]; + }); + } + Device.ready().then(function() { + + function replaceSecureStorage() { + exports.secure = exports.unsecure; + exports.secure.storage = null; + } + if (Device.enable) { exports.secure.storage = new cordova.plugins.SecureStorage( function () { @@ -101,6 +162,8 @@ angular.module('cesium.storage.services', ['ngResource', 'cesium.device.services replaceSecureStorage(); } + + }); return exports; diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 1a2cc986ee5f8538f57aaebb4b01333608030226..3d1b956682e0a405c3451470746eb4673cfb81f4 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -220,12 +220,15 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser store = function() { if (csSettings.data.useLocalStorage) { - if (isLogin() && csSettings.data.rememberMe) { var dataToStore = { - keypair: data.keypair, pubkey: data.pubkey }; +/* + var dataToStore = { + keypair: data.keypair, + pubkey: data.pubkey + };*/ if (data.tx && data.tx.pendings && data.tx.pendings.length>0) { var pendings = data.tx.pendings.reduce(function(res, tx){ diff --git a/www/js/sync-storage.js b/www/js/sync-storage.js new file mode 100644 index 0000000000000000000000000000000000000000..3b93568b2a2b4579866eeb991d9929ee74426978 --- /dev/null +++ b/www/js/sync-storage.js @@ -0,0 +1,7 @@ +window.addEventListener('message', function(event) { + console.log('[HTTPS frame] ', event); + alert('Received ' + event); +}); + + +alert('get ready !'); diff --git a/www/sync-storage.html b/www/sync-storage.html new file mode 100644 index 0000000000000000000000000000000000000000..d13e639531ed0b5df685926bf139fe0f5edfe8a8 --- /dev/null +++ b/www/sync-storage.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + + <script src="dist/dist_js/app/sync-storage.js"></script> +</head> +<body > + +</body> +</html>