Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:30
    straight-shoota synchronize #11472
  • 19:25
    straight-shoota demilestoned #11366
  • 19:09
    straight-shoota milestoned #11519
  • 17:09
    Blacksmoke16 synchronize #11533
  • 17:07
    beta-ziliani milestoned #11529
  • 16:34
    Blacksmoke16 opened #11533
  • 15:35
    straight-shoota synchronize #11530
  • 15:33
    straight-shoota labeled #11532
  • 15:33
    straight-shoota opened #11532
  • 15:33
    straight-shoota labeled #11532
  • 14:45
    straight-shoota labeled #11531
  • 14:45
    straight-shoota labeled #11531
  • 14:45
    straight-shoota opened #11531
  • 14:21
    straight-shoota opened #11530
  • 14:21
    straight-shoota labeled #11530
  • 14:21
    straight-shoota labeled #11530
  • 14:13
    beta-ziliani labeled #11529
  • 14:13
    beta-ziliani labeled #11529
  • 14:12
    beta-ziliani opened #11529
  • 13:28
    beta-ziliani edited #5430
mrx
@perfecto25
thx, was looking at old docs
George Dietrich
@Blacksmoke16
https://crystal-lang.org/api/Log.html is the one you want to use now. One you're using atm is the legacy one
:thumbsup:
Rishav Sharan
@rishavs

I am trying to verify google/AWS jwts using their public keys but not succeeding. Would anyone know how to do so?
For eg.
the google sign ins key is at;

pp! pub_key_jwk = HTTP::Client.get "https://www.googleapis.com/oauth2/v3/certs"
pp! pub_key_pem = HTTP::Client.get "https://www.googleapis.com/oauth2/v1/certs"

and I would want to decode like this;
payload, header = JWT.decode(token, pub_key_pem , JWT::Algorithm::HS256)
But I couldn't find a way to do this using https://github.com/crystal-community/jwt#usage

Ary Borenszweig
@asterite
I was also thinking that x.as?(T) could be rewritten as an if with is_a?... It's simpler for the compiler, no need to have extra logic
jhass
@jhass:m.aeshna.de
[m]
@rishavs: neither endpoint returns the expect PEM encoded key directly, the first returns a list of JWKs, the second returns a list of PEM encoded keys (certificates actually). the jwt's shard key argument expects the PEM encoded key directly, so you need to some parsing and extraction first. Second I don't know how you arrived at HS256 as algorithm, it's RSA keys so you'll want RS256, RS384 or RS512 respectively, whichever one the JWT actually uses. Admittedly the shard could be more helpful here and extract the right algorithm from the JWT header
Rishav Sharan
@rishavs

@jhass:m.aeshna.de , I did try to extract the keys and then use it in JWT decode, but that didn't work;


            # Fetch the Google public key
            pp! pub_key_jwk = HTTP::Client.get "https://www.googleapis.com/oauth2/v3/certs"
            pp! pub_key_pem = HTTP::Client.get "https://www.googleapis.com/oauth2/v1/certs"
            # pub_key.status_code      # => 200

            pp! parsed = JSON.parse(pub_key_jwk.body)
            pp! key1 = parsed["keys"][0]["kid"].to_s
            pp! key2 = parsed["keys"][1]["kid"].to_s

            payload1, header1 = JWT.decode(id_token, key1, JWT::Algorithm::RS256)
            pp! payload1
            pp! header1

would throw;

2021-07-05T09:51:34.441087Z  ERROR - Neither PUB or PRIV key: error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data
Neither PUB or PRIV key: error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data (OpenSSL::PKey::RsaError)
From IRC (bridge bot)
@FromIRC
<jhass[m]> Well yes, a JWK's kid field is not a PEM encoded public key. https://datatracker.ietf.org/doc/html/rfc7517#section-4.5
Rishav Sharan
@rishavs

Is this bit of string

