I rely on SSL_peek() to look at the first three bytes of the
decrypted data stream. Unfortunately, if the BIO_read it triggers
doesn't return a full load, it seems to lose its mind, and returns
bytes from the undecrypted datastream. I can demonstrate things working
properly in a test program when I have it send a certain amount of
data, and failing when I have it send a bit more.
I bet SSL_peek() is rarely used, so it hasn't had as much debugging
as SSL_read. And indeed, comparing ssl3_read() to ssl3_peek(),
it rather looks like ssl3_peek is suffering from the same bug
that ssl3_read has an elaborate workaround to. Can someone
who understands the code have a look, and see if they agree?
If it makes any difference, I'm using openssl-0.9.6 on
Red Hat Linux 6.2, and compiled from source. I bet this
bug's been around a while, though.
Thanks,
Dan
[EMAIL PROTECTED]
p.s. Here's an excerpt from my logs showing the bytes read by my
custom BIO in response to SSL_peek. First a run that worked,
then a slightly longer run that failed. The program is a server
that autodetects whether HTTP and/or SSL encapsulation is in use.
I have added some notes to the second log to point out the
interesting bits.
::::::::::::::
log.32 (works)
::::::::::::::
SSLConnection.cc:112: peek(0xbf5ffce8, 3,): entry
DI_BIO.cc: 92: di_read: read 5/5 '17 03 00 00 60'
DI_BIO.cc: 92: di_read: read 96/96 'ae 9e d5 1d 8e 4d ad ae 85 b9 2b 4f 60
cf bc c3 ...'
SSLConnection.cc:116: peek(0xbf5ffce8, 3,): got 'POS' 3/3
DIKServerPipe.cc:132: handle_io: peeked '50 4f 53'
DIKServerPipe.cc:142: handle_io: detected HTTP, setting top to m_hts
SSLConnection.cc:112: peek(0xbf5ffce8, 3,): entry
DI_BIO.cc: 92: di_read: read 5/5 '17 03 00 07 60'
DI_BIO.cc: 92: di_read: read 1888/1888 '48 05 bb 01 5c 59 94 ac e3 0f 3b db
47 67 15 b2 ...'
SSLConnection.cc:116: peek(0xbf5ffce8, 3,): got 'DIK' 3/3
HTTPTunnelServer.cc:327: peek: err 0 nread 3 'DIK'
DIKServerPipe.cc:132: handle_io: peeked '44 49 4b'
DIKServerPipe.cc:135: handle_io: detected DIKP, setting top to m_linebuf
::::::::::::::
log.33 (slightly more data; fails)
::::::::::::::
SSLConnection.cc:112: peek(0xbf5ffce8, 3,): entry
DI_BIO.cc: 92: di_read: read 5/5 '17 03 00 00 60'
DI_BIO.cc: 92: di_read: read 96/96 '52 28 ee 72 cc 57 04 a4 db 81 49 fb 34
88 99 59 ...'
SSLConnection.cc:116: peek(0xbf5ffce8, 3,): got 'POS' 3/3
DIKServerPipe.cc:132: handle_io: peeked '50 4f 53'
DIKServerPipe.cc:142: handle_io: detected HTTP, setting top to m_hts
SSLConnection.cc:112: peek(0xbf5ffce8, 3,): entry
DI_BIO.cc: 92: di_read: read 5/5 '17 03 00 07 98'
DI_BIO.cc: 92: di_read: read 1019/1944 'a0 4b 56 c4 c0 a5 a1 a2 8b 79 30 cd
26 69 4d 3b ...'
*** ^^^^
*** Note partial read
SSLConnection.cc:112: peek(0xbf5ffce8, 3,): entry
SSLConnection.cc:116: peek(0xbf5ffce8, 3,): got 'a0 4b 56' 3/3
*** ^^^^^^^^
*** Note that peek returns first three bytes from INPUT to ssl,
not OUTPUT!
HTTPTunnelServer.cc:327: peek: err 0 nread 3 'a0 4b 56'
DIKServerPipe.cc:132: handle_io: peeked 'a0 4b 56'
DIKServerPipe.cc:172: handle_io: first 3 bytes unrecognized 'a0 4b 56', returning
EPIPE
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]