Skip to content

Commit

Permalink
fixed issue where go/C pointer sharing rules were being violated (go …
Browse files Browse the repository at this point in the history
…1.6+).
  • Loading branch information
jb0n committed Sep 3, 2016
1 parent 9934c10 commit e018055
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions ctx.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ static long SSL_CTX_set_tlsext_servername_callback_not_a_macro(SSL_CTX* ctx, voi
return SSL_CTX_set_tlsext_servername_callback(ctx, fp);
}
typedef struct TlsServernameData {
typedef struct TlsExtData {
void *go_ctx;
SSL_CTX *ctx;
void *arg;
} TlsServernameData;
} TlsExtData;
extern int callServerNameCb(SSL* ssl, int ad, void* arg);
extern int callServernameCb(SSL* ssl, int ad, void* arg);
static int call_go_servername(SSL* ssl, int ad, void* arg) {
return callServerNameCb(ssl, ad, arg);
return callServernameCb(ssl, ad, arg);
}
static int servername_gateway(TlsServernameData* cw) {
static int servername_gateway(TlsExtData* cw) {
SSL_CTX* ctx = cw->ctx;
//TODO: figure out what to do with return codes. The first isn't 0
SSL_CTX_set_tlsext_servername_callback(ctx, call_go_servername);
SSL_CTX_set_tlsext_servername_arg(ctx, cw);
SSL_CTX_set_tlsext_servername_arg(ctx, cw.arg);
return 0;
}
Expand Down Expand Up @@ -141,13 +141,13 @@ var (
)

type Ctx struct {
ctx *C.SSL_CTX
cert *Certificate
chain []*Certificate
key PrivateKey
verify_cb VerifyCallback
servername_cb ServerNameCallback
ted C.TlsServernameData
ctx *C.SSL_CTX
cert *Certificate
chain []*Certificate
key PrivateKey
verify_cb VerifyCallback
//servername_cb ServerNameCallback
servername_cb func(ssl Conn, ad int, arg unsafe.Pointer) int
}

//export get_ssl_ctx_idx
Expand Down Expand Up @@ -634,11 +634,11 @@ func (c *Ctx) SessGetCacheSize() int {

// Set SSL_CTX_set_tlsext_servername_callback
// https://www.openssl.org/docs/manmaster/ssl/???
type ServerNameCallback func(ssl Conn, ad int, arg unsafe.Pointer) int
//type ServerNameCallback func(ssl *C.SSL, ad C.int, arg unsafe.Pointer) int

//export callServerNameCb
func callServerNameCb(ssl *C.SSL, ad C.int, arg unsafe.Pointer) C.int {
var ted *C.TlsServernameData = (*C.TlsServernameData)(arg)
//export callServernameCb
func callServernameCb(ssl *C.SSL, ad C.int, arg unsafe.Pointer) C.int {
var ted *C.TlsExtData = (*C.TlsExtData)(arg)
goCtx := (*Ctx)(ted.go_ctx)

//setup a dummy Conn so we can associate a SSL_CTX from user callback
Expand All @@ -650,13 +650,13 @@ func callServerNameCb(ssl *C.SSL, ad C.int, arg unsafe.Pointer) C.int {
return C.int(ret)
}

func (c *Ctx) SetTlsExtServerNameCallback(cb func(ssl Conn, ad int, arg unsafe.Pointer) int,
arg unsafe.Pointer) int {
//func (c *Ctx) SetTlsExtServerNameCallback(cb ServerNameCallback) int {
func (c *Ctx) SetTlsExtServerNameCallback(cb func(ssl Conn, ad int, arg unsafe.Pointer) int, arg unsafe.Pointer) int {
c.servername_cb = cb
c.ted = C.TlsServernameData{
cw := C.TlsExtData{
go_ctx: unsafe.Pointer(c),
ctx: c.ctx,
arg: arg,
}
return int(C.servername_gateway(&c.ted))
return int(C.servername_gateway(&cw))
}

0 comments on commit e018055

Please sign in to comment.