-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:Fr0ntierX/polaris-sdk into feature/i…
…mplement-streaming-capabilities
- Loading branch information
Showing
5 changed files
with
360 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import axios from "axios"; | ||
|
||
export const getKeysFromIssuer = async (iss: string): Promise<any[]> => { | ||
const { | ||
data: { jwks_uri }, | ||
} = await axios.get(`${iss}/.well-known/openid-configuration`); | ||
const { | ||
data: { keys }, | ||
} = await axios.get(jwks_uri); | ||
|
||
if (!keys || keys.length === 0) { | ||
throw new Error("No keys found in JWK response"); | ||
} | ||
|
||
return keys; | ||
}; | ||
|
||
export const performGCPChecks = (verifiedPayload: any) => { | ||
if ( | ||
verifiedPayload.iss !== "https://confidentialcomputing.googleapis.com" || | ||
verifiedPayload.aud !== "https://sts.googleapis.com" || | ||
verifiedPayload.secboot !== true || | ||
verifiedPayload.hwmodel !== "GCP_AMD_SEV" | ||
) { | ||
throw new Error("Invalid payload values for Google Confidential Computing"); | ||
} | ||
}; | ||
|
||
export const performAzureChecks = (verifiedPayload: any) => { | ||
const attestationType = verifiedPayload["x-ms-attestation-type"]; | ||
const complianceStatus = verifiedPayload["x-ms-compliance-status"]; | ||
const isolationTee = verifiedPayload["x-ms-isolation-tee"]?.["x-ms-attestation-type"]; | ||
|
||
if (!verifiedPayload.iss.endsWith(".attest.azure.net")) { | ||
throw new Error("Invalid issuer for Azure attestation"); | ||
} | ||
|
||
if (attestationType === "azurevm") { | ||
if (isolationTee !== "sevsnpvm" || complianceStatus !== "azure-compliant-cvm") { | ||
throw new Error("Invalid payload values for Azure VM with SEV-SNP"); | ||
} | ||
} else if (attestationType === "sevsnpvm") { | ||
if (complianceStatus !== "azure-compliant-uvm") { | ||
throw new Error("Invalid payload values for SEV-SNP VM in Azure"); | ||
} | ||
} else { | ||
throw new Error("Invalid or unsupported attestation type for Azure"); | ||
} | ||
}; | ||
|
||
export const performCustomChecks = (customChecks: {}, verifiedPayload: any) => { | ||
for (const [key, expectedValue] of Object.entries(customChecks)) { | ||
const actualValue = key.split(".").reduce((acc, part) => acc && acc[part], verifiedPayload); | ||
|
||
if (actualValue === undefined) { | ||
throw new Error(`Custom check failed: ${key} is missing in the payload`); | ||
} | ||
if (actualValue !== expectedValue) { | ||
throw new Error( | ||
`Custom check failed: ${key} does not match expected value. Got ${actualValue}, expected ${expectedValue}` | ||
); | ||
} | ||
} | ||
}; |
Oops, something went wrong.