Skip to content

Commit 103340c

Browse files
committed
Upgrade all agent-server communication to use HTTPS by default.
* Currently defaults to using HTTPs without peer verification * Users may optionally set -sslVerificationMode to improve security from NONE to NO_VERIFY_HOST to FULL * Upgrade from commons httpclient 3.0.1 to httpcomponents 4.5.2
1 parent d082665 commit 103340c

File tree

92 files changed

+2117
-2104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2117
-2104
lines changed

agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/AgentBootstrapper.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.agent.bootstrapper;
1818

1919
import com.thoughtworks.cruise.agent.common.launcher.AgentLauncher;
20+
import com.thoughtworks.go.agent.common.AgentBootstrapperArgs;
21+
import com.thoughtworks.go.agent.common.AgentCLI;
2022
import com.thoughtworks.go.agent.common.util.Downloader;
2123
import com.thoughtworks.go.util.SystemUtil;
2224
import com.thoughtworks.go.util.validators.FileValidator;
@@ -26,7 +28,7 @@
2628
import org.apache.log4j.NDC;
2729

2830
public class AgentBootstrapper {
29-
private static final int DEFAULT_PORT = 8153;
31+
3032
private static final int DEFAULT_WAIT_TIME_BEFORE_RELAUNCH_IN_MS = 10000;
3133
public static final String WAIT_TIME_BEFORE_RELAUNCH_IN_MS = "agent.bootstrapper.wait.time.before.relaunch.in.ms";
3234

@@ -46,24 +48,20 @@ public AgentBootstrapper(AgentLauncherCreator launcherCreator) {
4648
this.launcherCreator = launcherCreator;
4749
}
4850

49-
public static void main(String[] args) {
51+
public static void main(String[] argv) {
5052
BootstrapperLoggingHelper.initLog4j();
51-
if (args.length < 1 || args.length > 3) {
52-
System.out.println("Usage: agent-bootstrapper.jar <hostname> [port]");
53-
System.exit(1);
54-
}
55-
int port = args.length >= 2 ? Integer.parseInt(args[1]) : DEFAULT_PORT;
56-
new AgentBootstrapper().go(true, args[0], port);
53+
AgentBootstrapperArgs args = new AgentCLI().parse(argv);
54+
new AgentBootstrapper().go(true, args);
5755
}
5856

59-
public void go(boolean shouldLoop, String hostname, int port) {
57+
public void go(boolean shouldLoop, AgentBootstrapperArgs bootstrapperArgs) {
6058
loop = shouldLoop;
6159
launcherThread = Thread.currentThread();
6260

6361
validate();
6462

6563
int returnValue = 0;
66-
DefaultAgentLaunchDescriptorImpl descriptor = new DefaultAgentLaunchDescriptorImpl(hostname, port, this);
64+
DefaultAgentLaunchDescriptorImpl descriptor = new DefaultAgentLaunchDescriptorImpl(bootstrapperArgs, this);
6765

6866
do {
6967
ClassLoader tccl = launcherThread.getContextClassLoader();
@@ -181,5 +179,4 @@ AgentLauncherCreator getLauncherCreator() {
181179
}
182180
return launcherCreator;
183181
}
184-
185182
}

agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/DefaultAgentLaunchDescriptorImpl.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.agent.bootstrapper;
1818

19-
import java.util.Map;
20-
import java.util.concurrent.ConcurrentHashMap;
21-
2219
import com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptor;
20+
import com.thoughtworks.go.agent.common.AgentBootstrapperArgs;
2321

24-
import static com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptorKeys.HOSTNAME;
25-
import static com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptorKeys.PORT;
22+
import java.util.Map;
23+
import java.util.concurrent.ConcurrentHashMap;
2624

2725
class DefaultAgentLaunchDescriptorImpl implements AgentLaunchDescriptor {
2826

2927
private final AgentBootstrapper bootstrapper;
3028
private final Map context = new ConcurrentHashMap();
3129

32-
public DefaultAgentLaunchDescriptorImpl(String hostname, int port, AgentBootstrapper self) {
33-
this.bootstrapper = self;
34-
buildContext(hostname, port);
30+
public DefaultAgentLaunchDescriptorImpl(AgentBootstrapperArgs bootstrapperArgs, AgentBootstrapper agentBootstrapper) {
31+
this.bootstrapper = agentBootstrapper;
32+
buildContext(bootstrapperArgs);
3533
}
3634

37-
private void buildContext(String hostname, int port) {
38-
context.putAll(System.getenv());
39-
context.putAll(System.getProperties());
40-
context.put(HOSTNAME, hostname);
41-
context.put(PORT, port);
35+
private void buildContext(AgentBootstrapperArgs bootstrapperArgs) {
36+
context.putAll(bootstrapperArgs.toProperties());
4237
}
4338

44-
@Override public Map context() {
39+
@Override
40+
public Map context() {
4541
return context;
4642
}
4743

agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/DefaultAgentLauncherCreatorImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.agent.bootstrapper;
1818

1919
import com.thoughtworks.cruise.agent.common.launcher.AgentLauncher;
2020
import com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptor;
21-
import com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptorKeys;
2221
import com.thoughtworks.go.agent.common.util.Downloader;
2322
import com.thoughtworks.go.agent.common.util.JarUtil;
2423
import com.thoughtworks.go.util.SystemUtil;
@@ -50,7 +49,7 @@ public class DefaultAgentLauncherCreatorImpl implements AgentLauncherCreator {
5049
public AgentLauncher createLauncher() {
5150
inUseLauncher = createTempLauncherJar();
5251
return (AgentLauncher) JarUtil.objectFromJar(inUseLauncher.getName(),
53-
GO_AGENT_LAUNCHER_CLASS, GO_AGENT_LAUNCHER_LIB_DIR, AgentLauncher.class, AgentLaunchDescriptor.class, AgentLaunchDescriptorKeys.class);
52+
GO_AGENT_LAUNCHER_CLASS, GO_AGENT_LAUNCHER_LIB_DIR, AgentLauncher.class, AgentLaunchDescriptor.class);
5453
}
5554

5655
private File createTempLauncherJar() {
Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.agent.bootstrapper.osx;
1818

19-
import java.io.File;
20-
import java.io.FileInputStream;
21-
import java.io.FileNotFoundException;
22-
import java.io.FileOutputStream;
23-
import java.io.IOException;
24-
import java.util.Properties;
25-
import javax.swing.JFrame;
26-
2719
import com.apple.eawt.Application;
20+
import com.thoughtworks.go.agent.common.AgentBootstrapperArgs;
2821
import com.thoughtworks.go.agent.bootstrapper.BootstrapperLoggingHelper;
2922
import org.apache.commons.logging.Log;
3023
import org.apache.commons.logging.LogFactory;
3124

32-
import static java.lang.Integer.parseInt;
33-
import static org.apache.commons.io.IOUtils.closeQuietly;
25+
import javax.swing.*;
26+
import java.io.File;
27+
import java.io.FileInputStream;
28+
import java.io.FileOutputStream;
29+
import java.io.IOException;
30+
import java.net.MalformedURLException;
31+
import java.net.URL;
32+
import java.util.Properties;
3433

3534
public class AgentMacWindow extends JFrame {
36-
private static final File PREFS_FILE = new File(System.getProperty("user.home"),
37-
"/Library/Preferences/com.thoughtworks.studios.cruise.agent.properties");
35+
private static final File PREFS_FILE = new File(System.getProperty("user.home"), "/Library/Preferences/com.thoughtworks.go.agent.properties");
3836
private static final Log LOG = LogFactory.getLog(AgentMacWindow.class);
3937

40-
private final Properties properties;
38+
private AgentBootstrapperArgs bootstrapperArgs;
4139
private final boolean firstRun;
4240
private final MacBootstrapperApplicationAdapter macBootstrapperAppAdapter;
4341
private MacBootstrapperThread bootstrapLauncher;
@@ -54,20 +52,30 @@ private void go() {
5452
launchBootStrapper();
5553
}
5654

57-
private AgentMacWindow() throws IOException {
55+
private AgentMacWindow() {
5856
firstRun = !PREFS_FILE.exists();
5957

6058
if (firstRun) {
6159
saveDefaultPrefs();
6260
}
6361

64-
properties = loadPrefs();
62+
bootstrapperArgs = loadPrefs();
6563
macBootstrapperAppAdapter = initializeApplicationAdapter();
6664
}
6765

68-
private static void saveDefaultPrefs() {
66+
private void saveDefaultPrefs() {
6967
LOG.info("Initializing preferences in " + PREFS_FILE);
70-
savePrefs(defaultProperties());
68+
savePrefs(defaultArgs());
69+
}
70+
71+
private void savePrefs(AgentBootstrapperArgs args) {
72+
try {
73+
try (FileOutputStream fos = new FileOutputStream(PREFS_FILE)) {
74+
args.toProperties().store(fos, null);
75+
}
76+
} catch (IOException e) {
77+
LOG.error("IO error on " + PREFS_FILE, e);
78+
}
7179
}
7280

7381
private MacBootstrapperApplicationAdapter initializeApplicationAdapter() {
@@ -86,47 +94,29 @@ private MacBootstrapperApplicationAdapter initializeApplicationAdapter() {
8694
return applicationAdapter;
8795
}
8896

89-
private static Properties defaultProperties() {
90-
Properties props = new Properties();
91-
props.setProperty("server", "127.0.0.1");
92-
props.setProperty("port", "8153");
93-
return props;
97+
private AgentBootstrapperArgs defaultArgs() {
98+
try {
99+
return new AgentBootstrapperArgs(new URL("https://127.0.0.1:8154/go"), null, AgentBootstrapperArgs.SslMode.NONE);
100+
} catch (MalformedURLException e) {
101+
throw new RuntimeException(e);
102+
}
94103
}
95104

96-
private static Properties loadPrefs() throws IOException {
97-
FileInputStream stream = null;
98-
try {
99-
stream = new FileInputStream(PREFS_FILE);
100-
Properties myProps = defaultProperties();
105+
private AgentBootstrapperArgs loadPrefs() {
106+
try (FileInputStream stream = new FileInputStream(PREFS_FILE)) {
107+
Properties myProps = new Properties();
101108
myProps.load(stream);
102109
LOG.info("Loaded preferences from " + PREFS_FILE);
103-
return myProps;
110+
return AgentBootstrapperArgs.fromProperties(myProps);
104111
} catch (Exception e) {
105-
LOG.error("File not found for " + PREFS_FILE, e);
106-
} finally {
107-
closeQuietly(stream);
108-
}
109-
110-
return new Properties();
111-
}
112-
113-
private static void savePrefs(Properties prefs) {
114-
FileOutputStream stream = null;
115-
try {
116-
stream = new FileOutputStream(PREFS_FILE, false);
117-
prefs.store(stream, null);
118-
} catch (FileNotFoundException e) {
119-
LOG.error("File not found for " + PREFS_FILE, e);
120-
} catch (IOException e) {
121-
LOG.error("IO exception on " + PREFS_FILE, e);
122-
} finally {
123-
closeQuietly(stream);
112+
LOG.error("Error for " + PREFS_FILE, e);
124113
}
114+
return defaultArgs();
125115
}
126116

127117
void launchBootStrapper() {
128118
if (bootstrapLauncher == null) {
129-
bootstrapLauncher = new MacBootstrapperThread(getHost(), getPort());
119+
bootstrapLauncher = new MacBootstrapperThread(bootstrapperArgs);
130120
bootstrapLauncher.start();
131121
}
132122
}
@@ -144,13 +134,13 @@ void stopBootStrapper() {
144134
}
145135
}
146136

147-
public String getHost() {
148-
return properties.getProperty("server");
137+
public AgentBootstrapperArgs getBootstrapperArgs() {
138+
return bootstrapperArgs;
149139
}
150140

151-
public void setHost(String newHost) {
152-
properties.setProperty("server", newHost);
153-
savePrefs(properties);
141+
public void setBootstrapperArgs(AgentBootstrapperArgs bootstrapperArgs) {
142+
this.bootstrapperArgs = bootstrapperArgs;
143+
savePrefs(this.bootstrapperArgs);
154144
restartBootstrapper();
155145
}
156146

@@ -159,8 +149,4 @@ private void restartBootstrapper() {
159149
launchBootStrapper();
160150
}
161151

162-
private int getPort() {
163-
return parseInt(properties.getProperty("port"));
164-
}
165-
166152
}

agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacBootstrapperApplicationAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.agent.bootstrapper.osx;
1818

@@ -47,7 +47,6 @@ public void handlePreferences(ApplicationEvent e) {
4747
}
4848
LOG.info("Got Preferences event");
4949

50-
prefPane.setOriginalHost(agentMacWindow.getHost());
5150
prefPane.ask();
5251

5352
if (e != null) {

0 commit comments

Comments
 (0)