Http authentication....BASIC:

In the context of an HTTP transaction, basic access authentication is a method for a web browser or other client program to provide a user name and password when making a request.[1]

Before transmission, the user name is appended with a colon and concatenated with the password. The resulting string is encoded with the Base64 algorithm. For example, given the user name 'Aladdin' and password 'open sesame', the string 'Aladdin:open sesame' is Base64 encoded, resulting in 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='. The Base64-encoded string is transmitted in the HTTP header and decoded by the receiver, resulting in the colon-separated user name and password string.

While encoding the user name and password with the Base64 algorithm makes them unreadable to the unaided eye, they are as easily decoded as they are encoded. Security isnot the intent of the encoding step. Rather, the intent of the encoding is to encode non-HTTP-compatible characters that may be in the user name or password into those that are HTTP-compatible.

One advantage of the basic access authentication is all web browsers support it. Rarely it is used on publicly accessible Internet web sites but may sometimes be used by small, private systems. A later mechanism, digest access authentication, was developed in order to replace the basic access authentication and enable credentials to be passed in a relatively secure manner over an otherwise unsecure channel.

 
Http authentication.....DIGEST:

Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials with a user's web browser. It uses encryption to send the password over the network, which is safer than the Basic access authentication that sends plaintext.

Technically, digest authentication is an application of MD5 cryptographic hashing with usage of nonce values to discourage cryptanalysis. It uses the HTTP protocol.

HTTP digest authentication is designed to be more secure than traditional digest authentication schemes.

Digest access authentication is intended as a security trade-off. It is intended to replace unencrypted HTTP basic access authentication. It is not, however, intended to replace strong authentication protocols, such as public-key or Kerberos authentication.
 
HTTP协议(RFC2616)的两种认证机制(Basic和Digest) 

SIP类似Http协议。其认证模式也一样。Http协议(RFC 2616 )规定可以采用Basic模式和摘要模式(Digest schema)。RFC 2617 专门对两种认证模式做了规定。RFC 1321 是MD5标准。Digest对现代密码破解来说并不强壮,但比基本模式还是好很多。MD5已经被山东大学教授找到方法可以仿冒(我的理解),但现在还在广泛使用。 
 
1.最简单的攻击方式 
如果网站要求认证,客户端发送明文的用户名密码,那网络上的窃听者可以轻而易举的获得用户名密码,起不到安全作用。我上学时曾在科大实验室局域网内窃听别人的科大BBS的密码,发现BBS的用户名密码居然是明文传输的。那种做贼的心虚和做贼的兴奋让人激动莫名。偷人钱财会受到道德谴责,偷人密码只会暗自得意忘形。比"窃书不算偷"还没有罪恶感。因此你的用户名和密码明文传输的话,无异将一块肥肉放在嘴馋的人面前。现在很多ASP网站的认证都将用户名和密码用MD5加密。MD5是将任意长度的字符串和128位的随机数字运算后生成一个16byte的加密字符串。因此窃听者抓住的是一团乱码。但是,这有一个问题:如果窃听者就用这团乱码去认证,还是可以认证通过。因为服务器将用户名密码MD5加密后得到的字符串就是那一团乱码,自然不能区别谁是合法用户。这叫重放攻击(replay attack)。这和HTTP的基本认证模式差不多。为了安全,不要让别人不劳而获,自然要做基本的防范。下面是Http协议规定的两种认证模式。 
2.基本认证模式 
客户向服务器发送请求,服务器返回401(未授权),要求认证。401消息的头里面带了挑战信息。realm用以区分要不同认证的部分。客户端收到401后,将用户名密码和挑战信息用BASE64加密形成证书,发送回服务器认证。语法如下: 
challenge = "Basic" realm 
credentials = "Basic" basic-credentials 
示例: 
认证头: WWW-Authenticate: Basic realm="zhouhh@mydomain.com" 
证书:Authorization: Basic QsdfgWGHffuIcaNlc2FtZQ== 【虎.无名,格式如Authorization:Basic base64(username:password)。。。但是没定义如何处理realm信息,简单处理,可以针对每个realm分别有一组user:pass信息。进一步,可以走md5摘要,但这些已经超出标准,估计不被浏览器支持。】 
3.摘要访问认证 
为了防止重放攻击,采用摘要访问认证。在客户发送请求后,收到一个401(未授权)消息,包含一个Challenge。消息里面有一个唯一的字符串:nonce,每次请求都不一样。客户将用户名密码和401消息返回的挑战一起加密后传给服务器。这样即使有窃听,他也无法通过每次认证,不能重放攻击。Http并不是一个安全的协议。其内容都是明文传输。因此不要指望Http有多安全。语法如下: 
challenge = "Digest" digest-challenge 
digest-challenge = 1#( realm | [ domain ] | nonce | [opaque] |[stale] | [algorithm] | [qop-options] | [auth-param] ) 
domain = "domain" "=" <"> URI ( 1*SP URI ) <"> 
URI = absoluteURI | abs_path 
nonce = "nonce" "=" nonce-value 
nonce-value = quoted-string 
opaque = "opaque" "=" quoted-string 
stale = "stale" "=" ( "true" | "false" ) 
algorithm = "algorithm" "=" ( "MD5" | "MD5-sess" | token ) 
qop-options = "qop" "=" <"> 1#qop-value <"> 
qop-value = "auth" | "auth-int" | token 
realm:让客户知道使用哪个用户名和密码的字符串。不同的领域可能密码不一样。至少告诉用户是什么主机做认证,他可能会提示用哪个用户名登录,类似一个Email。 
domain:一个URI列表,指示要保护的域。可能是一个列表。提示用户这些URI采用一样的认证。如果为空或忽略则为整个服务器。 
nonce:随机字符串,每次401都不一样。跟算法有关。算法类似Base64加密:time-stamp H(time-stamp ":" ETag ":" private-key) 。time-stamp为服务器时钟,ETag为请求的Etag头。private-key为服务器知道的一个值。 
opaque:服务器产生的由客户下去请求时原样返回。最好是Base64串或十六进制字符串。 
auth-param:为扩展用的,现阶段忽略。 
其他域请参考RFC2617。授权头语法: 
credentials = "Digest" digest-response 
digest-response = 1#( username | realm | nonce | digest-uri | response | [ algorithm ] | [cnonce] | 
[opaque] | [message-qop] | [nonce-count] | [auth-param] ) 
username = "username" "=" username-value 
username-value = quoted-string 
digest-uri = "uri" "=" digest-uri-value 
digest-uri-value = request-uri ; As specified by HTTP/1.1 
message-qop = "qop" "=" qop-value 
cnonce = "cnonce" "=" cnonce-value 
cnonce-value = nonce-value 
nonce-count = "nc" "=" nc-value 
nc-value = 8LHEX 
response = "response" "=" request-digest 
request-digest = <"> 32LHEX <"> 
LHEX = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" 
response:加密后的密码 
digest-uri:拷贝Request-Line,用于Proxy 
cnonce:如果qop设置,才设置,用于双向认证,防止攻击。 
nonce-count:如果服务器看到同样的计数,就是一次重放。 
示例: 
401响应: HTTP/1.1 401 Unauthorized 
WWW-Authenticate: Digest 
realm="testrealm@host.com", 
qop="auth,auth-int", 
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", 
opaque="5ccc069c403ebaf9f0171e9517f40e41" 
再次请求: 
Authorization: Digest username="Mufasa", 
realm="testrealm@host.com", 
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", 
uri="/dir/index.html", 
qop=auth, 
nc=00000001, 
cnonce="0a4f113b", 
response="6629fae49393a05397450978507c4ef1", 
opaque="5ccc069c403ebaf9f0171e9517f40e41" 

http://blog.sina.com.cn/s/blog_721948c20100xw19.html

Http authentication(BASIC, DIGEST)的更多相关文章

  1. Paxos 实现日志复制同步(Basic Paxos)

    Paxos 实现日志复制同步 本篇文章以 John Ousterhout(斯坦福大学教授) 和 Diego Ongaro(斯坦福大学获得博士学位,Raft算法发明人) 在 Youtube 上的讲解视频 ...

  2. Python基础知识(Basic knowledge)

    Python基础知识(Basic knowledge) 1.认识Python&基础环境搭建 2.Python基础(上) 3.Python基础(中) 4.Python基础(下) 5.Python ...

  3. 2、基本方法(Basic Recipes)

    学习目录:树莓派学习之路-GPIO Zero 官网地址:http://gpiozero.readthedocs.io/en/stable/recipes.html 环境:UbuntuMeta-16.0 ...

  4. Flink资料(1)-- Flink基础概念(Basic Concept)

    Flink基础概念 本文描述Flink的基础概念,翻译自https://ci.apache.org/projects/flink/flink-docs-release-1.0/concepts/con ...

  5. 基本认证(Basic Authorization)

    ---------------------------------- import arcpy from base64 import encodestring username = 'xxx' pas ...

  6. CentOS7.0小随笔——指令基本操作(Part.A)

    与其说是CentOS7.0的小随笔,说老实话,基本指令在每个发行版本的Linux中都基本上是一致的. Part.A部分我们讲述以下四个方面:命令行界面与图形界面.Linux系统的关闭与重启.命令行帮助 ...

  7. 深入理解Java 8 Lambda(语言篇)

    State of Lambda by Brian Goetz 原文链接:http://lucida.me/blog/java-8-lambdas-insideout-language-features ...

  8. 清晰架构(Clean Architecture)的Go微服务: 依赖注入(Dependency Injection)

    在清晰架构(Clean Architecture)中,应用程序的每一层(用例,数据服务和域模型)仅依赖于其他层的接口而不是具体类型. 在运行时,程序容器¹负责创建具体类型并将它们注入到每个函数中,它使 ...

  9. 使用CSS选择器(第一部分)

    目录 使用CSS选择器(第一部分) 使用CSS基本选择器 选择所有元素 通用选择器 代码清单1 使用通用选择器 根据类型选择元素 元素类型选择器 代码清单2 使用元素类型选择器 提示 根据类选择元素 ...

随机推荐

  1. A trip through the Graphics Pipeline 2011_01

    It’s been awhile since I posted something here, and I figured I might use this spot to explain some ...

  2. RDBMS vs. NoSQL 合作还是竞争

    欢迎转载,转载请注明出处,徽沪一郎. 由于近期手头的工作和数据库的选型相关,纠结于是否使用一款NoSQL数据库来替换已有的MySQL数据库.在这个过程中随着学习研究的深入,对于二者的异同有了一些初步的 ...

  3. Cent OS 6.6 下安装mysql(5.5.20)和 PHP(5.3.10)

    0.准备步骤(没有连接网络的 linux): 挂载光盘.让网络 yum 源失效.修改光盘 yum 文件.安装 c 语言编译器 gcc. 1.MySQL(5.5.20) 下载 mysql 5.5.20 ...

  4. ecshop 完美解决动态ip登录超时和购物车清空问题

    ecshop 完美解决动态ip登录超时和购物车清空问题 ECSHOP模板/ecshop开发中心(www.68ecshop.com) / 2014-05-06 前一段时间,ECSHOP开发中心的一个客户 ...

  5. 放到u-boot/arch/arm/inlcude下面解压A20固件库制作笔记

    运行 build_dragonboard.sh,完成一次编译,首次编译需要消耗 20 分钟以上的时间.这里包括编译bootloader.kernel.rootfs. 修改 Linux 内核配置$ cd ...

  6. Arrays类的十大用法

    还有很多地方需要细细斟酌 0. 声明数组 String[] aArray = new String[5]; String[] bArray = {"a","b" ...

  7. Linux+环境使用vim搭建php+IDE

    让我们开始DIY吧-!!终端下执行命令:whereis vim     将列出vim安装的路径. 否则执行 sudo apt-get install vim 安装vim .成功安装了vim,只需要在用 ...

  8. MongoVUE的使用

    配置连接:   Ok,连接成功齐活儿~   下面来试一下,插入一个新的名为Message的Collection :     然后插入个Document  

  9. Apache Kafka源码分析 - autoLeaderRebalanceEnable

    在broker的配置中,auto.leader.rebalance.enable (false) 那么这个leader是如何进行rebalance的? 首先在controller启动的时候会打开一个s ...

  10. excel15个技巧

    自动定时保存Excel中的文件 点击“工具”菜单“自动保存”项,设置自动保存文件夹的间隔时间.如果在“工具”菜单下没有“自动保存”菜单项,那么执行“工具”菜单下“加载宏…”选上“自动保存”,“确定”. ...