Skip to content

Commit

Permalink
Merge pull request #17 from zachmann/fed_entity
Browse files Browse the repository at this point in the history
Fed entity
  • Loading branch information
zachmann authored Jul 16, 2024
2 parents 7812dd6 + 6293cdc commit 7ed113b
Show file tree
Hide file tree
Showing 43 changed files with 1,516 additions and 869 deletions.
3 changes: 1 addition & 2 deletions examples/rp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ var redirectURI string
func handleEntityConfiguration(w http.ResponseWriter, r *http.Request) {
var err error

c := fedLeaf().EntityConfiguration()
jwt, err := c.JWT()
jwt, err := fedLeaf().EntityConfigurationJWT()
if err != nil {
log.Fatal(err)
}
Expand Down
25 changes: 18 additions & 7 deletions examples/ta/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/zachmann/go-oidfed/pkg"
"github.com/zachmann/go-oidfed/pkg/fedentities"
)

type Config struct {
Expand All @@ -20,6 +21,15 @@ type Config struct {
ConfigurationLifetime int64 `yaml:"configuration_lifetime"`
OrganizationName string `yaml:"organization_name"`
DataLocation string `yaml:"data_location"`
ReadableStorage bool `yaml:"human_readable_storage"`
Endpoints Endpoints `yaml:"endpoints"`
}

type Endpoints struct {
FetchEndpoint fedentities.EndpointConf `yaml:"fetch"`
ListEndpoint fedentities.EndpointConf `yaml:"list"`
ResolveEndpoint fedentities.EndpointConf `yaml:"resolve"`
//TODO
}

var c Config
Expand Down Expand Up @@ -50,13 +60,14 @@ func Load(filename string) {
}
if c.MetadataPolicyFile == "" {
log.Println("WARNING: metadata_policy_file not set")
}
policyContent, err := os.ReadFile(c.MetadataPolicyFile)
if err != nil {
log.Fatal(err)
}
if err = json.Unmarshal(policyContent, &c.MetadataPolicy); err != nil {
log.Fatal(err)
} else {
policyContent, err := os.ReadFile(c.MetadataPolicyFile)
if err != nil {
log.Fatal(err)
}
if err = json.Unmarshal(policyContent, &c.MetadataPolicy); err != nil {
log.Fatal(err)
}
}

}
47 changes: 0 additions & 47 deletions examples/ta/example-config/metadata-policy.json

This file was deleted.

2 changes: 0 additions & 2 deletions examples/ta/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ module github.com/zachmann/go-oidfed/examples/ta
go 1.22

require (
github.com/gofiber/fiber/v2 v2.48.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/lestrrat-go/jwx v1.2.27
github.com/pkg/errors v0.9.1
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
9 changes: 8 additions & 1 deletion examples/ta/oidfed/jws.go → examples/ta/jws.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package oidfed
package main

import (
"crypto"
Expand All @@ -15,8 +15,15 @@ import (
"github.com/lestrrat-go/jwx/jwk"

"github.com/zachmann/go-oidfed/examples/ta/config"
"github.com/zachmann/go-oidfed/internal/jwx"
)

func genJWKS() jwk.Set {
sk := mustNewKey()
jwks := jwx.KeyToJWKS(sk.Public(), jwa.ES512)
return jwks
}

func mustNewKey() *ecdsa.PrivateKey {
sk, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
if err != nil {
Expand Down
87 changes: 80 additions & 7 deletions examples/ta/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package main

import (
"fmt"
"log"
"net/http"
"os"

"github.com/lestrrat-go/jwx/jwa"

"github.com/zachmann/go-oidfed/examples/ta/config"
"github.com/zachmann/go-oidfed/examples/ta/oidfed"
"github.com/zachmann/go-oidfed/examples/ta/server"
"github.com/zachmann/go-oidfed/examples/ta/server/routes"
"github.com/zachmann/go-oidfed/pkg"
"github.com/zachmann/go-oidfed/pkg/fedentities"
"github.com/zachmann/go-oidfed/pkg/fedentities/storage"
)

func main() {
Expand All @@ -15,8 +20,76 @@ func main() {
configFile = os.Args[1]
}
config.Load(configFile)
routes.Init()
oidfed.Init()
server.Init()
server.Start()
log.Println("Loaded Config")
c := config.Get()
initKey()
log.Println("Loaded signing key")

var subordinateStorage storage.SubordinateStorageBackend
if c.ReadableStorage {
warehouse := storage.NewFileStorage(c.DataLocation)
subordinateStorage = warehouse.SubordinateStorage()
} else {
warehouse, err := storage.NewBadgerStorage(c.DataLocation)
if err != nil {
log.Fatal(err)
}
subordinateStorage = warehouse.SubordinateStorage()
}
log.Println("Loaded storage backend")

entity, err := fedentities.NewFedEntity(
c.EntityID, c.AuthorityHints,
&pkg.Metadata{
FederationEntity: &pkg.FederationEntityMetadata{
CommonMetadata: pkg.CommonMetadata{
OrganizationName: c.OrganizationName,
},
},
},
signingKey, jwa.ES512, c.ConfigurationLifetime, fedentities.SubordinateStatementsConfig{
MetadataPolicies: nil,
Configs: map[string]*fedentities.SubordinateStatementTypeConfig{
"": {
SubordinateStatementLifetime: 3600,
// TODO read all of this from config or a storage backend
},
},
},
)
if err != nil {
panic(err)
}
entity.MetadataPolicies = c.MetadataPolicy
// TODO other constraints etc.
log.Println("Initialized Entity")

entity.AddFetchEndpoint(c.Endpoints.FetchEndpoint, subordinateStorage)
entity.AddSubordinateListingEndpoint(c.Endpoints.ListEndpoint, subordinateStorage)
entity.AddResolveEndpoint(c.Endpoints.ResolveEndpoint)
log.Println("Added Endpoints")

// subordinateStorage.Write(
// "https://op.example.org", storage.SubordinateInfo{
// JWKS: genJWKS(),
// EntityType: constants.EntityTypeOpenIDProvider,
// EntityID: "https://op.example.org",
// },
// )
// subordinateStorage.Write(
// "https://rp.example.org", storage.SubordinateInfo{
// JWKS: genJWKS(),
// EntityType: constants.EntityTypeOpenIDRelyingParty,
// EntityID: "https://rp.example.org",
// },
// )

log.Printf("Start serving on port %d\n", c.ServerPort)
if err = http.ListenAndServe(fmt.Sprintf(":%d", c.ServerPort), entity.HttpHandlerFunc()); err != nil {
panic(err)
}
// if err = entity.Listen(fmt.Sprintf(":%d", c.ServerPort)); err != nil {
// panic(err)
// }

}
151 changes: 0 additions & 151 deletions examples/ta/oidfed/oidcfed.go

This file was deleted.

Loading

0 comments on commit 7ed113b

Please sign in to comment.