martinthomson / ohttp

Rust library for encapsulating HTTP messages in a cryptographic wrapper
Apache License 2.0
30 stars 23 forks source link

ohttp-client config deserialization fails for hpke build #52

Closed DanGould closed 1 year ago

DanGould commented 1 year ago

In testing how OHTTP applies to an application I'm working on I came across this implementation but have had no luck getting a client-server connection yet. Tests pass on main (fc3f4c7) and tag v0.4.0, ohttp-sever runs properly, but ohttp-client fails following the readme with the following:

Running `target/debug/ohttp-client --trust ./ohttp-server/ca.crt 'https://localhost:9443/' -i ./examples/request.txt 
000020b5054ad7410f396e55650af612fb54d4d6b9958181fe54a12bfc6f2d8fea571800080001000100010003
Error: Io(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" })

I've tracked this down to an issue with the following line in decode_list, specifically usize::from(r.read_u16::<NetworkEndian>()?); always seems to evaluate to 0 in the following lines.

https://github.com/martinthomson/ohttp/blob/fc3f4c787d1f6a6a87bf5194f7152cc906b02973/ohttp/src/lib.rs#L243-L252

@notmandatory was also able to replicate

I'm running rust version cargo 1.70.0 (ec8a8a0ca 2023-04-25) on intel macOS 13.4.1

martinthomson commented 1 year ago

I see what is going on here. The server prints a single item, where it should be printing a list. Your pull request goes the other way, which isn't really what was intended. Give me a few minutes.

martinthomson commented 1 year ago

OK, the refactoring took a little longer than I might have liked, but it should be fixed now.

DanGould commented 1 year ago

Tested as fixed. Parsing a list does seem to be in more of a spirit of OHTTP so the fix makes sense to me. Thank you.