From 549e9c8d60e9340d37fc6195a63f3aee779d87ca Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 7 Mar 2018 19:05:33 -0500 Subject: [PATCH 1/7] Publish debug logs on debuglogs.org --- js/debugLog.js | 63 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/js/debugLog.js b/js/debugLog.js index cc213562e5..b787fedbd4 100644 --- a/js/debugLog.js +++ b/js/debugLog.js @@ -42,6 +42,7 @@ var MAX_MESSAGES = 2000; var PHONE_REGEX = /\+\d{7,12}(\d{3})/g; + var DEBUGLOGS_BASE_URL = 'https://debuglogs.org'; var log = new DebugLog(); if (window.console) { console._log = console.log; @@ -60,13 +61,61 @@ if (log === undefined) { log = console.get(); } - return new Promise(function(resolve) { - $.post('https://api.github.com/gists', textsecure.utils.jsonThing({ - "files": { "debugLog.txt": { "content": log } } - })).then(function(response) { - console._log('Posted debug log to ', response.html_url); - resolve(response.html_url); - }).fail(resolve); + + return new Promise(function(resolve, reject) { + // $.get(DEBUGLOGS_BASE_URL).then(function (signedForm) { + + var signedForm = { + "url": "https://s3.amazonaws.com/signal-debug-logs", + "fields": { + "bucket": "signal-debug-logs", + "X-Amz-Algorithm": "...", + "X-Amz-Credential": "...", + "X-Amz-Date": "...", + "X-Amz-Security-Token": "...", + "Policy": "...", + "X-Amz-Signature": "...", + "key": "..." + } + }; + + var url = signedForm.url; + var fields = signedForm.fields; + + var formData = new FormData(); + + // NOTE: Service expects `key` to come first: + formData.append('key', fields.key); + formData.append('Content-Type', 'text/plain'); + for (var key in fields) { + if (key === 'key') { + continue; + } + var value = fields[key]; + formData.append(key, value); + } + + var contentBlob = new Blob([log], { type: 'text/plain' }); + formData.append('file', contentBlob); + + var publishedLogURL = DEBUGLOGS_BASE_URL + '/' + fields.key; + + // jQuery 2.1.1-pre `FormData` upload results in this S3 error: + // + // The body of your POST request is not well-formed + // multipart/form-data.’ + $.ajax({ + method: 'POST', + url: url, + data: formData, + processData: false, + contentType: 'multipart/form-data', + }).then(function () { + resolve(publishedLogURL); + }).fail(function () { + reject(); + }); + // }); }); }; From 3180b6ca8d8e8a39a110a866adf36ed258a70c5f Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 7 Mar 2018 19:10:47 -0500 Subject: [PATCH 2/7] Use vanilla XHR for debug log publishing Chrome still reports CORS error as response from S3 bucket does not include CORS headers but upload succeeds nonetheless. --- js/debugLog.js | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/js/debugLog.js b/js/debugLog.js index b787fedbd4..bb9621128c 100644 --- a/js/debugLog.js +++ b/js/debugLog.js @@ -63,6 +63,9 @@ } return new Promise(function(resolve, reject) { + // NOTE: Fetching the signed form requires CORS headers + // on debuglogs.org: + // $.get(DEBUGLOGS_BASE_URL).then(function (signedForm) { var signedForm = { @@ -100,21 +103,28 @@ var publishedLogURL = DEBUGLOGS_BASE_URL + '/' + fields.key; - // jQuery 2.1.1-pre `FormData` upload results in this S3 error: - // - // The body of your POST request is not well-formed - // multipart/form-data.’ - $.ajax({ - method: 'POST', - url: url, - data: formData, - processData: false, - contentType: 'multipart/form-data', - }).then(function () { - resolve(publishedLogURL); - }).fail(function () { - reject(); - }); + var request = new XMLHttpRequest(); + request.open('POST', url); + request.onreadystatechange = function (event) { + if (request.readyState !== XMLHttpRequest.DONE) { + return; + } + + // NOTE: `request.status` is `0` and Chrome reports it + // as CORS error because S3 bucket response does not + // include CORS headers but the upload succeeds: + + // if (request.status === 204) { + return resolve(publishedLogURL); + // } + + // return reject( + // new Error('Failed to publish debug log. Status: ' + + // request.statusText + ' (' + request.status + ')' + // ) + // ); + }; + request.send(formData); // }); }); }; From 6621b8ac698bf3de07056296cd9701c065d15b84 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 9 Mar 2018 11:33:28 -0500 Subject: [PATCH 3/7] Add `debuglogs.org` and S3 to permissions Allows cross-origin calls to publish debug logs. See: https://developer.chrome.com/apps/xhr --- manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index b294498227..ed9558015b 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,9 @@ {"fileSystem": ["write", "directory"]}, "alarms", "fullscreen", - "audioCapture" + "audioCapture", + "https://debuglogs.org/", + "https://s3.amazonaws.com/signal-debug-logs" ], "icons": { From 2256fed7159216223355dd8fad1d68dcb434403c Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 9 Mar 2018 12:21:31 -0500 Subject: [PATCH 4/7] Publish debug logs to debuglogs.org --- js/debugLog.js | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/js/debugLog.js b/js/debugLog.js index bb9621128c..0d621ec46d 100644 --- a/js/debugLog.js +++ b/js/debugLog.js @@ -63,25 +63,7 @@ } return new Promise(function(resolve, reject) { - // NOTE: Fetching the signed form requires CORS headers - // on debuglogs.org: - - // $.get(DEBUGLOGS_BASE_URL).then(function (signedForm) { - - var signedForm = { - "url": "https://s3.amazonaws.com/signal-debug-logs", - "fields": { - "bucket": "signal-debug-logs", - "X-Amz-Algorithm": "...", - "X-Amz-Credential": "...", - "X-Amz-Date": "...", - "X-Amz-Security-Token": "...", - "Policy": "...", - "X-Amz-Signature": "...", - "key": "..." - } - }; - + $.get(DEBUGLOGS_BASE_URL).then(function (signedForm) { var url = signedForm.url; var fields = signedForm.fields; @@ -110,22 +92,20 @@ return; } - // NOTE: `request.status` is `0` and Chrome reports it - // as CORS error because S3 bucket response does not - // include CORS headers but the upload succeeds: + if (request.status !== 204) { + return reject( + new Error('Failed to publish debug log. Status: ' + + request.statusText + ' (' + request.status + ')' + ) + ); + } - // if (request.status === 204) { - return resolve(publishedLogURL); - // } - - // return reject( - // new Error('Failed to publish debug log. Status: ' + - // request.statusText + ' (' + request.status + ')' - // ) - // ); + return resolve(publishedLogURL); }; request.send(formData); - // }); + }).fail(function () { + reject(new Error('Failed to publish logs')); + }); }); }; From e99a81d56acbbb6ce508810c5e8ba3f8fe98a2d4 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Mon, 12 Mar 2018 23:16:14 -0400 Subject: [PATCH 5/7] Remove debuglogs.org from permissions CORS is now working. Still waiting for S3 POST requests to be CORS enabled. --- manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/manifest.json b/manifest.json index ed9558015b..dc7ae43551 100644 --- a/manifest.json +++ b/manifest.json @@ -16,7 +16,6 @@ "alarms", "fullscreen", "audioCapture", - "https://debuglogs.org/", "https://s3.amazonaws.com/signal-debug-logs" ], From 206196011f9d889fe9b39dabf75b7e3263c98e40 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 13 Mar 2018 16:14:35 -0400 Subject: [PATCH 6/7] Remove debuglogs S3 bucket from permissions CORS is now working. --- manifest.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index dc7ae43551..b294498227 100644 --- a/manifest.json +++ b/manifest.json @@ -15,8 +15,7 @@ {"fileSystem": ["write", "directory"]}, "alarms", "fullscreen", - "audioCapture", - "https://s3.amazonaws.com/signal-debug-logs" + "audioCapture" ], "icons": { From ba02fe6bbe6f7654982a8b19c4bde51f377e6f19 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 13 Mar 2018 13:41:33 -0700 Subject: [PATCH 7/7] Ensure that clicks in debug log dialog don't open new dialogs --- background.html | 4 ++-- js/views/migration_view.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/background.html b/background.html index f91f9a561b..c7cb3f6008 100644 --- a/background.html +++ b/background.html @@ -698,7 +698,7 @@ sudo apt update && sudo apt install signal-desktop @@ -717,7 +717,7 @@ sudo apt update && sudo apt install signal-desktop diff --git a/js/views/migration_view.js b/js/views/migration_view.js index dd1e36a5eb..4a90f622bc 100644 --- a/js/views/migration_view.js +++ b/js/views/migration_view.js @@ -145,7 +145,7 @@ 'click .start': 'onClickStart', 'click .installed': 'onClickInstalled', 'click .choose': 'onClickChoose', - 'click .debug-log': 'onClickDebugLog', + 'click .submit-debug-log': 'onClickDebugLog', 'click .cancel': 'onClickCancel', }, initialize: function() {