File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
src/opamp/remote_config/validators/signature Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,13 @@ pub mod tests {
131131 }
132132 }
133133 pub fn sign ( & self , msg : & [ u8 ] ) -> String {
134- BASE64_STANDARD . encode ( self . key_pair . sign ( msg) . as_ref ( ) )
134+ // Actual implementation from FC side signs the Base64 representation of the SHA256 digest
135+ // of the message (i.e. the remote configs). Hence, to verify the signature, we need to
136+ // compute the SHA256 digest of the message, then Base64 encode it, and finally verify
137+ // the signature against that.
138+ let digest = ring:: digest:: digest ( & ring:: digest:: SHA256 , msg) ;
139+ let msg = BASE64_STANDARD . encode ( digest) ;
140+ BASE64_STANDARD . encode ( self . key_pair . sign ( msg. as_bytes ( ) ) . as_ref ( ) )
135141 }
136142 }
137143
Original file line number Diff line number Diff line change @@ -677,8 +677,14 @@ pub mod tests {
677677 ) ;
678678
679679 let config = "value" ;
680+ // Actual implementation from FC side signs the Base64 representation of the SHA256 digest
681+ // of the message (i.e. the remote configs). Hence, to verify the signature, we need to
682+ // compute the SHA256 digest of the message, then Base64 encode it, and finally verify
683+ // the signature against that.
684+ let digest = ring:: digest:: digest ( & ring:: digest:: SHA256 , config. as_bytes ( ) ) ;
685+ let msg = BASE64_STANDARD . encode ( digest) ;
680686
681- let encoded_signature = test_signer. encoded_signature ( config ) ;
687+ let encoded_signature = test_signer. encoded_signature ( & msg ) ;
682688 let remote_config = OpampRemoteConfig :: new (
683689 AgentID :: AgentControl ,
684690 Hash :: from ( "test" ) ,
Original file line number Diff line number Diff line change @@ -326,7 +326,14 @@ fn build_response(
326326 } ) ,
327327 } ) ;
328328
329- let signature = key_pair. sign ( config. raw_body . as_bytes ( ) ) ;
329+ // Actual implementation from FC side signs the Base64 representation of the SHA256 digest
330+ // of the message (i.e. the remote configs). Hence, to verify the signature, we need to
331+ // compute the SHA256 digest of the message, then Base64 encode it, and finally verify
332+ // the signature against that.
333+ let digest = ring:: digest:: digest ( & ring:: digest:: SHA256 , config. raw_body . as_bytes ( ) ) ;
334+ let msg = BASE64_STANDARD . encode ( digest) ;
335+
336+ let signature = key_pair. sign ( msg. as_bytes ( ) ) ;
330337
331338 let custom_message_data = HashMap :: from ( [ (
332339 "fakeCRC" . to_string ( ) , //AC is not using the CRC.
You can’t perform that action at this time.
0 commit comments