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

Check for close_notify message in Base.isopen(ctx::SSLContext) #145

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion src/ssl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,33 @@ function Base.close(ctx::SSLContext)
nothing
end

Base.isopen(ctx::SSLContext) = ctx.isopen && isopen(ctx.bio)
function Base.isopen(ctx::SSLContext)

if !ctx.isopen || !isopen(ctx.bio)
return false
end

if bytesavailable(ctx.bio) == 0
# Ensure that libuv is processing data from this socket in case the peer
# has sent a close_notify message on an otherwise idle connection.
# https://tools.ietf.org/html/rfc5246#section-7.2.1
Base.start_reading(ctx.bio)
yield()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isopen isn't typically a yield-point. Should use Base.process_events(false) instead

end

# Zero-byte read causes MbedTLS to process buffered data
# (which may include a close_notify message).
@lockdata ctx begin
n = ccall((:mbedtls_ssl_read, libmbedtls), Cint,
(Ptr{Cvoid}, Ptr{Cvoid}, Csize_t),
ctx.data, C_NULL, 0)
if n == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY
ctx.isopen = false
end
end

return ctx.isopen && isopen(ctx.bio)
end

function get_peer_cert(ctx::SSLContext)
data = ccall((:mbedtls_ssl_get_peer_cert, libmbedtls), Ptr{Cvoid}, (Ptr{Cvoid},), ctx.data)
Expand Down