Compare commits

...

5 Commits

Author SHA1 Message Date
Craig Raw
08fd60cd52 update bouncycastle, guava, logback and slf4j dependencies 2024-02-14 15:47:09 +02:00
Craig Raw
afaf989e1f reduce http error logging 2023-11-17 09:40:27 +02:00
Craig Raw
45a2f0e2a6 add poststring to httpclient, remove user agent header 2023-11-10 13:28:33 +02:00
Craig Raw
6ef3ac37d4 v0.2.37 2023-11-08 09:04:58 +02:00
Craig Raw
e39809f1c5 normalize bip39 passphrase characters to nfkd encoding 2023-09-11 12:07:21 -05:00
7 changed files with 62 additions and 14 deletions

View File

@ -4,7 +4,7 @@ plugins {
}
group 'com.sparrowwallet.nightjar'
version '0.2.36'
version '0.2.40'
repositories {
mavenCentral()
@ -17,11 +17,11 @@ file("publish.properties").withInputStream {
}
dependencies {
implementation ('org.bouncycastle:bcprov-jdk15on:1.64') {
implementation ('org.bouncycastle:bcprov-jdk18on:1.77') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
implementation ('com.google.protobuf:protobuf-java:2.6.1')
implementation ('com.google.guava:guava:31.1-jre')
implementation ('com.google.guava:guava:33.0.0-jre')
implementation ('com.lambdaworks:scrypt:1.4.0')
implementation ('org.springframework:spring-websocket:5.2.2.RELEASE')
implementation ('org.springframework:spring-messaging:5.2.2.RELEASE')
@ -34,10 +34,10 @@ dependencies {
implementation ('com.fasterxml.jackson.core:jackson-databind:2.13.2')
implementation ('org.json:json:20180130')
implementation ('io.reactivex.rxjava2:rxjava:2.2.15')
implementation ('org.slf4j:slf4j-api:1.7.30')
implementation ('org.slf4j:slf4j-api:2.0.12')
implementation ('com.auth0:java-jwt:3.8.1')
implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20')
implementation ('ch.qos.logback:logback-classic:1.2.8') {
implementation ('ch.qos.logback:logback-classic:1.4.14') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
exclude group: 'org.slf4j'
}

View File

@ -9,4 +9,5 @@ public interface IBackendClient {
<T> T getJson(String url, Class<T> responseType, Map<String,String> headers, boolean async) throws HttpException;
<T> T postUrlEncoded(String url, Class<T> responseType, Map<String,String> headers, Map<String, String> body) throws HttpException;
String postString(String url, Map<String,String> headers, String contentType, String content) throws HttpException;
}

View File

@ -77,7 +77,7 @@ public class JavaHttpClient extends JacksonHttpClient {
protected String requestJsonGet(String urlStr, Map<String, String> headers, boolean async) throws Exception {
log.debug("GET " + urlStr);
Request req = computeHttpRequest(urlStr, HttpMethod.GET, headers);
return requestJson(req);
return makeRequest(req);
}
@Override
@ -85,7 +85,7 @@ public class JavaHttpClient extends JacksonHttpClient {
log.debug("POST " + urlStr);
Request req = computeHttpRequest(urlStr, HttpMethod.POST, headers);
req.content(new StringContentProvider(MediaType.APPLICATION_JSON_VALUE, jsonBody, StandardCharsets.UTF_8));
return requestJson(req);
return makeRequest(req);
}
@Override
@ -93,7 +93,30 @@ public class JavaHttpClient extends JacksonHttpClient {
log.debug("POST " + urlStr);
Request req = computeHttpRequest(urlStr, HttpMethod.POST, headers);
req.content(new FormContentProvider(computeBodyFields(body)));
return requestJson(req);
return makeRequest(req);
}
@Override
public String postString(String urlStr, Map<String, String> headers, String contentType, String content) throws HttpException {
try {
return requestPostString(urlStr, headers, contentType, content);
} catch (Exception e) {
onRequestError(e);
if (log.isDebugEnabled()) {
log.error("postString failed: " + urlStr + ":" + e.getMessage());
}
if (!(e instanceof HttpException)) {
e = new HttpException(e, null);
}
throw (HttpException) e;
}
}
protected String requestPostString(String urlStr, Map<String, String> headers, String contentType, String content) throws Exception {
log.debug("POST " + urlStr);
Request req = computeHttpRequest(urlStr, HttpMethod.POST, headers);
req.content(new StringContentProvider(content), contentType);
return makeRequest(req);
}
private Fields computeBodyFields(Map<String, String> body) {
@ -104,12 +127,14 @@ public class JavaHttpClient extends JacksonHttpClient {
return fields;
}
private String requestJson(Request req) throws Exception {
private String makeRequest(Request req) throws Exception {
ContentResponse response = req.send();
if(response.getStatus() != HttpStatus.OK_200 && response.getStatus() != HttpStatus.CREATED_201 && response.getStatus() != HttpStatus.ACCEPTED_202) {
String responseBody = response.getContentAsString();
log.error("Http query failed: status=" + response.getStatus() + ", responseBody=" + responseBody);
throw new HttpException(new Exception("Http query failed: status=" + response.getStatus()), responseBody);
if(log.isDebugEnabled()) {
log.error("Http query failed: status=" + response.getStatus() + ", responseBody=" + responseBody);
}
throw new JavaHttpException(new Exception("Http query failed: status=" + response.getStatus()), responseBody, response.getStatus());
}
return response.getContentAsString();
}

View File

@ -91,7 +91,7 @@ public class JavaHttpClientService implements IHttpClientService {
jettyHttpClient.setScheduler(new ScheduledExecutorScheduler(name + "-scheduler", true));
// prevent user-agent tracking
// jettyHttpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, userAgent));
jettyHttpClient.setUserAgentField(null);
// proxy
if(proxy != null) {

View File

@ -0,0 +1,21 @@
package com.sparrowwallet.nightjar.http;
import com.samourai.wallet.api.backend.beans.HttpException;
public class JavaHttpException extends HttpException {
private final int statusCode;
public JavaHttpException(Exception cause, String responseBody, int statusCode) {
super(cause, responseBody);
this.statusCode = statusCode;
}
public JavaHttpException(String message, String responseBody, int statusCode) {
super(message, responseBody);
this.statusCode = statusCode;
}
public int getStatusCode() {
return statusCode;
}
}

View File

@ -785,7 +785,7 @@ public class ECKey implements EncryptableItem {
ASN1TaggedObject pubkey = (ASN1TaggedObject) seq.getObjectAt(3);
checkArgument(pubkey.getTagNo() == 1, "Input has 'publicKey' with bad tag number");
byte[] pubbits = ((DERBitString)pubkey.getObject()).getBytes();
byte[] pubbits = ((DERBitString)pubkey.getBaseObject()).getBytes();
checkArgument(pubbits.length == 33 || pubbits.length == 65, "Input has 'publicKey' with invalid length");
int encoding = pubbits[0] & 0xFF;
// Only allow compressed(2,3) and uncompressed(4), not infinity(0) or hybrid(6,7)

View File

@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -144,7 +145,7 @@ public class MnemonicCode {
// derived key is 512 bits (= 64 bytes).
//
String pass = Utils.join(words);
String salt = "mnemonic" + passphrase;
String salt = "mnemonic" + Normalizer.normalize(passphrase, Normalizer.Form.NFKD);
final Stopwatch watch = Stopwatch.createStarted();
byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64);