mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* add DateTime sans mgo * change all uses of strfmt.DateTime to common.DateTime, remove test strfmt usage * remove api tests, system-test dep on api test multiple reasons to remove the api tests: * awkward dependency with fn_go meant generating bindings on a branched fn to vendor those to test new stuff. this is at a minimum not at all intuitive, worth it, nor a fun way to spend the finite amount of time we have to live. * api tests only tested a subset of functionality that the server/ api tests already test, and we risk having tests where one tests some thing and the other doesn't. let's not. we have too many test suites as it is, and these pretty much only test that we updated the fn_go bindings, which is actually a hassle as noted above and the cli will pretty quickly figure out anyway. * fn_go relies on openapi, which relies on mgo, which is deprecated and we'd like to remove as a dependency. openapi is a _huge_ dep built in a NIH fashion, that cannot simply remove the mgo dep as users may be using it. we've now stolen their date time and otherwise killed usage of it in fn core, for fn_go it still exists but that's less of a problem. * update deps removals: * easyjson * mgo * go-openapi * mapstructure * fn_go * purell * go-validator also, had to lock docker. we shouldn't use docker on master anyway, they strongly advise against that. had no luck with latest version rev, so i locked it to what we were using before. until next time. the rest is just playing dep roulette, those end up removing a ton tho * fix exec test to work * account for john le cache
121 lines
4.0 KiB
Go
121 lines
4.0 KiB
Go
// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>.
|
|
//
|
|
// Use of this source code is governed by an MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package sqlite3
|
|
|
|
import (
|
|
"crypto/sha1"
|
|
"crypto/sha256"
|
|
"crypto/sha512"
|
|
)
|
|
|
|
// This file provides several different implementations for the
|
|
// default embedded sqlite_crypt function.
|
|
// This function is uses a ceasar-cypher by default
|
|
// and is used within the UserAuthentication module to encode
|
|
// the password.
|
|
//
|
|
// The provided functions can be used as an overload to the sqlite_crypt
|
|
// function through the use of the RegisterFunc on the connection.
|
|
//
|
|
// Because the functions can serv a purpose to an end-user
|
|
// without using the UserAuthentication module
|
|
// the functions are default compiled in.
|
|
//
|
|
// From SQLITE3 - user-auth.txt
|
|
// The sqlite_user.pw field is encoded by a built-in SQL function
|
|
// "sqlite_crypt(X,Y)". The two arguments are both BLOBs. The first argument
|
|
// is the plaintext password supplied to the sqlite3_user_authenticate()
|
|
// interface. The second argument is the sqlite_user.pw value and is supplied
|
|
// so that the function can extract the "salt" used by the password encoder.
|
|
// The result of sqlite_crypt(X,Y) is another blob which is the value that
|
|
// ends up being stored in sqlite_user.pw. To verify credentials X supplied
|
|
// by the sqlite3_user_authenticate() routine, SQLite runs:
|
|
//
|
|
// sqlite_user.pw == sqlite_crypt(X, sqlite_user.pw)
|
|
//
|
|
// To compute an appropriate sqlite_user.pw value from a new or modified
|
|
// password X, sqlite_crypt(X,NULL) is run. A new random salt is selected
|
|
// when the second argument is NULL.
|
|
//
|
|
// The built-in version of of sqlite_crypt() uses a simple Ceasar-cypher
|
|
// which prevents passwords from being revealed by searching the raw database
|
|
// for ASCII text, but is otherwise trivally broken. For better password
|
|
// security, the database should be encrypted using the SQLite Encryption
|
|
// Extension or similar technology. Or, the application can use the
|
|
// sqlite3_create_function() interface to provide an alternative
|
|
// implementation of sqlite_crypt() that computes a stronger password hash,
|
|
// perhaps using a cryptographic hash function like SHA1.
|
|
|
|
// CryptEncoderSHA1 encodes a password with SHA1
|
|
func CryptEncoderSHA1(pass []byte, hash interface{}) []byte {
|
|
h := sha1.Sum(pass)
|
|
return h[:]
|
|
}
|
|
|
|
// CryptEncoderSSHA1 encodes a password with SHA1 with the
|
|
// configured salt.
|
|
func CryptEncoderSSHA1(salt string) func(pass []byte, hash interface{}) []byte {
|
|
return func(pass []byte, hash interface{}) []byte {
|
|
s := []byte(salt)
|
|
p := append(pass, s...)
|
|
h := sha1.Sum(p)
|
|
return h[:]
|
|
}
|
|
}
|
|
|
|
// CryptEncoderSHA256 encodes a password with SHA256
|
|
func CryptEncoderSHA256(pass []byte, hash interface{}) []byte {
|
|
h := sha256.Sum256(pass)
|
|
return h[:]
|
|
}
|
|
|
|
// CryptEncoderSSHA256 encodes a password with SHA256
|
|
// with the configured salt
|
|
func CryptEncoderSSHA256(salt string) func(pass []byte, hash interface{}) []byte {
|
|
return func(pass []byte, hash interface{}) []byte {
|
|
s := []byte(salt)
|
|
p := append(pass, s...)
|
|
h := sha256.Sum256(p)
|
|
return h[:]
|
|
}
|
|
}
|
|
|
|
// CryptEncoderSHA384 encodes a password with SHA256
|
|
func CryptEncoderSHA384(pass []byte, hash interface{}) []byte {
|
|
h := sha512.Sum384(pass)
|
|
return h[:]
|
|
}
|
|
|
|
// CryptEncoderSSHA384 encodes a password with SHA256
|
|
// with the configured salt
|
|
func CryptEncoderSSHA384(salt string) func(pass []byte, hash interface{}) []byte {
|
|
return func(pass []byte, hash interface{}) []byte {
|
|
s := []byte(salt)
|
|
p := append(pass, s...)
|
|
h := sha512.Sum384(p)
|
|
return h[:]
|
|
}
|
|
}
|
|
|
|
// CryptEncoderSHA512 encodes a password with SHA256
|
|
func CryptEncoderSHA512(pass []byte, hash interface{}) []byte {
|
|
h := sha512.Sum512(pass)
|
|
return h[:]
|
|
}
|
|
|
|
// CryptEncoderSSHA512 encodes a password with SHA256
|
|
// with the configured salt
|
|
func CryptEncoderSSHA512(salt string) func(pass []byte, hash interface{}) []byte {
|
|
return func(pass []byte, hash interface{}) []byte {
|
|
s := []byte(salt)
|
|
p := append(pass, s...)
|
|
h := sha512.Sum512(p)
|
|
return h[:]
|
|
}
|
|
}
|
|
|
|
// EOF
|