Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Xamarin.Android.Tools.AndroidSdk/DownloadUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ internal static string ComputeHashString (ChecksumType checksumType, byte[] data

static HashAlgorithm CreateHashAlgorithm (ChecksumType checksumType) => checksumType switch {
ChecksumType.Sha256 => (HashAlgorithm) SHA256.Create (),
ChecksumType.Sha1 => SHA1.Create (),
// Google Android SDK repository manifests currently provide only SHA-1 checksums for
// command-line tools. This compatibility hash only compares an archive with that vendor
// field; it is not used for authentication, signing, passwords, or authorization.
// SHA-256 remains the default for other downloads. Review when Google offers a stronger
// manifest checksum.
Comment thread
jonathanpeppers marked this conversation as resolved.
Resolved
ChecksumType.Sha1 => SHA1.Create (), // CodeQL [SM02196]
_ => throw new NotSupportedException ($"Unsupported checksum type: '{checksumType}'."),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public void VerifyChecksum_MatchingHash_DoesNotThrow ()
Assert.DoesNotThrow (() => DownloadUtils.VerifyChecksum (filePath, expected));
}

[Test]
public void VerifyChecksum_GoogleManifestSha1MatchingHash_DoesNotThrow ()
{
var filePath = Path.Combine (tempDir, "test.bin");
File.WriteAllBytes (filePath, new byte [] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }); // "Hello"

Assert.DoesNotThrow (() => DownloadUtils.VerifyChecksum (
filePath,
"f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0",
ChecksumType.Sha1));
Comment thread
jonathanpeppers marked this conversation as resolved.
Resolved
}

[Test]
public void VerifyChecksum_MismatchedHash_Throws ()
{
Expand Down