Add support for encryption

This commit is contained in:
Tor Hveem 2013-10-07 15:38:47 +02:00
parent 001b05beeb
commit 628961026b
2 changed files with 27 additions and 19 deletions

View File

@ -7,8 +7,6 @@
<title ng-bind-template="WeeChat {{ pageTitle}}"></title> <title ng-bind-template="WeeChat {{ pageTitle}}"></title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="shortcut icon" type="image/png" href="img/favicon.png" > <link rel="shortcut icon" type="image/png" href="img/favicon.png" >
<link href="css/glowingbear.css" rel="stylesheet" media="screen"> <link href="css/glowingbear.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="js/angular.min.js"></script> <script type="text/javascript" src="js/angular.min.js"></script>
@ -16,6 +14,8 @@
<script type="text/javascript" src="js/localstorage.js"></script> <script type="text/javascript" src="js/localstorage.js"></script>
<script type="text/javascript" src="js/protocol.js"></script> <script type="text/javascript" src="js/protocol.js"></script>
<script type="text/javascript" src="js/websockets.js"></script> <script type="text/javascript" src="js/websockets.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</head> </head>
<body> <body>
<div ng-controller="WeechatCtrl"> <div ng-controller="WeechatCtrl">
@ -33,6 +33,18 @@
/relay add weechat 9001</pre> /relay add weechat 9001</pre>
Note: The communication goes directly between your browser and your weechat in clear text. Note: The communication goes directly between your browser and your weechat in clear text.
Connection settings are saved between sessions, including password, in your own browser. Connection settings are saved between sessions, including password, in your own browser.
<h4>Encryption</h4>
If you want to use encrypted session you first have to set up the relay using SSL
<pre>
$ mkdir -p ~/.weechat/ssl
$ cd ~/.weechat/ssl
$ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out relay.pem
</pre>
If WeeChat is already running, you can reload the certificate and private key with command:
<pre>
/relay sslcertkey
/relay add ssl.weechat 8000
</pre>
</div> </div>
<h3>Connection settings</h3> <h3>Connection settings</h3>
<form role="form"> <form role="form">
@ -50,9 +62,9 @@
<p class="help-block">Password will be stored in your browser session</p> <p class="help-block">Password will be stored in your browser session</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label" for="proto">Proto</label> <label class="control-label" for="proto">Encryption</label>
<input type="text" class="form-control" id="proto" ng-model="proto" placeholder="proto"> <input type="checkbox" class="form-control" id="ssl" ng-model="ssl">
<p class="help-block">Default is fine.</p> <p class="help-block">Check the box if you want to encrypt communication between browser and WeeChat. <strong>Note</strong>: Due to a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=594502">bug</a> encryption will not work in Firefox. You must also first visit the URL https://weechathost:relayport/ to accept the certificate</p>
</div> </div>
<button class="btn btn-lg btn-primary" ng-click="connect()">Connect!</button> <button class="btn btn-lg btn-primary" ng-click="connect()">Connect!</button>
</form> </form>

View File

@ -453,23 +453,19 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
} }
// Takes care of the connection and websocket hooks // Takes care of the connection and websocket hooks
var connect = function (hostport, proto, password) { var connect = function (hostport, password, ssl) {
websocket = new WebSocket("ws://" + hostport + "/weechat"); var proto = ssl ? 'wss':'ws';
websocket = new WebSocket(proto+"://" + hostport + "/weechat");
websocket.binaryType = "arraybuffer" websocket.binaryType = "arraybuffer"
websocket.onopen = function (evt) { websocket.onopen = function (evt) {
var send = ""; var send = "";
// FIXME: does password need to be sent only if protocol is not weechat?
if (proto == "weechat") {
if (password) { if (password) {
send += "init compression=off,password=" + password + "\n"; send += "init compression=off,password=" + password + "\n";
} }
send += "(bufinfo) hdata buffer:gui_buffers(*) number,full_name,short_name,title\n"; send += "(bufinfo) hdata buffer:gui_buffers(*) number,full_name,short_name,title\n";
send += "sync\n"; send += "sync\n";
} else {
}
$log.info("Connected to relay"); $log.info("Connected to relay");
doSend(send); doSend(send);
$rootScope.connected = true; $rootScope.connected = true;
@ -490,7 +486,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
} }
websocket.onerror = function (evt) { websocket.onerror = function (evt) {
if (evt.type == "error" && websocket.readyState == 0) { if (evt.type == "error" && websocket.readyState != 1) {
$rootScope.errorMessage = true; $rootScope.errorMessage = true;
} }
$log.error("Relay error " + evt.data); $log.error("Relay error " + evt.data);
@ -565,7 +561,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'connection
}; };
$scope.connect = function() { $scope.connect = function() {
connection.connect($scope.hostport, $scope.proto, $scope.password); connection.connect($scope.hostport, $scope.password, $scope.ssl);
} }
$rootScope.getLines = function() { $rootScope.getLines = function() {
var count = 20; var count = 20;