mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-09 00:04:55 +00:00
add padding to writes when connected over tls
This commit is contained in:
@@ -16,6 +16,7 @@ import java.security.cert.Certificate;
|
||||
|
||||
public class TcpOverTlsTransport extends TcpTransport {
|
||||
private static final Logger log = LoggerFactory.getLogger(TcpOverTlsTransport.class);
|
||||
public static final int PAD_TO_MULTIPLE_OF_BYTES = 96;
|
||||
|
||||
protected final SSLSocketFactory sslSocketFactory;
|
||||
|
||||
@@ -41,6 +42,24 @@ public class TcpOverTlsTransport extends TcpTransport {
|
||||
sslSocketFactory = sslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeRequest(String request) throws IOException {
|
||||
int currentLength = request.length();
|
||||
int targetLength;
|
||||
if(currentLength % PAD_TO_MULTIPLE_OF_BYTES == 0) {
|
||||
targetLength = currentLength;
|
||||
} else {
|
||||
targetLength = ((currentLength / PAD_TO_MULTIPLE_OF_BYTES) + 1) * PAD_TO_MULTIPLE_OF_BYTES;
|
||||
}
|
||||
|
||||
int paddingNeeded = targetLength - currentLength;
|
||||
if(paddingNeeded > 0) {
|
||||
super.writeRequest(request + " ".repeat(paddingNeeded));
|
||||
} else {
|
||||
super.writeRequest(request);
|
||||
}
|
||||
}
|
||||
|
||||
private TrustManager[] getTrustManagers(File crtFile) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
|
||||
if(crtFile == null) {
|
||||
return new TrustManager[] {
|
||||
|
||||
@@ -97,7 +97,7 @@ public class TcpTransport implements CloseableTransport, TimeoutCounter {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeRequest(String request) throws IOException {
|
||||
protected void writeRequest(String request) throws IOException {
|
||||
if(log.isTraceEnabled()) {
|
||||
log.trace("Sending to electrum server at " + server + ": " + request);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class TcpTransport implements CloseableTransport, TimeoutCounter {
|
||||
throw new IllegalStateException("Socket connection has not been established.");
|
||||
}
|
||||
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)));
|
||||
out.println(request);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user