Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that signatureMask isn't an empty array #26

Merged
merged 2 commits into from
Dec 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public boolean verify(@NonNull String packageName, @NonNull URI uri)
requireAllSignatures = true;
}

if (signatureMask.length == 0) {
throw new CouldNotVerifyPackageException("Failed reading signatures for package " + packageName);
}

// Create and configure an AssetLinksJSONParser object
final StatementMatcher androidAppMatcher = StatementMatcher
.createAndroidAppStatementMatcher(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ public void testAppPackageVerificationSuccess()
assertTrue(verified);
}

@Test
public void testAppPackageVerificationNoCertificates() {
ArrayList<MockWebContentServer.Content> mockWebContent = new ArrayList<>();
mockWebContent.add(new MockWebContentServer.Content(
URI.create("https://www.test.com/.well-known/assetlinks.json"),
HttpURLConnection.HTTP_OK,
"application/json",
ANDROID_APP_STATEMENT_LIST_CERTS_2_3));

final PackageManager pm = mockPackageManagerFactory(
"com.test.sample", new byte[][] {}, true);

final AndroidAppPackageVerifierHarness verifier =
new AndroidAppPackageVerifierHarness(pm, mockWebContent);
assertThrows(AndroidAppPackageVerifier.CouldNotVerifyPackageException.class,
() ->verifier.verify("com.test.sample", URI.create("https://www.test.com")));
}

@Test
public void testAppPackageVerificationNoAssetLinks() {
ArrayList<MockWebContentServer.Content> mockWebContent = new ArrayList<>();
Expand Down Expand Up @@ -205,11 +223,11 @@ public void testAppPackageVerificationNoMatchingPackageInPackageManager() {
private static PackageManager mockPackageManagerFactory(@NonNull String packageName,
@NonNull byte[][] certificates,
boolean multipleSigners) {
if (certificates.length == 0) {
throw new IllegalArgumentException("at least 1 certificate required");
} else if (multipleSigners && certificates.length == 1) {
throw new IllegalArgumentException("multipleSigners requires at least 2 certificates");
}
// if (certificates.length == 0) {
// throw new IllegalArgumentException("at least 1 certificate required");
// } else if (multipleSigners && certificates.length == 1) {
// throw new IllegalArgumentException("multipleSigners requires at least 2 certificates");
// }
sdlaver marked this conversation as resolved.
Show resolved Hide resolved

final PackageInfo pi = new PackageInfo();
final int piFlags;
Expand Down