mirror of
https://github.com/google/nomulus.git
synced 2025-05-20 19:29:35 +02:00
Refactor TmchCertificateAuthority
The main goal of this CL is to make the clock constructor injectable (so that tests do not need to use InjectRule to override the clock). The complication is that the clock is used by two static caches (ROOT_CACHE directly and CRL_CACHE indirectly). The clock is not actually used to construct the lock, but rather to verify that the root certificate is within its validity period. For ROOT_CACHE we move the verification to its call sites. This adds a bit overhead because the validity check happens every time the cache is called, not just when the cache is built or refreshed. However this check is rather cheap. Also the resources are included in the jar and the cache is valid for 1 year. Given that we deploy every week, there's not much point making it an expiring cache rather than a static map. For CRL_CACHE we change the key to a tuple of TmchCaMode and X509Certificate. The certificate is no longer provided from the ROOT_CACHE directly and must be verified before it is provided as a cache key. We left the CRL verification inside the cache loader because it (signature verification) is more expensive compared to simple expiration check, and we do not want to do this every time the cache is called. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218385684
This commit is contained in:
parent
589e98a1db
commit
57d95d4bec
10 changed files with 65 additions and 79 deletions
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.tmch;
|
package google.registry.tmch;
|
||||||
|
|
||||||
import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PILOT;
|
import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PILOT;
|
||||||
import static google.registry.config.RegistryConfig.getSingletonCachePersistDuration;
|
import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PRODUCTION;
|
||||||
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
|
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
@ -23,17 +23,16 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
|
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
|
||||||
import google.registry.model.tmch.TmchCrl;
|
import google.registry.model.tmch.TmchCrl;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.NonFinalForTesting;
|
|
||||||
import google.registry.util.SystemClock;
|
|
||||||
import google.registry.util.X509Utils;
|
import google.registry.util.X509Utils;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.security.cert.CertificateParsingException;
|
||||||
import java.security.cert.X509CRL;
|
import java.security.cert.X509CRL;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -58,9 +57,12 @@ public final class TmchCertificateAuthority {
|
||||||
private static final String CRL_PILOT_FILE = "icann-tmch-pilot.crl";
|
private static final String CRL_PILOT_FILE = "icann-tmch-pilot.crl";
|
||||||
|
|
||||||
private final TmchCaMode tmchCaMode;
|
private final TmchCaMode tmchCaMode;
|
||||||
|
private final Clock clock;
|
||||||
|
|
||||||
public @Inject TmchCertificateAuthority(@Config("tmchCaMode") TmchCaMode tmchCaMode) {
|
@Inject
|
||||||
|
public TmchCertificateAuthority(@Config("tmchCaMode") TmchCaMode tmchCaMode, Clock clock) {
|
||||||
this.tmchCaMode = tmchCaMode;
|
this.tmchCaMode = tmchCaMode;
|
||||||
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,8 +72,8 @@ public final class TmchCertificateAuthority {
|
||||||
* string into an X509CRL instance is expensive and should itself be cached.
|
* string into an X509CRL instance is expensive and should itself be cached.
|
||||||
*
|
*
|
||||||
* <p>Note that the stored CRL won't exist for tests, and on deployed environments will always
|
* <p>Note that the stored CRL won't exist for tests, and on deployed environments will always
|
||||||
* correspond to the correct CRL for the given TMCH CA mode because {@link TmchCrlAction} can
|
* correspond to the correct CRL for the given TMCH CA mode because {@link TmchCrlAction} can only
|
||||||
* only persist the correct one for this given environment.
|
* persist the correct one for this given environment.
|
||||||
*/
|
*/
|
||||||
private static final LoadingCache<TmchCaMode, X509CRL> CRL_CACHE =
|
private static final LoadingCache<TmchCaMode, X509CRL> CRL_CACHE =
|
||||||
CacheBuilder.newBuilder()
|
CacheBuilder.newBuilder()
|
||||||
|
@ -89,37 +91,28 @@ public final class TmchCertificateAuthority {
|
||||||
crlContents = storedCrl.getCrl();
|
crlContents = storedCrl.getCrl();
|
||||||
}
|
}
|
||||||
X509CRL crl = X509Utils.loadCrl(crlContents);
|
X509CRL crl = X509Utils.loadCrl(crlContents);
|
||||||
try {
|
crl.verify(ROOT_CERTS.get(tmchCaMode).getPublicKey());
|
||||||
crl.verify(ROOT_CACHE.get(tmchCaMode).getPublicKey());
|
return crl;
|
||||||
return crl;
|
}
|
||||||
} catch (ExecutionException e) {
|
});
|
||||||
if (e.getCause() instanceof GeneralSecurityException) {
|
|
||||||
throw (GeneralSecurityException) e.getCause();
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Unexpected exception while loading CRL", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
|
|
||||||
/** A cached function that loads the CRT from a jar resource. */
|
/** CRTs from a jar resource. */
|
||||||
private static final LoadingCache<TmchCaMode, X509Certificate> ROOT_CACHE =
|
private static final ImmutableMap<TmchCaMode, X509Certificate> ROOT_CERTS =
|
||||||
CacheBuilder.newBuilder()
|
loadRootCertificates();
|
||||||
.expireAfterWrite(getSingletonCachePersistDuration().getMillis(), MILLISECONDS)
|
|
||||||
.build(
|
|
||||||
new CacheLoader<TmchCaMode, X509Certificate>() {
|
|
||||||
@Override
|
|
||||||
public X509Certificate load(final TmchCaMode tmchCaMode)
|
|
||||||
throws GeneralSecurityException {
|
|
||||||
String file = (tmchCaMode == PILOT) ? ROOT_CRT_PILOT_FILE : ROOT_CRT_FILE;
|
|
||||||
X509Certificate root =
|
|
||||||
X509Utils.loadCertificate(
|
|
||||||
readResourceUtf8(TmchCertificateAuthority.class, file));
|
|
||||||
root.checkValidity(clock.nowUtc().toDate());
|
|
||||||
return root;
|
|
||||||
}});
|
|
||||||
|
|
||||||
@NonFinalForTesting
|
private static ImmutableMap<TmchCaMode, X509Certificate> loadRootCertificates() {
|
||||||
private static Clock clock = new SystemClock();
|
try {
|
||||||
|
return ImmutableMap.of(
|
||||||
|
PILOT,
|
||||||
|
X509Utils.loadCertificate(
|
||||||
|
readResourceUtf8(TmchCertificateAuthority.class, ROOT_CRT_PILOT_FILE)),
|
||||||
|
PRODUCTION,
|
||||||
|
X509Utils.loadCertificate(
|
||||||
|
readResourceUtf8(TmchCertificateAuthority.class, ROOT_CRT_FILE)));
|
||||||
|
} catch (CertificateParsingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that {@code cert} is signed by the ICANN TMCH CA root and not revoked.
|
* Check that {@code cert} is signed by the ICANN TMCH CA root and not revoked.
|
||||||
|
@ -132,7 +125,7 @@ public final class TmchCertificateAuthority {
|
||||||
*/
|
*/
|
||||||
public void verify(X509Certificate cert) throws GeneralSecurityException {
|
public void verify(X509Certificate cert) throws GeneralSecurityException {
|
||||||
synchronized (TmchCertificateAuthority.class) {
|
synchronized (TmchCertificateAuthority.class) {
|
||||||
X509Utils.verifyCertificate(getRoot(), getCrl(), cert, clock.nowUtc().toDate());
|
X509Utils.verifyCertificate(getAndValidateRoot(), getCrl(), cert, clock.nowUtc().toDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,21 +138,26 @@ public final class TmchCertificateAuthority {
|
||||||
* refreshes itself.
|
* refreshes itself.
|
||||||
*
|
*
|
||||||
* @throws GeneralSecurityException for unsupported protocols, certs not signed by the TMCH,
|
* @throws GeneralSecurityException for unsupported protocols, certs not signed by the TMCH,
|
||||||
* incorrect keys, and for invalid, old, not-yet-valid or revoked certificates.
|
* incorrect keys, and for invalid, old, not-yet-valid or revoked certificates.
|
||||||
* @see X509Utils#verifyCrl
|
* @see X509Utils#verifyCrl
|
||||||
*/
|
*/
|
||||||
public void updateCrl(String asciiCrl, String url) throws GeneralSecurityException {
|
public void updateCrl(String asciiCrl, String url) throws GeneralSecurityException {
|
||||||
X509CRL crl = X509Utils.loadCrl(asciiCrl);
|
X509CRL crl = X509Utils.loadCrl(asciiCrl);
|
||||||
X509Utils.verifyCrl(getRoot(), getCrl(), crl, clock.nowUtc().toDate());
|
X509Utils.verifyCrl(getAndValidateRoot(), getCrl(), crl, clock.nowUtc().toDate());
|
||||||
TmchCrl.set(asciiCrl, url);
|
TmchCrl.set(asciiCrl, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public X509Certificate getRoot() throws GeneralSecurityException {
|
public X509Certificate getAndValidateRoot() throws GeneralSecurityException {
|
||||||
try {
|
try {
|
||||||
return ROOT_CACHE.get(tmchCaMode);
|
X509Certificate root = ROOT_CERTS.get(tmchCaMode);
|
||||||
|
// The current production certificate expires on 2023-07-23. Future code monkey be reminded,
|
||||||
|
// if you are looking at this code because the next line throws an exception, ask ICANN for a
|
||||||
|
// new root certificate! (preferably before the current one expires...)
|
||||||
|
root.checkValidity(clock.nowUtc().toDate());
|
||||||
|
return root;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e.getCause() instanceof GeneralSecurityException) {
|
if (e instanceof GeneralSecurityException) {
|
||||||
throw (GeneralSecurityException) e.getCause();
|
throw (GeneralSecurityException) e;
|
||||||
} else if (e instanceof RuntimeException) {
|
} else if (e instanceof RuntimeException) {
|
||||||
throw (RuntimeException) e;
|
throw (RuntimeException) e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import google.registry.testing.FakeHttpSession;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.ShardableTestCase;
|
import google.registry.testing.ShardableTestCase;
|
||||||
import google.registry.tmch.TmchCertificateAuthority;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -58,8 +57,6 @@ public class EppTestCase extends ShardableTestCase {
|
||||||
public void initTestCase() {
|
public void initTestCase() {
|
||||||
// For transactional flows
|
// For transactional flows
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
// For SignedMark signature validity
|
|
||||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -80,7 +80,7 @@ interface EppTestComponent {
|
||||||
return create(
|
return create(
|
||||||
clock,
|
clock,
|
||||||
metricBuilder,
|
metricBuilder,
|
||||||
new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PILOT)));
|
new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PILOT, clock)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FakesAndMocksModule create(
|
public static FakesAndMocksModule create(
|
||||||
|
|
|
@ -110,8 +110,6 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
||||||
ofy().saveWithoutBackup().entity(new ClaimsListSingleton()).now();
|
ofy().saveWithoutBackup().entity(new ClaimsListSingleton()).now();
|
||||||
// For transactional flows
|
// For transactional flows
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
// For SignedMark signature validity
|
|
||||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeServiceExtensionUri(String uri) {
|
protected void removeServiceExtensionUri(String uri) {
|
||||||
|
@ -286,7 +284,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
||||||
TmchXmlSignature tmchXmlSignature =
|
TmchXmlSignature tmchXmlSignature =
|
||||||
testTmchXmlSignature != null
|
testTmchXmlSignature != null
|
||||||
? testTmchXmlSignature
|
? testTmchXmlSignature
|
||||||
: new TmchXmlSignature(new TmchCertificateAuthority(tmchCaMode));
|
: new TmchXmlSignature(new TmchCertificateAuthority(tmchCaMode, clock));
|
||||||
return DaggerEppTestComponent.builder()
|
return DaggerEppTestComponent.builder()
|
||||||
.fakesAndMocksModule(FakesAndMocksModule.create(clock, eppMetricBuilder, tmchXmlSignature))
|
.fakesAndMocksModule(FakesAndMocksModule.create(clock, eppMetricBuilder, tmchXmlSignature))
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -24,7 +24,6 @@ import com.google.appengine.api.urlfetch.URLFetchService;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.BouncyCastleProviderRule;
|
import google.registry.testing.BouncyCastleProviderRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
|
||||||
import google.registry.testing.MockitoJUnitRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -44,7 +43,6 @@ public class TmchActionTestCase {
|
||||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
@Rule public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
|
@Rule public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
@Mock URLFetchService fetchService;
|
@Mock URLFetchService fetchService;
|
||||||
@Mock HTTPResponse httpResponse;
|
@Mock HTTPResponse httpResponse;
|
||||||
|
@ -55,7 +53,6 @@ public class TmchActionTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void commonBefore() throws Exception {
|
public void commonBefore() throws Exception {
|
||||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
|
||||||
marksdb.fetchService = fetchService;
|
marksdb.fetchService = fetchService;
|
||||||
marksdb.tmchMarksdbUrl = MARKSDB_URL;
|
marksdb.tmchMarksdbUrl = MARKSDB_URL;
|
||||||
marksdb.marksdbPublicKey = TmchData.loadPublicKey(TmchTestData.loadBytes("pubkey"));
|
marksdb.marksdbPublicKey = TmchData.loadPublicKey(TmchTestData.loadBytes("pubkey"));
|
||||||
|
|
|
@ -25,13 +25,11 @@ import static google.registry.util.X509Utils.loadCertificate;
|
||||||
import google.registry.model.tmch.TmchCrl;
|
import google.registry.model.tmch.TmchCrl;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.security.cert.CertificateExpiredException;
|
import java.security.cert.CertificateExpiredException;
|
||||||
import java.security.cert.CertificateNotYetValidException;
|
import java.security.cert.CertificateNotYetValidException;
|
||||||
import java.security.cert.CertificateRevokedException;
|
import java.security.cert.CertificateRevokedException;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -48,38 +46,35 @@ public class TmchCertificateAuthorityTest {
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||||
.withDatastore()
|
.withDatastore()
|
||||||
.build();
|
.build();
|
||||||
@Rule
|
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
private FakeClock clock = new FakeClock(DateTime.parse("2014-01-01T00:00:00Z"));
|
private FakeClock clock = new FakeClock(DateTime.parse("2014-01-01T00:00:00Z"));
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_prodRootExpired() {
|
public void testFailure_prodRootExpired() {
|
||||||
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION);
|
TmchCertificateAuthority tmchCertificateAuthority =
|
||||||
|
new TmchCertificateAuthority(PRODUCTION, clock);
|
||||||
clock.setTo(DateTime.parse("2024-01-01T00:00:00Z"));
|
clock.setTo(DateTime.parse("2024-01-01T00:00:00Z"));
|
||||||
CertificateExpiredException e =
|
CertificateExpiredException e =
|
||||||
assertThrows(CertificateExpiredException.class, tmchCertificateAuthority::getRoot);
|
assertThrows(
|
||||||
|
CertificateExpiredException.class, tmchCertificateAuthority::getAndValidateRoot);
|
||||||
assertThat(e).hasMessageThat().containsMatch("NotAfter: Sun Jul 23 23:59:59 UTC 2023");
|
assertThat(e).hasMessageThat().containsMatch("NotAfter: Sun Jul 23 23:59:59 UTC 2023");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_prodRootNotYetValid() {
|
public void testFailure_prodRootNotYetValid() {
|
||||||
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION);
|
TmchCertificateAuthority tmchCertificateAuthority =
|
||||||
|
new TmchCertificateAuthority(PRODUCTION, clock);
|
||||||
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
|
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
|
||||||
CertificateNotYetValidException e =
|
CertificateNotYetValidException e =
|
||||||
assertThrows(CertificateNotYetValidException.class, tmchCertificateAuthority::getRoot);
|
assertThrows(
|
||||||
|
CertificateNotYetValidException.class, tmchCertificateAuthority::getAndValidateRoot);
|
||||||
assertThat(e).hasMessageThat().containsMatch("NotBefore: Wed Jul 24 00:00:00 UTC 2013");
|
assertThat(e).hasMessageThat().containsMatch("NotBefore: Wed Jul 24 00:00:00 UTC 2013");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_crlDoesntMatchCerts() {
|
public void testFailure_crlDoesntMatchCerts() {
|
||||||
// Use the prod cl, which won't match our test certificate.
|
// Use the prod cl, which won't match our test certificate.
|
||||||
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT);
|
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT, clock);
|
||||||
TmchCrl.set(
|
TmchCrl.set(
|
||||||
readResourceUtf8(TmchCertificateAuthority.class, "icann-tmch.crl"), "http://cert.crl");
|
readResourceUtf8(TmchCertificateAuthority.class, "icann-tmch.crl"), "http://cert.crl");
|
||||||
SignatureException e =
|
SignatureException e =
|
||||||
|
@ -91,13 +86,14 @@ public class TmchCertificateAuthorityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_verify() throws Exception {
|
public void testSuccess_verify() throws Exception {
|
||||||
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT);
|
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT, clock);
|
||||||
tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE));
|
tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_verifySignatureDoesntMatch() {
|
public void testFailure_verifySignatureDoesntMatch() {
|
||||||
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION);
|
TmchCertificateAuthority tmchCertificateAuthority =
|
||||||
|
new TmchCertificateAuthority(PRODUCTION, clock);
|
||||||
SignatureException e =
|
SignatureException e =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
SignatureException.class,
|
SignatureException.class,
|
||||||
|
@ -107,7 +103,7 @@ public class TmchCertificateAuthorityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_verifyRevoked() {
|
public void testFailure_verifyRevoked() {
|
||||||
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT);
|
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT, clock);
|
||||||
CertificateRevokedException thrown =
|
CertificateRevokedException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
CertificateRevokedException.class,
|
CertificateRevokedException.class,
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class TmchCrlActionTest extends TmchActionTestCase {
|
||||||
private TmchCrlAction newTmchCrlAction(TmchCaMode tmchCaMode) throws MalformedURLException {
|
private TmchCrlAction newTmchCrlAction(TmchCaMode tmchCaMode) throws MalformedURLException {
|
||||||
TmchCrlAction action = new TmchCrlAction();
|
TmchCrlAction action = new TmchCrlAction();
|
||||||
action.marksdb = marksdb;
|
action.marksdb = marksdb;
|
||||||
action.tmchCertificateAuthority = new TmchCertificateAuthority(tmchCaMode);
|
action.tmchCertificateAuthority = new TmchCertificateAuthority(tmchCaMode, clock);
|
||||||
action.tmchCrlUrl = new URL("http://sloth.lol/tmch.crl");
|
action.tmchCrlUrl = new URL("http://sloth.lol/tmch.crl");
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import google.registry.flows.domain.DomainFlowTmchUtils;
|
||||||
import google.registry.model.smd.EncodedSignedMark;
|
import google.registry.model.smd.EncodedSignedMark;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.util.ResourceUtils;
|
import google.registry.util.ResourceUtils;
|
||||||
|
import google.registry.util.SystemClock;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -43,7 +44,8 @@ public class TmchTestDataExpirationTest {
|
||||||
public void testActiveSignedMarkFiles_areValidAndNotExpired() throws Exception {
|
public void testActiveSignedMarkFiles_areValidAndNotExpired() throws Exception {
|
||||||
DomainFlowTmchUtils tmchUtils =
|
DomainFlowTmchUtils tmchUtils =
|
||||||
new DomainFlowTmchUtils(
|
new DomainFlowTmchUtils(
|
||||||
new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PILOT)));
|
new TmchXmlSignature(
|
||||||
|
new TmchCertificateAuthority(TmchCaMode.PILOT, new SystemClock())));
|
||||||
|
|
||||||
for (Path path : listFiles(TmchTestDataExpirationTest.class, "testdata/active/")) {
|
for (Path path : listFiles(TmchTestDataExpirationTest.class, "testdata/active/")) {
|
||||||
if (path.toString().endsWith(".smd")) {
|
if (path.toString().endsWith(".smd")) {
|
||||||
|
|
|
@ -72,17 +72,17 @@ public class TmchXmlSignatureTest {
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2018-05-15T23:15:37.4Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2018-05-15T23:15:37.4Z"));
|
||||||
|
|
||||||
private byte[] smdData;
|
private byte[] smdData;
|
||||||
private TmchXmlSignature tmchXmlSignature;
|
private TmchXmlSignature tmchXmlSignature =
|
||||||
|
new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PILOT, clock));
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
|
||||||
tmchXmlSignature = new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PILOT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongCertificateAuthority() {
|
public void testWrongCertificateAuthority() {
|
||||||
tmchXmlSignature = new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PRODUCTION));
|
tmchXmlSignature =
|
||||||
|
new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PRODUCTION, clock));
|
||||||
smdData = loadSmd("active/Court-Agent-Arab-Active.smd");
|
smdData = loadSmd("active/Court-Agent-Arab-Active.smd");
|
||||||
CertificateSignatureException e =
|
CertificateSignatureException e =
|
||||||
assertThrows(CertificateSignatureException.class, () -> tmchXmlSignature.verify(smdData));
|
assertThrows(CertificateSignatureException.class, () -> tmchXmlSignature.verify(smdData));
|
||||||
|
|
|
@ -75,8 +75,6 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
// For SignedMark signature validity
|
|
||||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
createTld("xn--q9jyb4c");
|
createTld("xn--q9jyb4c");
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
@ -87,7 +85,7 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
|
||||||
.build());
|
.build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
command.tmchUtils =
|
command.tmchUtils =
|
||||||
new DomainFlowTmchUtils(new TmchXmlSignature(new TmchCertificateAuthority(PILOT)));
|
new DomainFlowTmchUtils(new TmchXmlSignature(new TmchCertificateAuthority(PILOT, clock)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DomainApplication reloadDomainApplication() {
|
private DomainApplication reloadDomainApplication() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue