Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide protocol version from consumers #577

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.ECPublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class MobileWalletAdapterSession extends MobileWalletAdapterSessionCommon {
private static final String TAG = MobileWalletAdapterSession.class.getSimpleName();
Expand All @@ -35,27 +34,27 @@ public class MobileWalletAdapterSession extends MobileWalletAdapterSessionCommon
private final KeyPair mAssociationKey;

@NonNull
private final List<SessionProperties.ProtocolVersion> mSupportedProtocolVersions;
private final Set<SessionProperties.ProtocolVersion> mSupportedProtocolVersions;

@Nullable
private SessionProperties mSessionProperties;

@Deprecated
public MobileWalletAdapterSession(@NonNull MessageReceiver decryptedPayloadReceiver,
@Nullable StateCallbacks stateCallbacks) {
this(decryptedPayloadReceiver, stateCallbacks, List.of(SessionProperties.ProtocolVersion.LEGACY));
this(decryptedPayloadReceiver, stateCallbacks,
Set.of(SessionProperties.ProtocolVersion.LEGACY, SessionProperties.ProtocolVersion.V1));
}

public MobileWalletAdapterSession(@NonNull MessageReceiver decryptedPayloadReceiver,
@Nullable StateCallbacks stateCallbacks,
@NonNull List<SessionProperties.ProtocolVersion> supportedProtocolVersions) {
protected MobileWalletAdapterSession(@NonNull MessageReceiver decryptedPayloadReceiver,
@Nullable StateCallbacks stateCallbacks,
@NonNull Set<SessionProperties.ProtocolVersion> supportedProtocolVersions) {
super(decryptedPayloadReceiver, stateCallbacks);
mAssociationKey = generateECP256KeyPair();
mSupportedProtocolVersions = supportedProtocolVersions;
mSessionProperties = null;
}

public List<SessionProperties.ProtocolVersion> getSupportedProtocolVersions() { return mSupportedProtocolVersions; }
public Set<SessionProperties.ProtocolVersion> getSupportedProtocolVersions() { return mSupportedProtocolVersions; }

@NonNull
@Override
Expand Down Expand Up @@ -124,12 +123,15 @@ protected void handleSessionEstablishmentMessage(@NonNull byte[] payload)
final ECPublicKey theirPublicKey = parseHelloRsp(payload);
generateSessionECDHSecret(theirPublicKey);

SessionProperties sessionProperties = new SessionProperties(SessionProperties.ProtocolVersion.LEGACY);
try {
byte[] encryptedSessionProperties =
Arrays.copyOfRange(payload, ECDSAKeys.ENCODED_PUBLIC_KEY_LENGTH_BYTES, payload.length);
mSessionProperties = parseSessionProps(encryptedSessionProperties);
} catch (IndexOutOfBoundsException e) {
mSessionProperties = new SessionProperties(SessionProperties.ProtocolVersion.LEGACY);
if (mSupportedProtocolVersions.contains(SessionProperties.ProtocolVersion.V1)) {
byte[] encryptedSessionProperties =
Arrays.copyOfRange(payload, ECDSAKeys.ENCODED_PUBLIC_KEY_LENGTH_BYTES, payload.length);
sessionProperties = parseSessionProps(encryptedSessionProperties);
}
} finally {
mSessionProperties = sessionProperties;
}

doSessionEstablished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import com.solana.mobilewalletadapter.common.AssociationContract;
import com.solana.mobilewalletadapter.common.protocol.SessionProperties;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class LocalAssociationIntentCreator {

Expand All @@ -35,14 +34,15 @@ public static Intent createAssociationIntent(@Nullable Uri endpointPrefix,
return new Intent()
.setAction(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(createAssociationUri(endpointPrefix, port, associationToken, session.getSupportedProtocolVersions()));
.setData(createAssociationUri(endpointPrefix, port, associationToken,
session.getSupportedProtocolVersions()));
}

public static boolean isWalletEndpointAvailable(@NonNull PackageManager pm) {
final Intent intent = new Intent()
.setAction(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(createAssociationUri(null, 0, "", new ArrayList<>()));
.setData(createAssociationUri(null, 0, "", Set.of()));
final ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
return (resolveInfo != null);
}
Expand All @@ -51,7 +51,7 @@ public static boolean isWalletEndpointAvailable(@NonNull PackageManager pm) {
private static Uri createAssociationUri(@Nullable Uri endpointPrefix,
@IntRange(from = 0, to = 65535) int port,
@NonNull String associationToken,
@NonNull List<SessionProperties.ProtocolVersion> supportedProtocolVersions) {
@NonNull Set<SessionProperties.ProtocolVersion> supportedProtocolVersions) {
if (endpointPrefix != null && (!"https".equals(endpointPrefix.getScheme()) || !endpointPrefix.isHierarchical())) {
throw new IllegalArgumentException("Endpoint-specific URI prefix must be absolute with scheme 'https' and hierarchical");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
import com.solana.mobilewalletadapter.clientlib.transport.websockets.MobileWalletAdapterWebSocket;
import com.solana.mobilewalletadapter.common.WebSocketsTransportContract;
import com.solana.mobilewalletadapter.common.protocol.MobileWalletAdapterSessionCommon;
import com.solana.mobilewalletadapter.common.protocol.SessionProperties;
import com.solana.mobilewalletadapter.common.util.NotifyOnCompleteFuture;
import com.solana.mobilewalletadapter.common.util.NotifyingCompletableFuture;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -57,13 +55,7 @@ public MobileWalletAdapterSession getSession() {
return mMobileWalletAdapterSession;
}

@Deprecated
public LocalAssociationScenario(@IntRange(from = 0) int clientTimeoutMs) {
this(clientTimeoutMs, List.of(SessionProperties.ProtocolVersion.LEGACY));
}

public LocalAssociationScenario(@IntRange(from = 0) int clientTimeoutMs,
@NonNull List<SessionProperties.ProtocolVersion> supportedProtocolVersions) {
super(clientTimeoutMs);

mPort = new Random().nextInt(WebSocketsTransportContract.WEBSOCKETS_LOCAL_PORT_MAX -
Expand All @@ -79,8 +71,7 @@ public LocalAssociationScenario(@IntRange(from = 0) int clientTimeoutMs,

mMobileWalletAdapterSession = new MobileWalletAdapterSession(
mMobileWalletAdapterClient,
mSessionStateCallbacks,
supportedProtocolVersions);
mSessionStateCallbacks);

Log.v(TAG, "Creating local association scenario for " + mWebSocketUri);
}
Expand Down
Loading