-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APP] Serialize challenge as protobuf, and remove snappy (no real gain).
- Loading branch information
Normand, Thibault
committed
Aug 24, 2017
1 parent
7e3629a
commit b5b9daa
Showing
7 changed files
with
247 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package forge | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/dchest/uniuri" | ||
) | ||
|
||
// SessionIDGenerator is the contract for Session ID generation implementation | ||
type SessionIDGenerator func() string | ||
|
||
// Options for challenge forging | ||
type Options struct { | ||
Expiration time.Duration | ||
IDGenerator SessionIDGenerator | ||
} | ||
|
||
// Option defines forge option contract option function | ||
type Option func(*Options) | ||
|
||
// WithExpiration defines the expiration interval | ||
func WithExpiration(expiration time.Duration) Option { | ||
return func(opts *Options) { | ||
opts.Expiration = expiration | ||
} | ||
} | ||
|
||
// WithSessionIDGenerator defines the SessionId generation function | ||
func WithSessionIDGenerator(generator SessionIDGenerator) Option { | ||
return func(opts *Options) { | ||
opts.IDGenerator = generator | ||
} | ||
} | ||
|
||
// WithRandomSessionID defines the SessionId generation | ||
func WithRandomSessionID() Option { | ||
return func(opts *Options) { | ||
opts.IDGenerator = DefaultSessionGenerator | ||
} | ||
} | ||
|
||
var ( | ||
// DefaultSessionGenerator defines the default session id generator | ||
DefaultSessionGenerator = func() string { | ||
return uniuri.NewLen(64) | ||
} | ||
) |
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,8 @@ | ||
package internal | ||
|
||
import "time" | ||
|
||
// IsExpired retruns the challenge expiration status | ||
func (ch *Challenge) IsExpired() bool { | ||
return time.Now().UTC().After(time.Unix(ch.Expiration, 0).UTC()) | ||
} |
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,27 @@ | ||
package internal | ||
|
||
import ( | ||
"encoding/base64" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
) | ||
|
||
// Marshal converts a protobuf message to a URL legal string. | ||
func Marshal(message proto.Message) (string, error) { | ||
data, err := proto.Marshal(message) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(data), nil | ||
} | ||
|
||
// Unmarshal decodes a protobuf message. | ||
func Unmarshal(s string, message proto.Message) error { | ||
data, err := base64.URLEncoding.WithPadding(base64.NoPadding).DecodeString(s) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return proto.Unmarshal(data, message) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
syntax = "proto3"; | ||
|
||
// Package internal holds protobuf types used by the server | ||
package internal; | ||
|
||
// Challenge is the authentication challenge to be used by client | ||
message Challenge { | ||
string session_id = 1; | ||
int64 issued_at = 2; | ||
int64 expiration = 3; | ||
string principal = 4; | ||
} |