Skip to content

Commit 37968e1

Browse files
committed
MIRTH-3604: ConnectServiceUtil now uses the protocols / cipher suites the same way ServerConnection does.
1 parent e9ee2a4 commit 37968e1

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

client/src/com/mirth/connect/client/ui/Frame.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ public void registerUser(final User user) {
16291629

16301630
public Void doInBackground() {
16311631
try {
1632-
ConnectServiceUtil.registerUser(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, user);
1632+
ConnectServiceUtil.registerUser(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, user, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
16331633
} catch (ClientException e) {
16341634
// ignore errors connecting to update/stats server
16351635
}
@@ -1651,7 +1651,7 @@ public void sendUsageStatistics() {
16511651
updateSettings = mirthClient.getUpdateSettings();
16521652
} catch (Exception e) {
16531653
}
1654-
1654+
16551655
if (updateSettings != null && updateSettings.getStatsEnabled()) {
16561656
final String workingId = startWorking("Sending usage statistics...");
16571657

@@ -1661,7 +1661,7 @@ public Void doInBackground() {
16611661
try {
16621662
String usageData = mirthClient.getUsageData();
16631663
if (usageData != null) {
1664-
boolean isSent = ConnectServiceUtil.sendStatistics(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, false, usageData);
1664+
boolean isSent = ConnectServiceUtil.sendStatistics(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, false, usageData, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
16651665
if (isSent) {
16661666
UpdateSettings settings = new UpdateSettings();
16671667
settings.setLastStatsTime(System.currentTimeMillis());

client/src/com/mirth/connect/client/ui/LoginPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public Void doInBackground() {
465465
archivedNotifications = ObjectXMLSerializer.getInstance().deserialize(archivedNotificationString, Set.class);
466466
}
467467
// Update the Other Tasks pane with the unarchived notification count
468-
int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), archivedNotifications);
468+
int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), archivedNotifications, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
469469
PlatformUI.MIRTH_FRAME.updateNotificationTaskName(unarchivedNotifications);
470470

471471
// Display notification dialog if enabled and if there are new notifications

client/src/com/mirth/connect/client/ui/NotificationDialog.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private void loadNotifications() {
122122

123123
public Void doInBackground() {
124124
try {
125-
notifications = ConnectServiceUtil.getNotifications(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions());
125+
notifications = ConnectServiceUtil.getNotifications(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
126126
} catch (Exception e) {
127127
PlatformUI.MIRTH_FRAME.alertError(PlatformUI.MIRTH_FRAME, "Failed to retrieve notifications. Please try again later.");
128128
}
@@ -148,7 +148,7 @@ public void done() {
148148

149149
worker.execute();
150150
}
151-
151+
152152
@Override
153153
public void onCloseAction() {
154154
doSave();
@@ -395,14 +395,14 @@ private class NotificationListCellRenderer extends DefaultListCellRenderer {
395395
private JPanel panel;
396396
private JLabel nameLabel;
397397
private JLabel dateLabel;
398-
398+
399399
public NotificationListCellRenderer() {
400400
nameLabel = new JLabel();
401-
401+
402402
dateLabel = new JLabel();
403403
dateLabel.setFont(list.getFont().deriveFont(10f));
404404
dateLabel.setForeground(Color.GRAY);
405-
405+
406406
panel = new JPanel();
407407
panel.setLayout(new MigLayout("insets 2, wrap"));
408408
panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.HIGHLIGHTER_COLOR));
@@ -432,7 +432,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
432432
return panel;
433433
}
434434
}
435-
435+
436436
private class NotificationModel extends AbstractListModel {
437437
private List<Notification> notifications = new ArrayList<Notification>();
438438

@@ -471,7 +471,6 @@ public void setData(List<Notification> notifications) {
471471
}
472472
}
473473

474-
475474
private Frame parent;
476475
private JPanel notificationPanel;
477476

server/src/com/mirth/connect/client/core/ConnectServiceUtil.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@
2828
import org.apache.http.client.methods.HttpPost;
2929
import org.apache.http.client.protocol.HttpClientContext;
3030
import org.apache.http.client.utils.HttpClientUtils;
31+
import org.apache.http.config.RegistryBuilder;
32+
import org.apache.http.config.SocketConfig;
33+
import org.apache.http.conn.socket.ConnectionSocketFactory;
34+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
35+
import org.apache.http.conn.ssl.SSLContexts;
3136
import org.apache.http.entity.ContentType;
3237
import org.apache.http.impl.client.CloseableHttpClient;
3338
import org.apache.http.impl.client.HttpClients;
39+
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
3440
import org.apache.http.message.BasicNameValuePair;
3541

3642
import com.fasterxml.jackson.core.type.TypeReference;
@@ -39,6 +45,7 @@
3945
import com.mirth.connect.model.User;
4046
import com.mirth.connect.model.converters.ObjectXMLSerializer;
4147
import com.mirth.connect.model.notification.Notification;
48+
import com.mirth.connect.util.MirthSSLUtil;
4249

4350
public class ConnectServiceUtil {
4451
private final static String URL_CONNECT_SERVER = "https://connect.mirthcorp.com";
@@ -50,7 +57,7 @@ public class ConnectServiceUtil {
5057
private final static int TIMEOUT = 10000;
5158
public final static Integer MILLIS_PER_DAY = 86400000;
5259

53-
public static void registerUser(String serverId, String mirthVersion, User user) throws ClientException {
60+
public static void registerUser(String serverId, String mirthVersion, User user, String[] protocols, String[] cipherSuites) throws ClientException {
5461
CloseableHttpClient httpClient = null;
5562
CloseableHttpResponse httpResponse = null;
5663
NameValuePair[] params = { new BasicNameValuePair("serverId", serverId),
@@ -65,7 +72,7 @@ public static void registerUser(String serverId, String mirthVersion, User user)
6572
try {
6673
HttpClientContext postContext = HttpClientContext.create();
6774
postContext.setRequestConfig(requestConfig);
68-
httpClient = HttpClients.createDefault();
75+
httpClient = getClient(protocols, cipherSuites);
6976
httpResponse = httpClient.execute(post, postContext);
7077
StatusLine statusLine = httpResponse.getStatusLine();
7178
int statusCode = statusLine.getStatusCode();
@@ -80,7 +87,7 @@ public static void registerUser(String serverId, String mirthVersion, User user)
8087
}
8188
}
8289

83-
public static List<Notification> getNotifications(String serverId, String mirthVersion, Map<String, String> extensionVersions) throws Exception {
90+
public static List<Notification> getNotifications(String serverId, String mirthVersion, Map<String, String> extensionVersions, String[] protocols, String[] cipherSuites) throws Exception {
8491
CloseableHttpClient client = null;
8592
HttpPost post = new HttpPost();
8693
CloseableHttpResponse response = null;
@@ -101,7 +108,7 @@ public static List<Notification> getNotifications(String serverId, String mirthV
101108

102109
HttpClientContext postContext = HttpClientContext.create();
103110
postContext.setRequestConfig(requestConfig);
104-
client = HttpClients.createDefault();
111+
client = getClient(protocols, cipherSuites);
105112
response = client.execute(post, postContext);
106113
StatusLine statusLine = response.getStatusLine();
107114
int statusCode = statusLine.getStatusCode();
@@ -138,7 +145,7 @@ public static List<Notification> getNotifications(String serverId, String mirthV
138145
return allNotifications;
139146
}
140147

141-
public static int getNotificationCount(String serverId, String mirthVersion, Map<String, String> extensionVersions, Set<Integer> archivedNotifications) {
148+
public static int getNotificationCount(String serverId, String mirthVersion, Map<String, String> extensionVersions, Set<Integer> archivedNotifications, String[] protocols, String[] cipherSuites) {
142149
CloseableHttpClient client = null;
143150
HttpPost post = new HttpPost();
144151
CloseableHttpResponse response = null;
@@ -159,7 +166,7 @@ public static int getNotificationCount(String serverId, String mirthVersion, Map
159166

160167
HttpClientContext postContext = HttpClientContext.create();
161168
postContext.setRequestConfig(requestConfig);
162-
client = HttpClients.createDefault();
169+
client = getClient(protocols, cipherSuites);
163170
response = client.execute(post, postContext);
164171
StatusLine statusLine = response.getStatusLine();
165172
int statusCode = statusLine.getStatusCode();
@@ -188,7 +195,7 @@ public static int getNotificationCount(String serverId, String mirthVersion, Map
188195
return notificationCount;
189196
}
190197

191-
public static boolean sendStatistics(String serverId, String mirthVersion, boolean server, String data) {
198+
public static boolean sendStatistics(String serverId, String mirthVersion, boolean server, String data, String[] protocols, String[] cipherSuites) {
192199
if (data == null) {
193200
return false;
194201
}
@@ -210,7 +217,7 @@ public static boolean sendStatistics(String serverId, String mirthVersion, boole
210217
try {
211218
HttpClientContext postContext = HttpClientContext.create();
212219
postContext.setRequestConfig(requestConfig);
213-
client = HttpClients.createDefault();
220+
client = getClient(protocols, cipherSuites);
214221
response = client.execute(post, postContext);
215222
StatusLine statusLine = response.getStatusLine();
216223
int statusCode = statusLine.getStatusCode();
@@ -224,4 +231,16 @@ public static boolean sendStatistics(String serverId, String mirthVersion, boole
224231
}
225232
return isSent;
226233
}
234+
235+
private static CloseableHttpClient getClient(String[] protocols, String[] cipherSuites) {
236+
RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory> create();
237+
String[] enabledProtocols = MirthSSLUtil.getEnabledHttpsProtocols(protocols);
238+
String[] enabledCipherSuites = MirthSSLUtil.getEnabledHttpsCipherSuites(cipherSuites);
239+
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(SSLContexts.createSystemDefault(), enabledProtocols, enabledCipherSuites, SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER);
240+
socketFactoryRegistry.register("https", sslConnectionSocketFactory);
241+
242+
BasicHttpClientConnectionManager httpClientConnectionManager = new BasicHttpClientConnectionManager(socketFactoryRegistry.build());
243+
httpClientConnectionManager.setSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT).build());
244+
return HttpClients.custom().setConnectionManager(httpClientConnectionManager).build();
245+
}
227246
}

server/src/com/mirth/connect/server/Mirth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ private void initializeLogging() {
737737
private class UsageSenderTask extends TimerTask {
738738
@Override
739739
public void run() {
740-
boolean isSent = ConnectServiceUtil.sendStatistics(configurationController.getServerId(), configurationController.getServerVersion(), true, usageController.createUsageStats());
740+
boolean isSent = ConnectServiceUtil.sendStatistics(configurationController.getServerId(), configurationController.getServerVersion(), true, usageController.createUsageStats(), configurationController.getHttpsClientProtocols(), configurationController.getHttpsCipherSuites());
741741
if (isSent) {
742742
UpdateSettings settings = new UpdateSettings();
743743
settings.setLastStatsTime(System.currentTimeMillis());

0 commit comments

Comments
 (0)