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); |
+} |