Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created September 20, 2020 18:09
Show Gist options
  • Save mwgamera/d12a1c60f5496c8687c22edf8690618c to your computer and use it in GitHub Desktop.
Save mwgamera/d12a1c60f5496c8687c22edf8690618c to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# klg, Sep 2020
# https://xmpp.org/extensions/inbox/omemo-media-sharing.html
# frozen_string_literal: true
require 'openssl'
require 'net/http'
ARGV.each do |arg|
uri = URI(arg)
raise 'Wrong URI scheme' unless uri.scheme == 'aesgcm'
frag = [uri.fragment].pack('H*')
raise 'Bad key' unless frag.length == 44
uri.scheme = 'https'
uri.fragment = nil
c = OpenSSL::Cipher::AES256.new(:GCM)
c.decrypt
c.key = frag[-32..]
c.iv = frag[..-33]
frag = nil
dat = Net::HTTP.get(URI(uri.to_s))
c.auth_tag = dat[-16..]
dat = c.update(dat[..-17]) + c.final
$stdout.write(dat)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment