def _signingPayload(self, canonical): return '\n'.join([ 'AWS4-HMAC-SHA256', timestampToHttpString(self._timestamp), self._scope(), hashlib.sha256(canonical).hexdigest() ])
def _signingChunkPayload(self, previousSignature, chunkData): return '\n'.join([ 'AWS4-HMAC-SHA256-PAYLOAD', timestampToHttpString(self._timestamp), self._scope(), previousSignature, hashlib.sha256('').hexdigest(), hashlib.sha256(chunkData).hexdigest() ])
def signRequest(self, request): request.headers.addRawHeader( 'Date', timestampToHttpString(self._timestamp) ) request.headers.addRawHeader( 'x-amz-content-sha256', request.bodyHash() ) headers, canonical = request.canonicalized() signingKey = self._signingKey() signingPayload = self._signingPayload(canonical) signature = sign(signingKey, signingPayload, True) authorization = ( 'AWS4-HMAC-SHA256 Credential={},SignedHeaders={},Signature={}' .format(self._credentials(), headers, signature) ) request.headers.addRawHeader('Authorization', authorization) self._previousSignature = signature