mirror of
https://github.com/google/nomulus.git
synced 2025-05-01 20:47:52 +02:00
This change required several things: - Separating out the interfaces that merely do HTTP calls to the backend from those that require the remote API (only load the remote API for the latter). Only the tools service provides the remote api endpoint. - Removing the XSRF token as an authentication mechanism (with OAUTH, we no longer need this, and trying to provide it requires initialization of the datastore code which requires the remote API) I can't think of a compelling unit test for this beyond what already exists. Tested: Verified that: - nomulus tool commands (e.g. "list_tlds") work against the tools service as they currently do - The "curl" command hits endpoints on "tools" by default. - We can use --server to specify endpoints on the default service. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211510454
119 lines
4.4 KiB
Java
119 lines
4.4 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.tools;
|
|
|
|
import static google.registry.keyring.api.KeySerializer.deserializeKeyPair;
|
|
import static google.registry.keyring.api.KeySerializer.deserializePublicKey;
|
|
import static google.registry.keyring.api.KeySerializer.deserializeString;
|
|
|
|
import com.beust.jcommander.Parameter;
|
|
import com.beust.jcommander.Parameters;
|
|
import google.registry.keyring.kms.KmsUpdater;
|
|
import google.registry.tools.params.KeyringKeyName;
|
|
import google.registry.tools.params.PathParameter;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import javax.inject.Inject;
|
|
|
|
/** Command to set and update {@code KmsKeyring} values. */
|
|
@Parameters(
|
|
separators = " =",
|
|
commandDescription = "Update values of secrets in KmsKeyring."
|
|
)
|
|
final class UpdateKmsKeyringCommand implements RemoteApiCommand {
|
|
|
|
@Inject KmsUpdater kmsUpdater;
|
|
|
|
@Inject
|
|
UpdateKmsKeyringCommand() {}
|
|
|
|
@Parameter(names = "--keyname", description = "The secret to update", required = true)
|
|
private KeyringKeyName keyringKeyName;
|
|
|
|
@Parameter(
|
|
names = {"--input"},
|
|
description =
|
|
"Name of input file for key data.",
|
|
validateWith = PathParameter.InputFile.class
|
|
)
|
|
private Path inputPath = null;
|
|
|
|
@Override
|
|
public void run() throws Exception {
|
|
byte[] input = Files.readAllBytes(inputPath);
|
|
|
|
switch (keyringKeyName) {
|
|
case BRDA_RECEIVER_PUBLIC_KEY:
|
|
kmsUpdater.setBrdaReceiverPublicKey(deserializePublicKey(input));
|
|
break;
|
|
case BRDA_SIGNING_KEY_PAIR:
|
|
kmsUpdater.setBrdaSigningKey(deserializeKeyPair(input));
|
|
break;
|
|
case BRDA_SIGNING_PUBLIC_KEY:
|
|
throw new IllegalArgumentException(
|
|
"Can't update BRDA_SIGNING_PUBLIC_KEY directly."
|
|
+ " Must update public and private keys together using BRDA_SIGNING_KEY_PAIR.");
|
|
case ICANN_REPORTING_PASSWORD:
|
|
kmsUpdater.setIcannReportingPassword(deserializeString(input));
|
|
break;
|
|
case JSON_CREDENTIAL:
|
|
kmsUpdater.setJsonCredential(deserializeString(input));
|
|
break;
|
|
case MARKSDB_DNL_LOGIN:
|
|
kmsUpdater.setMarksdbDnlLogin(deserializeString(input));
|
|
break;
|
|
case MARKSDB_LORDN_PASSWORD:
|
|
kmsUpdater.setMarksdbLordnPassword(deserializeString(input));
|
|
break;
|
|
case MARKSDB_SMDRL_LOGIN:
|
|
kmsUpdater.setMarksdbSmdrlLogin(deserializeString(input));
|
|
break;
|
|
case RDE_RECEIVER_PUBLIC_KEY:
|
|
kmsUpdater.setRdeReceiverPublicKey(deserializePublicKey(input));
|
|
break;
|
|
case RDE_SIGNING_KEY_PAIR:
|
|
kmsUpdater.setRdeSigningKey(deserializeKeyPair(input));
|
|
break;
|
|
case RDE_SIGNING_PUBLIC_KEY:
|
|
throw new IllegalArgumentException(
|
|
"Can't update RDE_SIGNING_PUBLIC_KEY directly."
|
|
+ " Must update public and private keys together using RDE_SIGNING_KEY_PAIR.");
|
|
// Note that RDE_SSH_CLIENT public / private keys are slightly different than other key pairs,
|
|
// since they are just regular strings rather than {@link PGPKeyPair}s (because OpenSSH
|
|
// doesn't use PGP-style keys)
|
|
//
|
|
// Hence we can and need to update the private and public keys individually.
|
|
case RDE_SSH_CLIENT_PRIVATE_KEY:
|
|
kmsUpdater.setRdeSshClientPrivateKey(deserializeString(input));
|
|
break;
|
|
case RDE_SSH_CLIENT_PUBLIC_KEY:
|
|
kmsUpdater.setRdeSshClientPublicKey(deserializeString(input));
|
|
break;
|
|
case RDE_STAGING_KEY_PAIR:
|
|
kmsUpdater.setRdeStagingKey(deserializeKeyPair(input));
|
|
break;
|
|
case SAFE_BROWSING_API_KEY:
|
|
kmsUpdater.setSafeBrowsingAPIKey(deserializeString(input));
|
|
break;
|
|
case RDE_STAGING_PUBLIC_KEY:
|
|
throw new IllegalArgumentException(
|
|
"Can't update RDE_STAGING_PUBLIC_KEY directly."
|
|
+ " Must update public and private keys together using RDE_STAGING_KEY_PAIR.");
|
|
}
|
|
|
|
kmsUpdater.update();
|
|
}
|
|
}
|
|
|