forked from ubuntu/authd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
golang-ci: Enable lll (long lines) linter and fix issues
Set the long lines linter to block lines longer than 120 chars an fix the cases in which we were not respecting this limit. This was somewhat mentioned during the sprint, and I wanted to finally tackle it :)
- Loading branch information
Showing
58 changed files
with
1,149 additions
and
465 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
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
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 |
---|---|---|
|
@@ -145,7 +145,8 @@ func New(name string) (b *Broker, fullName, brandIcon string) { | |
} | ||
|
||
// NewSession creates a new session for the specified user. | ||
func (b *Broker) NewSession(ctx context.Context, username, lang, mode string) (sessionID, encryptionKey string, err error) { | ||
func (b *Broker) NewSession(ctx context.Context, username, lang, mode string) ( | ||
sessionID, encryptionKey string, err error) { | ||
sessionID = uuid.New().String() | ||
info := sessionInfo{ | ||
username: username, | ||
|
@@ -214,8 +215,10 @@ func (b *Broker) NewSession(ctx context.Context, username, lang, mode string) (s | |
return sessionID, base64.StdEncoding.EncodeToString(pubASN1), nil | ||
} | ||
|
||
// GetAuthenticationModes returns the list of supported authentication modes for the selected broker depending on session info. | ||
func (b *Broker) GetAuthenticationModes(ctx context.Context, sessionID string, supportedUILayouts []map[string]string) (authenticationModes []map[string]string, err error) { | ||
// GetAuthenticationModes returns the list of supported authentication modes | ||
// for the selected broker depending on session info. | ||
func (b *Broker) GetAuthenticationModes(ctx context.Context, sessionID string, supportedUILayouts []map[string]string) ( | ||
authenticationModes []map[string]string, err error) { | ||
sessionInfo, err := b.sessionInfo(sessionID) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -312,8 +315,9 @@ func getSupportedModes(sessionInfo sessionInfo, supportedUILayouts []map[string] | |
"selection_label": fmt.Sprintf("Send URL to %[email protected]", sessionInfo.username), | ||
"email": fmt.Sprintf("%[email protected]", sessionInfo.username), | ||
"ui": mapToJSON(map[string]string{ | ||
"type": "form", | ||
"label": fmt.Sprintf("Click on the link received at %[email protected] or enter the code:", sessionInfo.username), | ||
"type": "form", | ||
"label": fmt.Sprintf("Click on the link received at %[email protected] or enter the code:", | ||
sessionInfo.username), | ||
"entry": "chars", | ||
"wait": "true", | ||
}), | ||
|
@@ -463,7 +467,8 @@ func qrcodeData(sessionInfo *sessionInfo) (content string, code string) { | |
} | ||
|
||
// SelectAuthenticationMode returns the UI layout information for the selected authentication mode. | ||
func (b *Broker) SelectAuthenticationMode(ctx context.Context, sessionID, authenticationModeName string) (uiLayoutInfo map[string]string, err error) { | ||
func (b *Broker) SelectAuthenticationMode(ctx context.Context, sessionID, authenticationModeName string) ( | ||
uiLayoutInfo map[string]string, err error) { | ||
// Ensure session ID is an active one. | ||
sessionInfo, err := b.sessionInfo(sessionID) | ||
if err != nil { | ||
|
@@ -513,7 +518,8 @@ func (b *Broker) SelectAuthenticationMode(ctx context.Context, sessionID, authen | |
} | ||
|
||
// IsAuthenticated evaluates the provided authenticationData and returns the authentication status for the user. | ||
func (b *Broker) IsAuthenticated(ctx context.Context, sessionID, authenticationData string) (access, data string, err error) { | ||
func (b *Broker) IsAuthenticated(ctx context.Context, sessionID, authenticationData string) ( | ||
access, data string, err error) { | ||
sessionInfo, err := b.sessionInfo(sessionID) | ||
if err != nil { | ||
return "", "", err | ||
|
@@ -574,7 +580,8 @@ func (b *Broker) sleepDuration(in time.Duration) time.Duration { | |
return time.Duration(math.Round(float64(in) * b.sleepMultiplier)) | ||
} | ||
|
||
func (b *Broker) handleIsAuthenticated(ctx context.Context, sessionInfo sessionInfo, authData map[string]string) (access, data string) { | ||
func (b *Broker) handleIsAuthenticated(ctx context.Context, sessionInfo sessionInfo, authData map[string]string) ( | ||
access, data string) { | ||
// Decrypt challenge if present. | ||
challenge, err := decodeRawChallenge(b.privateKey, authData["challenge"]) | ||
if err != nil { | ||
|
@@ -597,7 +604,8 @@ func (b *Broker) handleIsAuthenticated(ctx context.Context, sessionInfo sessionI | |
expectedChallenge := user.Password | ||
|
||
if challenge != expectedChallenge { | ||
return AuthRetry, fmt.Sprintf(`{"message": "invalid password '%s', should be '%s'"}`, challenge, expectedChallenge) | ||
return AuthRetry, fmt.Sprintf(`{"message": "invalid password '%s', should be '%s'"}`, | ||
challenge, expectedChallenge) | ||
} | ||
|
||
case "pincode": | ||
|
@@ -650,7 +658,8 @@ func (b *Broker) handleIsAuthenticated(ctx context.Context, sessionInfo sessionI | |
|
||
case "qrcodewithtypo", "qrcodeandcodewithtypo": | ||
if authData["wait"] != "true" { | ||
return AuthDenied, fmt.Sprintf(`{"message": "%s should have wait set to true"}`, sessionInfo.currentAuthMode) | ||
return AuthDenied, fmt.Sprintf(`{"message": "%s should have wait set to true"}`, | ||
sessionInfo.currentAuthMode) | ||
} | ||
// Simulate connexion with remote server to check that the correct code was entered | ||
select { | ||
|
@@ -673,7 +682,8 @@ func (b *Broker) handleIsAuthenticated(ctx context.Context, sessionInfo sessionI | |
} | ||
|
||
if challenge != expectedChallenge { | ||
return AuthRetry, fmt.Sprintf(`{"message": "new password does not match criteria: must be '%s'"}`, expectedChallenge) | ||
return AuthRetry, fmt.Sprintf(`{"message": "new password does not match criteria: must be '%s'"}`, | ||
expectedChallenge) | ||
} | ||
exampleUsersMu.Lock() | ||
exampleUsers[sessionInfo.username] = userInfoBroker{Password: challenge} | ||
|
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.