5
5
use anyhow:: { anyhow, Context , Result } ;
6
6
use attest_data:: { Attestation , Log , Nonce } ;
7
7
use clap:: { Parser , Subcommand , ValueEnum } ;
8
+ use dice_mfg_msgs:: PlatformId ;
8
9
use dice_verifier:: PkiPathSignatureVerifier ;
9
10
use env_logger:: Builder ;
10
11
use hubpack:: SerializedSize ;
@@ -76,6 +77,12 @@ enum AttestCommand {
76
77
Log ,
77
78
/// Get the length in bytes of the Log.
78
79
LogLen ,
80
+ /// Get the PlatformId string from the provided PkiPath
81
+ PlatformId {
82
+ /// Path to file holding the certificate chain / PkiPath
83
+ #[ clap( env) ]
84
+ cert_chain : PathBuf ,
85
+ } ,
79
86
/// Report a measurement to the `Attest` task for recording in the
80
87
/// measurement log.
81
88
Record {
@@ -498,7 +505,6 @@ fn main() -> Result<()> {
498
505
AttestCommand :: CertChainLen => println ! ( "{}" , attest. cert_chain_len( ) ?) ,
499
506
AttestCommand :: CertLen { index } => {
500
507
println ! ( "{}" , attest. cert_len( index) ?)
501
- }
502
508
AttestCommand :: Log => {
503
509
let mut log = vec ! [ 0u8 ; attest. log_len( ) ? as usize ] ;
504
510
attest. log ( & mut log) ?;
@@ -512,6 +518,18 @@ fn main() -> Result<()> {
512
518
io:: stdout ( ) . flush ( ) ?;
513
519
}
514
520
AttestCommand :: LogLen => println ! ( "{}" , attest. log_len( ) ?) ,
521
+ AttestCommand :: PlatformId { cert_chain } => {
522
+ let cert_chain = fs:: read ( cert_chain) ?;
523
+ let cert_chain: PkiPath = Certificate :: load_pem_chain ( & cert_chain) ?;
524
+
525
+ let platform_id = PlatformId :: try_from ( & cert_chain)
526
+ . context ( "PlatformId from attestation cert chain" ) ?;
527
+ let platform_id = platform_id
528
+ . as_str ( )
529
+ . map_err ( |_| anyhow ! ( "Invalid PlatformId" ) ) ?;
530
+
531
+ println ! ( "{platform_id}" ) ;
532
+ }
515
533
AttestCommand :: Record { digest } => {
516
534
let digest = fs:: read ( digest) ?;
517
535
attest. record ( & digest) ?;
0 commit comments