Skip to content

Commit

Permalink
Demonstrate sms and request regeneration in example broker
Browse files Browse the repository at this point in the history
Consequence select call will change temporary code or qr code. This is
to simulate and demonstrate sms resends and so on.
  • Loading branch information
didrocks committed Aug 10, 2023
1 parent fac494b commit 308139f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/brokers/examplebroker/examplebroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -155,6 +156,7 @@ func (b *Broker) GetAuthenticationModes(ctx context.Context, sessionID string, s
allModes["totp_with_button"] = map[string]string{
"selection_label": "Authentication code",
"phone": "+33…",
"wantedCode": "temporary pass",
"ui": mapToJSON(map[string]string{
"type": "form",
"label": "Enter your one time credential",
Expand All @@ -166,6 +168,7 @@ func (b *Broker) GetAuthenticationModes(ctx context.Context, sessionID string, s
allModes["totp"] = map[string]string{
"selection_label": "Authentication code",
"phone": "+33…",
"wantedCode": "temporary pass",
"ui": mapToJSON(map[string]string{
"type": "form",
"label": "Enter your one time credential",
Expand Down Expand Up @@ -283,13 +286,21 @@ func (b *Broker) SelectAuthenticationMode(ctx context.Context, sessionID, authen
switch authenticationModeName {
case "totp_with_button", "totp":
// send sms to sessionInfo.allModes[authenticationModeName]["phone"]
// add a 0 to simulate new code generation.
authenticationMode["wantedCode"] = authenticationMode["wantedCode"] + "0"
sessionInfo.allModes[authenticationModeName] = authenticationMode
b.currentSessionsMu.Lock()
b.currentSessions[sessionID] = sessionInfo
b.currentSessionsMu.Unlock()
case "phoneack1", "phoneack2":
// send request to sessionInfo.allModes[authenticationModeName]["phone"]
case "fidodevice1":
// start transaction with fideo device
case "qrcodewithtypo":
// generate the url and finish the prompt on the fly.
uiLayoutInfo["content"] = "https://ubuntu.com"
i := rand.Intn(3)

Check failure on line 301 in internal/brokers/examplebroker/examplebroker.go

View workflow job for this annotation

GitHub Actions / Code sanity

G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
contents := []string{"https://ubuntu.com", "https://ubuntu-fr.org", "https://canonical.com"}
uiLayoutInfo["content"] = contents[i]
uiLayoutInfo["label"] = uiLayoutInfo["label"] + "1337"
}

Expand Down Expand Up @@ -365,7 +376,8 @@ func (b *Broker) handleIsAuthorized(ctx context.Context, sessionInfo sessionInfo
}

case "totp_with_button", "totp":
if authData["challenge"] != "temporary pass" {
wantedCode := sessionInfo.allModes[sessionInfo.selectedMode]["wantedCode"]
if authData["challenge"] != wantedCode {
return responses.AuthDenied, "", nil
}

Expand Down

0 comments on commit 308139f

Please sign in to comment.