Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- set -e -u
- # Example Proxy-Authorization:
- #Digest username="*1337",realm="cy.sip.incenova.com",cnonce="6b8b4567",
- #nc=00000001,qop="auth",uri="sip:*9000@cy.sip.incenova.com",
- #nonce="c7903793-a86b-4129-98f0-e8893d44f3c1",
- #response="0ea0ce64854f6d6251a051a0572d75aa",algorithm=MD5
- if [ $# -ne 5 ]; then
- echo "Usage: username realm password digestUri nonce"
- exit 1
- fi
- username=$1
- realm=$2
- password=$3
- method=INVITE
- digestURI=$4
- nonce=$5
- qop=
- DEBUG() {
- : "$@" >&2
- }
- # HA1=MD5(username:realm:password)
- # HA2=MD5(method:digestURI)
- # response=MD5(HA1:nonce:HA2)
- # response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2) # when qop is given
- MD5() {
- for arg; do DEBUG printf ' "%s"' "$arg"; done
- DEBUG echo
- printf "$@" | md5sum | cut -d' ' -f1 | tr -d '\n'
- }
- HA1=$(MD5 '%s:%s:%s' "$username" "$realm" "$password")
- HA2=$(MD5 '%s:%s' "$method" "$digestURI")
- if [ -z "$qop" ]; then
- MD5 "%s:%s:%s" "$HA1" "$nonce" "$HA2"
- else
- MD5 "%s:%s:%s:%s:%s:%s" \
- "$HA1" "$nonce" "$nonceCount" "$clientNonce" "$qop" "$HA2"
- fi
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement