Giter Club home page Giter Club logo

Comments (2)

kplattret avatar kplattret commented on June 1, 2024 3

Hi @anakinj, thanks for your reply and sorry I'm only replying now. This was indeed a padding issue with the JWK. After trying a few things, we figured out that all we needed was to apply zero-padding to the non-encoded value, which we achieved this way:

private def apply_zero_padding_as_needed(jwk)
  valid_jwk = jwk.clone

  %i(x y).each do |elem|
    coords = Base64.urlsafe_decode64(valid_jwk[elem])
    length = coords.length
    diff = EXPECTED_COORDS_LENGTH - length # 66 bytes

    valid_jwk[elem] = Base64.urlsafe_encode64(("\x00" * diff) + coords) if diff > 0
  end

  valid_jwk
end

The error was neither with Ruby's openssl nor with the jwt gem. 👍

from ruby-jwt.

anakinj avatar anakinj commented on June 1, 2024

A little disclaimer: Im not an EC expert :)

It looks like the X value in the key is missing something, the encoded value is one char shorter than the y value. Is this JWK published publicly somewhere?

Also switching the x value to a valid encoded number makes the error different:

JWT::JWK::EC.import(
  kty: 'EC',
  crv: 'P-521',
  x: 'oLuW4nFqoUuR8d7FVsUoI62libYdQlWGtLStnqdudLY92bQ0ra5eZAbkunrGTR9-w9mr4o2Etyb6pC7YB2-23WM',
  y: 'AX1cjkGMiltikPrkX49qwuJDdcETaTsj-kyFP8jsF9W5XAB3Z4tBiQtc72DQnJYeKyAV_T6qZTtFKFr-Tp4iu-j7'
) => EC_POINT_bn2point: invalid encoding
JWT::JWK::EC.import(
  kty: 'EC',
  crv: 'P-521',
  x: 'AafgvMTsTt3-Z7g663VUz0CwW7GN8x83YV-dFwylobgjUKaGRuCgCvpOj5OP1mDPm7CHwGhI-yKUtMDYNfu7O_Uz',
  y: 'AX1cjkGMiltikPrkX49qwuJDdcETaTsj-kyFP8jsF9W5XAB3Z4tBiQtc72DQnJYeKyAV_T6qZTtFKFr-Tp4iu-j7'
) =>  EC_POINT_bn2point: point is not on curve

from ruby-jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.