标签: digest-authentication

带有 Python 请求模块的 HTTP 摘要/基本身份验证

我的目标是能够html/xml data从受密码保护的页面进行解析,然后根据我需要发送xml commands到另一台设备的数据(时间戳)进行解析。我试图访问的页面是由 IP 设备生成的网络服务器。另外,如果用另一种语言更容易完成,请告诉我。我的编程经验很少(一门C编程课)

我曾尝试使用 Requests for Basic 和 Digest Auth。我仍然无法通过身份验证,这使我无法进一步了解。

这是我的尝试:

import requests
from requests.auth import HTTPDigestAuth

url='http://myUsername:myPassword@example.com/cgi/metadata.cgi?template=html'
r = requests.get(url, auth=HTTPDigestAuth('myUsername', 'myPassword'))        
r.status_code

print(r.headers) 
print(r.status_code)
Run Code Online (Sandbox Code Playgroud)

输出:

401 
CaseInsensitiveDict({'Content-Length': '0', 'WWW-Authenticate': 'Digest realm="the realm of device", nonce="23cde09025c589f05f153b81306928c8", qop="auth"', 'Server': 'Device server name'})
Run Code Online (Sandbox Code Playgroud)

我也尝试BasicAuth过请求并获得相同的输出。我已经尝试过包括user:pass@url 内的 和 不包括在内。尽管当我将该输入放入浏览器时,它可以工作。

我认为请求处理了标头数据,Digest/BasicAuth但也许我还需要包含标头?

我使用了 Live HTTP Headers(firefox) 并得到了这个:

GET /cgi/metadata.cgi?template=html
HTTP/1.1 
Host: [Device IP] 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0 Accept: …
Run Code Online (Sandbox Code Playgroud)

xml http digest-authentication python-3.x python-requests

8
推荐指数
1
解决办法
1万
查看次数

CFHTTPMessageAddAuthentication无法向请求添加身份验证数据

我正在尝试扩展SocketRocket库的功能.我想添加身份验证功能.

由于此库使用CFNetwork CFHTTPMessage*API进行HTTP功能(需要启动Web套接字连接),我正在尝试使用此API来提供身份验证.
有完美匹配的功能:CFHTTPMessageAddAuthentication,但它不能像我期望的那样工作(据我理解的文档).

以下是显示问题的代码示例:

