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
=== modified file 'oauth.go'
--- oauth.go 2013-02-05 13:25:01 +0000
+++ oauth.go 2014-08-20 22:02:46 +0000
@@ -6,7 +6,6 @@
6import (6import (
7 "crypto/rand"7 "crypto/rand"
8 "fmt"8 "fmt"
9 "math/big"
10 "net/http"9 "net/http"
11 "net/url"10 "net/url"
12 "strconv"11 "strconv"
@@ -14,14 +13,14 @@
14 "time"13 "time"
15)14)
1615
17var nonceMax = big.NewInt(100000000)16// Not a true uuidgen, but at least creates same length random
18
19func generateNonce() (string, error) {17func generateNonce() (string, error) {
20 randInt, err := rand.Int(rand.Reader, nonceMax)18 randBytes := make([]byte, 16)
19 _, err := rand.Read(randBytes)
21 if err != nil {20 if err != nil {
22 return "", err21 return "", err
23 }22 }
24 return strconv.Itoa(int(randInt.Int64())), nil23 return fmt.Sprintf("%16x", randBytes), nil
25}24}
2625
27func generateTimestamp() string {26func generateTimestamp() string {

Subscribers

People subscribed via source and target branches

to all changes: