1
0
Fork 0

해시함수 제작중

This commit is contained in:
tom.cat 2016-03-14 20:03:39 +09:00
parent ecefc619e4
commit c21ca252a3
2 changed files with 49 additions and 2 deletions

View File

@ -92,7 +92,7 @@ func main() {
graceful.Run(":8080", 10*time.Second, r)
util.Log().Error("byez")
util.Log().Error("bye!")
}
func setMaxProcs() {

View File

@ -2,11 +2,52 @@
package util
import (
"crypto/rand"
"crypto/sha1"
"encoding/base64"
"fmt"
"strings"
"github.com/nmcclain/ldap"
)
type pwdStor string
func (p pwdStor) GetSaltedSha1() string {
source := strings.TrimSpace(string(p))
Log().Errorf("source %s", source)
var err error
salt := make([]byte, 4)
_, err = rand.Read(salt)
if err != nil {
panic(err)
}
hasher := sha1.New()
hasher.Write([]byte(source))
if err != nil {
panic(err)
}
hasher.Write(salt)
if err != nil {
panic(err)
}
encoded := base64.StdEncoding.EncodeToString(append(hasher.Sum(nil), salt...))
tag := "{SSHA}"
formatted := tag + encoded
Log().Errorf("sha1 %s", formatted)
return formatted
}
type ldapUnit struct {
dn string
filter string
@ -23,12 +64,14 @@ type ldapSource struct {
type AccountSource interface {
Connect()
Bind(uid string, password pwdStor)
Search()
Close()
}
//ldapSourceBool
func (l *ldapSource) Connect() {
l.Bind("test", "testpw")
addr := fmt.Sprintf("%s:%d", l.host, l.port)
conn, err := ldap.DialTLS("tcp", addr, nil)
if err == nil {
@ -56,7 +99,7 @@ func (l ldapSource) Search() {
nil,
nil)
searchResults, err := l.connection.Search(search)
// be sure to add error checking!
if err == nil {
for _, v := range searchResults.Entries {
@ -72,6 +115,10 @@ func (l ldapSource) Search() {
}
}
func (l ldapSource) Bind(uid string, password pwdStor) {
password.GetSaltedSha1()
}
func NewAccoauntSource() AccountSource {
user := ldapUnit{
dn: "ou=User,dc=amuz,dc=es",