Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: remoting/webapp/gnubby_auth_handler.js

Issue 205493005: Do minimal processing of gnubby data. Add request timeouts and send error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix parameter type Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« remoting/host/gnubby_socket.cc ('K') | « remoting/remoting_test.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Class that routes gnubby-auth extension messages to and from the gnubbyd 7 * Class that routes gnubby-auth extension messages to and from the gnubbyd
8 * extension. 8 * extension.
9 */ 9 */
10 10
(...skipping 12 matching lines...) Expand all
23 }; 23 };
24 24
25 /** 25 /**
26 * Processes gnubby-auth messages. 26 * Processes gnubby-auth messages.
27 * @param {string} data The gnubby-auth message data. 27 * @param {string} data The gnubby-auth message data.
28 */ 28 */
29 remoting.GnubbyAuthHandler.prototype.onMessage = function(data) { 29 remoting.GnubbyAuthHandler.prototype.onMessage = function(data) {
30 var message = getJsonObjectFromString(data); 30 var message = getJsonObjectFromString(data);
31 var messageType = getStringAttr(message, 'type'); 31 var messageType = getStringAttr(message, 'type');
32 if (messageType == 'data') { 32 if (messageType == 'data') {
33 var base64Data = getStringAttr(message, 'base64Data');
34 var requestData = window.atob(/** @type {string} */ base64Data);
Sergey Ulanov 2014/03/21 02:09:37 move @type above base64Data declaration
Sergey Ulanov 2014/03/21 02:09:37 The host encodes the data in base64 and here the c
psj 2014/03/21 21:30:45 Done.
psj 2014/03/21 21:30:45 The compiler can't figure out the type when it is
35 var connectionId = getNumberAttr(message, 'connectionId');
33 this.sendMessageToGnubbyd_( 36 this.sendMessageToGnubbyd_(
34 getJsonObjectFromString(getStringAttr(message, 'jsonMessage')), 37 {'type': 'auth-agent@openssh.com',
35 this.callback_.bind(this, getNumberAttr(message, 'connectionId'))); 38 'data': stringToBytes_(requestData)},
39 this.callback_.bind(this, connectionId));
36 } else { 40 } else {
37 console.error('Invalid gnubby-auth message: ' + messageType); 41 console.error('Invalid gnubby-auth message: ' + messageType);
38 } 42 }
39 }; 43 };
40 44
41 /** 45 /**
42 * Callback invoked with data to be returned to the host. 46 * Callback invoked with data to be returned to the host.
43 * @param {number} connectionId The connection id. 47 * @param {number} connectionId The connection id.
44 * @param {Object} data The JSON object to send to the host. 48 * @param {Object} response The JSON response with the data to send to the host.
45 * @private 49 * @private
46 */ 50 */
47 remoting.GnubbyAuthHandler.prototype.callback_ = 51 remoting.GnubbyAuthHandler.prototype.callback_ =
48 function(connectionId, data) { 52 function(connectionId, response) {
49 var json_data = JSON.stringify(data); 53 var base64Data;
54 try {
55 var responseData = getArrayAttr(response, 'data');
56 base64Data = window.btoa(bytesToString_(responseData));
57 } catch (err) {
58 console.error('gnubby callback failed: ', /** @type {*} */ (err));
Sergey Ulanov 2014/03/21 02:09:37 Not sure why it may fail here? If we fail to reenc
psj 2014/03/21 21:30:45 It will fail if response doesn't contain data, or
59 this.clientSession_.sendGnubbyAuthMessage({'type': 'error',
60 'connectionId': connectionId});
61 return;
62 }
63
50 this.clientSession_.sendGnubbyAuthMessage({'type': 'data', 64 this.clientSession_.sendGnubbyAuthMessage({'type': 'data',
51 'connectionId': connectionId, 65 'connectionId': connectionId,
52 'jsonMessage': json_data}); 66 'base64Data': base64Data});
53 }; 67 };
54 68
55 /** 69 /**
56 * Send data to the gnubbyd extension. 70 * Send data to the gnubbyd extension.
57 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension. 71 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension.
58 * @param {function(Object)} callback The callback to invoke with reply data. 72 * @param {function(Object)} callback The callback to invoke with reply data.
59 * @private 73 * @private
60 */ 74 */
61 remoting.GnubbyAuthHandler.prototype.sendMessageToGnubbyd_ = 75 remoting.GnubbyAuthHandler.prototype.sendMessageToGnubbyd_ =
62 function(jsonObject, callback) { 76 function(jsonObject, callback) {
(...skipping 16 matching lines...) Expand all
79 * @private 93 * @private
80 */ 94 */
81 function onGnubbydDevReply_(jsonObject, callback, reply) { 95 function onGnubbydDevReply_(jsonObject, callback, reply) {
82 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; 96 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco';
83 97
84 if (reply) { 98 if (reply) {
85 callback(reply); 99 callback(reply);
86 } else { 100 } else {
87 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); 101 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback);
88 } 102 }
89 }; 103 }
104
105 /**
106 * Convert a string to an array of bytes.
107 * @param {string} s The string to convert.
108 * @return {Array.<number>} The converted bytes.
109 */
110 function stringToBytes_(s) {
111 var bytes = Array(s.length);
112 for (var i = 0; i < s.length; ++i) {
113 bytes[i] = s.charCodeAt(i);
114 }
115 return bytes;
116 }
117
118 /**
119 * Convert an array of bytes to a string.
120 * @param {Array.<number>} b The bytes to convert.
121 * @return {string} The converted string.
122 */
123 function bytesToString_(b) {
124 return String.fromCharCode.apply(null, b);
125 }
OLDNEW
« remoting/host/gnubby_socket.cc ('K') | « remoting/remoting_test.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698