mirror of
https://github.com/google/nomulus.git
synced 2025-07-31 15:06:29 +02:00
Make EscrowDepositEncryptor work with BRDA deposits (#1512)
Also make it possible to specify a revision number. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/google/nomulus/1512) <!-- Reviewable:end -->
This commit is contained in:
parent
b412bdef9f
commit
09dca28122
3 changed files with 72 additions and 11 deletions
|
@ -18,6 +18,7 @@ import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
|
|||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import google.registry.model.rde.RdeMode;
|
||||
import google.registry.tools.params.PathParameter;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -46,11 +47,20 @@ class EncryptEscrowDepositCommand implements CommandWithRemoteApi {
|
|||
validateWith = PathParameter.OutputDirectory.class)
|
||||
private Path outdir = Paths.get(".");
|
||||
|
||||
@Inject
|
||||
EscrowDepositEncryptor encryptor;
|
||||
@Parameter(
|
||||
names = {"-m", "--mode"},
|
||||
description = "Specify the escrow mode, FULL for RDE and THIN for BRDA.")
|
||||
private RdeMode mode = RdeMode.FULL;
|
||||
|
||||
@Parameter(
|
||||
names = {"-r", "--revision"},
|
||||
description = "Specify the revision.")
|
||||
private int revision = 0;
|
||||
|
||||
@Inject EscrowDepositEncryptor encryptor;
|
||||
|
||||
@Override
|
||||
public final void run() throws Exception {
|
||||
encryptor.encrypt(canonicalizeDomainName(tld), input, outdir);
|
||||
encryptor.encrypt(mode, canonicalizeDomainName(tld), revision, input, outdir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import static google.registry.model.rde.RdeMode.FULL;
|
|||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import google.registry.keyring.api.KeyModule.Key;
|
||||
import google.registry.model.rde.RdeMode;
|
||||
import google.registry.model.rde.RdeNamingUtils;
|
||||
import google.registry.rde.RdeUtil;
|
||||
import google.registry.rde.RydeEncoder;
|
||||
|
@ -42,26 +43,44 @@ final class EscrowDepositEncryptor {
|
|||
|
||||
@Inject @Key("rdeSigningKey") Provider<PGPKeyPair> rdeSigningKey;
|
||||
@Inject @Key("rdeReceiverKey") Provider<PGPPublicKey> rdeReceiverKey;
|
||||
|
||||
@Inject
|
||||
@Key("brdaSigningKey")
|
||||
Provider<PGPKeyPair> brdaSigningKey;
|
||||
|
||||
@Inject
|
||||
@Key("brdaReceiverKey")
|
||||
Provider<PGPPublicKey> brdaReceiverKey;
|
||||
|
||||
@Inject EscrowDepositEncryptor() {}
|
||||
|
||||
/** Creates a {@code .ryde} and {@code .sig} file, provided an XML deposit file. */
|
||||
void encrypt(String tld, Path xmlFile, Path outdir)
|
||||
void encrypt(RdeMode mode, String tld, Integer revision, Path xmlFile, Path outdir)
|
||||
throws IOException, XmlException {
|
||||
try (InputStream xmlFileInput = Files.newInputStream(xmlFile);
|
||||
BufferedInputStream xmlInput = new BufferedInputStream(xmlFileInput, PEEK_BUFFER_SIZE)) {
|
||||
DateTime watermark = RdeUtil.peekWatermark(xmlInput);
|
||||
String name = RdeNamingUtils.makeRydeFilename(tld, watermark, FULL, 1, 0);
|
||||
String name = RdeNamingUtils.makeRydeFilename(tld, watermark, mode, 1, revision);
|
||||
Path rydePath = outdir.resolve(name + ".ryde");
|
||||
Path sigPath = outdir.resolve(name + ".sig");
|
||||
Path pubPath = outdir.resolve(tld + ".pub");
|
||||
PGPKeyPair signingKey = rdeSigningKey.get();
|
||||
PGPKeyPair signingKey;
|
||||
PGPPublicKey receiverKey;
|
||||
if (mode == FULL) {
|
||||
signingKey = rdeSigningKey.get();
|
||||
receiverKey = rdeReceiverKey.get();
|
||||
} else {
|
||||
signingKey = brdaSigningKey.get();
|
||||
receiverKey = brdaReceiverKey.get();
|
||||
}
|
||||
try (OutputStream rydeOutput = Files.newOutputStream(rydePath);
|
||||
OutputStream sigOutput = Files.newOutputStream(sigPath);
|
||||
RydeEncoder rydeEncoder = new RydeEncoder.Builder()
|
||||
.setRydeOutput(rydeOutput, rdeReceiverKey.get())
|
||||
.setSignatureOutput(sigOutput, signingKey)
|
||||
.setFileMetadata(name, Files.size(xmlFile), watermark)
|
||||
.build()) {
|
||||
RydeEncoder rydeEncoder =
|
||||
new RydeEncoder.Builder()
|
||||
.setRydeOutput(rydeOutput, receiverKey)
|
||||
.setSignatureOutput(sigOutput, signingKey)
|
||||
.setFileMetadata(name, Files.size(xmlFile), watermark)
|
||||
.build()) {
|
||||
ByteStreams.copy(xmlInput, rydeEncoder);
|
||||
}
|
||||
try (OutputStream pubOutput = Files.newOutputStream(pubPath);
|
||||
|
|
|
@ -40,6 +40,8 @@ public class EncryptEscrowDepositCommandTest
|
|||
EscrowDepositEncryptor res = new EscrowDepositEncryptor();
|
||||
res.rdeReceiverKey = () -> new FakeKeyringModule().get().getRdeReceiverKey();
|
||||
res.rdeSigningKey = () -> new FakeKeyringModule().get().getRdeSigningKey();
|
||||
res.brdaReceiverKey = () -> new FakeKeyringModule().get().getBrdaReceiverKey();
|
||||
res.brdaSigningKey = () -> new FakeKeyringModule().get().getBrdaSigningKey();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -61,4 +63,34 @@ public class EncryptEscrowDepositCommandTest
|
|||
"lol_2010-10-17_full_S1_R0.sig",
|
||||
"lol.pub");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_brda() throws Exception {
|
||||
Path depositFile = tmpDir.resolve("deposit.xml");
|
||||
Files.write(depositXml.read(), depositFile.toFile());
|
||||
runCommand(
|
||||
"--mode=THIN", "--tld=lol", "--input=" + depositFile, "--outdir=" + tmpDir.toString());
|
||||
assertThat(tmpDir.toFile().list())
|
||||
.asList()
|
||||
.containsExactly(
|
||||
"deposit.xml",
|
||||
"lol_2010-10-17_thin_S1_R0.ryde",
|
||||
"lol_2010-10-17_thin_S1_R0.sig",
|
||||
"lol.pub");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_revision() throws Exception {
|
||||
Path depositFile = tmpDir.resolve("deposit.xml");
|
||||
Files.write(depositXml.read(), depositFile.toFile());
|
||||
runCommand(
|
||||
"--revision=1", "--tld=lol", "--input=" + depositFile, "--outdir=" + tmpDir.toString());
|
||||
assertThat(tmpDir.toFile().list())
|
||||
.asList()
|
||||
.containsExactly(
|
||||
"deposit.xml",
|
||||
"lol_2010-10-17_full_S1_R1.ryde",
|
||||
"lol_2010-10-17_full_S1_R1.sig",
|
||||
"lol.pub");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue