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) graceful.Run(":8080", 10*time.Second, r)
util.Log().Error("byez") util.Log().Error("bye!")
} }
func setMaxProcs() { func setMaxProcs() {

View File

@ -2,11 +2,52 @@
package util package util
import ( import (
"crypto/rand"
"crypto/sha1"
"encoding/base64"
"fmt" "fmt"
"strings"
"github.com/nmcclain/ldap" "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 { type ldapUnit struct {
dn string dn string
filter string filter string
@ -23,12 +64,14 @@ type ldapSource struct {
type AccountSource interface { type AccountSource interface {
Connect() Connect()
Bind(uid string, password pwdStor)
Search() Search()
Close() Close()
} }
//ldapSourceBool //ldapSourceBool
func (l *ldapSource) Connect() { func (l *ldapSource) Connect() {
l.Bind("test", "testpw")
addr := fmt.Sprintf("%s:%d", l.host, l.port) addr := fmt.Sprintf("%s:%d", l.host, l.port)
conn, err := ldap.DialTLS("tcp", addr, nil) conn, err := ldap.DialTLS("tcp", addr, nil)
if err == nil { if err == nil {
@ -56,7 +99,7 @@ func (l ldapSource) Search() {
nil, nil,
nil) nil)
searchResults, err := l.connection.Search(search) searchResults, err := l.connection.Search(search)
// be sure to add error checking!
if err == nil { if err == nil {
for _, v := range searchResults.Entries { 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 { func NewAccoauntSource() AccountSource {
user := ldapUnit{ user := ldapUnit{
dn: "ou=User,dc=amuz,dc=es", dn: "ou=User,dc=amuz,dc=es",