@@ -7,11 +7,12 @@ use axum::{
77use reqwest:: { Request , Response } ;
88use serde:: Deserialize ;
99use serde_json:: Value ;
10- use tracing:: info;
10+ use tracing:: { debug , info} ;
1111use uuid:: Uuid ;
1212use web_prover_core:: {
1313 http:: {
14- ManifestRequest , ManifestResponse , ManifestResponseBody , NotaryResponse , NotaryResponseBody ,
14+ JsonKey , ManifestRequest , ManifestResponse , ManifestResponseBody , NotaryResponse ,
15+ NotaryResponseBody ,
1516 } ,
1617 manifest:: Manifest ,
1718 proof:: { TeeProof , TeeProofData } ,
@@ -57,7 +58,12 @@ pub async fn proxy(
5758 let response = from_reqwest_response ( reqwest_response) . await ;
5859 // debug!("{:?}", response);
5960
61+ if !response. matches_client_manifest ( & payload. manifest . response ) {
62+ return Err ( NotaryServerError :: ManifestResponseMismatch ) ;
63+ }
64+
6065 let tee_proof = create_tee_proof ( & payload. manifest , & request, & response, State ( state) ) ?;
66+ debug ! ( "{:?}" , tee_proof) ;
6167
6268 Ok ( Json ( tee_proof) )
6369}
@@ -122,8 +128,9 @@ pub fn create_tee_proof(
122128 State ( state) : State < Arc < SharedState > > ,
123129) -> Result < TeeProof , NotaryServerError > {
124130 validate_notarization_legal ( manifest, request, response) ?;
125-
126- let value = response. notary_response_body . clone ( ) . json . unwrap ( ) ;
131+ let path = manifest. response . body . json_path . clone ( ) ;
132+ let body = response. notary_response_body . clone ( ) . json . unwrap ( ) ;
133+ let value = get_value_from_json_path ( & body, & path) ;
127134 let serialized_value = serde_json:: to_string ( & value) . unwrap ( ) ;
128135 let manifest_hash = manifest. to_keccak_digest ( ) ?;
129136 let to_sign = VerifyOutput { value : serialized_value. clone ( ) , manifest : manifest. clone ( ) } ;
@@ -149,3 +156,61 @@ fn validate_notarization_legal(
149156 }
150157 Ok ( ( ) )
151158}
159+
160+ fn get_value_from_json_path ( json_body : & Value , path : & [ JsonKey ] ) -> Value {
161+ let mut current = json_body;
162+ for key in path {
163+ current = match key {
164+ JsonKey :: String ( s) => current. get ( s) ,
165+ JsonKey :: Num ( n) => current. get ( n) ,
166+ }
167+ . unwrap ( ) ;
168+ }
169+ current. clone ( )
170+ }
171+
172+ #[ test]
173+ fn test_get_value_from_json_path ( ) {
174+ let json_body = json ! ( {
175+ "foo" : {
176+ "bar" : "baz"
177+ }
178+ } ) ;
179+ let path = vec ! [ JsonKey :: String ( "foo" . to_string( ) ) , JsonKey :: String ( "bar" . to_string( ) ) ] ;
180+ let value = get_value_from_json_path ( & json_body, & path) . unwrap ( ) ;
181+ assert_eq ! ( value, "baz" ) ;
182+ }
183+
184+ #[ test]
185+ fn test_get_value_from_json_path_num ( ) {
186+ let json_body = json ! ( {
187+ "foo" : [ 1 , 2 , 3 ]
188+ } ) ;
189+ let path = vec ! [ JsonKey :: String ( "foo" . to_string( ) ) , JsonKey :: Num ( 1 ) ] ;
190+ let value = get_value_from_json_path ( & json_body, & path) . unwrap ( ) ;
191+ assert_eq ! ( value, 2 ) ;
192+ }
193+
194+ #[ test]
195+ fn test_get_value_from_json_path_bool ( ) {
196+ let json_body = json ! ( {
197+ "foo" : {
198+ "bar" : true
199+ }
200+ } ) ;
201+ let path = vec ! [ JsonKey :: String ( "foo" . to_string( ) ) , JsonKey :: String ( "bar" . to_string( ) ) ] ;
202+ let value = get_value_from_json_path ( & json_body, & path) . unwrap ( ) ;
203+ assert_eq ! ( value, true ) ;
204+ }
205+
206+ #[ test]
207+ fn test_get_value_from_json_path_null ( ) {
208+ let json_body = json ! ( {
209+ "foo" : {
210+ "bar" : null
211+ }
212+ } ) ;
213+ let path = vec ! [ JsonKey :: String ( "foo" . to_string( ) ) , JsonKey :: String ( "bar" . to_string( ) ) ] ;
214+ let value = get_value_from_json_path ( & json_body, & path) . unwrap ( ) ;
215+ assert_eq ! ( value, Value :: Null ) ;
216+ }
0 commit comments