fix and test for bad certificate version numbers (#1012)

closes #1012
This commit is contained in:
Vincent Breitmoser
2015-01-02 01:57:49 +01:00
parent 704fc2dd45
commit b52fb90380
4 changed files with 49 additions and 9 deletions

View File

@@ -34,6 +34,7 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockPar
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
@RunWith(RobolectricTestRunner.class)
@@ -129,4 +130,20 @@ public class UncachedKeyringTest {
pubRing.extractPublicKeyRing();
}
@Test(expected = IOException.class)
public void testBrokenVersionCert() throws Throwable {
// this is a test for one of the patches we use on top of stock bouncycastle, which
// returns an IOException rather than a RuntimeException in case of a bad certificate
// version byte
readRingFromResource("/test-keys/broken_cert_version.asc");
}
UncachedKeyRing readRingFromResource(String name) throws Throwable {
try {
return UncachedKeyRing.fromStream(UncachedKeyringTest.class.getResourceAsStream(name)).next();
} catch (RuntimeException e) {
throw e.getCause();
}
}
}