mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 15:37:54 -05:00
Tessera Orion-mode privacy ATs (#2166)
* Refactored privacy ATs to use both Orion and Tessera. Signed-off-by: Mark Terry <mark.terry@consensys.net>
This commit is contained in:
@@ -21,9 +21,9 @@ import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
import org.hyperledger.besu.enclave.types.PrivacyGroup;
|
||||
import org.hyperledger.besu.enclave.types.ReceiveResponse;
|
||||
import org.hyperledger.besu.enclave.types.SendResponse;
|
||||
import org.hyperledger.orion.testutil.OrionKeyConfiguration;
|
||||
import org.hyperledger.orion.testutil.OrionTestHarness;
|
||||
import org.hyperledger.orion.testutil.OrionTestHarnessFactory;
|
||||
import org.hyperledger.enclave.testutil.EnclaveKeyConfiguration;
|
||||
import org.hyperledger.enclave.testutil.OrionTestHarness;
|
||||
import org.hyperledger.enclave.testutil.OrionTestHarnessFactory;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -59,8 +59,9 @@ public class EnclaveTest {
|
||||
|
||||
testHarness =
|
||||
OrionTestHarnessFactory.create(
|
||||
"enclave",
|
||||
folder.newFolder().toPath(),
|
||||
new OrionKeyConfiguration("orion_key_0.pub", "orion_key_0.key"));
|
||||
new EnclaveKeyConfiguration("enclave_key_0.pub", "enclave_key_0.key"));
|
||||
|
||||
testHarness.start();
|
||||
|
||||
|
||||
@@ -168,12 +168,53 @@ public class Enclave {
|
||||
final int statusCode, final byte[] body, final Class<T> responseType) {
|
||||
try {
|
||||
return objectMapper.readValue(body, responseType);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
final String utf8EncodedBody = new String(body, StandardCharsets.UTF_8);
|
||||
throw new EnclaveClientException(statusCode, utf8EncodedBody);
|
||||
// Check if it's a Tessera error message
|
||||
try {
|
||||
return objectMapper.readValue(
|
||||
processTesseraError(utf8EncodedBody, responseType), responseType);
|
||||
} catch (final IOException ex) {
|
||||
throw new EnclaveClientException(statusCode, utf8EncodedBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> byte[] processTesseraError(final String errorMsg, final Class<T> responseType) {
|
||||
if (responseType == SendResponse.class) {
|
||||
final String base64Key =
|
||||
errorMsg.substring(errorMsg.substring(0, errorMsg.indexOf('=')).lastIndexOf(' '));
|
||||
return jsonByteArrayFromString("key", base64Key);
|
||||
} else if (responseType == ErrorResponse.class) {
|
||||
// Remove dynamic values
|
||||
return jsonByteArrayFromString("error", removeBase64(errorMsg));
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled response type.");
|
||||
}
|
||||
}
|
||||
|
||||
private String removeBase64(final String input) {
|
||||
if (input.contains("=")) {
|
||||
final String startInclBase64 = input.substring(0, input.indexOf('='));
|
||||
final String startTrimmed = startInclBase64.substring(0, startInclBase64.lastIndexOf(" "));
|
||||
final String end = input.substring(input.indexOf("="));
|
||||
if (end.length() > 1) {
|
||||
// Base64 in middle
|
||||
return startTrimmed + end.substring(1);
|
||||
} else {
|
||||
// Base64 at end
|
||||
return startTrimmed;
|
||||
}
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] jsonByteArrayFromString(final String key, final String value) {
|
||||
String format = String.format("{\"%s\":\"%s\"}", key, value);
|
||||
return format.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private boolean clientError(final int statusCode) {
|
||||
return statusCode >= 400 && statusCode < 500;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
package org.hyperledger.besu.enclave;
|
||||
|
||||
public class EnclaveClientException extends IllegalArgumentException {
|
||||
public class EnclaveClientException extends RuntimeException {
|
||||
private int statusCode;
|
||||
|
||||
public EnclaveClientException(final int statusCode, final String message) {
|
||||
|
||||
@@ -87,6 +87,7 @@ public class VertxRequestTransmitter implements RequestTransmitter {
|
||||
request.putHeader(HttpHeaderNames.ACCEPT, APPLICATION_JSON);
|
||||
}
|
||||
contentType.ifPresent(ct -> request.putHeader(HttpHeaders.CONTENT_TYPE, ct));
|
||||
|
||||
if (content.isPresent()) {
|
||||
request.end(content.get());
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user