-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support TLS transfer and user authorization between server and client.
- Loading branch information
Showing
29 changed files
with
522 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
"github.com/no-src/gofs/contract" | ||
) | ||
|
||
// ParseAuthCommandData parse auth command request data | ||
func ParseAuthCommandData(data []byte) (user *HashUser, err error) { | ||
authCmdLen := len(contract.AuthCommand) | ||
length := authCmdLen + 16 + 16 | ||
if len(data) != length { | ||
return nil, fmt.Errorf("auth command data is invalid => [%s]", string(data)) | ||
} | ||
user = &HashUser{ | ||
UserNameHash: string(data[authCmdLen : authCmdLen+16]), | ||
PasswordHash: string(data[authCmdLen+16 : authCmdLen+32]), | ||
} | ||
return user, nil | ||
} | ||
|
||
// GenerateAuthCommandData generate auth command request data | ||
func GenerateAuthCommandData(userNameHash, passwordHash string) []byte { | ||
authData := contract.AuthCommand | ||
authData = append(authData, []byte(userNameHash)...) | ||
authData = append(authData, []byte(passwordHash)...) | ||
return authData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package auth | ||
|
||
// HashUser store the hash info of User | ||
type HashUser struct { | ||
// UserNameHash a 16 bytes hash of username | ||
UserNameHash string | ||
// PasswordHash a 16 bytes hash of password | ||
PasswordHash string | ||
} | ||
|
||
// ToHashUserList convert User list to HashUser list | ||
func ToHashUserList(users []*User) (hashUsers []*HashUser, err error) { | ||
if len(users) == 0 { | ||
return hashUsers, nil | ||
} | ||
for _, user := range users { | ||
hashUser, err := user.ToHashUser() | ||
if err != nil { | ||
return nil, err | ||
} | ||
hashUsers = append(hashUsers, hashUser) | ||
} | ||
return hashUsers, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package auth | ||
|
||
import "encoding/gob" | ||
|
||
type SessionUser struct { | ||
UserId int | ||
UserName string | ||
Password string | ||
} | ||
|
||
func MapperToSessionUser(user *User) *SessionUser { | ||
if user == nil { | ||
return nil | ||
} | ||
return &SessionUser{ | ||
UserId: user.UserId(), | ||
UserName: user.UserName(), | ||
Password: user.Password(), | ||
} | ||
} | ||
|
||
func init() { | ||
gob.Register(SessionUser{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.