Skip to content

Commit 1ffbc40

Browse files
author
Eric Rasche
committed
Merge pull request #1 from erasche/develop
Develop
2 parents 7511fc8 + 4aff5a4 commit 1ffbc40

8 files changed

Lines changed: 56 additions & 50 deletions

File tree

static/js/crypto/base64.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
// ==== File: base64.js
12
var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2-
var b64padchar="=";
3+
var b64pad="=";
34

45
function hex2b64(h) {
56
var i;
@@ -17,7 +18,7 @@ function hex2b64(h) {
1718
c = parseInt(h.substring(i,i+2),16);
1819
ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
1920
}
20-
while((ret.length & 3) > 0) ret += b64padchar;
21+
while((ret.length & 3) > 0) ret += b64pad;
2122
return ret;
2223
}
2324

@@ -28,7 +29,7 @@ function b64tohex(s) {
2829
var k = 0; // b64 state, 0-3
2930
var slop;
3031
for(i = 0; i < s.length; ++i) {
31-
if(s.charAt(i) == b64padchar) break;
32+
if(s.charAt(i) == b64pad) break;
3233
v = b64map.indexOf(s.charAt(i));
3334
if(v < 0) continue;
3435
if(k == 0) {
@@ -69,3 +70,4 @@ function b64toBA(s) {
6970
}
7071
return a;
7172
}
73+

static/js/crypto/jsbn.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Downloaded from http://www-cs-students.stanford.edu/~tjw/ at Tue Nov 30 00:42:57 PST 2010
2+
// ==== File: jsbn.js
13
// Copyright (c) 2005 Tom Wu
24
// All Rights Reserved.
35
// See "LICENSE" for details.
@@ -118,7 +120,7 @@ function bnpFromInt(x) {
118120
this.t = 1;
119121
this.s = (x<0)?-1:0;
120122
if(x > 0) this[0] = x;
121-
else if(x < -1) this[0] = x+this.DV;
123+
else if(x < -1) this[0] = x+DV;
122124
else this.t = 0;
123125
}
124126

@@ -212,7 +214,7 @@ function bnCompareTo(a) {
212214
if(r != 0) return r;
213215
var i = this.t;
214216
r = i-a.t;
215-
if(r != 0) return (this.s<0)?-r:r;
217+
if(r != 0) return r;
216218
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
217219
return 0;
218220
}
@@ -557,3 +559,4 @@ BigInteger.prototype.modPowInt = bnModPowInt;
557559
// "constants"
558560
BigInteger.ZERO = nbv(0);
559561
BigInteger.ONE = nbv(1);
562+

static/js/crypto/prng4.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ==== File: prng4.js
12
// prng4.js - uses Arcfour as a PRNG
23

34
function Arcfour() {
@@ -43,3 +44,4 @@ function prng_newstate() {
4344
// Pool size must be a multiple of 4 and greater than 32.
4445
// An array of bytes the size of the pool will be passed to init()
4546
var rng_psize = 256;
47+

static/js/crypto/rng.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ==== File: rng.js
12
// Random number generator - requires a PRNG backend, e.g. prng4.js
23

34
// For best results, put code like
@@ -27,19 +28,12 @@ if(rng_pool == null) {
2728
rng_pool = new Array();
2829
rng_pptr = 0;
2930
var t;
30-
if(window.crypto && window.crypto.getRandomValues) {
31-
// Use webcrypto if available
32-
var ua = new Uint8Array(32);
33-
window.crypto.getRandomValues(ua);
34-
for(t = 0; t < 32; ++t)
35-
rng_pool[rng_pptr++] = ua[t];
36-
}
3731
if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
3832
// Extract entropy (256 bits) from NS4 RNG if available
3933
var z = window.crypto.random(32);
4034
for(t = 0; t < z.length; ++t)
4135
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
42-
}
36+
}
4337
while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
4438
t = Math.floor(65536 * Math.random());
4539
rng_pool[rng_pptr++] = t >>> 8;
@@ -73,3 +67,4 @@ function rng_get_bytes(ba) {
7367
function SecureRandom() {}
7468

7569
SecureRandom.prototype.nextBytes = rng_get_bytes;
70+

static/js/crypto/rsa.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ==== File: rsa.js
12
// Depends on jsbn.js and rng.js
23

34
// Version 1.1: support utf-8 encoding in pkcs1pad2
@@ -110,3 +111,4 @@ RSAKey.prototype.doPublic = RSADoPublic;
110111
RSAKey.prototype.setPublic = RSASetPublic;
111112
RSAKey.prototype.encrypt = RSAEncrypt;
112113
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
114+

static/js/ie.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ function test_ie_availability(url, success_callback){
3030
display_spinner();
3131
interval = setInterval(function(){
3232
$.ajax({
33+
url: url,
3334
type: "GET",
35+
timeout: 500,
3436
success: function(){
37+
console.log("Connected to IE, returning");
3538
clearInterval(interval);
3639
success_callback();
3740
},
38-
error: function(){
41+
error: function(jqxhr, status, error){
3942
request_count++;
43+
console.log("Request " + request_count);
4044
if(request_count > 30){
4145
clearInterval(interval);
4246
clear_main_area();

static/js/rstudio.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ function message_failed_connection(){
1414
);
1515
}
1616

17-
function message_no_auth(){
18-
toastr.warning(
19-
"IPython Notebook was lunched without authentication. This is a security issue. <a href='https://github.com/bgruening/galaxy-ipython/wiki/IPython-Notebook-was-lunched-without-authentication' target='_blank'>More details ...</a>",
20-
"Security warning",
21-
{'closeButton': true, 'timeOut': 20000, 'tapToDismiss': false}
22-
);
23-
}
24-
2517

2618
/**
2719
* Load an interactive environment (IE) from a remote URL
@@ -30,12 +22,30 @@ function message_no_auth(){
3022
* @param {String} notebook_access_url: the URL embeded in the page and loaded
3123
*
3224
*/
33-
function load_notebook(password, notebook_login_url, notebook_access_url){
25+
function load_notebook(notebook_login_url, notebook_access_url, notebook_pubkey_url, username){
3426
$( document ).ready(function() {
3527
// Test notebook_login_url for accessibility, executing the login+load function whenever
3628
// we've successfully connected to the IE.
37-
test_ie_availability(notebook_login_url, function(){
38-
_handle_notebook_loading(password, notebook_login_url, notebook_access_url);
29+
test_ie_availability(notebook_pubkey_url, function(){
30+
var payload = username + "\n" + ie_password;
31+
$.ajax({
32+
type: 'GET',
33+
url: notebook_pubkey_url,
34+
success: function(response_text){
35+
var chunks = response_text.split(':', 2);
36+
var exp = chunks[0];
37+
var mod = chunks[1];
38+
console.log("Found " + exp +" and " + mod);
39+
var rsa = new RSAKey();
40+
rsa.setPublic(mod, exp);
41+
console.log("Encrypting '" + username + "', '" + ie_password + "'");
42+
var enc_hex = rsa.encrypt(payload);
43+
var encrypted = hex2b64(enc_hex);
44+
console.log("E: " + encrypted);
45+
_handle_notebook_loading(encrypted, notebook_login_url, notebook_access_url);
46+
}
47+
});
48+
3949
});
4050
});
4151
}
@@ -52,9 +62,10 @@ function _handle_notebook_loading(password, notebook_login_url, notebook_access_
5262
url: notebook_login_url,
5363
// With our password
5464
data: {
55-
'package': password,
65+
'v': password,
5666
'persist': 1,
57-
'clientPath': window.location.pathname,
67+
'clientPath': '/rstudio/auth-sign-in',
68+
'appUri': '',
5869
},
5970
xhrFields: {
6071
withCredentials: true

templates/rstudio.mako

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import subprocess
88
99
# Sets ID and sets up a lot of other variables
1010
ie.set_id("rstudio")
11-
# Inform the IE of the remote port on docker's end
12-
ie.attr.docker_port = 8787
11+
# In order to keep 302 redirects happy, nginx needs to be aware there's a proxy in front of it,
12+
# which may be using a different port. As a result, we have to start nginx on whichever port it is
13+
# we plan to use.
14+
ie.attr.docker_port = ie.attr.PORT
1315
# Create tempdir in galaxy
1416
temp_dir = os.path.abspath( tempfile.mkdtemp() )
1517
# Write out conf file...needs work
@@ -18,38 +20,27 @@ USERNAME = "galaxy"
1820
1921
## General IE specific
2022
# Access URLs for the notebook from within galaxy.
21-
notebook_access_url = ie.url_template('${PROTO}://${HOST}/auth-sign-in')
22-
notebook_login_url = ie.url_template('${PROTO}://${HOST}/auth-sign-in')
23+
notebook_pubkey_url = ie.url_template('${PROTO}://${HOST}/rstudio/auth-public-key')
24+
notebook_access_url = ie.url_template('${PROTO}://${HOST}/rstudio/')
25+
notebook_login_url = ie.url_template('${PROTO}://${HOST}/rstudio/auth-do-sign-in')
2326
2427
docker_cmd = ie.docker_cmd(temp_dir)
2528
subprocess.call(docker_cmd, shell=True)
2629
print docker_cmd
27-
28-
time.sleep(5)
29-
30-
try:
31-
# Get n, e from public key file
32-
with open(os.path.join(temp_dir, 'rserver_pub_key'), 'r') as pub_key_handle:
33-
n, e = pub_key_handle.read().split(':')
34-
except:
35-
n = 0
36-
e = 0
37-
pass
38-
39-
4030
%>
4131
<html>
4232
<head>
4333
${ ie.load_default_js() }
4434
</head>
4535
<body>
4636

37+
${ ie.attr.notebook_pw }
4738
<script type="text/javascript">
4839
${ ie.default_javascript_variables() }
4940
var notebook_login_url = '${ notebook_login_url }';
5041
var notebook_access_url = '${ notebook_access_url }';
42+
var notebook_pubkey_url = '${ notebook_pubkey_url }';
5143
var notebook_username = '${ USERNAME }';
52-
var payload = "${ USERNAME }" + "\n" + ie_password;
5344
require.config({
5445
baseUrl: app_root,
5546
paths: {
@@ -66,11 +57,7 @@ requirejs([
6657
'crypto/jsbn',
6758
'crypto/base64'
6859
], function(){
69-
var rsa = new RSAKey();
70-
rsa.setPublic("${ e }", "${ n }");
71-
var res = rsa.encrypt(payload);
72-
var v = hex2b64(res);
73-
load_notebook(v, notebook_login_url, notebook_access_url);
60+
load_notebook(notebook_login_url, notebook_access_url, notebook_pubkey_url, "${ USERNAME }");
7461
});
7562
</script>
7663
<div id="main" width="100%" height="100%">

0 commit comments

Comments
 (0)