Created
February 28, 2023 06:13
-
-
Save seungjin/78e80840eb928170444d800eea435125 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'http' | |
require 'openssl' | |
document = File.read('create-hello-world.json') | |
date = Time.now.utc.httpdate | |
sha256 = OpenSSL::Digest::SHA256.new | |
digest = sha256.digest(document) | |
ed = 'SHA-256='+Base64.encode64(digest).strip | |
keypair = OpenSSL::PKey::RSA.new(File.read('private.pem')) | |
signed_string = "(request-target): post /inbox\nhost: mstd.seungjin.net\ndate: #{date}\ndigest: #{ed}" | |
signature= Base64.strict_encode64(keypair.sign(OpenSSL::Digest::SHA256.new, signed_string)) | |
header = 'keyId="https://ap.dev.seungjin.net/actor#main-key",algorithm="rsa-sha256",headers="(request-target) host date digest",signature="' + signature + '"' | |
print HTTP.headers({ 'Host': 'mstd.seungjin.net', | |
'Date': date, | |
'Accept': 'application/activity+json', | |
'Digest': ed, | |
'Signature': header }) | |
.post('https://mstd.seungjin.net/inbox', body: document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment