Merge lp:~lutostag/gomaasapi/fix_nonce_generation into lp:gomaasapi

Proposed by Greg Lutostanski
Status: Merged
Merged at revision: 53
Proposed branch: lp:~lutostag/gomaasapi/fix_nonce_generation
Merge into: lp:gomaasapi
Diff against target: 30 lines (+4/-5)
1 file modified
oauth.go (+4/-5)
To merge this branch: bzr merge lp:~lutostag/gomaasapi/fix_nonce_generation
Reviewer Review Type Date Requested Status
Ian Booth Approve
Review via email: mp+231638@code.launchpad.net

Commit message

Use a much larger random for the nonce to prevent collisions. This uses a naive 16 byte random -> String rather than a real uuidgen because I didn't want to add the dep to another package.

Description of the change

Use a much larger random for the nonce to prevent collisions. This uses a naive 16 byte random -> String rather than a real uuidgen because I didn't want to add the dep to another package.

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'oauth.go'
2--- oauth.go 2013-02-05 13:25:01 +0000
3+++ oauth.go 2014-08-20 22:02:46 +0000
4@@ -6,7 +6,6 @@
5 import (
6 "crypto/rand"
7 "fmt"
8- "math/big"
9 "net/http"
10 "net/url"
11 "strconv"
12@@ -14,14 +13,14 @@
13 "time"
14 )
15
16-var nonceMax = big.NewInt(100000000)
17-
18+// Not a true uuidgen, but at least creates same length random
19 func generateNonce() (string, error) {
20- randInt, err := rand.Int(rand.Reader, nonceMax)
21+ randBytes := make([]byte, 16)
22+ _, err := rand.Read(randBytes)
23 if err != nil {
24 return "", err
25 }
26- return strconv.Itoa(int(randInt.Int64())), nil
27+ return fmt.Sprintf("%16x", randBytes), nil
28 }
29
30 func generateTimestamp() string {

Subscribers

People subscribed via source and target branches

to all changes: