Commit 2e19c29c authored by jehan's avatar jehan

improve digest-response.py to add response computation from ha1

parent 894c814f
......@@ -30,14 +30,15 @@ def int16(x):
return int(x, 16)
def main(argv=None):
parser = argparse.ArgumentParser(description='Compute response parameter for a digest authetication. ex %(prog)s --qop-auth --cnonce f1b8598a --nonce-count 2b toto sip.linphone.org secret REGISTER sip:sip.linphone.org QPUC2gAAAABufvQmAABDq5AKuv4AAAAA')
parser.add_argument('userid',help='User identifier')
parser.add_argument('realm',help='realm as defined by the server in 401/407')
parser.add_argument('password',help='clear text password')
parser = argparse.ArgumentParser(description='Compute response parameter for a digest authetication. ex %(prog)s --qop-auth --cnonce f1b8598a --nonce-count 2b --userid toto --realm sip.linphone.org --password secret REGISTER sip:sip.linphone.org QPUC2gAAAABufvQmAABDq5AKuv4AAAAA')
parser.add_argument('--userid',help='User identifier')
parser.add_argument('--realm',help='realm as defined by the server in 401/407')
parser.add_argument('--password',help='clear text password')
parser.add_argument('method',help='sip method of the challanged request line')
parser.add_argument('uri',help='sip uri of the challanged request uri')
parser.add_argument('nonce',help='Nonce param as defined by the server in 401/407')
parser.add_argument('--ha1',help='ha1 MD5(username:realm:password)')
parser.add_argument('--qop-auth', help='Indicate if auth mode has to reuse nonce (I.E qop=auth',action='store_true')
parser.add_argument('--cnonce', help='client nonce')
......@@ -46,14 +47,18 @@ def main(argv=None):
args = parser.parse_args(argv)
if not args.ha1 :
#HA1=MD5(username:realm:password)
ha1 = hashlib.md5()
ha1.update((args.userid+":"+args.realm+":"+args.password).encode())
ha1_value = ha1.hexdigest()
else:
ha1_value = args.ha1
#HA1=MD5(username:realm:password)
ha1 = hashlib.md5()
ha1.update((args.userid+":"+args.realm+":"+args.password).encode())
#HA2=MD5(method:digestURI)
ha2 = hashlib.md5()
ha2.update((args.method+":"+args.uri).encode())
print ("ha1 = "+ha1.hexdigest());
print ("ha1 = "+ha1_value);
print ("ha2 = "+ha2.hexdigest());
if args.qop_auth :
......@@ -63,7 +68,7 @@ def main(argv=None):
#response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2)
response = hashlib.md5()
response.update( (ha1.hexdigest()
response.update( (ha1_value
+":"+args.nonce
+":" + '{:08x}'.format(args.nonce_count)
+":" + args.cnonce
......@@ -75,7 +80,7 @@ def main(argv=None):
else:
#response=MD5(HA1:nonce:HA2)
response = hashlib.md5()
response.update((ha1.hexdigest()+":"+args.nonce+":"+ha2.hexdigest()).encode())
response.update((ha1_value+":"+args.nonce+":"+ha2.hexdigest()).encode())
print ("responce = "+response.hexdigest());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment