Advertisement
Guest User

Untitled

a guest
Jun 5th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # Copyright © 2017 Jens Kuske <jenskuske@gmail.com>
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15.  
  16. # from https://gist.github.com/jemk/8e1006a44c7a2c796fc3fc2f74f7c6c3
  17.  
  18. require 'openssl'
  19. require 'hexdump'
  20.  
  21. #key = OpenSSL::PKey::RSA.new(File.read(ARGV[0]))
  22. key = OpenSSL::PKey::RSA.new(File.read("RSA.pem"))
  23.  
  24. n = key.params['n']
  25. e = key.params['e']
  26.  
  27. print("n:\n")
  28. print(n)
  29. print("\n")
  30.  
  31. print("e\n")
  32. print(e)
  33. print("\n")
  34.  
  35. #Hexdump.dump(n)
  36.  
  37. if n.num_bits != 2048
  38. puts 'Need 2048-bit RSA key'
  39. exit false
  40. end
  41.  
  42. n = [n.to_s(16)].pack('H*')
  43. e = [e.to_s(16)].pack('H*')
  44.  
  45. print("hexdump n\n")
  46. print(Hexdump.dump(n))
  47. print("hexdump e\n" )
  48. print(Hexdump.dump(e))
  49.  
  50.  
  51. if n.length != 256
  52. puts 'fatal: n.length != 256 bytes'
  53. exit false
  54. end
  55.  
  56. if e.length > 256
  57. puts 'fatal: e.length > 256 bytes'
  58. exit false
  59. end
  60.  
  61. data = n + e.ljust(256, "\x91".b)
  62.  
  63. print("hexdump data\n" )
  64. print(Hexdump.dump(data))
  65.  
  66. File.binwrite("rotpk_raw_data.bin", data)
  67.  
  68. rotpk = OpenSSL::Digest::SHA256.digest(data)
  69.  
  70. print("rotpk\n" )
  71. print(Hexdump.dump(rotpk))
  72.  
  73.  
  74.  
  75. #
  76. #require 'openssl'
  77. #
  78. #if ARGV.length < 3 || ARGV[2] != 'yes-i-know-that-burning-a-rotpk-might-brick-my-device'
  79. # puts 'Usage: mkrotpk public-key.pem rotpk.bin do-you-know-what-you-are-doing?'
  80. # exit false
  81. #end
  82. #
  83. #key = OpenSSL::PKey::RSA.new(File.read(ARGV[0]))
  84. #
  85. #n = key.params['n']
  86. #e = key.params['e']
  87. #
  88. #if n.num_bits != 2048
  89. # puts 'Need 2048-bit RSA key'
  90. # exit false
  91. #end
  92. #
  93. #n = [n.to_s(16)].pack('H*')
  94. #e = [e.to_s(16)].pack('H*')
  95. #
  96. #if n.length != 256
  97. # puts 'fatal: n.length != 256 bytes'
  98. # exit false
  99. #end
  100. #
  101. #if e.length > 256
  102. # puts 'fatal: e.length > 256 bytes'
  103. # exit false
  104. #end
  105. #
  106. #data = n + e.ljust(256, "\x91".b)
  107. #rotpk = OpenSSL::Digest::SHA256.digest(data)
  108. #
  109. #File.binwrite(ARGV[1], rotpk)
  110. #
  111. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement