You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gverify 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/ruby
  2. require 'optparse'
  3. require 'yaml'
  4. require 'fileutils'
  5. require 'pathname'
  6. @options = {}
  7. def system!(cmd)
  8. system(cmd) or raise "failed to run #{cmd}"
  9. end
  10. def sanitize(str, where)
  11. raise "unsanitary string in #{where}" if (str =~ /[^\w.-]/)
  12. str
  13. end
  14. def sanitize_path(str, where)
  15. raise "unsanitary string in #{where}" if (str =~ /[^@\w\/.:+-]/)
  16. str
  17. end
  18. def info(str)
  19. puts str if @options[:verbose]
  20. end
  21. ################################
  22. OptionParser.new do |opts|
  23. opts.banner = "Usage: build [options] <build-description>.yml"
  24. opts.on("-v", "--verbose", "be more verbose") do |v|
  25. @options[:verbose] = v
  26. end
  27. opts.on("-r REL", "--release REL", "release name") do |v|
  28. @options[:release] = v
  29. end
  30. opts.on("-d DEST", "--destination DEST", "directory to place signature in") do |v|
  31. @options[:destination] = v
  32. end
  33. end.parse!
  34. base_dir = Pathname.new(__FILE__).expand_path.dirname.parent
  35. build_desc_file = ARGV.shift or raise "must supply YAML build description file"
  36. build_desc = YAML.load_file(build_desc_file)
  37. in_sums = []
  38. result_dir = 'result'
  39. package_name = build_desc["name"] or raise "must supply name"
  40. package_name = sanitize(package_name, "package name")
  41. destination = @options[:destination] || File.join(base_dir, "sigs", package_name)
  42. release = @options[:release] || "current"
  43. release = sanitize(release, "release")
  44. release_path = File.join(destination, release)
  45. File.exists?(release_path) or raise "#{release_path} does not exist"
  46. result_file = "#{package_name}-build.assert"
  47. sig_file = "#{result_file}.sig"
  48. current_manifest = nil
  49. did_fail = false
  50. Dir.foreach(release_path) do |signer_dir|
  51. next if signer_dir == "." or signer_dir == ".."
  52. signer_path = sanitize_path(File.join(release_path, signer_dir), "signer path")
  53. next if !File.directory?(signer_path)
  54. result_path = sanitize_path(File.join(signer_path, result_file), "result path")
  55. sig_path = sanitize_path(File.join(signer_path, sig_file), "result path")
  56. if !File.exist?(result_path)
  57. puts "missing result at #{result_path}"
  58. next
  59. end
  60. if !File.exist?(sig_path)
  61. puts "missing signature at #{sig_path}"
  62. next
  63. end
  64. result = YAML.load_file(result_path)
  65. system("gpg --keyserver pgp.mit.edu --recv-keys `gpg --quiet --batch --verify \"#{File.join(signer_path, 'signature.pgp')}\" \"#{result_path}\" 2>&1 | head -n1 | grep \"key ID\" | awk '{ print $15 }'` > /dev/null 2>&1")
  66. out = `gpg --quiet --batch --verify \"#{sig_path}\" \"#{result_path}\" 2>&1`
  67. if $? != 0
  68. out.each_line do |line|
  69. if line =~ /^gpg: Signature made/
  70. info(line)
  71. else
  72. puts line
  73. end
  74. end
  75. puts "#{signer_dir}: BAD SIGNATURE"
  76. did_fail = true
  77. elsif current_manifest and (result['out_manifest'] != current_manifest or result['release'] != release or result['name'] != package_name)
  78. out.each_line do |line|
  79. if line =~ /^gpg: Signature made/
  80. info(line)
  81. elsif line =~ /^gpg: Good signature/
  82. info(line)
  83. elsif line =~ /^gpg: aka/
  84. info(line)
  85. else
  86. puts line
  87. end
  88. end
  89. puts "#{signer_dir}: MISMATCH"
  90. did_fail = true
  91. else
  92. out.each_line do |line|
  93. if line =~ /^gpg: Signature made/
  94. info(line)
  95. elsif line =~ /^gpg: Good signature/
  96. info(line)
  97. elsif line =~ /^gpg: aka/
  98. info(line)
  99. else
  100. puts line
  101. end
  102. end
  103. puts "#{signer_dir}: OK"
  104. end
  105. current_manifest = result['out_manifest']
  106. end
  107. exit 1 if did_fail