- (CFHTTPMessageRef)createAuthenticationHandShakeRequest: (CFHTTPMessageRef)chalengeMessage {
    CFHTTPMessageRef request = [self createHandshakeRequest];
    BOOL result = CFHTTPMessageAddAuthentication(request,
                                                 chalengeMessage,
                                                 (__bridge CFStringRef)self.credentials.user,
                                                 (__bridge CFStringRef)self.credentials.password,
                                                 kCFHTTPAuthenticationSchemeDigest, /* I've also tried NULL for use strongest supplied authentication */
                                                 NO);
    if (!result) {
        NSString *chalengeDescription = [[NSString alloc] initWithData: CFBridgingRelease(CFHTTPMessageCopySerializedMessage(chalengeMessage))
                                                              encoding: NSUTF8StringEncoding];
        NSString  *requestDescription = [[NSString alloc] initWithData: CFBridgingRelease(CFHTTPMessageCopySerializedMessage(request))
                                                              encoding: NSUTF8StringEncoding];
        SRFastLog(@"Failed to add authentication data `%@` to a request:\n%@After a chalenge:\n%@",
                  self.credentials, requestDescription, chalengeDescription); …
Run Code Online (Sandbox Code Playgroud)

macos objective-c cfnetwork digest-authentication ios

8
推荐指数
1
解决办法
917
查看次数

Javascript摘要手动身份验证

我阅读了有关摘要认证的所有帖子,我正在尝试,但我有任何问题,我有一个实施摘要认证的restlet,并与javascript api我正在尝试进行身份验证.

首先,我对服务器执行xmlhttprequest POST(从file://到localhost:8111,因此我遇到了CORS问题但是已经解决了),以及服务器响应401和WWW-Authenticate标头:

WWW-Authenticate:Digest realm="Guard", domain="/",        nonce="MTMzOTA5Mjk1NTE2NDo0NzY2NjJiOTgyMjE1ZDc0OWU3NzM5MTkzMWNjNGQzNw==", algorithm=MD5, qop="auth"
Run Code Online (Sandbox Code Playgroud)

所以我采用这个标题并应用身份验证摘要算法:首先创建2个变量,"cnonce"和"nc":

tokensObj["cnonce"] = 'bd5fd9b093dccaa1'; (invented)
tokensObj["nc"] = '00000001';
Run Code Online (Sandbox Code Playgroud)

我在我的文字对象中创建'uri'参数(在服务器响应中有一个"域":?)我取'domain'的值并放入我的对象的'uri'键.

之后,我做了算法:

var HA1 = MD5("login:Guard:mypassword");
var HA2 = MD5("POST:/");
var authResponse = MD5(HA1 + ':' + 

        unquotes(tokensObj["nonce"]) +
        ':' +
        tokensObj["nc"] +
        ':' +
        tokensObj["cnonce"] +
        ':' +
                    unquotes(tokensObj["qop"]) +
        ':' +
        HA2);
var responseContentHeader = 'Digest username:"login"' +', realm=' + tokensObj["realm"] +
                           ', nonce=' + tokensObj["nonce"] +
                           ', uri=' + tokensObj["domain"]  +
               ', algorithm=' + tokensObj["algorithm"] +
               ', response="' + …
Run Code Online (Sandbox Code Playgroud)

javascript xmlhttprequest digest digest-authentication

7
推荐指数
1
解决办法
5283
查看次数

我可以在摘要式身份验证中使用已经MD5编码的密码吗?

我在数据库中有MD5哈希密码,我想用来对抗HTTP AUTH DIGEST.但是在阅读文档时,看起来摘要哈希包含用户名,域和明文密码的哈希值.在这种情况下有没有办法使用密码的MD5哈希?

passwords hash md5 digest-authentication

6
推荐指数
2
解决办法
3535
查看次数

PHP Digest auth,注销

有没有办法注销在php中完成的摘要认证.

我试过unset($ _ SERVER ["PHP_AUTH_DIGEST"]); 但它不会要求重新登录.我知道如果我关闭浏览器然后它将工作,这是我的功能.

    function login(){
        $realm = "Restricted area";
        $users = array("jamesm"=>"");
        if (empty($_SERVER["PHP_AUTH_DIGEST"])) {
            header("HTTP/1.1 401 Unauthorized");
            header("WWW-Authenticate: Digest realm=\"{$realm}\",qop=\"auth\",nonce=\"".uniqid()."\",opaque=\"".md5($realm)."\"");
            return false;
        }
        if (!($data = http_digest_parse($_SERVER["PHP_AUTH_DIGEST"])) || !isset($users[$data["username"]]))
            return false;
        $A1 = md5($data["username"] . ":{$realm}:{$users[$data["username"]]}");
        $A2 = md5($_SERVER["REQUEST_METHOD"].":{$data["uri"]}");
        $valid_response = md5("{$A1}:{$data["nonce"]}:{$data["nc"]}:{$data["cnonce"]}:{$data["qop"]}:{$A2}");
        if ($data["response"] != $valid_response)
            return false;
        return true;
    }
    function logout(){
        unset($_SERVER["PHP_AUTH_DIGEST"]);
        return true;
    }
Run Code Online (Sandbox Code Playgroud)

我还需要添加到注销功能以完成此操作.

如果我改变了它的作用,但我不希望它被改变.

php security logout digest-authentication http-status-code-401

6
推荐指数
2
解决办法
1万
查看次数

red5读取tomcat-users.xml

我一直忙着为Red5创建一个应用程序.想象一下,当我尝试配置基本/摘要身份验证时,我感到惊讶,但事实并非如此.令我感到奇怪的是,我有一个正在运行的tomcat实例,可以使用以下xmls正确运行和验证:

web.xml(部分)

<security-constraint>
        <web-resource-collection>
            <web-resource-name>A Protected Page</web-resource-name>
            <url-pattern>/stats.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>tomcat</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>DIGEST</auth-method>
        <realm-name>BLAAAAAAAAAAAAAAAAA</realm-name>
    </login-config>
    <security-role>
        <description/>
        <role-name>tomcat</role-name>
    </security-role>
Run Code Online (Sandbox Code Playgroud)

/ conf 中的tomcat-users.xml看起来有点像这样:

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
  <role rolename="tomcat"/>
  <user username="ide" password="bogus" roles="tomcat"/>
</tomcat-users>
Run Code Online (Sandbox Code Playgroud)

令人讨厌的是配置在tomcat的servlet容器上正确验证,但在red5的修改后的容器上,它只是不断要求验证.我变得疯了还是应该像魅力一样工作?

  1. Red5是版本0_9_1
  2. stats.jsp可以在两个servlet容器中访问,唯一的区别是当你在tomcat中输入正确的密码和用户名时,你已经登录了,而在red5中你不是,它只是一直在问你输入密码.

有什么指针吗?我错过了什么吗?

这是我尝试登录时收到的错误的堆栈跟踪:

Caused by: java.io.IOException: Unable to locate a login configuration
        at com.sun.security.auth.login.ConfigFile.init(ConfigFile.java:250) [na:1.6.0_22]
        at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:91) [na:1.6.0_22]
        ... 27 common frames omitted
[ERROR] [http-127.0.0.1-5080-1] org.apache.catalina.realm.JAASRealm - Cannot find message associated with key jaasRealm.unexpectedError
java.lang.SecurityException: Unable to locate a …
Run Code Online (Sandbox Code Playgroud)

java tomcat web.xml red5 digest-authentication

6
推荐指数
1
解决办法
2943
查看次数

Android:Volley HTTP Request自定义标头

运行应用程序时出现以下错误:BasicNetwork.performRequest:意外的响应代码401

我需要传递电子邮件,密码和令牌来访问URL,但它无法正常工作

我上周开始学习android,我不太了解

package quest.testvolley;

import com.android.volley.AuthFailureError;
import com.android.volley.VolleyLog;
import com.kpbird.volleytest.R;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;

import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity {

    private String TAG = this.getClass().getSimpleName();
    private ListView lstView;
    private RequestQueue mRequestQueue;
    private ArrayList<NewsModel> arrNews ;
    private LayoutInflater …
Run Code Online (Sandbox Code Playgroud)

android httprequest digest-authentication android-volley

6
推荐指数
1
解决办法
2万
查看次数

使用HA1的HTTPURLSession摘要认证(不是密码)

简单地说,我有使用user nameHA1值进行摘要认证的场景(在过去某处计算过,或者通过对其他服务器的认证是提供者).密码不可用.

现在我该如何处理这种情况NSURLSession

我是否必须手动完成(计算HA2response我自己)或者是否有一些解决方案?(它应该存在,因为将密码保存为纯文本是一个安全问题).

请注意我的场景HA1来自对其他服务器的身份验证,因此NSURLCredential 持久化NSURLCredentialPersistencePermanent不能解决我的问题.

macos objective-c digest-authentication ios nsurlsession

6
推荐指数
0
解决办法
166
查看次数

Epson TM-T88V-i摘要认证无效

我的Epson TM-T88V-i收据打印机尝试从服务器URL获取XML数据,该服务器URL需要打印机通过HTTP摘要进行身份验证.(此Epson功能称为" 服务器直接打印 ")

从打印机的Web控制台,我能够向服务器发送测试请求,但HTTP摘要认证失败.如果让打印机尝试在服务器上进行身份验证,也会发生同样的情况.

如果我尝试通过浏览器访问URL,则会出现HTTP摘要用户名+密码框,如果我输入凭据,XML将按预期显示在浏览器中.这表明服务器端的HTTP摘要机制设置正确(我使用的是PHP框架Symfony 2.8).

在服务器端,我看到以下日志信息:

步骤1
[2016-04-03 16:33:01] security.INFO:抛出了AuthenticationException; 重定向到身份验证入口点.{"exception":"[object](Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code:0):在TokenStorage中找不到令牌.在/home/.../src/Symfony/Component/安全/ HTTP /防火墙/ AccessListener.php:53)"}


步骤2
[2016-04-03 16:33:01] security.DEBUG:调用认证入口点.


步骤3
[2016-04-03 16:33:01] security.DEBUG:从用户代理收到的摘要授权标头.{"header":"username = \"printer \",realm = \"example \",nonce = \"MTQ1OTk5Mzk4MS40NjQ3OmI0OTVmN2ZkZTlhYmE1NmNjNDIxNmIxMWU0OGVmYjUz \",uri = \"/ export \",cnonce = \"MDAxNjM0 \",nc = 00000001 ,qop = \"auth \",response = \" c6ad88607624efd17f7de602f6ee9def \""}
步骤4
[2016-04-03 16:33:01] security.DEBUG:来自DigestAuth的意外响应; 标题返回明文密码? {"expected":" 741bff6abed513b6948c26eae529b6b6 ","已收到":" c6ad88607624efd17f7de602f6ee9def "}


步骤5
[2016-04-03 16:33:01] security.INFO:摘要认证失败.{"exception":"[object](Symfony\Component\Security\Core\Exception\BadCredentialsException(code:0):/home/.../src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener的响应不正确.PHP:107)"}

日志文件告诉我们服务器端发生了什么:

  1. 在步骤1 + 2中,Epson尝试访问受HTTP摘要保护的服务器URL,服务器发送带有nonce的401"未授权"响应(我们在此日志文件中没有看到此信息)

  2. 在步骤3中,Epson发送HTTP摘要客户端授权请求,包括所有必要的数据.所述响应参数包含散列出其他授权参数来生成

  3. 在步骤4中,我的symfony 2.8应用程序说,Epson在步骤3中发送的散列响应参数不是HTTP摘要过程所期望的参数.

  4. 最后,步骤5显示HTTP摘要认证失败.

据我所知,摘要认证过程(如维基百科上所述)是正确的,除了Epson不在他的认证请求中计算正确的哈希值. …

authentication digest epson digest-authentication symfony

6
推荐指数
1
解决办法
258
查看次数

urllib 的“握手操作超时”,适用于请求

首先,这是针对 Gira Homeserver 的,它是家庭自动化服务器。它有Python 2.7,我无法安装外部模块。

但为了测试和示例,我一直在使用 python 2.7.15 和 python 3.6.8 (但也尝试了一些其他版本 - 相同的结果)

我想做的是从我的飞利浦 Android TV 的网络服务器读取内容。这适用于浏览器,适用于 Curl,也适用于 Python 请求。但它不适用于 urllib2,而我需要使用 urllib2 才能与我的家庭自动化系统一起使用。

电视在需要摘要身份验证的 https 网页上提供 json 输出。

Urllib 示例(Python3,能够与请求进行比较):

import urllib.request
import ssl

url="https://192.168.3.100:1926/6/powerstate"
username="6AJeu5Ffdm9dQnum"
password="5a21386d952c2f1fbe66be2471d98c391bb918a6d2130cdf1b6deb2b87872eaa"

ctx = ssl._create_unverified_context()

auth = urllib.request.HTTPDigestAuthHandler(urllib.request.HTTPPasswordMgrWithDefaultRealm())
auth.add_password (None, url, username, password)

opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=ctx,debuglevel=1), auth)
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url,None,10)
Run Code Online (Sandbox Code Playgroud)

请求示例:

import requests
import ssl

url="https://192.168.3.100:1926/6/powerstate"
username="6AJeu5Ffdm9dQnum"
password="5a21386d952c2f1fbe66be2471d98c391bb918a6d2130cdf1b6deb2b87872eaa"


from requests.auth import HTTPDigestAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
r = requests.get(url, auth=HTTPDigestAuth(username, password), timeout=10, …
Run Code Online (Sandbox Code Playgroud)

python ssl urllib2 digest-authentication python-3.x

6
推荐指数
1
解决办法
2万
查看次数