Skip to content

Commit

Permalink
space monkey internal commit export
Browse files Browse the repository at this point in the history
[katamari commit: 1f7b029c86f864c2bb38fbd916b99202c8793066]
  • Loading branch information
Jeff Wendling authored and jtolio committed Jan 21, 2014
1 parent bf87572 commit f9ae27d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
29 changes: 23 additions & 6 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ package openssl
// return SSL_CTX_set_session_cache_mode(ctx, modes);
// }
//
// #ifndef SSL_MODE_RELEASE_BUFFERS
// #define SSL_MODE_RELEASE_BUFFERS 0
// #endif
// #ifndef SSL_OP_NO_COMPRESSION
// #define SSL_OP_NO_COMPRESSION 0
// #endif
// #ifndef TLSv1_1_method
// const SSL_METHOD *TLSv1_1_method() { return NULL; }
// #endif
// #ifndef TLSv1_2_method
// const SSL_METHOD *TLSv1_2_method() { return NULL; }
// #endif
import "C"

import (
Expand Down Expand Up @@ -58,20 +70,23 @@ const (
// NewCtxWithVersion creates an SSL context that is specific to the provided
// SSL version. See http://www.openssl.org/docs/ssl/SSL_CTX_new.html for more.
func NewCtxWithVersion(version SSLVersion) (*Ctx, error) {
var method *C.SSL_METHOD
switch version {
case SSLv3:
return newCtx(C.SSLv3_method())
method = C.SSLv3_method()
case TLSv1:
return newCtx(C.TLSv1_method())
method = C.TLSv1_method()
case TLSv1_1:
return newCtx(C.TLSv1_1_method())
method = C.TLSv1_1_method()
case TLSv1_2:
return newCtx(C.TLSv1_2_method())
method = C.TLSv1_2_method()
case AnyVersion:
return newCtx(C.SSLv23_method())
default:
method = C.SSLv23_method()
}
if method == nil {
return nil, errors.New("unknown ssl/tls version")
}
return newCtx(method)
}

// NewCtx creates a context that supports any TLS version 1.0 and newer.
Expand Down Expand Up @@ -197,6 +212,7 @@ func (c *Ctx) LoadVerifyLocations(ca_file string, ca_path string) error {
type Options int

const (
// NoCompression is only valid if you are using OpenSSL 1.0.1 or newer
NoCompression Options = C.SSL_OP_NO_COMPRESSION
NoSSLv2 Options = C.SSL_OP_NO_SSLv2
NoSSLv3 Options = C.SSL_OP_NO_SSLv3
Expand All @@ -216,6 +232,7 @@ func (c *Ctx) SetOptions(options Options) Options {
type Modes int

const (
// ReleaseBuffers is only valid if you are using OpenSSL 1.0.1 or newer
ReleaseBuffers Modes = C.SSL_MODE_RELEASE_BUFFERS
)

Expand Down
8 changes: 4 additions & 4 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ package openssl
#include <openssl/evp.h>
#include <openssl/engine.h>
extern void sslThreadId(CRYPTO_THREADID *id);
extern unsigned long sslThreadId();
extern void sslMutexOp(int mode, int n, char *file, int line);
static void OpenSSL_add_all_algorithms_not_a_macro() {
Expand Down Expand Up @@ -87,7 +87,7 @@ func init() {
C.SSL_library_init()
C.OpenSSL_add_all_algorithms_not_a_macro()
sslMutexes = make([]sync.Mutex, int(C.CRYPTO_num_locks()))
C.CRYPTO_THREADID_set_callback((*[0]byte)(C.sslThreadId))
C.CRYPTO_set_id_callback((*[0]byte)(C.sslThreadId))
C.CRYPTO_set_locking_callback((*[0]byte)(C.sslMutexOp))

// TODO: support dynlock callbacks
Expand Down Expand Up @@ -120,6 +120,6 @@ func sslMutexOp(mode, n C.int, file *C.char, line C.int) {
}

//export sslThreadId
func sslThreadId(id *C.CRYPTO_THREADID) {
C.CRYPTO_THREADID_set_pointer(id, utils.ThreadId())
func sslThreadId() C.ulong {
return C.ulong(uintptr(utils.ThreadId()))
}

0 comments on commit f9ae27d

Please sign in to comment.