Replace KeystoreKeyring with KmsKeystore comparison

Replace KeystoreKeyring with ComparatorKeyring between KeystoreKeyring and
KmsKeystore. In the opensource version, will replace DummyKeyring with
KmsKeyring directly.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152893767
This commit is contained in:
guyben 2017-04-11 19:38:14 -07:00 committed by Ben McIlwain
parent dea386d08a
commit ab515cb352
16 changed files with 94 additions and 36 deletions

View file

@ -23,6 +23,7 @@ import com.beust.jcommander.Parameters;
import com.google.common.io.ByteStreams;
import google.registry.keyring.api.KeyModule.Key;
import google.registry.rde.Ghostryde;
import google.registry.tools.Command.RemoteApiCommand;
import google.registry.tools.params.PathParameter;
import java.io.IOException;
import java.io.InputStream;
@ -32,6 +33,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import javax.inject.Inject;
import javax.inject.Provider;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
@ -39,7 +41,7 @@ import org.joda.time.DateTime;
/** Command to encrypt/decrypt {@code .ghostryde} files. */
@Parameters(separators = " =", commandDescription = "Encrypt/decrypt a ghostryde file.")
final class GhostrydeCommand implements Command {
final class GhostrydeCommand implements RemoteApiCommand {
@Parameter(
names = {"-e", "--encrypt"},
@ -71,11 +73,11 @@ final class GhostrydeCommand implements Command {
@Inject
@Key("rdeStagingEncryptionKey")
PGPPublicKey rdeStagingEncryptionKey;
Provider<PGPPublicKey> rdeStagingEncryptionKey;
@Inject
@Key("rdeStagingDecryptionKey")
PGPPrivateKey rdeStagingDecryptionKey;
Provider<PGPPrivateKey> rdeStagingDecryptionKey;
@Override
public final void run() throws Exception {
@ -93,7 +95,7 @@ final class GhostrydeCommand implements Command {
: output;
try (OutputStream out = Files.newOutputStream(outFile);
Ghostryde.Encryptor encryptor =
ghostryde.openEncryptor(out, rdeStagingEncryptionKey);
ghostryde.openEncryptor(out, rdeStagingEncryptionKey.get());
Ghostryde.Compressor kompressor = ghostryde.openCompressor(encryptor);
Ghostryde.Output ghostOutput =
ghostryde.openOutput(kompressor, input.getFileName().toString(),
@ -106,7 +108,7 @@ final class GhostrydeCommand implements Command {
private void runDecrypt() throws IOException, PGPException {
try (InputStream in = Files.newInputStream(input);
Ghostryde.Decryptor decryptor =
ghostryde.openDecryptor(in, rdeStagingDecryptionKey);
ghostryde.openDecryptor(in, rdeStagingDecryptionKey.get());
Ghostryde.Decompressor decompressor = ghostryde.openDecompressor(decryptor);
Ghostryde.Input ghostInput = ghostryde.openInput(decompressor)) {
Path outFile = Files.isDirectory(output)