Skip to content

Commit e3c53ee

Browse files
author
Amir Tocker
committed
Use binary encoding for signature
In Node v6 the default encoding in Crypto changed from binary to utf-8.
1 parent 6e8b1f4 commit e3c53ee

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

lib/utils.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ exports.url = (public_id, options = {}) ->
417417
if sign_url
418418
to_sign = [transformation, source_to_sign].filter((part) -> part? && part != '').join('/')
419419
shasum = crypto.createHash('sha1')
420-
shasum.update(utf8_encode(to_sign + api_secret))
420+
shasum.update(utf8_encode(to_sign + api_secret), 'binary')
421421
signature = shasum.digest('base64').replace(/\//g, '_').replace(/\+/g, '-').substring(0, 8)
422422
signature = "s--#{signature}--"
423423

@@ -597,7 +597,7 @@ exports.signed_preloaded_image = (result) ->
597597
exports.api_sign_request = (params_to_sign, api_secret) ->
598598
to_sign = _.sortBy("#{k}=#{utils.build_array(v).join(",")}" for k, v of params_to_sign when v?, _.identity).join("&")
599599
shasum = crypto.createHash('sha1')
600-
shasum.update(utf8_encode(to_sign + api_secret))
600+
shasum.update(utf8_encode(to_sign + api_secret), 'binary')
601601
shasum.digest('hex')
602602

603603
exports.clear_blank = (hash) ->
@@ -626,7 +626,7 @@ exports.webhook_signature = (data, timestamp, options = {}) ->
626626
throw "Must supply timestamp" unless timestamp
627627
api_secret = options.api_secret ? config().api_secret ? throw("Must supply api_secret")
628628
shasum = crypto.createHash('sha1')
629-
shasum.update(data + timestamp + api_secret)
629+
shasum.update(data + timestamp + api_secret, 'binary')
630630
shasum.digest('hex')
631631

632632
exports.process_request_params = (params, options) ->

test/archivespec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ describe "uploader", ->
136136
it "should include keys: #{expected_keys.join(', ')}", ->
137137
expect(archive_result).to.have.keys(expected_keys)
138138
describe '.create_zip', ->
139+
@timeout helper.TIMEOUT_LONG
139140
spy = undefined
140141
before ->
141142
spy = sinon.spy cloudinary.uploader, "create_archive"

0 commit comments

Comments
 (0)