"-----BEGIN CERTIFICATE-----\nMIIDJjCCAg6gAwIBAgIIRAoQks63w4EwDQYJKoZIhvcNAQEFBQAwNjE0MDIGA1UE\nAxMrZmVkZXJhdGVkLXNpZ25vbi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTAe\nFw0yMTA2MjAwNDI5NTdaFw0yMTA3MDYxNjQ0NTdaMDYxNDAyBgNVBAMTK2ZlZGVy\nYXRlZC1zaWdub24uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wggEiMA0GCSqG\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCsf17gul45G1GRC6jm8ov5yws+cmbJZT+o\neI6pbJdWyg/KZQoiY2w+Vps5y+RhiU9+VYT6qa1AIf4AIOPHMKHIiS2v7nN4IRmJ\n2WfylYSYOr5H5peL+xCAlSv7sf9jr2EPxxHQrcvILzpBFumKDFbwXqFRT1qP/1Va\n5XCwy8uJCdtvNLgJa+L9bMhb2IbSA62GyyV99r/quqhCkdzQZ+wS7d73vVBlwnIz\nGvqm1j9u9PAhirBG/2m3G0pMyqi9XpgE3mf8uEIOaTWAEuZJ6PqZ8dJbaKjpNdlp\nXc9rIvZRO17qqu8CQX9FdS1V64PGbixxR7VF1/5N2wBcWbUo82rjAgMBAAGjODA2\nMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBYGA1UdJQEB/wQMMAoGCCsG\nAQUFBwMCMA0GCSqGSIb3DQEBBQUAA4IBAQCGOTPITDKeIsTJhueXYtp9t3u0L8Id\nO58xb5dDbNGbi9E/C0cdDq8SfdFBHvOL8eJJSjzCRefRi1NhMlWaWsT471GgXdUV\nHR0CSV87Gj6BvMcAq9WFQu9k6LFtN2qp8CsFFEbjgPW3GFSXriy0W/VRzmb4aUbz\nVjo+EOTAiQP05qQ0bahaXWxXyftctMqpmM/EjFKZZwSH2fuFRNiq+0prIG8xRUYp\nakyr4D+GC0RrUpCa2SfGoojSYQPlQfkZGyeGLBi1UQImCKBJ8wYVaSIaVlLHYZik\nu/lQUGTPW3NLCn0id4AKAx3Ojf0t2jhsPy9u7kW5mPQA/CeRWjsPZ2uX\n-----END CERTIFICATE-----\n"

what I need in my JWT.decode(id_token, key_pem, JWT::Algorithm::RS256)?

From IRC (bridge bot)
@FromIRC
<jhass[m]> I guess, try it!
Rishav Sharan
@rishavs
getting a slightly different error now;
2021-07-05T14:12:29.721163Z  ERROR - Neither PUB or PRIV key: error:0909006C:PEM routines:get_name:no start line
Neither PUB or PRIV key: error:0909006C:PEM routines:get_name:no start line (OpenSSL::PKey::RsaError)
From IRC (bridge bot)
@FromIRC
From IRC (bridge bot)
@FromIRC
<kevinsjoberg> If I define a macro in a shard, and then call this macro from a project using this shard, shouldn't that work?
<kevinsjoberg> I would expect the macro (it creates a method based on input) to be present, but it doesn't seem to be the case.
From IRC (bridge bot)
@FromIRC
<kevinsjoberg> Basically, I expected the following to work. https://play.crystal-lang.org/#/r/bh8i
<kevinsjoberg> But if I uncomment the last code, it does not compile.
<kevinsjoberg> Oh, I'm dumb. Never mind, haha.
<kevinsjoberg> This works, https://play.crystal-lang.org/#/r/bh8o. I realized self is something else entirely when calling it outside the MyShard namespace.
Lewis E. Bogan
@lebogan

More with the raspberry pi compiling. So I'm clear: I need the current crystal version to compile the current crystal? I user the Portalier 0.33.0 and it compiled 0.33.0 but not 0.36.1. I got an error

In src/number.cr:147:67

 147 | def step(*, to limit = nil, by step, exclusive : Bool = false, &) : Nil
                                                                       ^
Error: duplicated argument name: 
make: *** [Makefile:122: .build/crystal] Error 1

The same happened when trying to compile 1.0.0.
Thanks

George Dietrich
@Blacksmoke16
You'd need to use 0.36.0 to complile 0.36.1 most likely
I.e. the one right before the one you want
Lewis E. Bogan
@lebogan
Yea, kinda thought so. Still trying to get 1.0.0 to compile for teaching purposes.
Jonathan Silverman
@mixflame
I got my websocket patch almost ready
I need to get around this IO::Error
Unhandled exception in spawn: Error writing to socket: Broken pipe (IO::Error)
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/evented.cr:82:13 in 'unbuffered_write'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/buffered.cr:217:5 in 'flush'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:106:5 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:103:3 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:90:5 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket.cr:78:5 in 'send'
  from lib/amber/src/amber/websockets/channel.cr:80:34 in 'rebroadcast!'
  from src/channels/text_channel.cr:18:5 in 'handle_message'
  from lib/amber/src/amber/websockets/channel.cr:49:9 in 'on_message'
  from lib/amber/src/amber/websockets/channel.cr:88:13 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in 'dispatch_received_message'
  from lib/redis/src/redis/strategy/subscription_loop.cr:34:17 in 'enter_message_reception_loop'
  from lib/redis/src/redis/strategy/subscription_loop.cr:19:7 in 'command'
  from lib/redis/src/redis.cr:311:7 in 'command'
  from lib/redis/src/redis/command_execution/value_oriented.cr:81:9 in 'void_command'
  from lib/redis/src/redis/commands.cr:1675:7 in 'subscribe'
  from lib/redis/src/redis/commands.cr:1665:7 in 'subscribe'
  from lib/amber/src/amber/websockets/adapters/redis.cr:24:11 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in 'run'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/fiber.cr:92:34 in '->'
  from ???
