amoghe / go-crypt Goto Github PK
View Code? Open in Web Editor NEWGolang wrappers for glibc crypt(3)
License: MIT License
Golang wrappers for glibc crypt(3)
License: MIT License
For compiling this on Ubuntu 19.10 you must include a new include
#include <stdlib.h>
According to the docs:
Any C function (even void functions) may be called in a multiple assignment context to retrieve both the return value (if any) and the C
errno
variable as an error
But crypt()
does not set errno
, and the call to C.crypt()
is building a error
variable with a value of some other call. If errno
is not 0, then err
is not nil
. Both
https://github.com/amoghe/go-crypt/blob/master/crypt.go#L41
and
https://github.com/amoghe/go-crypt/blob/master/crypt.go#L48
are returning an unrelated value.
So this code might or might fail:
password, err := Crypt(password, salt)
if err != nil {
// TODO: oh no!
log.Printf("crypt: [%v] %v", password, err)
return err
}
Like this:
2019/11/12 05:56:42 $6$iq.dbF2KUB2h, x
2019/11/12 05:56:42 crypt: [$6$iq.dbF2KUB2h$nV.xPcJUqHN1r46FQ/MJJc7OVbSb5Yd4nsOLU.XZ3QsVdwgGjqVoNeEx.u8MIFC1seQcS8jAelI95Z8BlBmeC/] errno -8191
Trying to build with the musl libc variant e.g. on Alpine Linux fails, due to some glibc specific code in the version test:
# github.com/amoghe/go-crypt
./version.go:6:10: fatal error: gnu/libc-version.h: No such file or directory
6 | #include <gnu/libc-version.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
I want to run this program on old linux operating systems.
I got this error: /lib/x86_64-linux-gnu/libcrypt.so.1: version `XCRYPT_2.0' not found
is it possible to link this library in the binary so that i can run it without libcrypt.so
Running the tests on a recent build of openSUSE Tumbleweed gives me this:
src/go-crypt> go test
--- FAIL: TestCryptErrors (0.00s)
crypt_test.go:64: Expected error when testing no salt, instead got *0
crypt_test.go:64: Expected error when testing single char, instead got *0
crypt_test.go:64: Expected error when testing first char bad, instead got *0
crypt_test.go:64: Expected error when testing second char bad, instead got *0
crypt_test.go:64: Expected error when testing both chars bad, instead got *0
crypt_test.go:64: Expected error when testing un$upported algorithm, instead got *0
crypt_test.go:64: Expected error when testing unsupported_algorithm, instead got *0
FAIL
exit status 1
FAIL github.com/amoghe/go-crypt 0.860s
This might be related to the fact that many recent distros have switched away from glibc's implementation of crypt() to e.g. libxcrypt which supports a broader set of password hashes. Apparently the behaviour in case of errors is slightly different in some cases. From the crypt man-page:
Upon error, crypt_r, crypt_rn, and crypt_ra write an invalid hashed passphrase to the output field of their data argument, and crypt writes an invalid hash to its static storage area. This string will be shorter than 13 characters, will begin with a ‘*’, and will not compare equal to setting.
The current code in go-crypt does not check for that type of error condition.
Hi,
can go-crypt support yescript algorithm?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.