MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_authorization

Method get_authorization

Lib/urllib/request.py:1116–1176  ·  view source on GitHub ↗
(self, req, chal)

Source from the content-addressed store, hash-verified

1114 return dig[:16]
1115
1116 def get_authorization(self, req, chal):
1117 try:
1118 realm = chal['realm']
1119 nonce = chal['nonce']
1120 qop = chal.get('qop')
1121 algorithm = chal.get('algorithm', 'MD5')
1122 # mod_digest doesn't send an opaque, even though it isn't
1123 # supposed to be optional
1124 opaque = chal.get('opaque', None)
1125 except KeyError:
1126 return None
1127
1128 H, KD = self.get_algorithm_impls(algorithm)
1129 if H is None:
1130 return None
1131
1132 user, pw = self.passwd.find_user_password(realm, req.full_url)
1133 if user is None:
1134 return None
1135
1136 # XXX not implemented yet
1137 if req.data is not None:
1138 entdig = self.get_entity_digest(req.data, chal)
1139 else:
1140 entdig = None
1141
1142 A1 = "%s:%s:%s" % (user, realm, pw)
1143 A2 = "%s:%s" % (req.get_method(),
1144 # XXX selector: what about proxies and full urls
1145 req.selector)
1146 # NOTE: As per RFC 2617, when server sends "auth,auth-int", the client could use either `auth`
1147 # or `auth-int` to the response back. we use `auth` to send the response back.
1148 if qop is None:
1149 respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
1150 elif 'auth' in qop.split(','):
1151 if nonce == self.last_nonce:
1152 self.nonce_count += 1
1153 else:
1154 self.nonce_count = 1
1155 self.last_nonce = nonce
1156 ncvalue = '%08x' % self.nonce_count
1157 cnonce = self.get_cnonce(nonce)
1158 noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, 'auth', H(A2))
1159 respdig = KD(H(A1), noncebit)
1160 else:
1161 # XXX handle auth-int.
1162 raise URLError("qop '%s' is not supported." % qop)
1163
1164 # XXX should the partial digests be encoded too?
1165
1166 base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
1167 'response="%s"' % (user, realm, nonce, req.selector,
1168 respdig)
1169 if opaque:
1170 base += ', opaque="%s"' % opaque
1171 if entdig:
1172 base += ', digest="%s"' % entdig
1173 base += ', algorithm="%s"' % algorithm

Callers 1

Calls 9

get_algorithm_implsMethod · 0.95
get_entity_digestMethod · 0.95
get_cnonceMethod · 0.95
URLErrorClass · 0.90
HClass · 0.50
getMethod · 0.45
find_user_passwordMethod · 0.45
get_methodMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected