Skip to content

Commit

Permalink
Merge pull request #386 from uProxy/trevj-ssh2-0.5.0
Browse files Browse the repository at this point in the history
migrate to ssh2 0.5+
  • Loading branch information
trevj committed Apr 14, 2016
2 parents d4acdb7 + 68cff2b commit 599d5ca
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
10 changes: 4 additions & 6 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ config =
# with a couple of fixes.
'./src/cloud/social/shim/net.js:net'
'./src/cloud/social/shim/dns.js:dns'
# Subset of ssh2-streams (all except SFTP) which works well in
# the browser.
'./src/cloud/social/alias/ssh2-streams.js:ssh2-streams'
# Alternative that works for freedomjs modules.
'./src/cloud/social/alias/brorand.js:brorand'
# Fallback for crypto-browserify's randombytes, for Firefox.
'./src/cloud/social/alias/randombytes.js:randombytes'
]
Expand All @@ -327,9 +326,8 @@ config =
# with a couple of fixes.
'./src/cloud/social/shim/net.js:net'
'./src/cloud/social/shim/dns.js:dns'
# Subset of ssh2-streams (all except SFTP) which works well in
# the browser.
'./src/cloud/social/alias/ssh2-streams.js:ssh2-streams'
# Alternative that works for freedomjs modules.
'./src/cloud/social/alias/brorand.js:brorand'
# Fallback for crypto-browserify's randombytes, for Firefox.
'./src/cloud/social/alias/randombytes.js:randombytes'
]
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
"lodash": "^3.10.1",
"request": "^2.53.0",
"socks5-http-client": "^1.0.2",
"ssh2": "0.4.12",
"ssh2-streams": "0.0.18",
"ssh2": "0.5.0",
"tslint": "^3.3.0",
"typescript": "~1.8.2",
"typings": "^0.7.12",
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/install/installer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference path='../../../../third_party/typings/browser.d.ts' />

require('../social/monkey/process');

import arraybuffers = require('../../arraybuffers/arraybuffers');
import linefeeder = require('../../net/linefeeder');
import logging = require('../../logging/logging');
Expand Down
18 changes: 18 additions & 0 deletions src/cloud/social/alias/brorand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// brorand alias which works in a freedomjs module context.
// Uses randombytes, for which we have an alias which works
// for Firefox.

const randombytes = require('randombytes');

module.exports = function rand(len) {
return randombytes(len);
};

function Rand(fallback) {
// no-op: always use randombytes
}
module.exports.Rand = Rand;

Rand.prototype.generate = function generate(len) {
return randombytes(len);
};
8 changes: 6 additions & 2 deletions src/cloud/social/alias/randombytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ try {
cryptoAvailable = false;
}

module.exports = function(size) {
module.exports = function(size, cb) {
var buffer = new Buffer(size);
if (cryptoAvailable) {
// Although this looks weird, it's how crypto-browserify does it too:
Expand All @@ -25,5 +25,9 @@ module.exports = function(size) {
buffer[i] = Math.floor(Math.random() * 256);
}
}
return buffer;
if (cb) {
cb(undefined, buffer);
} else {
return buffer;
}
}
11 changes: 0 additions & 11 deletions src/cloud/social/alias/ssh2-streams.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/cloud/social/monkey/process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Monkey patch for browserify's process shim, for ssh2-streams.

// Node.js 4.2 is an LTS release and, very roughly, is what the
// browserify shims, e.g. Buffer, provide.
process.version = '4.2.0';

process.binding = function() {
return {};
};
2 changes: 2 additions & 0 deletions src/cloud/social/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference path='../../../../third_party/typings/browser.d.ts' />

require('../social/monkey/process');

import arraybuffers = require('../../arraybuffers/arraybuffers');
import linefeeder = require('../../net/linefeeder');
import logging = require('../../logging/logging');
Expand Down

0 comments on commit 599d5ca

Please sign in to comment.