Module: JsonJws::Verify

Included in:
JSON_JWS
Defined in:
lib/json_jws/verify.rb

Instance Method Summary collapse

Instance Method Details

#verify(jws, jwks) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/json_jws/verify.rb', line 16

def verify(jws, jwks)
  # verify payload is base64 encoded
  Base64.urlsafe_decode64(jws["payload"])

  jws["signatures"].each_with_index do |signature, index|
    return false unless verify_signature(jwks[index], jws["payload"], signature)
  end

  true
rescue
  return false
end

#verify_signature(jwk, b64_payload, jws_json_signature) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/json_jws/verify.rb', line 6

def verify_signature(jwk, b64_payload, jws_json_signature)
  verify_hash = {
    "payload" => b64_payload,
    "protected" => jws_json_signature["protected"],
    "signature" => jws_json_signature["signature"],
  }

  JOSE::JWS.verify(jwk, verify_hash).first
end