Open vongohren opened 1 year ago
I believe what you are decrypting and seeing here is the "forward" message for the routing protocol. Your encryption is wrapping the message with 2 layers and you are unwrapping 1 layer and expecting to see the inner envelope. The "next" property in the body tells you to now send that message to that did
@brianorwhatever thanks for your suggestion, but im just following the demos. But based on what you say do you suggest that i send the unpacked message through the unpack again? Ref the attached image. This is SICPAs suggestion of what is common case: https://github.com/sicpa-dlab/didcomm-rust/blob/main/wasm/README.md#1-build-an-encrypted-didcomm-message-for-the-given-recipient. Very similar
This is the leading code in, meaning its not that much one can screw up
hmm yeah, and looking closer your did:peer doesn't have routingKeys in it as I had assumed. Not sure what else to suggest.. will need feedback from sicpa folks
@brianorwhatever yeah I was hoping I could avoid routing keys, as I dont see the need as of now? I will push hardman on discord and see if there is anything he can push
The problem at hand is that I expect to be able to read decrypted data when I unpack
Adding code so its easier to copy paste. But its really just the example code.
const to = "did:peer:2.Vz6MkhMTSwCfytUNmrEQ4We5i6B2ywM8hAcHvRDD293QGrqSS.Ez6LSm3LPosAtT2qUtFNU9Y2y9P9wQUfJjGgs98uchVJtZjfS.SeyJpZCI6IiNkaWRjb21tIiwidCI6ImRtIiwicyI6Imh0dHBzOi8vZGV2LW9wZW4tbWVzc2FnZXMtYXBpLWx0aDRnb3dkeXEtZXcuYS5ydW4uYXBwL21lc3NhZ2VzIiwiYSI6WyJkaWRjb21tL3YyIl19"
const from = "did:peer:2.Vz6MkkkhBpeffjdyRCpyv1h17ZH4fJ6amEu2cujuaBcf2bmor.Ez6LScPkBqUGgUnFdxEPviCBAhdeKrhrHidLCyrcjq6SdvSj6.SeyJpZCI6IiNkaWRjb21tIiwidCI6ImRtIiwicyI6Imh0dHBzOi8vZGV2LW9wZW4tbWVzc2FnZXMtYXBpLWx0aDRnb3dkeXEtZXcuYS5ydW4uYXBwL21lc3NhZ2VzIiwiYSI6WyJkaWRjb21tL3YyIl19"
const msg = new Message({
id: "1234567890",
typ: "application/didcomm-plain+json",
type: "http://example.com/protocols/lets_do_lunch/1.0/proposal",
from: from,
to: [to],
created_time: 1516269022,
expires_time: 1516385931,
body: { messagespecificattribute: "and its value" },
});
// This resolver just resolves as expected and modifys data objects to fit the code. Lots of transformations
const resolver = new DiwalaDIDResolver();
// This resolver just calls the nessecary methods and NRIS reads out the key values nessecary to do this secret action. It succeeds so I think it is not relevant.
const secrets_resolver = new DiwalaSecretsResolver(nris);
try {
const [encryptedMsg, encryptMetadata] = await msg.pack_encrypted(to,from,from,resolver, secrets_resolver, {})
console.log("Metadata of message", encryptMetadata)
console.log(`Sending message: ${encryptedMsg}`)
const [unpackedMsg, unpackMetadata] = await Message.unpack(
encryptedMsg,
resolver,
secrets_resolver,
{}
);
console.log("Reveived message is\n", JSON.stringify(unpackedMsg.as_value()));
console.log("Reveived message unpack metadata is\n", unpackMetadata);
} catch (error) {
console.log(error)
throw new Error('faild encryption and decryption')
}
Ok, so this is awkward. Its very easily solvable with adding an unpack option of
{unwrap_re_wrapping_forward: true}
This is default false according to their inline comments.
Adding this, I got the original plain text message and Im able to continue onwards.
It would be great with some clearer documentation, or tests around this so it is clear to how this works
I think I have discovered that this only happens on signed messages. I haven't yet been able to reproduce though as I can't successfully create a signed message. It throws Unsupported signature alg
which looks to be coming from here
@brianorwhatever i tried not to sign it, leaving the sign option to null. And it did not make a difference.
Your unsupported alg, i traversed as well. I dont remember what the solution was. I jsut know that I generate did:peer methods with the following logic:
Meaning im able to use the 2020 keys and sign and create. As you mention in #95.
But when it comes to unsupported alg, I needed to have a key that also had keyAgreement. Both sides of the message senders had to have key agreements og the right keytype.
Just important transformation for secrets to work
getSecretFormat(type: string) {
if(type='X25519KeyAgreementKey2020') return 'Multibase'
if(type='Ed25519VerificationKey2020') return 'Multibase'
if(type='JsonWebKey2020') return 'JWK'
throw new Error('Unsupported secret format');
}
getSecretValue(secret, format) {
const valueAttribute = formatMap[format]
const secretValue = secret[valueAttribute]
if(secretValue) return secretValue
throw new Error('Unsupported secret value')
}
findAndTransformSecret(secrets:DecryptedKMSObject, id: string, did: string) {
const thisSecret = secrets.keys.find(k=>k.keyId===`#${id}`)
const type = thisSecret.decrypted.type
const format = this.getSecretFormat(type)
const value = this.getSecretValue(thisSecret.decrypted, format)
const obj = {
id: `${did}#${id}`,
type: type,
secret_material: {
format,
value
}
}
return obj
}
What
When I receive a message that is encrypted, and run it through unpack with the right secrets and resolvers. I expect that I get an object I can work with that is decrypted and possible to read the datat itself.
But the object that is provided is an object with a ciphertext. Since I was not the one encrypting the initial ciphertext, I expect that the library will provide me with a way to get the clear text message out.
Here is an example of the
unpacked.as_value()
messageWhy
Because its not usable to actually consume the message itself that was sent.
The message below was the original message going through the
encrypt message
function. And I want to see that after I unpack with the right secrets.What am i missing?
Success Criteria
encrypt and pack a message, and un pack and decrypt the same message with the same library