ssl: support client mode
parent
33841887c0
commit
b1f27b143e
|
@ -13,6 +13,9 @@ SSL_CTX_new(method::Ptr{SSL_Method}) =
|
||||||
SSL_accept_state(client::SSLClient) =
|
SSL_accept_state(client::SSLClient) =
|
||||||
ccall((:SSL_set_accept_state, libssl), Ptr{Cvoid}, (Ptr{Cvoid},), client.ssl)
|
ccall((:SSL_set_accept_state, libssl), Ptr{Cvoid}, (Ptr{Cvoid},), client.ssl)
|
||||||
|
|
||||||
|
SSL_connect_state(client::SSLClient) =
|
||||||
|
ccall((:SSL_set_connect_state, libssl), Ptr{Cvoid}, (Ptr{Cvoid},), client.ssl)
|
||||||
|
|
||||||
ssl_init_finished(client::SSLClient) =
|
ssl_init_finished(client::SSLClient) =
|
||||||
ccall((:SSL_is_init_finished, libssl), Bool, (Ptr{Cvoid},), client.ssl)
|
ccall((:SSL_is_init_finished, libssl), Bool, (Ptr{Cvoid},), client.ssl)
|
||||||
|
|
||||||
|
|
13
src/types.jl
13
src/types.jl
|
@ -3,16 +3,23 @@ struct SSL_Method ptr end
|
||||||
struct BIO_Method ptr end
|
struct BIO_Method ptr end
|
||||||
struct SSL_Context ptr end
|
struct SSL_Context ptr end
|
||||||
|
|
||||||
|
@enum TLSMode begin
|
||||||
|
ClientMode
|
||||||
|
ServerMode
|
||||||
|
end
|
||||||
|
|
||||||
mutable struct SSLContext <: IO
|
mutable struct SSLContext <: IO
|
||||||
data::Vector{UInt8}
|
data::Vector{UInt8}
|
||||||
ptr::Ptr{SSL_Context}
|
ptr::Ptr{SSL_Context}
|
||||||
|
mode::TLSMode
|
||||||
"Construct the SSLContext object, initializing its relatvie SSL_Context
|
"Construct the SSLContext object, initializing its relatvie SSL_Context
|
||||||
pointer.
|
pointer.
|
||||||
|
|
||||||
Might throw ErrorException if the ccall fails"
|
Might throw ErrorException if the ccall fails"
|
||||||
function SSLContext(; method::Ptr{SSL_Method} = TLS_method())
|
function SSLContext(; mode::TLSMode = ClientMode)
|
||||||
ssl_context = new()
|
ssl_context = new()
|
||||||
|
ssl_context.mode = mode
|
||||||
|
method = mode == ServerMode ? TLS_server_method() : TLS_client_method()
|
||||||
ssl_context.ptr = SSL_CTX_new(method)
|
ssl_context.ptr = SSL_CTX_new(method)
|
||||||
if ssl_context.ptr == C_NULL
|
if ssl_context.ptr == C_NULL
|
||||||
# TODO: check error stack and report the right exception
|
# TODO: check error stack and report the right exception
|
||||||
|
@ -38,7 +45,7 @@ mutable struct SSLClient{T}
|
||||||
client.context = ctx
|
client.context = ctx
|
||||||
client.ssl = SSL_new(ctx)
|
client.ssl = SSL_new(ctx)
|
||||||
client.io_on_read = (data) -> append!(client.context.data, data)
|
client.io_on_read = (data) -> append!(client.context.data, data)
|
||||||
SSL_accept_state(client)
|
(ctx.mode == ServerMode ? SSL_accept_state : SSL_connect_state)(client)
|
||||||
set_bio!(client, bio_new(), bio_new())
|
set_bio!(client, bio_new(), bio_new())
|
||||||
client.write_buf = UInt8[]
|
client.write_buf = UInt8[]
|
||||||
client.encrypt_buf = UInt8[]
|
client.encrypt_buf = UInt8[]
|
||||||
|
|
Loading…
Reference in New Issue