Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
align Ilp-over-http custom settings to match update property style
Browse files Browse the repository at this point in the history
style should match property definition in issue #383
removed deprecated incomingHttpLinkSettings and outgoingHttpLinkSettings accessors

Signed-off-by: nhartner <[email protected]>
  • Loading branch information
nhartner committed Dec 23, 2019
1 parent c768db0 commit e009829
Show file tree
Hide file tree
Showing 18 changed files with 697 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.interledger.link.http.IlpOverHttpLinkSettings;
import org.interledger.link.http.IncomingLinkSettings;
import org.interledger.link.http.OutgoingLinkSettings;
import org.interledger.link.http.SimpleAuthSettings;
import org.interledger.link.http.auth.SimpleBearerTokenSupplier;
import org.interledger.spsp.PaymentPointer;
import org.interledger.spsp.StreamConnectionDetails;
Expand Down Expand Up @@ -90,15 +91,10 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
private static Link newIlpOverHttpLink() {
String sharedSecret = "some random secret here";
final IlpOverHttpLinkSettings linkSettings = IlpOverHttpLinkSettings.builder()
.incomingLinkSettings(IncomingLinkSettings.builder()
.authType(IlpOverHttpLinkSettings.AuthType.SIMPLE)
.encryptedTokenSharedSecret(sharedSecret)
.build())
.outgoingLinkSettings(OutgoingLinkSettings.builder()
.authType(IlpOverHttpLinkSettings.AuthType.SIMPLE)
.tokenSubject(SENDER_ACCOUNT_USERNAME)
.url(HttpUrl.parse(TESTNET_URI + "/ilp"))
.encryptedTokenSharedSecret(sharedSecret)
.url(HttpUrl.parse(TESTNET_URI + "/accounts/" + SENDER_ACCOUNT_USERNAME + "/ilp"))
.simpleAuthSettings(SimpleAuthSettings.forAuthToken(sharedSecret))
.build())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,10 @@ public void testConnection() {
.orElseGet(() -> {
logger.warn("Falling back to deprecated means of loading outgoing settings. " +
"Please switch to using outgoingLinkSettings() instead");
return this.getLinkSettings().outgoingHttpLinkSettings();
return this.getLinkSettings().outgoingLinkSettings().get();
});
final String tokenSubject = outgoingLinkSettings.tokenSubject();
try {

try {
final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET);

try (Response response = okHttpClient.newCall(okHttpRequest).execute()) {
Expand All @@ -211,26 +210,26 @@ public void testConnection() {
.isPresent();

if (responseHasOctetStreamContentType) {
logger.info("Remote peer-link supports ILP-over-HTTP. tokenSubject={} url={} responseHeaders={}",
outgoingLinkSettings.tokenSubject(), outgoingLinkSettings.url(), response
logger.info("Remote peer-link supports ILP-over-HTTP. authType={} url={} responseHeaders={}",
outgoingLinkSettings.authType(), outgoingLinkSettings.url(), response
);
} else {
logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. tokenSubject={} url={} "
logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. authType={} url={} "
+ "response={}",
outgoingLinkSettings.tokenSubject(), outgoingLinkSettings.url(), response
outgoingLinkSettings.authType(), outgoingLinkSettings.url(), response
);
}
} else {
if (response.code() == 406 || response.code() == 415) { // NOT_ACCEPTABLE || UNSUPPORTED_MEDIA_TYPE
throw new LinkException(
String.format("Remote peer-link DOES NOT support ILP-over-HTTP. tokenSubject=%s url=%s response=%s",
tokenSubject, outgoingLinkSettings.url(), response
String.format("Remote peer-link DOES NOT support ILP-over-HTTP. authType=%s url=%s response=%s",
outgoingLinkSettings.authType(), outgoingLinkSettings.url(), response
), getLinkId()
);
} else {
throw new LinkException(
String.format("Unable to connect to ILP-over-HTTP. tokenSubject=%s url=%s response=%s",
tokenSubject, outgoingLinkSettings.url(), response
String.format("Unable to connect to ILP-over-HTTP. authType=%s url=%s response=%s",
outgoingLinkSettings.authType(), outgoingLinkSettings.url(), response
), getLinkId()
);
}
Expand Down Expand Up @@ -303,7 +302,7 @@ private Request constructSendPacketRequest(final InterledgerPreparePacket prepar
.orElseGet(() -> {
logger.warn("Falling back to deprecated means of loading outgoing settings. " +
"Please switch to using outgoingLinkSettings() instead");
return this.getLinkSettings().outgoingHttpLinkSettings();
return this.getLinkSettings().outgoingLinkSettings().get();
});

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public Link<?> constructLink(
.orElseGet(() -> {
logger.warn("Falling back to deprecated means of loading outgoing settings. " +
"Please switch to using outgoingLinkSettings() instead");
return ilpOverHttpLinkSettings.outgoingHttpLinkSettings();
return ilpOverHttpLinkSettings.outgoingLinkSettings().get();
});
if (outgoingLinkSettings.authType().equals(IlpOverHttpLinkSettings.AuthType.SIMPLE)) {
// Decrypt whatever is inside of the encryptedTokenSharedSecret. For the SIMPLE profile, this will decrypt to the
// actual bearer token.
bearerTokenSupplier = new SimpleBearerTokenSupplier(new String(
decryptor.decrypt(outgoingLinkSettings.encryptedTokenSharedSecret().getBytes())
decryptor.decrypt(outgoingLinkSettings.simpleAuthSettings().get().authToken().getBytes())
));
} else {
// TODO: For now, we assume the bytes are a String that conform to the Crypt CLI. However, this should be made
Expand All @@ -101,7 +101,7 @@ public Link<?> constructLink(
// NOTE: This supplier will always create a copy of the decrypted bytes so that the consumer of each call can
// safely wipe the bytes from memory without affecting other callers.
final SharedSecretBytesSupplier sharedSecretSupplier = () -> decryptor
.decrypt(outgoingLinkSettings.encryptedTokenSharedSecret().getBytes());
.decrypt(outgoingLinkSettings.jwtAuthSettings().get().encryptedTokenSharedSecret().get().getBytes());

bearerTokenSupplier = new JwtHs256BearerTokenSupplier(
sharedSecretSupplier, outgoingLinkSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public interface IlpOverHttpLinkSettings extends LinkSettings {

String OUTGOING = "outgoing";
String INCOMING = "incoming";

String AUTH_TYPE = "auth_type";
String SIMPLE = "simple";
String JWT = "jwt";

String TOKEN_ISSUER = "token_issuer";
String TOKEN_AUDIENCE = "token_audience";
Expand All @@ -32,6 +32,7 @@ public interface IlpOverHttpLinkSettings extends LinkSettings {

// Used to grab the auth credential from custom settings...
String SHARED_SECRET = "shared_secret";
String AUTH_TOKEN = "auth_token";
String URL = "url";

static ImmutableIlpOverHttpLinkSettings.Builder builder() {
Expand Down Expand Up @@ -74,10 +75,6 @@ static ImmutableIlpOverHttpLinkSettings.Builder applyCustomSettings(
ImmutableOutgoingLinkSettings outgoing = outgoingLinkSettingsBuilder.build();
builder.outgoingLinkSettings(outgoing);

// FIXME initialize in deprecated as well until removed
builder.incomingHttpLinkSettings(incoming);
builder.outgoingHttpLinkSettings(outgoing);

builder.customSettings(customSettings);

return builder;
Expand All @@ -88,26 +85,6 @@ default LinkType getLinkType() {
return IlpOverHttpLink.LINK_TYPE;
}

/**
* @deprecated use {@link #incomingLinkSettings()}. To be removed in 1.0.4
* Link settings for the incoming HTTP link.
*
* @return A {@link IncomingLinkSettings}.
*/
@Deprecated
@Nullable
IncomingLinkSettings incomingHttpLinkSettings();

/**
* @deprecated use {@link #outgoingLinkSettings()}. To be removed in 1.0.4
* Link settings for the outgoing HTTP link.
*
* @return A {@link OutgoingLinkSettings}.
*/
@Deprecated
@Nullable
OutgoingLinkSettings outgoingHttpLinkSettings();

/**
* Optional link settings for the incoming HTTP link.
*
Expand Down Expand Up @@ -135,14 +112,9 @@ enum AuthType {
SIMPLE,

/**
* Use shared-secret symmetric keys to create and verify JWT_HS_256 tokens.
*/
JWT_HS_256,

/**
* Use RSA asymmetric keys to create aand verify JWT_RS_256 tokens.
* Use JWTs to autheticate using RS256 or HS256
*/
//JWT_RS_256
JWT
}

@Value.Immutable
Expand Down
Loading

0 comments on commit e009829

Please sign in to comment.