-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): provide access tokens dynamically to KAS (#51)
* give the `KASClient` a way to create channels that are configured in the way the user expects * add stub interfaces for `Policy` and `KASInfo`
- Loading branch information
Showing
5 changed files
with
178 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.opentdf.platform.sdk; | ||
|
||
import io.grpc.Channel; | ||
import io.opentdf.platform.kas.AccessServiceGrpc; | ||
import io.opentdf.platform.kas.PublicKeyRequest; | ||
import io.opentdf.platform.kas.RewrapRequest; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.Function; | ||
|
||
public class KASClient implements SDK.KAS { | ||
|
||
private final Function<SDK.KASInfo, Channel> channelFactory; | ||
|
||
public KASClient(Function <SDK.KASInfo, Channel> channelFactory) { | ||
this.channelFactory = channelFactory; | ||
} | ||
|
||
@Override | ||
public String getPublicKey(SDK.KASInfo kasInfo) { | ||
return getStub(kasInfo).publicKey(PublicKeyRequest.getDefaultInstance()).getPublicKey(); | ||
} | ||
|
||
@Override | ||
public byte[] unwrap(SDK.KASInfo kasInfo, SDK.Policy policy) { | ||
// this is obviously wrong. we still have to generate a correct request and decrypt the payload | ||
return getStub(kasInfo).rewrap(RewrapRequest.getDefaultInstance()).getEntityWrappedKey().toByteArray(); | ||
} | ||
|
||
private final HashMap<SDK.KASInfo, AccessServiceGrpc.AccessServiceBlockingStub> stubs = new HashMap<>(); | ||
|
||
private synchronized AccessServiceGrpc.AccessServiceBlockingStub getStub(SDK.KASInfo kasInfo) { | ||
if (!stubs.containsKey(kasInfo)) { | ||
var channel = channelFactory.apply(kasInfo); | ||
var stub = AccessServiceGrpc.newBlockingStub(channel); | ||
stubs.put(kasInfo, stub); | ||
} | ||
|
||
return stubs.get(kasInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters