-
Notifications
You must be signed in to change notification settings - Fork 9
UID2-4808 Add AKS protocol for AzureCCCoreAttestationService
#374
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
27d93d5
Add paraent class for `AzureCCCoreAttestationService`
cYKatherine 25ef824
Fix UT
cYKatherine 78aa455
Change log info for different azureCcProtocol
cYKatherine 4e0d4c4
Remove wrong comment
cYKatherine faef366
Add unit tests for policy validator
cYKatherine 68bc1e7
[CI Pipeline] Released Snapshot version: 8.0.33-alpha-190-SNAPSHOT
7352bea
Remove parent child hierarchy
cYKatherine 0c3957d
Add debug message
cYKatherine 14572f8
[CI Pipeline] Released Snapshot version: 8.0.34-alpha-191-SNAPSHOT
3372d69
Change constant variable to AZURE_CC_ACI_PROTOCOL
cYKatherine 69a7fc0
Rename jwt_payload_aci.json file
cYKatherine 623118f
Rename testAciPayload UT
cYKatherine b068084
Use ParameterizedTest to test payload
cYKatherine 40c518e
Use String.format to format log message
cYKatherine 9f806e6
Use logback parameterized logging
cYKatherine a34056a
Throw AttestationClientException when protocol not valid
cYKatherine b9c1cc7
Refactor MaaTokenSignatureValidatorTest
cYKatherine 35851d1
Use @MethodSource("argumentProvider")
cYKatherine ed3c07d
Replace string with MaaTokenPayload contant
cYKatherine 929dd0c
Fix typo
cYKatherine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/uid2/shared/secure/AzureCCAksCoreAttestationService.java
This file contains hidden or 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,31 @@ | ||
| package com.uid2.shared.secure; | ||
|
|
||
| import com.uid2.shared.Utils; | ||
| import com.uid2.shared.secure.azurecc.IMaaTokenSignatureValidator; | ||
| import com.uid2.shared.secure.azurecc.IPolicyValidator; | ||
| import com.uid2.shared.secure.azurecc.MaaTokenSignatureValidator; | ||
| import com.uid2.shared.secure.azurecc.PolicyValidator; | ||
| import io.vertx.core.AsyncResult; | ||
| import io.vertx.core.Future; | ||
| import io.vertx.core.Handler; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| // CC stands for Confidential Container | ||
| @Slf4j | ||
| public class AzureCCAksCoreAttestationService extends AzureCCCoreAttestationServiceBase { | ||
| private static final String AZURE_CC_PROTOCOL = "azure-cc-aks"; | ||
|
|
||
| public AzureCCAksCoreAttestationService(String maaServerBaseUrl, String attestationUrl) { | ||
| super(new MaaTokenSignatureValidator(maaServerBaseUrl), new PolicyValidator(attestationUrl), AZURE_CC_PROTOCOL); | ||
| } | ||
|
|
||
| // used in UT | ||
| protected AzureCCAksCoreAttestationService(IMaaTokenSignatureValidator tokenSignatureValidator, IPolicyValidator policyValidator) { | ||
| super(tokenSignatureValidator, policyValidator, AZURE_CC_PROTOCOL); | ||
| } | ||
| } | ||
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
src/main/java/com/uid2/shared/secure/AzureCCCoreAttestationServiceBase.java
This file contains hidden or 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,84 @@ | ||
| package com.uid2.shared.secure; | ||
|
|
||
| import com.uid2.shared.Utils; | ||
| import com.uid2.shared.secure.azurecc.IMaaTokenSignatureValidator; | ||
| import com.uid2.shared.secure.azurecc.IPolicyValidator; | ||
| import com.uid2.shared.secure.azurecc.MaaTokenSignatureValidator; | ||
| import com.uid2.shared.secure.azurecc.PolicyValidator; | ||
| import io.vertx.core.AsyncResult; | ||
| import io.vertx.core.Future; | ||
| import io.vertx.core.Handler; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| // CC stands for Confidential Container | ||
| @Slf4j | ||
| public abstract class AzureCCCoreAttestationServiceBase implements ICoreAttestationService { | ||
|
|
||
| protected final Set<String> allowedEnclaveIds = new HashSet<>(); | ||
|
|
||
| protected final IMaaTokenSignatureValidator tokenSignatureValidator; | ||
|
|
||
| protected final IPolicyValidator policyValidator; | ||
|
|
||
| protected final String azureCcProtocol; | ||
|
|
||
| protected AzureCCCoreAttestationServiceBase(IMaaTokenSignatureValidator tokenSignatureValidator, IPolicyValidator policyValidator, String azureCcProtocol) { | ||
| this.tokenSignatureValidator = tokenSignatureValidator; | ||
| this.policyValidator = policyValidator; | ||
| this.azureCcProtocol = azureCcProtocol; | ||
| } | ||
|
|
||
| public void attest(byte[] attestationRequest, byte[] publicKey, Handler<AsyncResult<AttestationResult>> handler) { | ||
| try { | ||
| var tokenString = new String(attestationRequest, StandardCharsets.US_ASCII); | ||
|
|
||
| log.debug("Validating signature..."); | ||
| var tokenPayload = tokenSignatureValidator.validate(tokenString, azureCcProtocol); | ||
|
|
||
| log.debug("Validating policy..."); | ||
| var encodedPublicKey = Utils.toBase64String(publicKey); | ||
|
|
||
| var enclaveId = policyValidator.validate(tokenPayload, encodedPublicKey); | ||
|
|
||
| if (allowedEnclaveIds.contains(enclaveId)) { | ||
| log.info("Successfully attested " + azureCcProtocol + " against registered enclaves, enclave id: " + enclaveId); | ||
| handler.handle(Future.succeededFuture(new AttestationResult(publicKey, enclaveId))); | ||
| } else { | ||
| log.warn("Got unsupported " + azureCcProtocol + " enclave id: " + enclaveId); | ||
| handler.handle(Future.succeededFuture(new AttestationResult(AttestationFailure.FORBIDDEN_ENCLAVE))); | ||
| } | ||
| } | ||
| catch (AttestationClientException ace){ | ||
| handler.handle(Future.succeededFuture(new AttestationResult(ace))); | ||
| } catch (AttestationException ae) { | ||
| handler.handle(Future.failedFuture(ae)); | ||
| } catch (Exception ex) { | ||
| handler.handle(Future.failedFuture(new AttestationException(ex))); | ||
| } | ||
| }; | ||
|
|
||
| public void registerEnclave(String encodedIdentifier) throws AttestationException { | ||
| try { | ||
| allowedEnclaveIds.add(encodedIdentifier); | ||
| } catch (Exception e) { | ||
| throw new AttestationException(e); | ||
| } | ||
| } | ||
|
|
||
| public void unregisterEnclave(String encodedIdentifier) throws AttestationException { | ||
| try { | ||
| allowedEnclaveIds.remove(encodedIdentifier); | ||
| } catch (Exception e) { | ||
| throw new AttestationException(e); | ||
| } | ||
| } | ||
|
|
||
| public Collection<String> getEnclaveAllowlist() { | ||
| return allowedEnclaveIds; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,5 +10,5 @@ public interface IMaaTokenSignatureValidator { | |
| * @return Parsed token payload. | ||
| * @throws AttestationException | ||
| */ | ||
| MaaTokenPayload validate(String tokenString) throws AttestationException; | ||
| MaaTokenPayload validate(String tokenString, String protocol) throws AttestationException; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we introduce an enum for the protocols instead of using a |
||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need child classes for these? Could they just be one class that takes in the AZURE_CC_PROTOCOL?