Skip to content

Commit 599d5ca

Browse files
committed
Merge pull request #386 from uProxy/trevj-ssh2-0.5.0
migrate to ssh2 0.5+
2 parents d4acdb7 + 68cff2b commit 599d5ca

8 files changed

Lines changed: 42 additions & 21 deletions

File tree

Gruntfile.coffee

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,8 @@ config =
314314
# with a couple of fixes.
315315
'./src/cloud/social/shim/net.js:net'
316316
'./src/cloud/social/shim/dns.js:dns'
317-
# Subset of ssh2-streams (all except SFTP) which works well in
318-
# the browser.
319-
'./src/cloud/social/alias/ssh2-streams.js:ssh2-streams'
317+
# Alternative that works for freedomjs modules.
318+
'./src/cloud/social/alias/brorand.js:brorand'
320319
# Fallback for crypto-browserify's randombytes, for Firefox.
321320
'./src/cloud/social/alias/randombytes.js:randombytes'
322321
]
@@ -327,9 +326,8 @@ config =
327326
# with a couple of fixes.
328327
'./src/cloud/social/shim/net.js:net'
329328
'./src/cloud/social/shim/dns.js:dns'
330-
# Subset of ssh2-streams (all except SFTP) which works well in
331-
# the browser.
332-
'./src/cloud/social/alias/ssh2-streams.js:ssh2-streams'
329+
# Alternative that works for freedomjs modules.
330+
'./src/cloud/social/alias/brorand.js:brorand'
333331
# Fallback for crypto-browserify's randombytes, for Firefox.
334332
'./src/cloud/social/alias/randombytes.js:randombytes'
335333
]

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
"lodash": "^3.10.1",
6161
"request": "^2.53.0",
6262
"socks5-http-client": "^1.0.2",
63-
"ssh2": "0.4.12",
64-
"ssh2-streams": "0.0.18",
63+
"ssh2": "0.5.0",
6564
"tslint": "^3.3.0",
6665
"typescript": "~1.8.2",
6766
"typings": "^0.7.12",

src/cloud/install/installer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path='../../../../third_party/typings/browser.d.ts' />
22

3+
require('../social/monkey/process');
4+
35
import arraybuffers = require('../../arraybuffers/arraybuffers');
46
import linefeeder = require('../../net/linefeeder');
57
import logging = require('../../logging/logging');

src/cloud/social/alias/brorand.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// brorand alias which works in a freedomjs module context.
2+
// Uses randombytes, for which we have an alias which works
3+
// for Firefox.
4+
5+
const randombytes = require('randombytes');
6+
7+
module.exports = function rand(len) {
8+
return randombytes(len);
9+
};
10+
11+
function Rand(fallback) {
12+
// no-op: always use randombytes
13+
}
14+
module.exports.Rand = Rand;
15+
16+
Rand.prototype.generate = function generate(len) {
17+
return randombytes(len);
18+
};

src/cloud/social/alias/randombytes.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ try {
1414
cryptoAvailable = false;
1515
}
1616

17-
module.exports = function(size) {
17+
module.exports = function(size, cb) {
1818
var buffer = new Buffer(size);
1919
if (cryptoAvailable) {
2020
// Although this looks weird, it's how crypto-browserify does it too:
@@ -25,5 +25,9 @@ module.exports = function(size) {
2525
buffer[i] = Math.floor(Math.random() * 256);
2626
}
2727
}
28-
return buffer;
28+
if (cb) {
29+
cb(undefined, buffer);
30+
} else {
31+
return buffer;
32+
}
2933
}

src/cloud/social/alias/ssh2-streams.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/cloud/social/monkey/process.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Monkey patch for browserify's process shim, for ssh2-streams.
2+
3+
// Node.js 4.2 is an LTS release and, very roughly, is what the
4+
// browserify shims, e.g. Buffer, provide.
5+
process.version = '4.2.0';
6+
7+
process.binding = function() {
8+
return {};
9+
};

src/cloud/social/provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path='../../../../third_party/typings/browser.d.ts' />
22

3+
require('../social/monkey/process');
4+
35
import arraybuffers = require('../../arraybuffers/arraybuffers');
46
import linefeeder = require('../../net/linefeeder');
57
import logging = require('../../logging/logging');

0 commit comments

Comments
 (0)