Files
gerrit/java/com/google/gerrit/server/git/TransferConfig.java
David Ostrovsky fb64381f7c Revert "Revert "Allow to enable git protocol version 2 for upload pack""
Reason for revert: The original revert was done because of security
vulnerability in JGit. This vulnerability was fixed meantime.

Another argument for procrastination with Git v2 protocol support in
upcoming Gerrit release may be the fact that we do not have any
integration tests for execution of AdvertiseRefsHook hook.

However, this argument is not specific for git v2 protocol, as
mentioned in JGit 5.0 release: [1], but other Git protocol versions
were affected as well, and thus does not hold. In fact bidirectional
v0 HTTP protocol also has not executed AdvertiseRefsHook hook and
this was not discovered for 8 years and all released Gerrit versions
were affected.

Test Plan:

1. Install git version 2.18 or later
2. Activate git v2 protocol on the client side
3. Enable git v2 protocol support in gerrit, by setting this config:
   receive.enableProtocolV2 = true
3. Run $ GIT_TRACE_PACKET=1 git ls-remote
4. Confirm that git v2 protocol is used
5. Confirm that the method: DefaultRefFilter#filter is get called
6. Confirm that the call stack looks sane: [2]

This reverts commit f51a97d523.

[1] https://projects.eclipse.org/projects/technology.jgit/releases/5.0.0
[2] http://paste.openstack.org/show/742267

Change-Id: I5e2e5c7c69cc1433bc8539a8c36cb2ebd70804fc
2019-04-24 07:49:35 +00:00

82 lines
2.5 KiB
Java

// Copyright (C) 2010 The Android Open Source Project
//
// 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 com.google.gerrit.server.git;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.pack.PackConfig;
@Singleton
public class TransferConfig {
private final int timeout;
private final PackConfig packConfig;
private final long maxObjectSizeLimit;
private final String maxObjectSizeLimitFormatted;
private final boolean inheritProjectMaxObjectSizeLimit;
private final boolean enableProtocolV2;
@Inject
TransferConfig(@GerritServerConfig Config cfg) {
timeout =
(int)
ConfigUtil.getTimeUnit(
cfg,
"transfer",
null,
"timeout", //
0,
TimeUnit.SECONDS);
maxObjectSizeLimit = cfg.getLong("receive", "maxObjectSizeLimit", 0);
maxObjectSizeLimitFormatted = cfg.getString("receive", null, "maxObjectSizeLimit");
inheritProjectMaxObjectSizeLimit =
cfg.getBoolean("receive", "inheritProjectMaxObjectSizeLimit", false);
enableProtocolV2 = cfg.getBoolean("receive", "enableProtocolV2", false);
packConfig = new PackConfig();
packConfig.setDeltaCompress(false);
packConfig.setThreads(1);
packConfig.fromConfig(cfg);
}
/** @return configured timeout, in seconds. 0 if the timeout is infinite. */
public int getTimeout() {
return timeout;
}
public PackConfig getPackConfig() {
return packConfig;
}
public long getMaxObjectSizeLimit() {
return maxObjectSizeLimit;
}
public String getFormattedMaxObjectSizeLimit() {
return maxObjectSizeLimitFormatted;
}
public boolean inheritProjectMaxObjectSizeLimit() {
return inheritProjectMaxObjectSizeLimit;
}
public boolean enableProtocolV2() {
return enableProtocolV2;
}
}