Line data Source code
1 : // Copyright (C) 2015 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.gpg; 16 : 17 : import com.google.common.flogger.FluentLogger; 18 : import com.google.gerrit.extensions.config.FactoryModule; 19 : import com.google.gerrit.gpg.api.GpgApiModule; 20 : import com.google.gerrit.server.EnableSignedPush; 21 : import org.eclipse.jgit.lib.Config; 22 : 23 : public class GpgModule extends FactoryModule { 24 152 : private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 25 : 26 : private final Config cfg; 27 : 28 152 : public GpgModule(Config cfg) { 29 152 : this.cfg = cfg; 30 152 : } 31 : 32 : @Override 33 : protected void configure() { 34 152 : boolean configEnableSignedPush = cfg.getBoolean("receive", null, "enableSignedPush", false); 35 152 : boolean configEditGpgKeys = cfg.getBoolean("gerrit", null, "editGpgKeys", true); 36 152 : boolean havePgp = BouncyCastleUtil.havePGP(); 37 152 : boolean enableSignedPush = configEnableSignedPush && havePgp; 38 152 : bindConstant().annotatedWith(EnableSignedPush.class).to(enableSignedPush); 39 : 40 152 : if (configEnableSignedPush && !havePgp) { 41 0 : logger.atInfo().log("Bouncy Castle PGP not installed; signed push verification is disabled"); 42 : } 43 152 : if (enableSignedPush) { 44 7 : install(new SignedPushModule()); 45 : } 46 152 : install(new GpgApiModule(enableSignedPush && configEditGpgKeys)); 47 152 : } 48 : }