Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dep, JWK and groups #635

Merged
merged 7 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ before_install:
- sudo apt-get install curl

install:
- go get -u github.com/go-swagger/go-swagger/cmd/swagger github.com/bradfitz/goimports github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/Masterminds/glide github.com/mitchellh/gox github.com/ory/go-acc
- go get -u github.com/go-swagger/go-swagger/cmd/swagger github.com/bradfitz/goimports github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/Masterminds/glide github.com/mitchellh/gox github.com/golang/dep/cmd/dep github.com/ory/go-acc
- git clone https://github.com/docker-library/official-images.git ~/official-images
- glide install
- go install github.com/ory/hydra
- glide update
- go install github.com/ory/hydra
- dep ensure
- go install github.com/ory/hydra

script:
- ./scripts/test-format.sh
Expand Down
79 changes: 79 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[[constraint]]
name = "github.com/dgrijalva/jwt-go"
version = "3.0.0"

[[constraint]]
name = "github.com/go-sql-driver/mysql"
version = "1.3.0"

[[constraint]]
name = "github.com/gorilla/context"
version = "1.1.0"

[[constraint]]
name = "github.com/gorilla/sessions"
version = "1.1.0"

[[constraint]]
name = "github.com/imdario/mergo"
version = "0.2.2"

[[constraint]]
name = "github.com/julienschmidt/httprouter"
version = "1.1.0"

[[constraint]]
name = "github.com/oleiade/reflections"
version = "1.0.0"

[[constraint]]
name = "github.com/ory/fosite"
version = "0.11.3"

[[constraint]]
name = "github.com/ory/graceful"
version = "0.1.0"

[[constraint]]
name = "github.com/ory/herodot"
version = "0.1.1"

[[constraint]]
name = "github.com/ory/ladon"
version = "0.8.2"

[[constraint]]
name = "github.com/pborman/uuid"
version = "1.0.0"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"

[[constraint]]
name = "github.com/pkg/profile"
version = "1.2.1"

[[constraint]]
name = "github.com/square/go-jose"
version = "2.1.3"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.1.4"

[[constraint]]
name = "github.com/toqueteos/webbrowser"
version = "1.0.0"

[[constraint]]
name = "github.com/urfave/negroni"
version = "0.2.0"

[[constraint]]
name = "github.com/go-resty/resty"
version = "1.0.0"

[[constraint]]
name = "github.com/segmentio/analytics-go"
version = "2.1.1"
2 changes: 1 addition & 1 deletion cmd/keys_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ var keysCreateCmd = &cobra.Command{

func init() {
keysCmd.AddCommand(keysCreateCmd)
keysCreateCmd.Flags().StringP("alg", "a", "", "REQUIRED name that identifies the algorithm intended for use with the key. Supports: RS256, ES521, HS256")
keysCreateCmd.Flags().StringP("alg", "a", "", "REQUIRED name that identifies the algorithm intended for use with the key. Supports: RS256, ES256, ES521, HS256")

}
4 changes: 2 additions & 2 deletions cmd/server/helper_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func getOrCreateTLSCertificate(cmd *cobra.Command, c *config.Config) tls.Certifi

private := jwk.First(keys.Key("private"))
private.Certificates = []*x509.Certificate{cert}
keys = &jose.JsonWebKeySet{
Keys: []jose.JsonWebKey{
keys = &jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
*private,
*jwk.First(keys.Key("public")),
},
Expand Down
50 changes: 30 additions & 20 deletions docs/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1487,8 +1487,8 @@
"tags": [
"warden"
],
"summary": "Find groups by member",
"operationId": "findGroupsByMember",
"summary": "List groups",
"operationId": "listGroups",
"security": [
{
"oauth2": [
Expand All @@ -1504,11 +1504,27 @@
"name": "member",
"in": "query",
"required": true
},
{
"type": "integer",
"format": "int64",
"x-go-name": "Offset",
"description": "The offset from where to start looking if member isn't specified.",
"name": "offset",
"in": "query"
},
{
"type": "integer",
"format": "int64",
"x-go-name": "Limit",
"description": "The maximum amount of policies returned if member isn't specified.",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/findGroupsByMemberResponse"
"$ref": "#/responses/listGroupsResponse"
},
"401": {
"$ref": "#/responses/genericError"
Expand Down Expand Up @@ -1928,12 +1944,6 @@
"Handler": {
"type": "object",
"properties": {
"Generators": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/KeyGenerator"
}
},
"H": {
"$ref": "#/definitions/Writer"
},
Expand All @@ -1944,7 +1954,7 @@
"$ref": "#/definitions/Firewall"
}
},
"x-go-package": "github.com/ory/hydra/jwk"
"x-go-package": "github.com/ory/hydra/warden/group"
},
"KeyGenerator": {
"type": "object",
Expand Down Expand Up @@ -2173,7 +2183,7 @@
],
"properties": {
"alg": {
"description": "The algorithm to be used for creating the key. Supports \"RS256\", \"ES521\" and \"HS256\"",
"description": "The algorithm to be used for creating the key. Supports \"RS256\", \"ES256\", \"ES521\" and \"HS256\"",
"type": "string",
"x-go-name": "Algorithm"
},
Expand Down Expand Up @@ -3021,15 +3031,6 @@
"emptyResponse": {
"description": "An empty response"
},
"findGroupsByMemberResponse": {
"description": "A list of groups the member is belonging to",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/group"
}
}
},
"genericError": {
"description": "The standard error format",
"schema": {
Expand Down Expand Up @@ -3094,6 +3095,15 @@
"$ref": "#/definitions/oAuth2TokenIntrospection"
}
},
"listGroupsResponse": {
"description": "A list of groups the member is belonging to",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/group"
}
}
},
"oAuth2ClientList": {
"description": "A list of clients.",
"schema": {
Expand Down
6 changes: 2 additions & 4 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import:
- package: github.com/sirupsen/logrus
version: master
- package: github.com/Sirupsen/logrus
version: master
repo: https://github.com/sirupsen/logrus.git
vcs: git
version: master
- package: github.com/dgrijalva/jwt-go
version: 3.0.0
- package: github.com/go-sql-driver/mysql
Expand Down Expand Up @@ -58,9 +58,7 @@ import:
- package: github.com/spf13/cobra
- package: github.com/spf13/viper
- package: github.com/square/go-jose
version: ~1.1.0
subpackages:
- json
version: 2.1.3
- package: github.com/stretchr/testify
version: 1.1.4
subpackages:
Expand Down
8 changes: 4 additions & 4 deletions jwk/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/square/go-jose"
)

func MustRSAPublic(key *jose.JsonWebKey) *rsa.PublicKey {
func MustRSAPublic(key *jose.JSONWebKey) *rsa.PublicKey {
res, err := ToRSAPublic(key)
if err != nil {
panic(err.Error())
Expand All @@ -16,23 +16,23 @@ func MustRSAPublic(key *jose.JsonWebKey) *rsa.PublicKey {

}

func ToRSAPublic(key *jose.JsonWebKey) (*rsa.PublicKey, error) {
func ToRSAPublic(key *jose.JSONWebKey) (*rsa.PublicKey, error) {
res, ok := key.Key.(*rsa.PublicKey)
if !ok {
return res, errors.New("Could not convert key to RSA Private Key.")
}
return res, nil
}

func MustRSAPrivate(key *jose.JsonWebKey) *rsa.PrivateKey {
func MustRSAPrivate(key *jose.JSONWebKey) *rsa.PrivateKey {
res, err := ToRSAPrivate(key)
if err != nil {
panic(err.Error())
}
return res
}

func ToRSAPrivate(key *jose.JsonWebKey) (*rsa.PrivateKey, error) {
func ToRSAPrivate(key *jose.JSONWebKey) (*rsa.PrivateKey, error) {
res, ok := key.Key.(*rsa.PrivateKey)
if !ok {
return res, errors.New("Could not convert key to RSA Private Key.")
Expand Down
2 changes: 1 addition & 1 deletion jwk/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package jwk
import "github.com/square/go-jose"

type KeyGenerator interface {
Generate(id string) (*jose.JsonWebKeySet, error)
Generate(id string) (*jose.JSONWebKeySet, error)
}
6 changes: 3 additions & 3 deletions jwk/generator_ecdsa256.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (

type ECDSA256Generator struct{}

func (g *ECDSA256Generator) Generate(id string) (*jose.JsonWebKeySet, error) {
func (g *ECDSA256Generator) Generate(id string) (*jose.JSONWebKeySet, error) {
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return nil, errors.Errorf("Could not generate key because %s", err)
}

return &jose.JsonWebKeySet{
Keys: []jose.JsonWebKey{
return &jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
{
Key: key,
KeyID: ider("private", id),
Expand Down
6 changes: 3 additions & 3 deletions jwk/generator_ecdsa521.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (

type ECDSA521Generator struct{}

func (g *ECDSA521Generator) Generate(id string) (*jose.JsonWebKeySet, error) {
func (g *ECDSA521Generator) Generate(id string) (*jose.JSONWebKeySet, error) {
key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
if err != nil {
return nil, errors.Errorf("Could not generate key because %s", err)
}

return &jose.JsonWebKeySet{
Keys: []jose.JsonWebKey{
return &jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
{
Key: key,
KeyID: ider("private", id),
Expand Down
6 changes: 3 additions & 3 deletions jwk/generator_hs256.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type HS256Generator struct {
Length int
}

func (g *HS256Generator) Generate(id string) (*jose.JsonWebKeySet, error) {
func (g *HS256Generator) Generate(id string) (*jose.JSONWebKeySet, error) {
if g.Length < 12 {
g.Length = 12
}
Expand All @@ -26,8 +26,8 @@ func (g *HS256Generator) Generate(id string) (*jose.JsonWebKeySet, error) {
return nil, errors.Errorf("Could not generate key because %s", err)
}

return &jose.JsonWebKeySet{
Keys: []jose.JsonWebKey{
return &jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
{
Algorithm: "HS256",
Key: []byte(string(key)),
Expand Down
6 changes: 3 additions & 3 deletions jwk/generator_rs256.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type RS256Generator struct {
KeyLength int
}

func (g *RS256Generator) Generate(id string) (*jose.JsonWebKeySet, error) {
func (g *RS256Generator) Generate(id string) (*jose.JSONWebKeySet, error) {
if g.KeyLength < 4096 {
g.KeyLength = 4096
}
Expand All @@ -28,8 +28,8 @@ func (g *RS256Generator) Generate(id string) (*jose.JsonWebKeySet, error) {

// jose does not support this...
key.Precomputed = rsa.PrecomputedValues{}
return &jose.JsonWebKeySet{
Keys: []jose.JsonWebKey{
return &jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
{
Algorithm: "RS256",
Key: key,
Expand Down
10 changes: 5 additions & 5 deletions jwk/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ func TestGenerator(t *testing.T) {

for k, c := range []struct {
g KeyGenerator
check func(*jose.JsonWebKeySet)
check func(*jose.JSONWebKeySet)
}{
{
g: &RS256Generator{},
check: func(ks *jose.JsonWebKeySet) {
check: func(ks *jose.JSONWebKeySet) {
assert.Len(t, ks, 2)
},
},
{
g: &ECDSA521Generator{},
check: func(ks *jose.JsonWebKeySet) {
check: func(ks *jose.JSONWebKeySet) {
assert.Len(t, ks, 2)
},
},
{
g: &ECDSA256Generator{},
check: func(ks *jose.JsonWebKeySet) {
check: func(ks *jose.JSONWebKeySet) {
assert.Len(t, ks, 2)
},
},
{
g: &HS256Generator{
Length: 32,
},
check: func(ks *jose.JsonWebKeySet) {
check: func(ks *jose.JSONWebKeySet) {
assert.Len(t, ks, 1)
},
},
Expand Down
Loading