zoukankan      html  css  js  c++  java
  • 【Coursera】Security Introduction -Eighth Week(2)

    Review -Terminology(术语): Confidentiallity & Integrity 泄密 & 欺骗

    Confidentiallity:

    • Prevent unauthorized viewing of private information. 防止第三方窃取信息。

    Integrity:

    • Information is from who you think it is from and has not been modified(修改) since it was sent. 保证信息的来源是可靠的。

    Cryptographic Hashes Integrity

    在以前,传递信息 一般来说会加上一个signature,以证明自己的身份,寄信的时候用特定的蜡封,防止在中途被偷窃从而使有些不怀好意的人伪造它。
    那么同样的,在计算机世界里,信息的传递也需要一个这样的“防伪标签”。从“signature”,我们能够获知数据的来源。
    它是怎么实现的呢?Cryptographic Hashing

    A Cryptographic Hash Fuction is a function that takes an arbitrary(任意的) block of data and returns a fixed-size bit string, the (cryptographic) hash value, such that an accidental(偶然的) or intentional(有意的) change to the data will change the hash value. The data to be encoded is often called "message", and the hash value is sometimes called the message digest(摘要) or simple digest.

    哈希密码函数 的实参可以是 任意的数据段,并且会返回一个 固定大小的比特字符串。对数据偶然或者有意的改变 都会造成哈希值的变化,编成电码的数据 经常被称作“信息”,哈希值也被称作 message digest 或者是 simple digest。

    Hash Function 把很大的文本信息 转换成了 小的数字集合,A large block of data ---> fixed-size bit string。
    关键是,有不同的技术 来把这些文本 对应到(map) 数字集合,一些技术会比较优秀,使用精确的数学算法来理解优秀的哈希密码系统是什么样的。比如 SHA1 或者 MD5.

    MD5的作用是让大容量信息在用数字签名软件签署私人密钥前被"压缩"成一种保密的格式(就是把一个任意长度的字节串变换成一定长的十六进制数字串)。除了MD5以外,其中比较有名的还有sha-1、RIPEMD以及Haval等。
    

    每一项技术 都是非常久的科研的成果。
    比如,我在信息中加了一些数字的记号,它们不会扩展也不会压缩,但是在某些时刻(可能你忘记了这些记号),我想改变这些记号,但是又不想改变数据。所以 哈希函数 是长期以来 严谨的精确的 科学的研究努力的结果。


    左边的数据输入,可以是兆级别的,也可以是很短的几个字节,但是右边的输出 必须是 固定的格式,不同的哈希函数实现的格式可能会不一样,但是同一个哈希函数的输出格式长度一定是固定的。
    数据的输入只要有一个字母不一样,整个的Digest就会立刻改变。第二和第四个输入,v 和 e 的顺序改变了,但是输出的Digest完全不一样。
    缺陷:但糟糕的是,输入两串不一样的数据,有可能输出的Digest会相同。这就证明了 哈希函数产生的这一串数字可能会指明两串不同的数据。如果阅读 MD5 或者 SHA-1 的哈希函数内容,它们都有谈论到这一缺陷。
    所以,一直都有研究来改进哈希函数的缺陷,使它更加精确。

    在Chuck的网站上尝试了一下 sha1:

    http://www.dr-chuck.com/sha1.php
    
    I love you ---> ce48c9870c7ae19796438aed65458c8bdc335157
    I lvoe you ---> 91df06b81b9b99120d923a495f01aeae297dd51a
    

    Hashing Passwords

    As a general rule, systems do not store your password in plain text their databases in case(以防) they "lose" their data.
    When you set the password, they compute a hash and store the hash.
    When you try to log in, they compute the hash of what you type as a password and if it matches what they have stored, they let you in.
    This is why a respectable(相当大的) system will never send your PW to you -they can only reset it!

    介绍的第一个用到哈希函数的应用 是 Hashing Passwords。比如,你登入Coursera.org,界面让你创建一个账户,设置一个密码。如果Coursera database是 以明文密码的形式 储存你的密码的,那么将会非常非常糟糕:如果某时数据库陷入危险,攻击者会得到所有的明文密码,将会利用它们来登录 不一定是Coursera 可能会登陆Twitter等等,因为大部分人都会在不同的系统使用相同的密码。
    所以较为安全的做法是,当你创建了一个密码的时候,数据库调用哈希函数来reset你的密码,转换成 hash value,然后存储它。然后当你想要登陆的时候,它们再次将你输入的密码转换成hash然后与数据库中的存储内容进行比对,如果是准确的,那么就允许你登陆。这就是为什么系统从来不回显你的密码的原因。
    将你的信息转换为hash之后,并没有办法再从hash转换成对应的信息,因为原始信息已经丢失了。这和 encryption 和 decryption 有很大的区别。

    Digital Signatures Message Integrity

    课程来到了 使用 hash fuction 以及产生的 hash value 来达成 Message Integrity。
    我们现在有了使用数据库存储密码的概念,我们现在要将这个概念迁移到 保证Message Integrity 上面。我们要解决的问题是:保证数据的来源 确实是 发送数据的来源,而不是第三者。
    系统在你输入密码的时候所做的工作,就是保证另外一端的你确实是账户的主人,所以这就是 Integrity 的一种形式:Identification(身份认证) is a form of Integrity.

    Message Integrity

    When you get a message from someone,did that message really come from who you think it came from?
    Was the message altered(更改) while in transit or is the copy you received the same as the copy that was sent?

    比如,翔翔向你发送了一条信息:“多喝水”,我们现在关心的问题,并不是“多喝水”这个文本信息,而是这个信息 是否是翔翔发送的。这是因为 我们所接收的信息 是来自 不可靠的媒介。

    Simple Message Signing 简单的文件签名

    Shared secret transported securely 'out of band'
    Before sending the message_1, concatenate(使···连接起来) the secret to the message_1.
    Compute the SHA digest of the message_1+secret.
    Send message_1+digest across the insecure transport.

    在发送数据之前,我们在数据的末尾加上secret,计算 message_1+secret 的 SHA数据摘要 也就是 digest。
    随后发送这个数据,secret并没有发送,发送的是 message_1+digest。

    Receiving a Signed Message

    Receive message_2+digest from insecure transport.
    Remove digest and add secret.
    Compute SHA digest for message_2+secret.
    Compare the computed digest(from message_2) and the received digest(from message_1).

    用我自己的语言来阐述这个过程:

    首先发送数据的一端,就叫它是A端吧,那么接收端就是B端了。

    A端首先和B端共享了 一个秘密解码(secret),SHA通过这个秘密解码可以计算出 数据和解码(message_1secret)的 SHA值,也就是我们所说的 数据摘要digest了。

    好了,A端发送了数据 message_1 和 数据1的摘要 digest_1。也就是 message_1+digest_1。

    ···经过了不可靠的媒介传送到了B端···

    OK,此时B端拥有的东西是 和A端相同的 秘密解码(secret)。接收的是 message_2(可能是message_1,也可能是message_1的变种) 和 digest_1。

    那么此时B端需要知道的是,数据是否是A端传送过来的,或者说,传送的数据是不是发生了改变。

    通过什么来验证呢:就是我们所说的数据摘要了。B端 使用 秘密解码(secret) 和 接收到的 不知道有没有发生改变的 message_2 计算出了 数据2(message_2secret)的摘要 digest_2。

    那么进行比对:digest_1 和 digest_2 如果一样 ---> message_1 和 message_2 一样 ---> 数据是A端发生的,传送过程中数据很安全,没有发生改变。

    唯一知道如何匹配的方法是 知道这个secret。也就是说,除了知道 secret 的 发送端 和 接收端,其他人并不知道 怎么样计算出 数据的摘要digest。


    传输的数据是:Eat More Ovaltine. 秘密解码:Santa SHA转换之后的digest摘要:a79540。
    发送的数据:Eat More Ovaltine.a79540

    接收方:

    总的过程(正确的匹配):

    错误的过程:

    Secret Key Shortcomings 缺点

    Every pair of person/systems needs a secret key.
    In the Internet, the key distribution(分配) cannot be via(经过) the Internet because communications are insecure until you get the key!

    For the Internet to work we need an approach(途径) where keys can across the insecure Internet and be intercepted(拦截) without compromising(妥协) security.

    2016/8/11

  • 相关阅读:
    一行代码跨平台适配颠覆传统手机建站模式
    struts2接收参数的几种形式<转>
    MyEclipse生成多对多映射文件和POJO <转>
    Hibernate延迟加载机制
    Hibernate常见面试知识点<转>
    Hibernate一级缓存详解
    App Icon and Launch Images for iOS7.0 or Later
    iOS7 UITextView 光标问题
    iOS中让颜色赋值简单一点吧
    iOS状态栏变文字颜色改变
  • 原文地址:https://www.cnblogs.com/qq952693358/p/5761097.html
Copyright © 2011-2022 走看看