Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- #
- # Copyright © 2017 Jens Kuske <jenskuske@gmail.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # from https://gist.github.com/jemk/8e1006a44c7a2c796fc3fc2f74f7c6c3
- require 'openssl'
- require 'hexdump'
- #key = OpenSSL::PKey::RSA.new(File.read(ARGV[0]))
- key = OpenSSL::PKey::RSA.new(File.read("RSA.pem"))
- n = key.params['n']
- e = key.params['e']
- print("n:\n")
- print(n)
- print("\n")
- print("e\n")
- print(e)
- print("\n")
- #Hexdump.dump(n)
- if n.num_bits != 2048
- puts 'Need 2048-bit RSA key'
- exit false
- end
- n = [n.to_s(16)].pack('H*')
- e = [e.to_s(16)].pack('H*')
- print("hexdump n\n")
- print(Hexdump.dump(n))
- print("hexdump e\n" )
- print(Hexdump.dump(e))
- if n.length != 256
- puts 'fatal: n.length != 256 bytes'
- exit false
- end
- if e.length > 256
- puts 'fatal: e.length > 256 bytes'
- exit false
- end
- data = n + e.ljust(256, "\x91".b)
- print("hexdump data\n" )
- print(Hexdump.dump(data))
- File.binwrite("rotpk_raw_data.bin", data)
- rotpk = OpenSSL::Digest::SHA256.digest(data)
- print("rotpk\n" )
- print(Hexdump.dump(rotpk))
- #
- #require 'openssl'
- #
- #if ARGV.length < 3 || ARGV[2] != 'yes-i-know-that-burning-a-rotpk-might-brick-my-device'
- # puts 'Usage: mkrotpk public-key.pem rotpk.bin do-you-know-what-you-are-doing?'
- # exit false
- #end
- #
- #key = OpenSSL::PKey::RSA.new(File.read(ARGV[0]))
- #
- #n = key.params['n']
- #e = key.params['e']
- #
- #if n.num_bits != 2048
- # puts 'Need 2048-bit RSA key'
- # exit false
- #end
- #
- #n = [n.to_s(16)].pack('H*')
- #e = [e.to_s(16)].pack('H*')
- #
- #if n.length != 256
- # puts 'fatal: n.length != 256 bytes'
- # exit false
- #end
- #
- #if e.length > 256
- # puts 'fatal: e.length > 256 bytes'
- # exit false
- #end
- #
- #data = n + e.ljust(256, "\x91".b)
- #rotpk = OpenSSL::Digest::SHA256.digest(data)
- #
- #File.binwrite(ARGV[1], rotpk)
- #
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement