blacknon / go-sshlib

easy ssh library for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static Build Pass with CGO Disabled

bobbaker6667 opened this issue · comments

Hi,

I'm wondering if it would be a good idea for the project to work towards being able to be built as a fully static binary?
I want to use this library in a project that I've been working on, (Static builds are prerequisite) but found that if you try to build with CGO_ENABLED=0
As is required to have a fully static binary and not depend on any of the systems C libraries it all seems to go OK until it
attempts to compile the following libraries with CGO disabled:

`# github.com/miekg/pkcs11/p11
vendor/github.com/miekg/pkcs11/p11/crypto.go:18:42: undefined: pkcs11.Mechanism
vendor/github.com/miekg/pkcs11/p11/crypto.go:34:39: undefined: pkcs11.Mechanism
vendor/github.com/miekg/pkcs11/p11/crypto.go:50:39: undefined: pkcs11.Mechanism
vendor/github.com/miekg/pkcs11/p11/crypto.go:66:40: undefined: pkcs11.Mechanism
vendor/github.com/miekg/pkcs11/p11/module.go:103:7: undefined: pkcs11.Ctx
vendor/github.com/miekg/pkcs11/p11/module.go:107:25: undefined: pkcs11.Info
vendor/github.com/miekg/pkcs11/p11/object.go:21:15: undefined: pkcs11.ObjectHandle
vendor/github.com/miekg/pkcs11/p11/session.go:61:10: undefined: pkcs11.Ctx
vendor/github.com/miekg/pkcs11/p11/session.go:62:9: undefined: pkcs11.SessionHandle
vendor/github.com/miekg/pkcs11/p11/slot.go:7:7: undefined: pkcs11.Ctx
vendor/github.com/miekg/pkcs11/p11/slot.go:7:7: too many errors

github.com/ThalesIgnite/crypto11

vendor/github.com/ThalesIgnite/crypto11/aead.go:56:71: undefined: pkcs11.Mechanism
vendor/github.com/ThalesIgnite/crypto11/aead.go:56:90: undefined: pkcs11.GCMParams
vendor/github.com/ThalesIgnite/crypto11/attributes.go:15:18: undefined: pkcs11.Attribute
vendor/github.com/ThalesIgnite/crypto11/crypto11.go:127:9: undefined: pkcs11.ObjectHandle
vendor/github.com/ThalesIgnite/crypto11/crypto11.go:174:7: undefined: pkcs11.Ctx
vendor/github.com/ThalesIgnite/crypto11/crypto11.go:177:9: undefined: pkcs11.TokenInfo
vendor/github.com/ThalesIgnite/crypto11/crypto11.go:183:20: undefined: pkcs11.SessionHandle
`

If we were able to get it to build with CGO_ENABLED we would be able to increase the range of devices that would be able to run the library by a large margin,

What are your thoughts on above and do you think it could be ever feasible that this library would be able to be build with CGO_ENABLED=0?

Looking at the miekg/pkcs11/p11 library when someone enquired about issues staticly compiling the developer theirs response was to get the end user to dynamically compile the binary, In my eyes this isn't perfect as we should be working towards having a 100% golang ecosystem and to not be relying on dynamically linked C libraries to handle something as crucial as crypto would be a benefit to the project/library.

Any thoughts/Ideas, Happy to chip in where I can but didn't want to just start ripping code out to see if I could get it working without touching base as to how crucial the above two libraries/dependencies are to the main functionality of your library, what they provide, and then what would need to be replaced/rewritten to have a fully Golang library with no dynamically linked C dependencies

github.com/miekg/pkcs11 is a library required when using PKCS11 authentication (authentication using hardware tokens such as Yubikey).
Since pkcs11 will be a feature that I personally use, it is difficult to remove.

It would also be difficult to completely replace the library at github.com/miekg/pkcs11 with Go.

For this reason, we are considering not building pkcs11-related Functions when cgo is disabled as a temporary measure. I think that functions other than PKCS11 authentication can be used with this.