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

Unified 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 side-by-side diff with in-line comments
Download patch
« remoting/host/gnubby_socket.cc ('K') | « remoting/remoting_test.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/gnubby_auth_handler.js
diff --git a/remoting/webapp/gnubby_auth_handler.js b/remoting/webapp/gnubby_auth_handler.js
index 848ab1e018b02563b99226426066ddc9aaad8b4d..1291b8669815f1c1cb4c8e15b7dd2dd02341d83c 100644
--- a/remoting/webapp/gnubby_auth_handler.js
+++ b/remoting/webapp/gnubby_auth_handler.js
@@ -30,9 +30,13 @@ remoting.GnubbyAuthHandler.prototype.onMessage = function(data) {
var message = getJsonObjectFromString(data);
var messageType = getStringAttr(message, 'type');
if (messageType == 'data') {
+ var base64Data = getStringAttr(message, 'base64Data');
+ 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
+ var connectionId = getNumberAttr(message, 'connectionId');
this.sendMessageToGnubbyd_(
- getJsonObjectFromString(getStringAttr(message, 'jsonMessage')),
- this.callback_.bind(this, getNumberAttr(message, 'connectionId')));
+ {'type': 'auth-agent@openssh.com',
+ 'data': stringToBytes_(requestData)},
+ this.callback_.bind(this, connectionId));
} else {
console.error('Invalid gnubby-auth message: ' + messageType);
}
@@ -41,15 +45,25 @@ remoting.GnubbyAuthHandler.prototype.onMessage = function(data) {
/**
* Callback invoked with data to be returned to the host.
* @param {number} connectionId The connection id.
- * @param {Object} data The JSON object to send to the host.
+ * @param {Object} response The JSON response with the data to send to the host.
* @private
*/
remoting.GnubbyAuthHandler.prototype.callback_ =
- function(connectionId, data) {
- var json_data = JSON.stringify(data);
+ function(connectionId, response) {
+ var base64Data;
+ try {
+ var responseData = getArrayAttr(response, 'data');
+ base64Data = window.btoa(bytesToString_(responseData));
+ } catch (err) {
+ 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
+ this.clientSession_.sendGnubbyAuthMessage({'type': 'error',
+ 'connectionId': connectionId});
+ return;
+ }
+
this.clientSession_.sendGnubbyAuthMessage({'type': 'data',
'connectionId': connectionId,
- 'jsonMessage': json_data});
+ 'base64Data': base64Data});
};
/**
@@ -86,4 +100,26 @@ function onGnubbydDevReply_(jsonObject, callback, reply) {
} else {
chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback);
}
-};
+}
+
+/**
+ * Convert a string to an array of bytes.
+ * @param {string} s The string to convert.
+ * @return {Array.<number>} The converted bytes.
+ */
+function stringToBytes_(s) {
+ var bytes = Array(s.length);
+ for (var i = 0; i < s.length; ++i) {
+ bytes[i] = s.charCodeAt(i);
+ }
+ return bytes;
+}
+
+/**
+ * Convert an array of bytes to a string.
+ * @param {Array.<number>} b The bytes to convert.
+ * @return {string} The converted string.
+ */
+function bytesToString_(b) {
+ return String.fromCharCode.apply(null, b);
+}
« 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