Skip to content

Commit bda2052

Browse files
committed
add TLS SNI to ghidra client connections
1 parent c51183f commit bda2052

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteBlockStreamHandle.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import java.io.*;
1919
import java.net.Socket;
2020
import java.security.SecureRandom;
21+
import java.util.*;
2122

22-
import javax.net.SocketFactory;
23-
import javax.net.ssl.SSLSocketFactory;
23+
import javax.net.*;
24+
import javax.net.ssl.*;
2425

2526
import db.buffers.BlockStream;
2627
import db.buffers.DataBuffer;
@@ -278,7 +279,12 @@ protected Socket connect() throws IOException {
278279
}
279280

280281
SocketFactory socketFactory = SSLSocketFactory.getDefault();
281-
Socket socket = socketFactory.createSocket(streamServerIPAddress, streamServerPort);
282+
SSLSocket socket = (SSLSocket)socketFactory.createSocket(streamServerIPAddress, streamServerPort);
283+
284+
List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(streamServerIPAddress));
285+
SSLParameters params = socket.getSSLParameters();
286+
params.setServerNames(serverNames);
287+
socket.setSSLParameters(params);
282288

283289
// TODO: set socket options ?
284290

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ###
2+
* IP: GHIDRA
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ghidra.framework.client;
17+
18+
import java.io.IOException;
19+
import java.net.*;
20+
import java.util.*;
21+
22+
import javax.net.ssl.*;
23+
import javax.rmi.ssl.SslRMIClientSocketFactory;
24+
25+
/**
26+
* <code>GhidraSSLClientSocket</code> facilitates ability to impose client authentication
27+
* for SSL server sockets used with Ghidra Server RMI connection.
28+
*/
29+
public class GhidraSSLClientSocket extends SslRMIClientSocketFactory {
30+
/**
31+
* Creates an SSLSocket on a given port
32+
*
33+
* @throws IOException if an error occurs on socket creation.
34+
*/
35+
public Socket createSocket(String host, int port) throws IOException
36+
{
37+
SSLSocket sslSocket = (SSLSocket) super.createSocket(host, port);
38+
List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(host));
39+
SSLParameters params = sslSocket.getSSLParameters();
40+
params.setServerNames(serverNames);
41+
sslSocket.setSSLParameters(params);
42+
return sslSocket;
43+
}
44+
}

Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ServerConnectTask.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import javax.net.ssl.SSLHandshakeException;
2626
import javax.net.ssl.SSLSocket;
27-
import javax.rmi.ssl.SslRMIClientSocketFactory;
2827
import javax.security.auth.Subject;
2928
import javax.security.auth.callback.Callback;
3029
import javax.security.auth.callback.PasswordCallback;
@@ -163,7 +162,7 @@ public static GhidraServerHandle getGhidraServerHandle(ServerInfo server) throws
163162
}
164163
catch (IOException e) {
165164
reg = LocateRegistry.getRegistry(server.getServerName(), server.getPortNumber(),
166-
new SslRMIClientSocketFactory());
165+
new GhidraSSLClientSocket());
167166
checkServerBindNames(reg);
168167
}
169168

@@ -321,7 +320,7 @@ else if (pkiSignatureCb != null) {
321320
private static void testServerSSLConnection(ServerInfo server) throws IOException {
322321

323322
RMIServerPortFactory portFactory = new RMIServerPortFactory(server.getPortNumber());
324-
SslRMIClientSocketFactory factory = new SslRMIClientSocketFactory();
323+
GhidraSSLClientSocket factory = new GhidraSSLClientSocket();
325324
String serverName = server.getServerName();
326325
int sslRmiPort = portFactory.getRMISSLPort();
327326

0 commit comments

Comments
 (0)