Created
June 6, 2015 06:31
-
-
Save drewbug/17a5d97e13233e64dd10 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
#!/usr/bin/env ruby | |
# create temporary auth key first via gui, then export your whole keyring and modify it | |
require 'digest' | |
unpatched = File.read 'temp_auth.key' | |
unpatched_bytes = unpatched.bytes | |
packets = [] | |
until unpatched_bytes.empty? | |
tag = unpatched_bytes.shift | |
case (tag & 0x03) | |
when 0 | |
length = unpatched_bytes.shift(1) | |
count = length[0] | |
when 1 | |
length = unpatched_bytes.shift(2) | |
count = length.pack('CC').unpack('n')[0] | |
end | |
body = unpatched_bytes.shift(count) | |
packet = [tag, length, body] | |
packets << packet | |
end | |
fail unless packets.count == 5 | |
# primary key | |
primary_key = packets[0] | |
length = primary_key[1] | |
length.unshift(0) unless length.count == 2 | |
primary_key[0] = 0x99 | |
# subkey | |
subkey = packets[3] | |
length = subkey[1] | |
length.unshift(0) unless length.count == 2 | |
subkey[0] = 0x99 | |
# signature | |
sig = packets[4][2] | |
hashed_subpacket_data_count = sig[4..5].pack('CC').unpack('n')[0] | |
sig = sig[0,6+hashed_subpacket_data_count] | |
# trailer | |
trailer = [0x04, 0xFF, sig.length] | |
trailer.insert(2, 0) until trailer.length == 6 | |
# hashyay | |
bytes_to_hash = [primary_key, subkey, sig, trailer] | |
to_hash = bytes_to_hash.flatten.pack('c*') | |
sha256 = Digest::SHA256.new | |
sha256.update to_hash | |
p sha256.hexdigest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment