mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
add padding to writes when connected over tls
This commit is contained in:
parent
f48fa7e23c
commit
2ff7a15d1e
2 changed files with 21 additions and 2 deletions
|
|
@ -16,6 +16,7 @@ import java.security.cert.Certificate;
|
||||||
|
|
||||||
public class TcpOverTlsTransport extends TcpTransport {
|
public class TcpOverTlsTransport extends TcpTransport {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TcpOverTlsTransport.class);
|
private static final Logger log = LoggerFactory.getLogger(TcpOverTlsTransport.class);
|
||||||
|
public static final int PAD_TO_MULTIPLE_OF_BYTES = 96;
|
||||||
|
|
||||||
protected final SSLSocketFactory sslSocketFactory;
|
protected final SSLSocketFactory sslSocketFactory;
|
||||||
|
|
||||||
|
|
@ -41,6 +42,24 @@ public class TcpOverTlsTransport extends TcpTransport {
|
||||||
sslSocketFactory = sslContext.getSocketFactory();
|
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 {
|
private TrustManager[] getTrustManagers(File crtFile) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
|
||||||
if(crtFile == null) {
|
if(crtFile == null) {
|
||||||
return new TrustManager[] {
|
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()) {
|
if(log.isTraceEnabled()) {
|
||||||
log.trace("Sending to electrum server at " + server + ": " + request);
|
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.");
|
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.println(request);
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue