Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix secret message parsing when message is plaintext in IBC #1199

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn get_resp_based_on_num(env: Env, num: u64) -> StdResult<IbcBasicResponse>
msg: CosmosMsg::Wasm(WasmMsg::Execute {
code_hash: env.contract.code_hash,
contract_addr: env.contract.address.into_string(),
msg: Binary::from("{\"increment\":{\"addition\":5}}".as_bytes().to_vec()),
msg: Binary::from("{\"increment\":{ \"addition\":5}}".as_bytes().to_vec()),
funds: vec![],
})
.into(),
Expand Down
15 changes: 13 additions & 2 deletions cosmwasm/enclaves/shared/contract-engine/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ pub fn parse_message(
base64::encode(&message)
);

let secret_msg = get_secret_msg(message);
let secret_msg = SecretMessage {
nonce: [0; 32],
user_public_key: [0; 32],
msg: message.into(),
};

let decrypted_msg = secret_msg.msg.clone();

Ok(ParsedMessage {
Expand Down Expand Up @@ -484,7 +489,7 @@ pub fn parse_message(
let tmp_secret_data =
get_secret_msg(parsed_encrypted_ibc_packet.packet.data.as_slice());
let mut was_msg_encrypted = false;
let orig_secret_msg = tmp_secret_data;
let mut orig_secret_msg = tmp_secret_data;

match orig_secret_msg.decrypt() {
Ok(decrypted_msg) => {
Expand All @@ -505,6 +510,12 @@ pub fn parse_message(
"ibc_packet_receive data was plaintext: {:?}",
base64::encode(&message)
);

orig_secret_msg = SecretMessage {
nonce: [0; 32],
user_public_key: [0; 32],
msg: message.into(),
};
}
}
Ok(ParsedMessage {
Expand Down
4 changes: 2 additions & 2 deletions x/compute/internal/keeper/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ func TestIBCPacketReceive(t *testing.T) {
},
} {
t.Run(fmt.Sprintf("%s-Encryption:%t", test.description, isEncrypted), func(t *testing.T) {
ibcPacket := createIBCPacket(createIBCEndpoint(PortIDForContract(contractAddress), "channel.1"),
createIBCEndpoint(PortIDForContract(contractAddress), "channel.0"),
ibcPacket := createIBCPacket(createIBCEndpoint(PortIDForContract(contractAddress), "channel.11231231231231232112312321321321331232132131232132131232"),
createIBCEndpoint(PortIDForContract(contractAddress), "channel.0123123213213123123213123123123123123312321321321312321313213"),
test.sequence,
createIBCTimeout(math.MaxUint64),
[]byte{},
Expand Down