Add MD5 verification for emoji pack source
authorEkaterina Vaartis <vaartis@cock.li>
Thu, 18 Apr 2019 12:46:07 +0000 (15:46 +0300)
committerEkaterina Vaartis <vaartis@cock.li>
Sat, 20 Apr 2019 08:17:17 +0000 (11:17 +0300)
lib/mix/tasks/pleroma/emoji.ex

index 526b09b1122501d140d0c188b40a0abfc5b20d25..29c5d0c93c42ce54ebe405b521c79233d15436d7 100644 (file)
@@ -77,6 +77,16 @@ defmodule Mix.Tasks.Pleroma.Emoji do
         )
 
         binary_archive = Tesla.get!(src_url).body
+        archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16()
+
+        md5_status_text = ["MD5 of ", :bright, pack_name, :normal, " source file is ", :bright]
+        if archive_md5 == String.upcase(pack["src_md5"]) do
+          IO.puts(IO.ANSI.format(md5_status_text ++ [:green, "OK"]))
+        else
+          IO.puts(IO.ANSI.format(md5_status_text ++ [:red, "BAD"]))
+
+          raise "Bad MD5 for #{pack_name}"
+        end
 
         # The url specified in files should be in the same directory
         files_url = Path.join(Path.dirname(manifest_url), pack["files"])