【问题标题】:Is there any way to access certificate information from a Chrome Extension有什么方法可以从 Chrome 扩展程序访问证书信息
【发布时间】:2011-09-27 20:03:07
【问题描述】:

我想从 Google Chrome 扩展程序访问 SSL 证书信息。

我在这里查看了 API:http://code.google.com/chrome/extensions/api_index.html,但没有看到任何可以完成工作的东西。

理想情况下,我想访问颁发者、有效期、主题、序列号等...

这在 Mozilla/Firefox 中似乎是可能的:

https://developer.mozilla.org/En/How_to_check_the_security_state_of_an_XMLHTTPRequest_over_SSL

http://www.sslshopper.com/article-perspectives-extension-to-change-how-firefox-handles-ssl-certificates.html

【问题讨论】:

标签: javascript google-chrome google-chrome-extension ssl-certificate chromium


【解决方案1】:

2018 年回答:webextensions(使用 Chrome 扩展 API)可以在 Firefox 62 中执行此操作

您需要制作一个 WebExtension,也称为浏览器扩展。

见accessing security information on MDN

您还可以查看以下文档:

您需要 Firefox 62。

这是一个有效的background.js

var log = console.log.bind(console)

log(`\n\nTLS browser extension loaded`)

// https://developer.chrome.com/extensions/match_patterns
var ALL_SITES = { urls: ['<all_urls>'] }

// Mozilla doesn't use tlsInfo in extraInfoSpec 
var extraInfoSpec = ['blocking']; 

// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onHeadersReceived
browser.webRequest.onHeadersReceived.addListener(async function(details){
    log(`\n\nGot a request for ${details.url} with ID ${details.requestId}`)

    // Yeah this is a String, even though the content is a Number
    var requestId = details.requestId

    var securityInfo = await browser.webRequest.getSecurityInfo(requestId, {
        certificateChain: true,
        rawDER: false
    });

    log(`securityInfo: ${JSON.stringify(securityInfo, null, 2)}`)

}, ALL_SITES, extraInfoSpec) 

log('Added listener')

manifest.json:

{
    "manifest_version": 2,
    "name": "Test extension",
    "version": "1.0",
    "description": "Test extension.",
    "icons": {
        "48": "icons/border-48.png"
    },
    "background": {
        "scripts": ["background.js"]
    },
    "permissions": [
        "webRequest",
        "webRequestBlocking",
        "<all_urls>"
    ]
}

它也可以在 Chromium 中实现一次this code is merged。

【讨论】:

    【解决方案2】:

    目前不可用,但有处理此主题的 Chromium API 提案 webRequest SSL Hooks(来自 2012 年 2 月 27 日)。

    【讨论】:

    【解决方案3】:

    您可以使用NPAPI plugin 来执行此操作。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-06
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 2014-08-19
    相关资源
    最近更新 更多