Esempio n. 1
0
    def _ExtraHeaders(self, handler, body):
        hmac = hmac_utils.CreateRequestHmac(bytes(b'POST'), handler, body,
                                            self._hmac_secret)

        extra_headers = {'content-type': 'application/json'}
        extra_headers[JEDIHTTP_HMAC_HEADER] = b64encode(hmac)
        return extra_headers
Esempio n. 2
0
def CreateRequestHmac_WithBytes_test():
    eq_(
        hexlify(
            hu.CreateRequestHmac(bytes(b'GET'), bytes(b'/foo'), bytes(b'body'),
                                 bytes(b'key'))),
        bytes(b'bfbb6bc7a2b3eca2a78f4e7ec8a7dfa7'
              b'e58bb8974166eaf20e0224d999894b34'))
Esempio n. 3
0
def RequestAuthenticated(method, path, body, hmac_secret):
    if _HMAC_HEADER not in request.headers:
        return False

    return hmac_utils.SecureStringsEqual(
        hmac_utils.CreateRequestHmac(method, path, body, hmac_secret),
        b64decode(request.headers[_HMAC_HEADER]))
Esempio n. 4
0
    def _ComputeRequestHmac(self, method, path, body):
        if not body:
            body = ''

        hmac = hmac_utils.CreateRequestHmac(method, path, body,
                                            self._hmac_secret)
        return binascii.hexlify(hmac)
Esempio n. 5
0
def CreateRequestHmac_WithPy2Str_test():
  eq_( hexlify( hu.CreateRequestHmac(
    'GET',
    '/foo',
    'body',
    'key' ) ),
    'bfbb6bc7a2b3eca2a78f4e7ec8a7dfa7'
    'e58bb8974166eaf20e0224d999894b34' )
Esempio n. 6
0
def RequestAuthenticated(method, path, body, hmac_secret):
    if _HMAC_HEADER not in request.headers:
        return False

    return hmac_utils.SecureBytesEqual(
        hmac_utils.CreateRequestHmac(ToBytes(method), ToBytes(path),
                                     ToBytes(body), ToBytes(hmac_secret)),
        ToBytes(b64decode(request.headers[_HMAC_HEADER])))
Esempio n. 7
0
 def test_CreateRequestHmac_WithBytes(self):
     assert_that(
         hexlify(
             hu.CreateRequestHmac(bytes(b'GET'), bytes(b'/foo'),
                                  bytes(b'body'), bytes(b'key'))),
         equal_to(
             bytes(b'bfbb6bc7a2b3eca2a78f4e7ec8a7dfa7'
                   b'e58bb8974166eaf20e0224d999894b34')))
Esempio n. 8
0
    def _ExtraHeaders(self, method, handler, body):
        if not body:
            body = bytes()

        hmac = hmac_utils.CreateRequestHmac(method, handler, body,
                                            self._hmac_secret)
        final_hmac_value = native(ToBytes(binascii.hexlify(hmac)))

        extra_headers = {'content-type': 'application/json'}
        extra_headers[RACERD_HMAC_HEADER] = final_hmac_value
        return extra_headers