Skip to content

Erlang error bad key length#81

Open
Copser wants to merge 5 commits intomweibel:masterfrom
Copser:erlang_error_bad_key_length
Open

Erlang error bad key length#81
Copser wants to merge 5 commits intomweibel:masterfrom
Copser:erlang_error_bad_key_length

Conversation

@Copser
Copy link

@Copser Copser commented Oct 2, 2021

Hello @mweibel, first awesome library, I'm using it on some of my projects, now I have tried to update our staging project and tried the new Erlang 24 and Elixir 12 but I had a problem with the library so I have started poking around.

First I have reverted back to Erlang 23 and Elixir 10.4 run the mix test and saw this

Generated credo app
==> facebook
Compiling 6 files (.ex)
Generated facebook app
...............................

  1) test signing decode (FacebookTest)
     test/facebook_test.exs:543
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: }} = Facebook.decode_signed_request(signed_request)
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "eyJpZCI6IjExNjM5NzMwMzg2NTk2In0=")
       (facebook 0.24.0) lib/facebook.ex:825: Facebook.decode_signed_request/1
       test/facebook_test.exs:550: (test)



  2) test fan_count success (FacebookTest)
     test/facebook_test.exs:252
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: Facebook.fan_count(
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "123|456")
       (facebook 0.24.0) lib/facebook.ex:895: Facebook.signature_base16/1
       (facebook 0.24.0) lib/facebook.ex:904: Facebook.add_app_secret/2
       (facebook 0.24.0) lib/facebook.ex:417: Facebook.get_object/3
       test/facebook_test.exs:256: (test)

.

  3) test fan_count error (FacebookTest)
     test/facebook_test.exs:263
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: assert {:error, _} = Facebook.fan_count(@page_id, invalid_access_token)
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "123")
       (facebook 0.24.0) lib/facebook.ex:895: Facebook.signature_base16/1
       (facebook 0.24.0) lib/facebook.ex:904: Facebook.add_app_secret/2
       (facebook 0.24.0) lib/facebook.ex:417: Facebook.get_object/3
       test/facebook_test.exs:265: (test)



  4) test publish feed - success (FacebookTest)
     test/facebook_test.exs:124
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: Facebook.publish(
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "123")
       (facebook 0.24.0) lib/facebook.ex:895: Facebook.signature_base16/1
       (facebook 0.24.0) lib/facebook.ex:904: Facebook.add_app_secret/2
       (facebook 0.24.0) lib/facebook.ex:215: Facebook.publish/4
       test/facebook_test.exs:128: (test)



  5) test get_object error (FacebookTest)
     test/facebook_test.exs:282
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: assert {:error, _} = Facebook.get_object("1234567", invalid_access_token)
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "123")
       (facebook 0.24.0) lib/facebook.ex:895: Facebook.signature_base16/1
       (facebook 0.24.0) lib/facebook.ex:904: Facebook.add_app_secret/2
       (facebook 0.24.0) lib/facebook.ex:417: Facebook.get_object/3
       test/facebook_test.exs:284: (test)



  6) test signing payload (FacebookTest)
     test/facebook_test.exs:536
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: Facebook.sign(payload)
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "eyJpZCI6IjExNjM5NzMwMzg2NTk2In0=")
       (facebook 0.24.0) lib/facebook.ex:890: Facebook.signature_base64/1
       (facebook 0.24.0) lib/facebook.ex:837: Facebook.sign/1
       test/facebook_test.exs:540: (test)

....

  7) test page feed success (FacebookTest)
     test/facebook_test.exs:396
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: Facebook.page_feed(
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "123|456")
       (facebook 0.24.0) lib/facebook.ex:895: Facebook.signature_base16/1
       (facebook 0.24.0) lib/facebook.ex:904: Facebook.add_app_secret/2
       (facebook 0.24.0) lib/facebook.ex:440: Facebook.get_object_edge/4
       test/facebook_test.exs:400: (test)



  8) test object count success (FacebookTest)
     test/facebook_test.exs:430
     ** (ErlangError) Erlang error: {:badarg, {'mac.c', 231}, 'Bad key length'}
     code: Facebook.object_count(
     stacktrace:
       (crypto 4.9) :crypto.mac_nif(:poly1305, :sha256, "456", "123")
       (facebook 0.24.0) lib/facebook.ex:895: Facebook.signature_base16/1
       (facebook 0.24.0) lib/facebook.ex:904: Facebook.add_app_secret/2
       (facebook 0.24.0) lib/facebook.ex:534: Facebook.object_count/3
       test/facebook_test.exs:434: (test)

....

Finished in 13.9 seconds
48 tests, 8 failures

Randomized with seed 864838

I have changes the app_id and app_secret to more let's say "realistic" string and fix the tests, I have also changed the deprecated load_file to require_file in test_helper. Tests are also passing on Erlang 24.0.5/Elixir 1.12.3-otp-24 versions.

Is this something you will be interested in merging if it meets your criteria?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant