Skip to content

Commit 8ee8c4b

Browse files
committed
Enable building on Unix and Windows
The Linux limitation is somewhat artificial. The only platform-specific parts of the module are dynamic linking and loading of the OpenSSL library, and the OpenSSL 1.0.2 threading callbacks. The implementations of both are already portable to any Unix-like OS as dlfcn.h and pthreads are part of the POSIX standard. The only issue with the dynamic loader implementation is that it assumes the naming convention for the library shared object is "libcrypto.so.<version>" which limits support for darwin and other platforms which follow a different convention. Change openssl.Init() and openssl.CheckVersion() to take the library file name as its argument to make the bindings agnostic to the target platform's library file naming convention. Widen the build constraints to allow the module with the dlopen()-based loader to be built on any OS which satisfies the "unix" Go build constraint. Windows's dynamic library loader API is shaped very similarly to POSIX's, aside from the function names. Add support for Windows by adding Windows implementations for linking and loading the OpenSSL library, and the threading callbacks. Signed-off-by: Cory Snider <[email protected]>
1 parent 758238f commit 8ee8c4b

32 files changed

+159
-73
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ This feature does not require any additional configuration, but it only works wi
5050

5151
## Limitations
5252

53-
OpenSSL is used for a given build only in limited circumstances:
54-
55-
- The platform must be `GOOS=linux`.
53+
- Only Unix, Unix-like and Windows platforms are supported.
5654
- The build must set `CGO_ENABLED=1`.
5755

5856
## Acknowledgements

aes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

aes_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package openssl
42

53
import (

ec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

ecdh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

ecdh_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package openssl_test
42

53
import (

ecdsa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

ecdsa_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package openssl_test
42

53
import (

evp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

goopenssl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
//go:build linux
1+
//go:build unix || windows
22

33
#include "goopenssl.h"
44

5-
#include <dlfcn.h> // dlsym
5+
#ifdef _WIN32
6+
# include <windows.h>
7+
# define dlsym (void*)GetProcAddress
8+
#else
9+
# include <dlfcn.h> // dlsym
10+
#endif
611
#include <stdio.h> // fprintf
712

813
// Approach taken from .Net System.Security.Cryptography.Native

0 commit comments

Comments
 (0)