Specifications

F-3
Cisco Internet Streamer CDS 2.0-2.2 API Guide
OL-14319-03
Appendix F URL Signing and Validation
URL Signing Script
import time
import sys
def sign_url(url,key):
""" Signs url using key and returns the signed URL with the signature appended. """
# Generate a MD5 hash of the key string (not the url)
foo = md5.new(key)
# Update the hash generated with the url string
# This effectively means concatenating key and url and generating
# a hash for the two
foo.update(url)
# Get the digest in hex format (human readable)
return url+foo.hexdigest()
def usage():
""" Prints usage for the URL signing script. """
print "Usage:"
print "python cds-ims-urlsign.py <url> <client-ip> <expiry-delay-seconds>
<key-id-owner> <key-id-number> <key>"
print "Example:"
print "python cds-ims-urlsign.py rtsp://abc.com/content/Apocalypto.mov 171.71.50.123
120 1 2 pl023MDQlk"
if __name__ == "__main__":
""" Prints signed URL """
if len(sys.argv) < 7:
usage()
sys.exit(2)
url = sys.argv[1] # URL
client_ip = sys.argv[2]
delay_seconds = sys.argv[3] # Number of seconds after which URL expires
ko = sys.argv[4] # Key ID Owner
kn = sys.argv[5] # Key ID Number
key = sys.argv[6] # Key
# Set expiry time as current time (seconds since epoch) + delay
et = time.time() + int(delay_seconds)
expires = str(int(et))
if url.find('?')==-1:
url2 = url + "?"
else:
url2 = url + "&"
# This string format is fixed and should not be modified.
# Note that we sign even the "&US=" part that will point to the signature
url2 = url2 + "IS=0"+"&ET="+expires+"&CIP="+client_ip+"&KO="+ko+"&KN="+kn+"&US=";
url3 = sign_url(url2,key)
#print url
#print url2
print url3
Running a Python URL Signing Script
The example script, call it “cds-ims-urlsign.py,” can be used as follows:
python cds-ims-urlsign.py url client-ip expiry-delay-seconds key-id-owner key-id-number key