Advertisement
Guest User

Untitled

a guest
May 7th, 2017
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/bin/sh
  2. set -e -u
  3.  
  4. # Example Proxy-Authorization:
  5. #Digest username="*1337",realm="cy.sip.incenova.com",cnonce="6b8b4567",
  6. #nc=00000001,qop="auth",uri="sip:*9000@cy.sip.incenova.com",
  7. #nonce="c7903793-a86b-4129-98f0-e8893d44f3c1",
  8. #response="0ea0ce64854f6d6251a051a0572d75aa",algorithm=MD5
  9. if [ $# -ne 5 ]; then
  10. echo "Usage: username realm password digestUri nonce"
  11. exit 1
  12. fi
  13. username=$1
  14. realm=$2
  15. password=$3
  16. method=INVITE
  17. digestURI=$4
  18. nonce=$5
  19. qop=
  20.  
  21. DEBUG() {
  22. : "$@" >&2
  23. }
  24.  
  25.  
  26. # HA1=MD5(username:realm:password)
  27. # HA2=MD5(method:digestURI)
  28. # response=MD5(HA1:nonce:HA2)
  29. # response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2) # when qop is given
  30.  
  31. MD5() {
  32. for arg; do DEBUG printf ' "%s"' "$arg"; done
  33. DEBUG echo
  34. printf "$@" | md5sum | cut -d' ' -f1 | tr -d '\n'
  35. }
  36.  
  37. HA1=$(MD5 '%s:%s:%s' "$username" "$realm" "$password")
  38. HA2=$(MD5 '%s:%s' "$method" "$digestURI")
  39.  
  40. if [ -z "$qop" ]; then
  41. MD5 "%s:%s:%s" "$HA1" "$nonce" "$HA2"
  42. else
  43. MD5 "%s:%s:%s:%s:%s:%s" \
  44. "$HA1" "$nonce" "$nonceCount" "$clientNonce" "$qop" "$HA2"
  45. fi
  46. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement