1
+ use base64:: { engine:: general_purpose:: STANDARD , Engine } ;
1
2
use mc_sgx_dcap_types:: QlError ;
2
3
use once_cell:: sync:: OnceCell ;
3
4
use serde:: { Deserialize , Serialize } ;
4
5
use std:: fs;
5
6
6
7
use crate :: signing:: AttestationKey ;
7
- use p256 :: { ecdsa:: SigningKey , PublicKey , elliptic_curve :: sec1 :: ToEncodedPoint } ;
8
+ use k256 :: ecdsa:: { SigningKey , VerifyingKey as PublicKey } ;
8
9
use pkcs8:: { DecodePrivateKey , EncodePrivateKey , LineEnding } ;
9
10
use rand_chacha:: {
10
11
rand_core:: { OsRng , SeedableRng } ,
@@ -86,10 +87,15 @@ async fn gramine_quote() -> Result<Quote, QuoteError> {
86
87
// Write to `/dev/attestation/target_info`
87
88
fs:: write ( "/dev/attestation/target_info" , my_target_info) ?;
88
89
89
- //// Writing the pubkey to bind the instance to the hw (note: this is not mrsigner)
90
+ //// Writing the pubkey to bind the instance to the hw (note: this is not
91
+ //// mrsigner)
90
92
fs:: write (
91
93
"/dev/attestation/user_report_data" ,
92
- PUBLIC_KEY . get ( ) . expect ( "pub_key_get" ) . to_encoded_point ( true ) . as_bytes ( )
94
+ PUBLIC_KEY
95
+ . get ( )
96
+ . expect ( "pub_key_get" )
97
+ . to_encoded_point ( true )
98
+ . as_bytes ( ) ,
93
99
) ?;
94
100
95
101
//// Reading from the gramine quote pseudo-hardware `/dev/attestation/quote`
@@ -102,8 +108,8 @@ async fn gramine_quote() -> Result<Quote, QuoteError> {
102
108
return Err ( QuoteError :: IntelQuoteLibrary ( QlError :: InvalidReport ) ) ;
103
109
}
104
110
105
- //// Extract mrenclave: enclave image, and mrsigner: identity key bound to enclave
106
- //// https://github.com/intel/linux-sgx/blob/main/common/inc/sgx_quote.h
111
+ //// Extract mrenclave: enclave image, and mrsigner: identity key bound to
112
+ //// enclave https://github.com/intel/linux-sgx/blob/main/common/inc/sgx_quote.h
107
113
let mrenclave = hex:: encode ( & quote[ 112 ..144 ] ) ;
108
114
let mrsigner = hex:: encode ( & quote[ 176 ..208 ] ) ;
109
115
@@ -124,16 +130,23 @@ pub fn ephemeral_keypair() -> (AttestationKey, String) {
124
130
let signing_key = SigningKey :: random ( & mut rng) ;
125
131
let pem_string = signing_key
126
132
. clone ( )
127
- . to_pkcs8_pem ( LineEnding :: default ( ) )
133
+ . to_pkcs8_pem ( LineEnding :: LF )
128
134
. expect ( "to pem" ) ;
129
135
let attkey = AttestationKey :: from_pkcs8_pem ( & pem_string) . expect ( "from pem" ) ;
136
+ let derk = signing_key
137
+ . verifying_key ( )
138
+ . to_encoded_point ( true )
139
+ . to_bytes ( ) ;
140
+ let b64k = STANDARD . encode ( derk. as_ref ( ) ) ;
141
+ let pem = format ! (
142
+ "-----BEGIN PUBLIC KEY-----\n {}\n -----END PUBLIC KEY-----\n " ,
143
+ b64k
144
+ ) ;
145
+
130
146
let _ = PUBLIC_KEY
131
- . set ( PublicKey :: from ( * signing_key. verifying_key ( ) ) )
147
+ . set ( * signing_key. verifying_key ( ) )
132
148
. map_err ( |_| "Public key has already been set" ) ;
133
- return (
134
- attkey,
135
- PublicKey :: from ( * signing_key. verifying_key ( ) ) . to_string ( ) ,
136
- ) ;
149
+ return ( attkey, pem) ;
137
150
}
138
151
139
152
pub async fn quote ( ) -> Quote {
0 commit comments