module Amber::WebSockets::Adapters
  # Allows websocket connections through redis pub/sub.
  class RedisAdapter
    @subscriber : Redis
    @publisher : Redis
    @listener : Hash(String,Proc(String, JSON::Any, Nil)) = Hash(String, Proc(String, JSON::Any, Nil)).new
    @subscribed : Bool = false

    def self.instance
      @@instance ||= new
    end

    # Establish subscribe and publish connections to Redis
    def initialize
      @subscriber = Redis.new(url: Amber.settings.redis_url)
      @publisher = Redis.new(url: Amber.settings.redis_url)

      if !@subscribed == true
        spawn do
          Fiber.yield
          puts "subscribing to #{CHANNEL_TOPIC_PATHS}"

          @subscribed = true
          @subscriber.subscribe(CHANNEL_TOPIC_PATHS) do |on|
            on.message do |_, m|
              msg = JSON.parse(m)
              sender_id = msg["sender"].as_s
              message = msg["msg"]
              topic = message["topic"].to_s.split(":").first
              @listener[topic].call(sender_id, message)
            end
            on.subscribe do |_, _|
              puts "subscribed to #{CHANNEL_TOPIC_PATHS}"
            end
            spawn do
              Fiber.yield
              to_subscribe = SUBSCRIBE_CHANNEL.receive
              @subscriber.subscribe(to_subscribe)
            end
          end
        end
      end
    end

    # Publish the *message* to the redis publisher with topic *topic_path*
    def publish(topic_path, client_socket, message)
      @publisher.publish(topic_path, {sender: client_socket.id, msg: message}.to_json)
    end

    # Register listener with topic path after one-time subscribe on initialization
    # So that it will be called when Redis pushes data to the subscription channel
    def on_message(topic_path, listener)
      @listener[topic_path] = listener
      SUBSCRIBE_CHANNEL.send(topic_path)
    end
  end
end
what am i doing that breaks thepipe?
Unhandled exception in spawn: Error writing to socket: Broken pipe (IO::Error)
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/evented.cr:82:13 in 'unbuffered_write'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/buffered.cr:217:5 in 'flush'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:106:5 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:103:3 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:257:5 in 'close'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket.cr:111:5 in 'close'
  from lib/amber/src/amber/websockets/client_socket.cr:111:9 in 'disconnect!'
  from lib/amber/src/amber/websockets/client_socket.cr:102:9 in 'beat'
  from lib/amber/src/amber/websockets/client_sockets.cr:17:13 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in 'run'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/fiber.cr:92:34 in '->'
  from ???
Jonathan Silverman
@mixflame
nevermind i fixed it
hopefully someone merges my stuff soon, it works to give scalability in websocket apps on amber
From IRC (bridge bot)
@FromIRC
<delucks> hey folks! I'm trying to compile a Crystal "hello world" on a SPARCv9 machine running OpenBSD6.8 using LLVM 10. I've built a ll file of the code on a x86 machine running the latest release of the compiler, but when building it on the target machine using llc, I get a segfault running DAG Pattern Instruction Selection. LLVM claims to support this target triplet :⁠) Has anyone successfully compiled Crystal
<delucks> code on SPARCv9/SPARC64?
George Dietrich
@Blacksmoke16
never heard of it
i dont see it on there so would prob need a PR to support it
From IRC (bridge bot)
@FromIRC
<delucks> thanks Blacksmoke16. Do you have any suggestions for how to debug this llvm compilation failure and get more info about where in the crystal codebase needs to be modified?
George Dietrich
@Blacksmoke16
from my understanding since this is a totally new arch, you'd need something like crystal-lang/crystal#3491
however that PR is quite old so im not sure if the exact implementation is still relevant
crystal-lang/crystal#9360 is a more recent example, but it's based on x86_64 as well, so it didn't need to define an abi for that arch
George Dietrich
@Blacksmoke16
granted im no expert on this, just basing things off stuff i read in past PRs/issues but the majority of platform support would be defining the related libC bindings in https://github.com/crystal-lang/crystal/tree/master/src/lib_c, then an abi like the ones https://github.com/crystal-lang/crystal/tree/master/src/llvm/abi, then letting the compiler know about this new target, then any other platform specifics
From IRC (bridge bot)
@FromIRC
<delucks> thanks, super helpful. is there a process for accepting new architectures like this, or would that be a discussion for a future PR?
George Dietrich
@Blacksmoke16
afaik the last one just made a PR
that would probably suffice
could prob reference the rust implementation of the abi as it also uses llvm
nanobowers
@nanobowers
Hello all, new to crystal and trying to migrate some ruby code to crystal in an attempt to learn it. I'm trying to port something that uses rspec yield matchers: https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/yield-matchers
and cannot seem to find a feature in Crystal's Spec that has equivalent functionality. Did I miss something, or is there a shard that does this?
George Dietrich
@Blacksmoke16
whats the thing you're wanting to test?
id just test that versus worrying about how many times something yields or something
nanobowers
@nanobowers
Also, if anyone knows of a cheat-sheet (mapping) of ruby stdlib to crystal stdlib, that would be helpful. There are a lot of similarities, but also plenty of differences and a lot of hunting to find the nearly equivalent thing
Jonathan Silverman
@mixflame
whew ok
Amber patch is perfect, 2 tests, working, and confirmed you don't have to use the hack anymore.