【发布时间】:2020-04-11 15:50:03
【问题描述】:
import httplib2
import hmac
import hashlib
import time
import sys
import struct
import json
root = "https://api.challenge.hennge.com/challenges/003"
content_type = "application/json"
userid = "toufiqurrahman45@gmail.com"
name = "HENNGECHALLENGE003"
shared_secret = userid+name
timestep = 30
T0 = 0
def HOTP(K, C, digits=10):
K_bytes = str.encode(K)
C_bytes = struct.pack(">Q", C)
hmac_sha512 = hmac.new(key = K_bytes, msg=C_bytes, digestmod=hashlib.sha512).hexdigest()
return Truncate(hmac_sha512)[-digits:]
def Truncate(hmac_sha512):
offset = int(hmac_sha512[-1], 16)
binary = int(hmac_sha512[(offset *2):((offset*2)+8)], 16) & 0x7FFFFFFF
return str(binary)
def TOTP(K, digits=10, timeref = 0, timestep = 30):
C = int ( time.time() - timeref ) // timestep
return HOTP(K, C, digits = digits)
data = { "github_url": "https://gist.github.com/TaufiqurRahman45/f5347e5ba6e7d24aa61ac8c78fda452e", "contact_email": "toufiqurrahman45@gmail.com" }
password = TOTP(shared_secret, 10, T0, timestep).zfill(10)
h = httplib2.Http()
h.add_credentials( userid, password )
header = {"content-type": "application/json"}
resp, content = h.request(root, "POST", headers = header, body = json.dumps(data))
print(resp)
print(content)
授权
URL 受 HTTP 基本身份验证保护,RFC2617 第 2 章对此进行了说明,因此您必须在 POST 请求中提供 Authorization: 标头字段
对于 HTTP 基本身份验证的用户 ID,请使用您在 JSON 字符串中输入的相同电子邮件地址。 对于密码,请提供符合 RFC6238 TOTP 的 10 位基于时间的一次性密码。
我还生成密码并使用哈希函数 HMAC-SHA-512
【问题讨论】:
-
嗨 Toufiqur,我也遇到了同样的问题,你找到为什么这不起作用了吗? :(
-
@SuperKogito 是的。使用邮递员,在授权下找到基本身份验证并输入您的电子邮件ID和随机密码...然后选择POST类型并单击发送
-
@ToufiqurRahman 邮递员和蟒蛇?
-
@Math_Avengers 你能说清楚你想知道什么吗?