Skip to content

Commit 2a27827

Browse files
committed
test: fix
1 parent 7eceb21 commit 2a27827

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

agent-control/src/opamp/remote_config/validators/signature/public_key_fetcher.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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

agent-control/src/opamp/remote_config/validators/signature/validator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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"),

agent-control/tests/common/opamp.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)