ipartola / hawkeye

An simple and fast USB webcam MJPEG streaming server.
Other
206 stars 28 forks source link

[proposed bug] SSL partial write causing distorted image #15

Open alwilson opened 6 years ago

alwilson commented 6 years ago

Important things first, setting up HTTPS and password protection worked like a charm and I have really enjoyed using this project. Thank you!

After enabling SSL I have noticed that grabbing stills at /still/# will now only show the first quarter or so of a 640x480 image (68-72 kB). I poked around and noticed that client_write with SSL enabled for the still images gets called 5 times maxing out at 16 kB per write, but when I disable SSL the still images get written out in a single client_write. Looking at corrupted JPEG I see what look like multiple headers (AVI1, which I believe is for MJPEG AVI?)

I haven't looked further in the source, but I take it that since OpenSSL is currently configured with SSL_MODE_ENABLE_PARTIAL_WRITE that client_write is getting broken down into 16 kB chunks and each time the server attempts to send the next chunk it starts at the beginning of a new frame. I have removed this mode on my server and now the stills come through just fine. I have noticed wget complaining about TLS not being closed correctly and I moved from TLSv1_2_server_method (deprecated) to TLS_server_method, but I don't believe those have affected this image corruption issue.

Anyways, it was fun digging into that. Now I've got to grab a i2c thermometer and add temp tracking/graphing to all of this!

ipartola commented 3 years ago

Just pushed a new version that uses latest TLS. If you are still around, let me know if you get the same bug with this and I'll dig in further.