Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use "sha384": No such hash algorithm #3

Closed
esmeetu opened this issue Apr 25, 2017 · 5 comments
Closed

Cannot use "sha384": No such hash algorithm #3

esmeetu opened this issue Apr 25, 2017 · 5 comments

Comments

@esmeetu
Copy link

esmeetu commented Apr 25, 2017

when i run:
select basic_auth.sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret', 'HS384')

output this:

 [22023] ERROR: Cannot use "sha384": No such hash algorithm
 Where: SQL function "algorithm_sign" statement 1
 SQL function "sign" statement 1

other hash algorithms are same.

This is my algorithm_sign function:

create function basic_auth.algorithm_sign(signables text, secret text, algorithm text) returns text
LANGUAGE SQL
AS $$
WITH
  alg AS (
    SELECT CASE
      WHEN algorithm = 'HS256' THEN 'sha256'
      WHEN algorithm = 'HS384' THEN 'sha384'
      WHEN algorithm = 'HS512' THEN 'sha512'
      ELSE '' END AS id)  -- hmac throws error
SELECT basic_auth.url_encode(basic_auth.hmac(signables, secret, alg.id)) FROM alg;
$$;
@michelp
Copy link
Owner

michelp commented Apr 25, 2017

I'm not sure why you have 'basic_auth.hmac', it should just be 'hmac' unless you installed pgcypto into the same schema, I presume you did something like that since the function is being called.

@esmeetu try this:

select basic_auth.hmac('foo', 'secret', 'sha384');

You should get:

\x0edb7068ecbf4de2c47b8819fd534333379f208f989c51018d03ee1155e4c0740a418ec220d4260eabcb2d090b16de6e

If not, then it sounds like your pgcypto is not correctly installed.

@esmeetu
Copy link
Author

esmeetu commented Apr 25, 2017

Thanks for your reply!
Well, I install pgcypto in the same schema basic_auth.
Under your code, i still get the error: [22023] ERROR: Cannot use "sha384": No such hash algorithm
I reinstall pgcrypto and pgjwt, there is error as before. But the extension works fine a few days before, I don't know what's wrong.

@michelp
Copy link
Owner

michelp commented Apr 25, 2017

Are you reinstall pgcrypto by a os package like apt or rpm or did you build it from source? If you built it you might be missing some libraries.

After you reinstalled did you restart postgres? 'hmac' comes from pycrypto, so I'm not really an expert in building it, I installed it from an ubuntu package.

@esmeetu
Copy link
Author

esmeetu commented Apr 25, 2017

I use datagrip, enter this CREATE EXTENSION pgjwt CASCADE in my console. It has pgcrypto default, and i drop it, recreate it. As you say, i should try down the source code, and rebuild it.

@esmeetu
Copy link
Author

esmeetu commented Apr 25, 2017

@michelp I find the reason, It my fault thati forget that i updated my postgresql today.
After reboot the system, It works fine! But i am not clear why it fails, may be pgcrypto has some changes.
Thanks you again. Good extention. :)

@esmeetu esmeetu closed this as completed Apr 25, 2017
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

No branches or pull requests

2 participants