Merge "Skip the parsing of the refresh interval in CertXml"
This commit is contained in:
committed by
Android (Google) Code Review
commit
272c12360f
@@ -20,6 +20,8 @@ import android.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.X509Certificate;
|
||||
@@ -28,8 +30,6 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parses and holds the XML file containing the list of THM public-key certificates and related
|
||||
* metadata.
|
||||
@@ -38,24 +38,20 @@ public final class CertXml {
|
||||
|
||||
private static final String METADATA_NODE_TAG = "metadata";
|
||||
private static final String METADATA_SERIAL_NODE_TAG = "serial";
|
||||
private static final String METADATA_REFRESH_INTERVAL_NODE_TAG = "refresh-interval";
|
||||
private static final String ENDPOINT_CERT_LIST_TAG = "endpoints";
|
||||
private static final String ENDPOINT_CERT_ITEM_TAG = "cert";
|
||||
private static final String INTERMEDIATE_CERT_LIST_TAG = "intermediates";
|
||||
private static final String INTERMEDIATE_CERT_ITEM_TAG = "cert";
|
||||
|
||||
private final long serial;
|
||||
private final long refreshInterval;
|
||||
private final List<X509Certificate> intermediateCerts;
|
||||
private final List<X509Certificate> endpointCerts;
|
||||
|
||||
private CertXml(
|
||||
long serial,
|
||||
long refreshInterval,
|
||||
List<X509Certificate> intermediateCerts,
|
||||
List<X509Certificate> endpointCerts) {
|
||||
this.serial = serial;
|
||||
this.refreshInterval = refreshInterval;
|
||||
this.intermediateCerts = intermediateCerts;
|
||||
this.endpointCerts = endpointCerts;
|
||||
}
|
||||
@@ -65,15 +61,6 @@ public final class CertXml {
|
||||
return serial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the refresh interval in the XML file containing public-key certificates. The refresh
|
||||
* interval denotes the number of seconds that the client should follow to contact the server to
|
||||
* refresh the XML file.
|
||||
*/
|
||||
public long getRefreshInterval() {
|
||||
return refreshInterval;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
List<X509Certificate> getAllIntermediateCerts() {
|
||||
return intermediateCerts;
|
||||
@@ -121,7 +108,6 @@ public final class CertXml {
|
||||
Element rootNode = CertUtils.getXmlRootNode(bytes);
|
||||
return new CertXml(
|
||||
parseSerial(rootNode),
|
||||
parseRefreshInterval(rootNode),
|
||||
parseIntermediateCerts(rootNode),
|
||||
parseEndpointCerts(rootNode));
|
||||
}
|
||||
@@ -136,16 +122,6 @@ public final class CertXml {
|
||||
return Long.parseLong(contents.get(0));
|
||||
}
|
||||
|
||||
private static long parseRefreshInterval(Element rootNode) throws CertParsingException {
|
||||
List<String> contents =
|
||||
CertUtils.getXmlNodeContents(
|
||||
CertUtils.MUST_EXIST_EXACTLY_ONE,
|
||||
rootNode,
|
||||
METADATA_NODE_TAG,
|
||||
METADATA_REFRESH_INTERVAL_NODE_TAG);
|
||||
return Long.parseLong(contents.get(0));
|
||||
}
|
||||
|
||||
private static List<X509Certificate> parseIntermediateCerts(Element rootNode)
|
||||
throws CertParsingException {
|
||||
List<String> contents =
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<certificates>
|
||||
<metadata>
|
||||
<serial>
|
||||
1000
|
||||
</serial>
|
||||
<creation-time>
|
||||
1515697631
|
||||
</creation-time>
|
||||
<refresh-interval>
|
||||
2592000
|
||||
</refresh-interval>
|
||||
<refresh-interval>
|
||||
2592000
|
||||
</refresh-interval>
|
||||
<previous>
|
||||
<serial>
|
||||
0
|
||||
</serial>
|
||||
<hash>
|
||||
47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
|
||||
</hash>
|
||||
</previous>
|
||||
</metadata>
|
||||
<endpoints>
|
||||
<cert>
|
||||
MIIDCDCB8aADAgECAgYBYOlweDswDQYJKoZIhvcNAQELBQAwLTErMCkGA1UEAwwi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
</cert>
|
||||
</endpoints>
|
||||
</certificates>
|
||||
@@ -47,7 +47,6 @@ public final class CertXmlTest {
|
||||
public void parse_succeeds() throws Exception {
|
||||
CertXml certXml = CertXml.parse(certXmlBytes);
|
||||
assertThat(certXml.getSerial()).isEqualTo(1000L);
|
||||
assertThat(certXml.getRefreshInterval()).isEqualTo(2592000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,6 +73,13 @@ public final class CertXmlTest {
|
||||
assertThat(endpointCerts).containsAllOf(TestData.LEAF_CERT_1, TestData.LEAF_CERT_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_doesNotThrowIfNoRefreshInterval() throws Exception {
|
||||
CertXml.parse(
|
||||
TestData.readTestFile(
|
||||
"xml/valid-cert-file-no-refresh-interval.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_throwsIfNoEndpointCert() throws Exception {
|
||||
CertParsingException expected =
|
||||
@@ -86,18 +92,6 @@ public final class CertXmlTest {
|
||||
assertThat(expected.getMessage()).contains("at least one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_throwsIfNoRefreshInterval() throws Exception {
|
||||
CertParsingException expected =
|
||||
expectThrows(
|
||||
CertParsingException.class,
|
||||
() ->
|
||||
CertXml.parse(
|
||||
TestData.readTestFile(
|
||||
"xml/invalid-cert-file-no-refresh-interval.xml")));
|
||||
assertThat(expected.getMessage()).contains("exactly one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_throwsIfNoSerial() throws Exception {
|
||||
CertParsingException expected =
|
||||
@@ -110,19 +104,6 @@ public final class CertXmlTest {
|
||||
assertThat(expected.getMessage()).contains("exactly one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_throwsIfTwoRefreshIntervals() throws Exception {
|
||||
CertParsingException expected =
|
||||
expectThrows(
|
||||
CertParsingException.class,
|
||||
() ->
|
||||
CertXml.parse(
|
||||
TestData.readTestFile(
|
||||
"xml/invalid-cert-file-two-refresh-intervals"
|
||||
+ ".xml")));
|
||||
assertThat(expected.getMessage()).contains("exactly one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_throwsIfTwoSerials() throws Exception {
|
||||
CertParsingException expected =
|
||||
|
||||
Reference in New Issue
Block a user