Post

Replies

Boosts

Views

Activity

Reply to Validate StoreKit2 in-app purchase jwsRepresentation in backend (node ideally, but anything works)
`def good_signature?(jws_token) raw = File.read "/Users/steve1/downloads/AppleRootCA-G3.cer" apple_root_cert = OpenSSL::X509::Certificate.new(raw) parts = jws_token.split(".") decoded_parts = parts.map { |part| Base64.decode64(part) } header = JSON.parse(decoded_parts[0]) cert_chain = header["x5c"].map { |part| OpenSSL::X509::Certificate.new(Base64.decode64(part))} return false unless cert_chain.last == apple_root_cert for n in 0..(cert_chain.count - 2) return false unless cert_chain[n].verify(cert_chain[n+1].public_key) end begin decoded_token = JWT.decode(jws_token, cert_chain[0].public_key, true, { algorithms: ['ES256'] }) !decoded_token.nil? rescue JWT::JWKError false rescue JWT::DecodeError false end end`
Jan ’22