Changeset fcdc60 in indico for indico/web/http_api/handlers.py
- Timestamp:
- 08/23/11 15:38:51 (21 months ago)
- Branches:
- master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
- Children:
- 92ad85
- Parents:
- 315708
- git-author:
- Adrian Moennich <jerome.ernst.monnich@…> (05/12/11 14:59:04)
- git-committer:
- Jose Benito <jose.benito.gonzalez@…> (08/23/11 15:38:51)
- File:
-
- 1 edited
-
indico/web/http_api/handlers.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/web/http_api/handlers.py
r315708 rfcdc60 68 68 69 69 70 def normalizeQuery(path, query, ts=None, remove=('timestamp', 'signature')):70 def normalizeQuery(path, query, remove=('signature',)): 71 71 """Normalize request path and query so it can be used for caching and signing 72 72 … … 78 78 for key in remove: 79 79 qdata.pop(key, None) 80 if ts is not None:81 qdata['timestamp'] = ts82 80 sortedQuery = sorted(qdata.items(), key=lambda x: x[0].lower()) 83 81 if sortedQuery: … … 87 85 88 86 89 def validateSignature(key, signature, path, query, timestamp=None): 90 if timestamp is None: 91 timestamp = int(time.time()) 92 ts = timestamp / 300 93 candidates = [] 94 for i in xrange(-1, 2): 95 h = hmac.new(key, normalizeQuery(path, query, ts + i), hashlib.sha1) 96 candidates.append(h.hexdigest()) 97 if signature not in candidates: 98 raise HTTPAPIError('Signature invalid (check system clock)', apache.HTTP_FORBIDDEN) 99 100 101 def getAK(apiKey, signature, path, query): 87 def validateSignature(key, signature, timestamp, path, query): 88 ttl = HelperMaKaCInfo.getMaKaCInfoInstance().getAPISignatureTTL() 89 if not timestamp: 90 raise HTTPAPIError('Signature invalid (no timestamp)', apache.HTTP_FORBIDDEN) 91 elif abs(timestamp - int(time.time())) > ttl: 92 raise HTTPAPIError('Signature invalid (bad timestamp)', apache.HTTP_FORBIDDEN) 93 digest = hmac.new(key, normalizeQuery(path, query), hashlib.sha1).hexdigest() 94 if signature != digest: 95 raise HTTPAPIError('Signature invalid', apache.HTTP_FORBIDDEN) 96 97 98 def checkAK(apiKey, signature, timestamp, path, query): 102 99 minfo = HelperMaKaCInfo.getMaKaCInfoInstance() 103 100 apiMode = minfo.getAPIMode() … … 115 112 onlyPublic = False 116 113 if signature: 117 validateSignature(ak.getSignKey(), signature, path, query)114 validateSignature(ak.getSignKey(), signature, timestamp, path, query) 118 115 elif apiMode in (API_MODE_SIGNED, API_MODE_ALL_SIGNED): 119 116 raise HTTPAPIError('Signature missing', apache.HTTP_FORBIDDEN) … … 203 200 apiKey = get_query_parameter(qdata, ['ak', 'apikey'], None) 204 201 signature = get_query_parameter(qdata, ['signature']) 202 timestamp = get_query_parameter(qdata, ['timestamp'], 0, integer=True) 205 203 no_cache = get_query_parameter(qdata, ['nc', 'nocache'], 'no') == 'yes' 206 204 pretty = get_query_parameter(qdata, ['p', 'pretty'], 'no') == 'yes' … … 216 214 try: 217 215 # Validate the API key (and its signature) 218 ak, enforceOnlyPublic = getAK(apiKey, signature, path, query)216 ak, enforceOnlyPublic = checkAK(apiKey, signature, timestamp, path, query) 219 217 if enforceOnlyPublic: 220 218 onlyPublic = True
Note: See TracChangeset
for help on using the changeset viewer.
