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

Support for animated QR code #12

Open
anfly0 opened this issue Aug 16, 2020 · 7 comments
Open

Support for animated QR code #12

anfly0 opened this issue Aug 16, 2020 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@anfly0
Copy link
Owner

anfly0 commented Aug 16, 2020

Add support for generating animated QR-codes. 4.2

  • Add timestamp to authentication and sign responses to keep track of "the number of seconds since the response from auth or sign was returned"
  • For now, only generate the binary needed to create the QR-code.
@anfly0 anfly0 added enhancement New feature or request Hacktoberfest help wanted Extra attention is needed good first issue Good for newcomers labels Oct 3, 2020
@Preen
Copy link

Preen commented Dec 11, 2020

And do something like this to generate the QR-code?

qrStartSecret = "d28db9a7-4cde-429e-a983-359be676944c"
time = "t=0"
:crypto.hmac(:sha256, qrStartSecret, time) |> Base.encode16(case: :lower)

@anfly0
Copy link
Owner Author

anfly0 commented Dec 11, 2020

I'm not sure that I understand your example 100%, but yes qrAuthCode would have to be computed, and the correct binary would have to be constructed.
Feel free to take a crack at implementing this!

@Preen
Copy link

Preen commented Dec 11, 2020

I'm referring to this:

time is the number of seconds since the result from auth or sign was returned
qrAuthCode is computed as HMACSHA256(qrStartSecret, time) where
• time is the number of seconds since the response from auth or sign was returned
• qrStartSecret is from the auth or sign response.

Screenshot 2020-12-11 at 14 44 20

It's a nice library you've built, will see if I get the time to do this :)

@anfly0
Copy link
Owner Author

anfly0 commented Dec 12, 2020

Great, we are on the same page! 👍

@Ineedsolution
Copy link

Hi, I want to integrate swedish bankid with wordpress, so that anyone can signup, signin, show interest in custom post using bankid authorization. Could you please help me or tell me the way of solve this issue.

Thanks in advance.

Regares

@carlgleisner
Copy link

Hej! I would like to help out on this issue. Will get back to you with a PR.

Great job with this library. I would like to offer more support in development and maintenance going forward, if you don't mind.

Kind regards,
Carl

@carlgleisner
Copy link

Hey again 👋🏻

@Preen, I looked into this a while ago (judging by my comment above) and there is no longer a :crypto.hmac/3 function defined. One has to use :crypto.mac/4 instead.

** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private, use crypto:mac/4 instead
    (crypto 5.3) :crypto.hmac(:sha256, "d28db9a7-4cde-429e-a983-359be676944c", "t=0")

I think that the below would work.

defmodule QRTestModule do
  def generate_qr(qr_start_token, qr_start_secret, time) do
    digest =
      :crypto.mac(:hmac, :sha256, String.to_charlist(qr_start_secret), String.to_charlist(time))
      |> Base.encode16(case: :lower)

    "bankid." <> qr_start_token <> "." <> time <> "." <> digest
  end
end

It would then be used like this using the same numbers as in the documentation that you posted a screenshot of (a few years ago 🙃).

result =
  QRTestModule.generate_qr(
    "67df3917-fa0d-44e5-b327-edcc928297f8",
    "d28db9a7-4cde-429e-a983-359be676944c",
    "0"
  )

expected =
  "bankid.67df3917-fa0d-44e5-b327-edcc928297f8.0.dc69358e712458a66a7525beef148ae8526b1c71610eff2c16cdffb4cdac9bf8"

result == expected

Aaand it works on my machine 😇

true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants