Skip to content

Commit 3fa6e52

Browse files
committedJul 28, 2014
modified to better work with chrome app:
- instead of logger, use console.log or debug, error, warn, info - window.Components instead of Components - storing host_keys in localStorage if on a website. - removed the need of observer.
1 parent e278399 commit 3fa6e52

22 files changed

+335
-206
lines changed
 

‎Gruntfile.js

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
module.exports = function(grunt) {
2+
3+
// Project configuration.
4+
grunt.initConfig({
5+
pkg: grunt.file.readJSON('package.json'),
6+
uglify: {
7+
options: {
8+
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
9+
},
10+
build: {
11+
src: 'build/<%= pkg.name %>.concat.js',
12+
dest: 'build/<%= pkg.name %>.min.js'
13+
}
14+
},
15+
concat: {
16+
js: {
17+
options: {
18+
process: function(src, filepath) {
19+
return '// Source: ' + filepath + '\n' + src;
20+
}
21+
},
22+
src: [
23+
'common.js',
24+
25+
'kryptos/kryptos.js',
26+
'kryptos/Cipher/AES.js',
27+
'kryptos/Cipher/Blowfish.js',
28+
'kryptos/Cipher/DES3.js',
29+
'kryptos/Cipher/ARC4.js',
30+
'kryptos/Hash/baseHash.js',
31+
'kryptos/Hash/SHA.js',
32+
'kryptos/Hash/SHA256.js',
33+
'kryptos/Hash/MD5.js',
34+
'kryptos/Hash/HMAC.js',
35+
'kryptos/PublicKey/RSA.js',
36+
'kryptos/PublicKey/DSA.js',
37+
'kryptos/Random/_UserFriendlyRNG.js',
38+
'kryptos/Random/Fortuna/SHAd256.js',
39+
'kryptos/Random/Fortuna/FortunaAccumulator.js',
40+
'kryptos/Random/Fortuna/FortunaGenerator.js',
41+
'kryptos/Random/OSRNG/browser.js',
42+
43+
'python_shim.js',
44+
'BigInteger.js',
45+
46+
'agent.js',
47+
'auth_handler.js',
48+
'ber.js',
49+
'channel.js',
50+
'client.js',
51+
'compress.js',
52+
'dsskey.js',
53+
'file.js',
54+
'hostkeys.js',
55+
'kex_gex.js',
56+
'kex_group1.js',
57+
'message.js',
58+
'packet.js',
59+
'pkey.js',
60+
'rsakey.js',
61+
'sftp_attr.js',
62+
'sftp_client.js',
63+
'sftp_file.js',
64+
'sftp.js',
65+
'ssh_exception.js',
66+
'transport.js',
67+
'util.js',
68+
'win_pageant.js',
69+
],
70+
dest: 'build/<%= pkg.name %>.concat.js',
71+
},
72+
},
73+
jshint: {
74+
files: [
75+
'kryptos/kryptos.js',
76+
'kryptos/Cipher/AES.js',
77+
'kryptos/Cipher/Blowfish.js',
78+
'kryptos/Cipher/DES3.js',
79+
'kryptos/Cipher/ARC4.js',
80+
'kryptos/Hash/baseHash.js',
81+
'kryptos/Hash/SHA.js',
82+
'kryptos/Hash/SHA256.js',
83+
'kryptos/Hash/MD5.js',
84+
'kryptos/Hash/HMAC.js',
85+
'kryptos/PublicKey/RSA.js',
86+
'kryptos/PublicKey/DSA.js',
87+
'kryptos/Random/_UserFriendlyRNG.js',
88+
'kryptos/Random/Fortuna/SHAd256.js',
89+
'kryptos/Random/Fortuna/FortunaAccumulator.js',
90+
'kryptos/Random/Fortuna/FortunaGenerator.js',
91+
'kryptos/Random/OSRNG/browser.js',
92+
93+
'common.js',
94+
'python_shim.js',
95+
'BigInteger.js',
96+
97+
'agent.js',
98+
'auth_handler.js',
99+
'ber.js',
100+
'channel.js',
101+
'client.js',
102+
'compress.js',
103+
'dsskey.js',
104+
'file.js',
105+
'hostkeys.js',
106+
'kex_gex.js',
107+
'kex_group1.js',
108+
'message.js',
109+
'packet.js',
110+
'pkey.js',
111+
'rsakey.js',
112+
'sftp_attr.js',
113+
'sftp_client.js',
114+
'sftp_file.js',
115+
'sftp.js',
116+
'ssh_exception.js',
117+
'transport.js',
118+
'util.js',
119+
'win_pageant.js',
120+
],
121+
options: {
122+
// options here to override JSHint defaults
123+
shadow: true,
124+
esnext: true,
125+
globals: {
126+
jQuery: true,
127+
console: true,
128+
module: true,
129+
document: true
130+
}
131+
}
132+
}
133+
});
134+
135+
// Load the plugin that provides the "uglify" task.
136+
grunt.loadNpmTasks('grunt-contrib-uglify');
137+
grunt.loadNpmTasks('grunt-contrib-concat');
138+
grunt.loadNpmTasks('grunt-contrib-jshint');
139+
140+
// Default task(s).
141+
//grunt.registerTask('default', ['jshint', 'concat:js', 'uglify']);
142+
grunt.registerTask('default', ['concat:js', 'uglify']);
143+
144+
};

