From 772582518e8690201244edc8465d531c1b41e004 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Sat, 9 Jul 2016 16:18:49 +0800 Subject: [PATCH] Add a way to view TLS certificates when error Fix #1057 --- .../brave/content/scripts/brave-about.js | 3 ++ .../brave/locales/en-US/app.properties | 1 + app/index.js | 9 +++++ js/about/aboutActions.js | 14 +++++++ js/about/certerror.js | 40 +++++++++++++++++-- js/constants/messages.js | 2 + package.json | 1 + 7 files changed, 66 insertions(+), 4 deletions(-) diff --git a/app/extensions/brave/content/scripts/brave-about.js b/app/extensions/brave/content/scripts/brave-about.js index 52825f22efa..5c213be8540 100644 --- a/app/extensions/brave/content/scripts/brave-about.js +++ b/app/extensions/brave/content/scripts/brave-about.js @@ -16,6 +16,9 @@ window.addEventListener('cert-error-accepted', (e) => { ipcRenderer.send('cert-error-accepted', e.detail.url) }) + window.addEventListener('get-cert-error-detail', (e) => { + ipcRenderer.send('get-cert-error-detail', e.detail.url) + }) window.addEventListener('new-frame', (e) => { ipcRenderer.sendToHost('new-frame', e.detail.frameOpts, e.detail.openInForeground) }) diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index 46ab66a6624..3599208c618 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -25,6 +25,7 @@ certErrorText=This site cannot be loaded due to a certificate error: certErrorAdvanced=Advanced settings certErrorSafety=Back to safety certErrorButtonText=Ignore certificate error (dangerous!) +certErrorShowCertificate=Show Certificate safebrowsingError=Dangerous Site Blocked safebrowsingErrorText=For your safety, Brave has blocked this site because it is distributing malware or stealing login credentials. safebrowsingErrorAdvanced=Advanced diff --git a/app/index.js b/app/index.js index 1ff7e4539c8..5eb719f835f 100644 --- a/app/index.js +++ b/app/index.js @@ -55,6 +55,7 @@ let lastWindowClosed = false // Domains to accept bad certs for. TODO: Save the accepted cert fingerprints. let acceptCertDomains = {} +let errorCerts = {} // URLs to callback for auth. let authCallbacks = {} // Don't show the keytar prompt more than once per 24 hours @@ -208,6 +209,8 @@ app.on('ready', () => { return } + errorCerts[url] = cert + // Tell the page to show an unlocked icon. Note this is sent to the main // window webcontents, not the webview webcontents let sender = webContents.hostWebContents || webContents @@ -450,6 +453,12 @@ app.on('ready', () => { } }) + ipcMain.on(messages.GET_CERT_ERROR_DETAIL, (event, url) => { + event.sender.send(messages.SET_CERT_ERROR_DETAIL, { + cert: errorCerts[url] + }) + }) + // save app state every 5 minutes regardless of update frequency setInterval(initiateSessionStateSave, 1000 * 60 * 5) AppStore.addChangeListener(() => { diff --git a/js/about/aboutActions.js b/js/about/aboutActions.js index 3ece6a6a0af..aead0b61d96 100644 --- a/js/about/aboutActions.js +++ b/js/about/aboutActions.js @@ -101,6 +101,20 @@ const AboutActions = { window.dispatchEvent(event) }, + /** + * Get certificate detail when error. + * + * @param {string} url - The URL with the cert error + */ + getCertErrorDetail: function (url) { + const event = new window.CustomEvent(messages.GET_CERT_ERROR_DETAIL, { + detail: { + url + } + }) + window.dispatchEvent(event) + }, + /** * Opens a context menu */ diff --git a/js/about/certerror.js b/js/about/certerror.js index 5793edc59ea..014c4eeaec4 100644 --- a/js/about/certerror.js +++ b/js/about/certerror.js @@ -15,8 +15,11 @@ class CertErrorPage extends React.Component { constructor () { super() this.state = { - advanced: false + advanced: false, + cert: null } + this.onSetCertErrorDetail = this.onSetCertErrorDetail.bind(this) + window.addEventListener('set-cert-error-detail', this.onSetCertErrorDetail) } onAccept () { @@ -40,6 +43,17 @@ class CertErrorPage extends React.Component { this.setState({advanced: true}) } + onDetail () { + aboutActions.getCertErrorDetail(this.state.url) + } + + onSetCertErrorDetail (e) { + e.stopPropagation() + this.setState({ + cert: e.detail.cert + }) + } + render () { return
@@ -49,12 +63,30 @@ class CertErrorPage extends React.Component {   {this.state.url || ''} {this.state.error || ''} + {this.state.cert + ? (
+ {'Issued To'} + {'Common Name (CN): '} + {'Organization (O): '} + {'Organization Unit(OU): '} + {'Serial Number: '} + {'Issued By'} + {'Common Name (CN): ' + this.state.cert.issuerName} + {'Organization (O): '} + {'Organization Unit(OU): '} + {'Period of Validity'} + {'Begins On: '} + {'Expires On: '} +
) : null}
) + :