如何以加密方式验证网页必备条件? [英] How to cryptographically verify web page requisites?

查看:162
本文介绍了如何以加密方式验证网页必备条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工作表或(最重要的)脚本(可能不受信任的内容交付网络),是否可以强制客户端浏览器在使用前加密验证下载资源的散列?是否有一些HTML属性或URL方案,或者手动编写一些JavaScript来做到这一点?



原理是通过HTTPS提供HTML中的哈希值提供了一个额外的防御措施,以防受损(或错误)CDN-s。



关于SO的相关问题:


  • 用于提供jQuery的CDN安全性如何?
  • 截至2016年6月23日子资源完整性是一项W3C推荐标准,允许您执行此操作(草稿版本 here )。根据实施报告,它已在Firefox 43和Chrome 45中实施。

    使用子资源完整性的一个简单示例如下所示:

     < script src =https://example.com/example.js
    integrity =sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts =
    crossorigin =anonymous>< / script>

    也可以在完整性字段中指定多个算法哈希对(称为元数据)空白并忽略无效数据(§3.3.3)。预计客户端会筛选出最强大的元数据值( §3.3.4),并将实际数据的散列值与最强元数据集中的散列值进行比较(§3.3.5)来确定资源是否有效。例如:

     < script src =https://example.com/example.js
    完整性=
    MD5-kS7IA7LOSeSlQQaNSVq1cA ==
    MD5-pfZdWPRbfElkn7w8rizxpw ==
    sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts =
    SHA256-gx3NQgFlBqcbJoC6a / OLM / CHTcqDC7zTuJx3lGLzc38 =
    SHA384-pp598wskwELsVAzLvb + xViyFeHA4yIV0nB5Aji1i + jZkLNAHX6NR6CLiuKWROc2d
    sha384-BnYJFwkG74mEUWH4elpCm8d + RFIMDgjWWbAyaXAb8Oo // cHPOeYturyDHF / UcnUB
    crossorigin =anonymous>< / script>

    如果客户端理解SHA256和SHA384而不是MD5,那么它标记< c $ c> integrity 属性,并将 md5 - 元数据标记作为垃圾丢弃。客户端然后确定元数据中最强的哈希值是SHA384,并将它们的值与接收的实际数据的SHA384哈希值进行比较。


    How to cryptographically verify web page requisites in HTML?

    For example, if I have some external resource like an image, a style sheet or (most importantly) a script on a (potentially untrusted) content delivery network, is it possible to force the client browser to cryptographically verify the hash of the downloaded resource before usage? Is there some HTML attribute or URL scheme for this or does one manually have to write some JavaScript to do it?

    The rationale is that providing the hashes in HTML served over HTTPS provides an extra defence against compromised (or faulty) CDN-s.

    Related questions on SO:

    解决方案

    As of 23 June 2016 Subresource Integrity is a W3C Recommendation which allows you to do just that (draft version here). According to the Implementation Report it is already implemented in Firefox 43 and Chrome 45.

    A simple example using subresource integrity would be something like:

    <script src="https://example.com/example.js"
        integrity="sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts="
        crossorigin="anonymous"></script>
    

    It is also possible to specify multiple algorithm-hash pairs (called metadata) in integrity field, separated by whitespace and ignoring invalid data (§3.3.3). The client is expected to filter out the strongest metadata values (§3.3.4), and compare the hash of the actual data to the hash values in set of the strongest metadata values (§3.3.5) to determine whether the resource is valid. For example:

    <script src="https://example.com/example.js"
        integrity="
           md5-kS7IA7LOSeSlQQaNSVq1cA==
           md5-pfZdWPRbfElkn7w8rizxpw==
           sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts=
           sha256-gx3NQgFlBqcbJoC6a/OLM/CHTcqDC7zTuJx3lGLzc38=
           sha384-pp598wskwELsVAzLvb+xViyFeHA4yIV0nB5Aji1i+jZkLNAHX6NR6CLiuKWROc2d
           sha384-BnYJFwkG74mEUWH4elpCm8d+RFIMDgjWWbAyaXAb8Oo//cHPOeYturyDHF/UcnUB"
        crossorigin="anonymous"></script>
    

    If the client understands SHA256 and SHA384, but not MD5, then it tokenizes the value of the integrity attribute by whitespace and throws away the md5- metadata tokens as garbage. The client then determines that the strongest hashes in the metadata are SHA384 and compares their values to the SHA384 hash of the actual data received.

    这篇关于如何以加密方式验证网页必备条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