‎agent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ paramikojs.Agent = function () {
2020

2121
this.conn = null;
2222
this.keys = [];
23-
var userEnvironment = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment);
23+
var userEnvironment = window.Components.classes["@mozilla.org/process/environment;1"].getService(window.Components.interfaces.nsIEnvironment);
2424
if (userEnvironment.exists('SSH_AUTH_SOCK') && sys.platform != 'win32') {
2525
var conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM); // todo, fixme, doesn't work right now :-/
2626
var auth_sock = userEnvironment.get('SSH_AUTH_SOCK');

‎auth_handler.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ paramikojs.AuthHandler.prototype = {
134134
_parse_service_accept : function(m) {
135135
var service = m.get_string();
136136
if (service == 'ssh-userauth') {
137-
this.transport._log(DEBUG, 'userauth is OK');
137+
console.debug('userauth is OK');
138138
var m = new paramikojs.Message();
139139
m.add_byte(String.fromCharCode(paramikojs.MSG_USERAUTH_REQUEST));
140140
m.add_string(this.username);
@@ -146,7 +146,7 @@ paramikojs.AuthHandler.prototype = {
146146
try {
147147
password = this.transport.toUTF8.convertStringToUTF8(password, "UTF-8", 1);
148148
} catch(ex) {
149-
this.transport._log(DEBUG, ex);
149+
console.debug(ex);
150150
}
151151
m.add_string(password);
152152
} else if (this.auth_method == 'publickey') {
@@ -172,19 +172,19 @@ paramikojs.AuthHandler.prototype = {
172172
}
173173
this.transport._send_message(m);
174174
} else {
175-
this.transport._log(DEBUG, 'Service request "' + service + '" accepted (?)');
175+
console.debug('Service request "' + service + '" accepted (?)');
176176
}
177177
},
178178

179179
_send_auth_result : function(username, method, result) {
180180
// okay, send result
181181
var m = new paramikojs.Message();
182182
if (result == paramikojs.AUTH_SUCCESSFUL) {
183-
this.transport._log(INFO, 'Auth granted (' + method + ').');
183+
console.info('Auth granted (' + method + ').');
184184
m.add_byte(String.fromCharCode(paramikojs.MSG_USERAUTH_SUCCESS));
185185
this.authenticated = true;
186186
} else {
187-
this.transport._log(INFO, 'Auth rejected (' + method + ').');
187+
console.info('Auth rejected (' + method + ').');
188188
m.add_byte(String.fromCharCode(paramikojs.MSG_USERAUTH_FAILURE));
189189
m.add_string(this.transport.server_object.get_allowed_auths(username));
190190
if (result == paramikojs.AUTH_PARTIALLY_SUCCESSFUL) {
@@ -235,13 +235,13 @@ paramikojs.AuthHandler.prototype = {
235235
var username = m.get_string();
236236
var service = m.get_string();
237237
var method = m.get_string();
238-
this.transport._log(DEBUG, 'Auth request (type=' + method + ') service=' + service + ', username=' + username);
238+
console.debug('Auth request (type=' + method + ') service=' + service + ', username=' + username);
239239
if (service != 'ssh-connection') {
240240
this._disconnect_service_not_available();
241241
return;
242242
}
243243
if (this.auth_username && this.auth_username != username) {
244-
this.transport._log(INFO, 'Auth rejected because the client attempted to change username in mid-flight');
244+
console.info('Auth rejected because the client attempted to change username in mid-flight');
245245
this._disconnect_no_more_auth();
246246
return;
247247
}
@@ -258,7 +258,7 @@ paramikojs.AuthHandler.prototype = {
258258
if (changereq) {
259259
// always treated as failure, since we don't support changing passwords, but collect
260260
// the list of valid auth types from the callback anyway
261-
this.transport._log(DEBUG, 'Auth request to change passwords (rejected)');
261+
console.debug('Auth request to change passwords (rejected)');
262262
var newpassword = m.get_string();
263263
newpassword = this.transport.fromUTF8.ConvertFromUnicode(newpassword) + this.transport.fromUTF8.Finish();
264264
result = paramikojs.AUTH_FAILED;
@@ -272,7 +272,7 @@ paramikojs.AuthHandler.prototype = {
272272
try {
273273
key = this.transport._key_info[keytype](new paramikojs.Message(keyblob));
274274
} catch(ex) {
275-
this.transport._log(INFO, 'Auth rejected: public key: ' + ex.toString());
275+
console.info('Auth rejected: public key: ' + ex.toString());
276276
key = null;
277277
}
278278
if (!key) {
@@ -296,7 +296,7 @@ paramikojs.AuthHandler.prototype = {
296296
var sig = new paramikojs.Message(m.get_string());
297297
var blob = this._get_session_blob(key, service, username);
298298
if (!key.verify_ssh_sig(blob, sig)) {
299-
this.transport._log(INFO, 'Auth rejected: invalid signature');
299+
console.info('Auth rejected: invalid signature');
300300
result = paramikojs.AUTH_FAILED;
301301
}
302302
}
@@ -317,7 +317,7 @@ paramikojs.AuthHandler.prototype = {
317317
},
318318

319319
_parse_userauth_success : function(m) {
320-
this.transport._log(INFO, 'Authentication (' + this.auth_method + ') successful!');
320+
console.info('Authentication (' + this.auth_method + ') successful!');
321321
this.authenticated = true;
322322
this.transport._auth_trigger();
323323
this.transport.auth_callback(true);
@@ -328,17 +328,17 @@ paramikojs.AuthHandler.prototype = {
328328
var partial = m.get_boolean();
329329
var nextOptions = null;
330330
if (partial) {
331-
this.transport._log(INFO, 'Authentication continues...');
332-
this.transport._log(DEBUG, 'Methods: ' + authlist.toString());
331+
console.info('Authentication continues...');
332+
console.debug('Methods: ' + authlist.toString());
333333
//this.transport.saved_exception = new paramikojs.ssh_exception.PartialAuthentication(authlist);
334334
nextOptions = authlist;
335335
} else if (authlist.indexOf(this.auth_method) == -1) {
336-
this.transport._log(DEBUG, 'Authentication type (' + this.auth_method + ') not permitted.');
337-
this.transport._log(DEBUG, 'Allowed methods: ' + authlist.toString());
336+
console.debug('Authentication type (' + this.auth_method + ') not permitted.');
337+
console.debug('Allowed methods: ' + authlist.toString());
338338
//this.transport.saved_exception = new paramikojs.ssh_exception.BadAuthenticationType('Bad authentication type', authlist);
339339
nextOptions = authlist;
340340
} else {
341-
this.transport._log(INFO, 'Authentication (' + this.auth_method + ') failed.');
341+
console.info('Authentication (' + this.auth_method + ') failed.');
342342
}
343343
this.authenticated = false;
344344
this.username = null;
@@ -348,7 +348,7 @@ paramikojs.AuthHandler.prototype = {
348348
_parse_userauth_banner : function(m) {
349349
var banner = m.get_string();
350350
var lang = m.get_string();
351-
this.transport._log(INFO, 'Auth banner: ' + banner);
351+
console.info('Auth banner: ' + banner);
352352
// who cares.
353353
},
354354

‎channel.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ paramikojs.Channel = function (chanid) {
4141
this.in_window_threshold = 0;
4242
this.in_window_sofar = 0;
4343
this._name = chanid.toString();
44-
this.logger = paramikojs.util.get_logger();
4544
this._pipe = null;
4645
this.event_ready = false;
4746
this.combine_stderr = false;
@@ -831,19 +830,19 @@ paramikojs.Channel.prototype = {
831830
// threshold of bytes we receive before we bother to send a window update
832831
this.in_window_threshold = parseInt(window_size / 10);
833832
this.in_window_sofar = 0;
834-
this._log(DEBUG, 'Max packet in: ' + max_packet_size + ' bytes');
833+
console.debug('Max packet in: ' + max_packet_size + ' bytes');
835834
},
836835

837836
_set_remote_channel : function(chanid, window_size, max_packet_size) {
838837
this.remote_chanid = chanid;
839838
this.out_window_size = window_size;
840839
this.out_max_packet_size = Math.max(max_packet_size, paramikojs.Channel.MIN_PACKET_SIZE);
841840
this.active = 1;
842-
this._log(DEBUG, 'Max packet out: ' + max_packet_size + ' bytes');
841+
console.debug('Max packet out: ' + max_packet_size + ' bytes');
843842
},
844843

845844
_request_success : function(m) {
846-
this._log(DEBUG, 'Sesch channel ' + this.chanid + ' request ok');
845+
console.debug('Sesch channel ' + this.chanid + ' request ok');
847846
},
848847

849848
_request_failed : function(m) {
@@ -871,7 +870,7 @@ paramikojs.Channel.prototype = {
871870
var code = m.get_int();
872871
var s = m.get_string();
873872
if (code != 1) {
874-
this._log(ERROR, 'unknown extended_data type ' + code + '; discarding');
873+
console.error('unknown extended_data type ' + code + '; discarding');
875874
return;
876875
}
877876
if (this.combine_stderr) {
@@ -884,7 +883,7 @@ paramikojs.Channel.prototype = {
884883
_window_adjust : function(m) {
885884
var nbytes = m.get_int();
886885
if (this.ultra_debug) {
887-
this._log(DEBUG, 'window up ' + nbytes);
886+
console.debug('window up ' + nbytes);
888887
}
889888
this.out_window_size += nbytes;
890889
},
@@ -953,7 +952,7 @@ paramikojs.Channel.prototype = {
953952
ok = server.check_channel_x11_request(this, single_connection, auth_proto, auth_cookie, screen_number);
954953
}
955954
} else {
956-
this._log(DEBUG, 'Unhandled channel request "' + key + '"');
955+
console.debug('Unhandled channel request "' + key + '"');
957956
ok = false;
958957
}
959958
if (want_reply) {
@@ -977,7 +976,7 @@ paramikojs.Channel.prototype = {
977976
this._pipe.set_forever();
978977
}
979978
}
980-
this._log(DEBUG, 'EOF received (' + this._name + ')');
979+
console.debug('EOF received (' + this._name + ')');
981980
},
982981

983982
_handle_close : function(m) {
@@ -994,10 +993,6 @@ paramikojs.Channel.prototype = {
994993

995994
// internals...
996995

997-
_log : function(level, msg) {
998-
this.logger.log(level, msg);
999-
},
1000-
1001996
_set_closed : function() {
1002997
this.closed = true;
1003998
this.in_buffer = "";
@@ -1012,7 +1007,7 @@ paramikojs.Channel.prototype = {
10121007
m.add_byte(String.fromCharCode(paramikojs.MSG_CHANNEL_EOF));
10131008
m.add_int(this.remote_chanid);
10141009
this.eof_sent = true;
1015-
this._log(DEBUG, 'EOF sent (' + this._name + ')');
1010+
console.debug('EOF sent (' + this._name + ')');
10161011
return m;
10171012
},
10181013

@@ -1044,14 +1039,14 @@ paramikojs.Channel.prototype = {
10441039
return 0;
10451040
}
10461041
if (this.ultra_debug) {
1047-
this._log(DEBUG, 'addwindow ' + n);
1042+
console.debug('addwindow ' + n);
10481043
}
10491044
this.in_window_sofar += n;
10501045
if (this.in_window_sofar <= this.in_window_threshold) {
10511046
return 0;
10521047
}
10531048
if (this.ultra_debug) {
1054-
this._log(DEBUG, 'addwindow send ' + this.in_window_sofar);
1049+
console.debug('addwindow send ' + this.in_window_sofar);
10551050
}
10561051
var out = this.in_window_sofar;
10571052
this.in_window_sofar = 0;
@@ -1083,7 +1078,7 @@ paramikojs.Channel.prototype = {
10831078
}
10841079
this.out_window_size -= size;
10851080
if (this.ultra_debug) {
1086-
this._log(DEBUG, 'window down to ' + this.out_window_size);
1081+
console.debug('window down to ' + this.out_window_size);
10871082
}
10881083
return size;
10891084
}

0 commit comments

Comments
 (0)
Please sign in to comment.