forked from intel-analytics/ipex-llm
-
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.
[PPML] Implement VerificationCLI to verify Attestation Service (intel…
…-analytics#5742) * Implement VerificationCLI and a bash to use VerificationCLI * Refine Co-authored-by: xiangyuT <[email protected]>
- Loading branch information
1 parent
3a082a3
commit 7958dfc
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
scala/ppml/src/main/scala/com/intel/analytics/bigdl/ppml/attestation/VerificationCLI.scala
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,88 @@ | ||
/* | ||
* Copyright 2016 The BigDL Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
package com.intel.analytics.bigdl.ppml.attestation | ||
|
||
import org.apache.logging.log4j.LogManager | ||
import scopt.OptionParser | ||
|
||
import java.util.Base64 | ||
|
||
/** | ||
* Simple Command Line tool to verify attestation service | ||
*/ | ||
object VerificationCLI { | ||
def main(args: Array[String]): Unit = { | ||
|
||
val logger = LogManager.getLogger(getClass) | ||
case class CmdParams(appID: String = "test", | ||
apiKey: String = "test", | ||
attestationType: String = ATTESTATION_CONVENTION.MODE_EHSM_KMS, | ||
attestationURL: String = "127.0.0.1:9000", | ||
challenge: String = "test") | ||
|
||
val cmdParser = new OptionParser[CmdParams]("PPML Quote Verification Cmd tool") { | ||
opt[String]('i', "appID") | ||
.text("app id for this app") | ||
.action((x, c) => c.copy(appID = x)) | ||
opt[String]('k', "apiKey") | ||
.text("app key for this app") | ||
.action((x, c) => c.copy(apiKey = x)) | ||
opt[String]('u', "attestationURL") | ||
.text("attestation service url, default is 127.0.0.1:9000") | ||
.action((x, c) => c.copy(attestationURL = x)) | ||
opt[String]('t', "attestationType") | ||
.text("attestation service type, default is EHSMKeyManagementService") | ||
.action((x, c) => c.copy(attestationType = x)) | ||
opt[String]('c', "challenge") | ||
.text("challenge to attestation service, default is '' which skip bi-attestation") | ||
.action((x, c) => c.copy(challenge = x)) | ||
} | ||
val params = cmdParser.parse(args, CmdParams()).get | ||
|
||
// Attestation Client | ||
val as = params.attestationType match { | ||
case ATTESTATION_CONVENTION.MODE_EHSM_KMS => | ||
new EHSMAttestationService(params.attestationURL.split(":")(0), | ||
params.attestationURL.split(":")(1), params.appID, params.apiKey) | ||
case ATTESTATION_CONVENTION.MODE_DUMMY => | ||
new DummyAttestationService() | ||
case _ => throw new AttestationRuntimeException("Wrong Attestation service type") | ||
} | ||
|
||
val challengeString = params.challenge | ||
if (params.attestationType != ATTESTATION_CONVENTION.MODE_DUMMY) { | ||
val asQuote = params.attestationType match { | ||
case ATTESTATION_CONVENTION.MODE_EHSM_KMS => | ||
Base64.getDecoder().decode(as.getQuoteFromServer(challengeString)) | ||
case _ => throw new AttestationRuntimeException("Wrong Attestation service type") | ||
} | ||
val quoteVerifier = new SGXDCAPQuoteVerifierImpl() | ||
val verifyQuoteResult = quoteVerifier.verifyQuote(asQuote) | ||
if (verifyQuoteResult == 0) { | ||
System.out.println("Quote Verification Success!") | ||
System.exit(0) | ||
} else { | ||
System.out.println("Quote Verification Fail! Application killed") | ||
System.exit(1) | ||
} | ||
} else { | ||
System.out.println("Dummy attestation service cannot be verified!") | ||
System.exit(1) | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...l/src/main/scala/com/intel/analytics/bigdl/ppml/attestation/verify-attestation-service.sh
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,48 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
export ATTESTATION_URL=your_attestation_url | ||
export ATTESTATION_TYPE=your_attestation_service_type | ||
export APP_ID=your_app_id | ||
export API_KEY=your_api_key | ||
export CHALLENGE=your_challenge_string | ||
export SPARK_HOME=your_spark_home | ||
export BIGDL_PPML_JAR=your_bigdl_ppml_jar | ||
|
||
if [ "$ATTESTATION_URL" = "your_attestation_url" ]; then | ||
echo "[ERROR] ATTESTATION_URL is not set!" | ||
echo "[INFO] PPML Application Exit!" | ||
exit 1 | ||
fi | ||
if [ "$ATTESTATION_TYPE" = "your_attestation_service_type" ]; then | ||
ATTESTATION_TYPE="EHSMAttestationService" | ||
fi | ||
if [ "$APP_ID" = "your_app_id" ]; then | ||
echo "[ERROR] APP_ID is not set!" | ||
echo "[INFO] PPML Application Exit!" | ||
exit 1 | ||
fi | ||
if [ "$API_KEY" = "your_api_key" ]; then | ||
echo "[ERROR] API_KEY is not set!" | ||
echo "[INFO] PPML Application Exit!" | ||
exit 1 | ||
fi | ||
if [ "$CHALLENGE" = "your_challenge_string" ]; then | ||
echo "[ERROR] CHALLENGE is not set!" | ||
echo "[INFO] PPML Application Exit!" | ||
exit 1 | ||
fi | ||
if [ "$SPARK_HOME" = "your_spark_home" ]; then | ||
echo "[ERROR] SPARK_HOME is not set!" | ||
echo "[INFO] PPML Application Exit!" | ||
exit 1 | ||
fi | ||
if [ "$BIGDL_PPML_JAR" = "your_bigdl_ppml_jar" ]; then | ||
echo "[ERROR] BIGDL_PPML_JAR is not set!" | ||
echo "[INFO] PPML Application Exit!" | ||
exit 1 | ||
fi | ||
|
||
JARS="$SPARK_HOME/jars/*:$SPARK_HOME/examples/jars/*:$BIGDL_PPML_JAR" | ||
|
||
java -cp $JARS com.intel.analytics.bigdl.ppml.attestation.VerificationCLI -i $APP_ID -k $API_KEY -c $CHALLENGE -u $ATTESTATION_URL -t $ATTESTATION_TYPE |