use of com.android.apksig.util.DataSource in project apksig by venshine.
the class FileChannelDataSourceTest method testFeedsCorrectData_whenSeveralMbRead.
@Test
public void testFeedsCorrectData_whenSeveralMbRead() throws Exception {
byte[] fullFileContent = createFileContent(3 * 1024 * 1024 + 987654);
RandomAccessFile raf = createRaf(fullFileContent);
DataSource rafDataSource = new FileChannelDataSource(raf.getChannel());
ByteArrayDataSink dataSink = new ByteArrayDataSink();
int offset = 23456;
int bytesToFeed = 2 * 1024 * 1024 + 12345;
rafDataSource.feed(offset, bytesToFeed, dataSink);
byte[] expectedBytes = Arrays.copyOfRange(fullFileContent, offset, offset + bytesToFeed);
byte[] resultBytes = getDataSinkBytes(dataSink);
assertArrayEquals(expectedBytes, resultBytes);
}
use of com.android.apksig.util.DataSource in project apksig by venshine.
the class SigningCertificateLineageTest method testLineageFromBytesContainsExpectedSigners.
@Test
public void testLineageFromBytesContainsExpectedSigners() throws Exception {
// This file contains the lineage with the three rsa-2048 signers
DataSource lineageDataSource = Resources.toDataSource(getClass(), "rsa-2048-lineage-3-signers");
SigningCertificateLineage lineage = SigningCertificateLineage.readFromBytes(lineageDataSource.getByteBuffer(0, (int) lineageDataSource.size()).array());
List<SignerConfig> signers = new ArrayList<>(3);
signers.add(Resources.toLineageSignerConfig(getClass(), FIRST_RSA_2048_SIGNER_RESOURCE_NAME));
signers.add(Resources.toLineageSignerConfig(getClass(), SECOND_RSA_2048_SIGNER_RESOURCE_NAME));
signers.add(Resources.toLineageSignerConfig(getClass(), THIRD_RSA_2048_SIGNER_RESOURCE_NAME));
assertLineageContainsExpectedSigners(lineage, signers);
}
use of com.android.apksig.util.DataSource in project apksig by venshine.
the class SigningCertificateLineageTest method testLineageFromFileContainsExpectedSigners.
@Test
public void testLineageFromFileContainsExpectedSigners() throws Exception {
// This file contains the lineage with the three rsa-2048 signers
DataSource lineageDataSource = Resources.toDataSource(getClass(), "rsa-2048-lineage-3-signers");
SigningCertificateLineage lineage = SigningCertificateLineage.readFromDataSource(lineageDataSource);
List<SignerConfig> signers = new ArrayList<>(3);
signers.add(Resources.toLineageSignerConfig(getClass(), FIRST_RSA_2048_SIGNER_RESOURCE_NAME));
signers.add(Resources.toLineageSignerConfig(getClass(), SECOND_RSA_2048_SIGNER_RESOURCE_NAME));
signers.add(Resources.toLineageSignerConfig(getClass(), THIRD_RSA_2048_SIGNER_RESOURCE_NAME));
assertLineageContainsExpectedSigners(lineage, signers);
}
use of com.android.apksig.util.DataSource in project apksig by venshine.
the class SigningCertificateLineageTest method testLineageFromAPKWithNoLineageFails.
@Test
public void testLineageFromAPKWithNoLineageFails() throws Exception {
// This test verifies that attempting to read the lineage from an APK without a lineage
// fails.
// This is a valid APK that has only been signed with the V1 and V2 signature schemes;
// since the lineage is an attribute in the V3 signature block this test should fail.
DataSource apkDataSource = Resources.toDataSource(getClass(), "golden-aligned-v1v2-out.apk");
try {
SigningCertificateLineage.readFromApkDataSource(apkDataSource);
fail("A failure should have been reported due to the APK not containing a V3 signing " + "block");
} catch (IllegalArgumentException expected) {
}
// This is a valid APK signed with the V1, V2, and V3 signature schemes, but there is no
// lineage in the V3 signature block.
apkDataSource = Resources.toDataSource(getClass(), "golden-aligned-v1v2v3-out.apk");
try {
SigningCertificateLineage.readFromApkDataSource(apkDataSource);
fail("A failure should have been reported due to the APK containing a V3 signing " + "block without the lineage attribute");
} catch (IllegalArgumentException expected) {
}
// This APK is based off the v1v2v3-with-rsa-2048-lineage-3-signers.apk with a bit flip
// in the lineage attribute ID in the V3 signature block.
apkDataSource = Resources.toDataSource(getClass(), "v1v2v3-with-rsa-2048-lineage-3-signers-invalid-lineage-attr.apk");
try {
SigningCertificateLineage.readFromApkDataSource(apkDataSource);
fail("A failure should have been reported due to the APK containing a V3 signing " + "block with a modified lineage attribute ID");
} catch (IllegalArgumentException expected) {
}
}
Aggregations