google-nomulus/java/google/registry/keyring/api/KeyModule.java
jianglai 886aa62d46 Expose encrypted data from the keyring
This makes it possible to request the encrypted data directly in application code. It will be used to download service account credential during "nomulus login".

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222847905
2018-12-03 19:01:15 -05:00

137 lines
3.9 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.keyring.api;
import static com.google.common.base.Strings.emptyToNull;
import dagger.Module;
import dagger.Provides;
import java.lang.annotation.Documented;
import java.util.Optional;
import java.util.function.Function;
import javax.inject.Named;
import javax.inject.Qualifier;
import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
/** Dagger module for keys stored in {@link Keyring}. */
@Module
public final class KeyModule {
/** Dagger qualifier for keys from {@link Keyring}. */
@Qualifier
@Documented
public @interface Key {
String value();
}
@Provides
@Key("brdaReceiverKey")
static PGPPublicKey provideBrdaReceiverKey(Keyring keyring) {
return keyring.getBrdaReceiverKey();
}
@Provides
@Key("brdaSigningKey")
static PGPKeyPair provideBrdaSigningKey(Keyring keyring) {
return keyring.getBrdaSigningKey();
}
@Provides
@Key("icannReportingPassword")
static String provideIcannReportingPassword(Keyring keyring) {
return keyring.getIcannReportingPassword();
}
@Provides
@Key("marksdbDnlLogin")
static Optional<String> provideMarksdbDnlLogin(Keyring keyring) {
return Optional.ofNullable(emptyToNull(keyring.getMarksdbDnlLogin()));
}
@Provides
@Key("marksdbLordnPassword")
static Optional<String> provideMarksdbLordnPassword(Keyring keyring) {
return Optional.ofNullable(emptyToNull(keyring.getMarksdbLordnPassword()));
}
@Provides
@Key("marksdbSmdrlLogin")
static Optional<String> provideMarksdbSmdrlLogin(Keyring keyring) {
return Optional.ofNullable(emptyToNull(keyring.getMarksdbSmdrlLogin()));
}
@Provides
@Key("rdeStagingEncryptionKey")
static PGPPublicKey provideRdeStagingEncryptionKey(Keyring keyring) {
return keyring.getRdeStagingEncryptionKey();
}
@Provides
@Key("rdeStagingEncryptionKey")
static byte[] provideRdeStagingEncryptionKeyAsBytes(
@Key("rdeStagingEncryptionKey") PGPPublicKey rdeStagingEncryptionKey) {
return PgpHelper.convertPublicKeyToBytes(rdeStagingEncryptionKey);
}
@Provides
@Key("rdeStagingDecryptionKey")
static PGPPrivateKey provideRdeStagingDecryptionKey(Keyring keyring) {
return keyring.getRdeStagingDecryptionKey();
}
@Provides
@Key("rdeReceiverKey")
static PGPPublicKey provideRdeReceiverKey(Keyring keyring) {
return keyring.getRdeReceiverKey();
}
@Provides
@Key("rdeSigningKey")
static PGPKeyPair provideRdeSigningKey(Keyring keyring) {
return keyring.getRdeSigningKey();
}
@Provides
@Key("rdeSshClientPrivateKey")
static String provideRdeSshClientPrivateKey(Keyring keyring) {
return keyring.getRdeSshClientPrivateKey();
}
@Provides
@Key("rdeSshClientPublicKey")
static String provideRdeSshClientPublicKey(Keyring keyring) {
return keyring.getRdeSshClientPublicKey();
}
@Provides
@Key("safeBrowsingAPIKey")
static String provideSafeBrowsingAPIKey(Keyring keyring) {
return keyring.getSafeBrowsingAPIKey();
}
@Provides
@Key("jsonCredential")
static String provideJsonCredential(Keyring keyring) {
return keyring.getJsonCredential();
}
@Provides
@Named("encryptedDataRetriever")
static Function<String, String> provideEncryptedDataRetriever(Keyring keyring) {
return keyring::getEncryptedData;
}
}