diff --git a/.schema/api.openapi.json b/.schema/api.openapi.json index fe62c9cda00c..8abef87e0478 100644 --- a/.schema/api.openapi.json +++ b/.schema/api.openapi.json @@ -1932,6 +1932,81 @@ ] } }, + "/self-service/saml/metadata":{ + "get":{ + "description": "This endpoint is for the IDP to obtain kratos metadata", + "operationId": "getSamlMetadata", + "response": { + "302":{ + "$ref": "#/components/responses/emptyResponse" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/genericError" + } + } + }, + "description": "genericError" + } + }, + "summary": "Expose metadata of the SAML Service Provider (Kratos)", + "tags": [ + "public" + ] + } + }, + "/self-service/saml/idp":{ + "get":{ + "description": "This endpoint is to redirect the user to the idp auth flow", + "operationId": "getUrlIdp", + "response": { + "302":{ + "$ref": "#/components/responses/emptyResponse" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/genericError" + } + } + }, + "description": "genericError" + } + }, + "summary": "Redirect the user to the IDP flow", + "tags": [ + "public" + ] + } + }, + "/self-service/saml/acs":{ + "get":{ + "description": "AssertionConsumerService : handle saml response from the IDP", + "operationId": "getSamlAcs", + "response": { + "302":{ + "$ref": "#/components/responses/emptyResponse" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/genericError" + } + } + }, + "description": "genericError" + } + }, + "summary": "Handle SAML response from the IDP", + "tags": [ + "public" + ] + } + }, "/self-service/login/browser": { "get": { "description": "This endpoint initializes a browser-based user login flow. Once initialized, the browser will be redirected to\n`selfservice.flows.login.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session\nexists already, the browser will be redirected to `urls.default_redirect_url` unless the query parameter\n`?refresh=true` was set.\n\nThis endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).\n\nMore information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).", diff --git a/.schema/openapi.json b/.schema/openapi.json index da9c0c742d55..1c049cd787cc 100644 --- a/.schema/openapi.json +++ b/.schema/openapi.json @@ -2006,6 +2006,81 @@ ] } }, + "/self-service/saml/idp":{ + "get":{ + "description": "This endpoint is to redirect the user to the idp auth flow", + "operationId": "getUrlIdp", + "response": { + "302":{ + "$ref": "#/components/responses/emptyResponse" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/genericError" + } + } + }, + "description": "genericError" + } + }, + "summary": "Redirect the user to the IDP flow", + "tags": [ + "public" + ] + } + }, + "/self-service/saml/metadata":{ + "get":{ + "description": "This endpoint is for the IDP to obtain kratos metadata", + "operationId": "getSamlMetadata", + "response": { + "302":{ + "$ref": "#/components/responses/emptyResponse" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/genericError" + } + } + }, + "description": "genericError" + } + }, + "summary": "Expose metadata of the SAML Service Provider (Kratos)", + "tags": [ + "public" + ] + } + }, + "/self-service/saml/acs":{ + "get":{ + "description": "AssertionConsumerService : handle saml response from the IDP", + "operationId": "getSamlAcs", + "response": { + "302":{ + "$ref": "#/components/responses/emptyResponse" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/genericError" + } + } + }, + "description": "genericError" + } + }, + "summary": "Handle SAML response from the IDP", + "tags": [ + "public" + ] + } + }, "/self-service/login/flows": { "get": { "description": "This endpoint returns a login flow's context with, for example, error details and other information.\n\nMore information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).", diff --git a/continuity/manager.go b/continuity/manager.go index c3f50a4798ef..a2b2b92e88ac 100644 --- a/continuity/manager.go +++ b/continuity/manager.go @@ -17,6 +17,10 @@ type ManagementProvider interface { ContinuityManager() Manager } +type ManagementProviderRelayState interface { + RelayStateContinuityManager() Manager +} + type Manager interface { Pause(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) error Continue(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) (*Container, error) diff --git a/continuity/manager_relaystate.go b/continuity/manager_relaystate.go new file mode 100644 index 000000000000..74b3422886bf --- /dev/null +++ b/continuity/manager_relaystate.go @@ -0,0 +1,151 @@ +package continuity + +import ( + "bytes" + "context" + "encoding/json" + "net/http" + + "github.com/gofrs/uuid" + "github.com/pkg/errors" + + "github.com/ory/herodot" + "github.com/ory/x/sqlcon" + + "github.com/ory/kratos/session" + "github.com/ory/kratos/x" +) + +var _ Manager = new(ManagerRelayState) +var ErrNotResumableRelayState = *herodot.ErrBadRequest.WithError("no resumable session found").WithReasonf("The browser does not contain the necessary RelayState value to resume the session. This is a security violation and was blocked. Please try again!") + +type ( + managerRelayStateDependencies interface { + PersistenceProvider + x.RelayStateProvider + session.ManagementProvider + } + ManagerRelayState struct { + dr managerRelayStateDependencies + dc managerCookieDependencies + } +) + +// To ensure continuity even after redirection to the IDP, we cannot use cookies because the IDP and the SP are on two different domains. +// So we have to pass the continuity value through the relaystate. +// This value corresponds to the session ID +func NewManagerRelayState(dr managerRelayStateDependencies, dc managerCookieDependencies) *ManagerRelayState { + return &ManagerRelayState{dr: dr, dc: dc} +} + +func (m *ManagerRelayState) Pause(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) error { + if len(name) == 0 { + return errors.Errorf("continuity container name must be set") + } + + o, err := newManagerOptions(opts) + if err != nil { + return err + } + c := NewContainer(name, *o) + + // We have to put the continuity value in the cookie to ensure that value are passed between API and UI + // It is also useful to pass the value between SP and IDP with POST method because RelayState will take its value from cookie + if err = x.SessionPersistValues(w, r, m.dc.ContinuityCookieManager(ctx), CookieName, map[string]interface{}{ + name: c.ID.String(), + }); err != nil { + return err + } + + if err := m.dr.ContinuityPersister().SaveContinuitySession(r.Context(), c); err != nil { + return errors.WithStack(err) + } + + return nil +} + +func (m *ManagerRelayState) Continue(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) (*Container, error) { + container, err := m.container(ctx, w, r, name) + if err != nil { + return nil, err + } + + o, err := newManagerOptions(opts) + if err != nil { + return nil, err + } + + if err := container.Valid(o.iid); err != nil { + return nil, err + } + + if o.payloadRaw != nil && container.Payload != nil { + if err := json.NewDecoder(bytes.NewBuffer(container.Payload)).Decode(o.payloadRaw); err != nil { + return nil, errors.WithStack(err) + } + } + + if err := x.SessionUnsetKey(w, r, m.dc.ContinuityCookieManager(ctx), CookieName, name); err != nil { + return nil, err + } + + if err := m.dc.ContinuityPersister().DeleteContinuitySession(ctx, container.ID); err != nil && !errors.Is(err, sqlcon.ErrNoRows) { + return nil, err + } + + return container, nil +} + +func (m *ManagerRelayState) sid(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) (uuid.UUID, error) { + var sid uuid.UUID + if s, err := x.SessionGetStringRelayState(r, m.dc.ContinuityCookieManager(ctx), CookieName, name); err != nil { + return sid, errors.WithStack(ErrNotResumable.WithDebugf("%+v", err)) + + } else if sid = x.ParseUUID(s); sid == uuid.Nil { + return sid, errors.WithStack(ErrNotResumable.WithDebug("session id is not a valid uuid")) + + } + + return sid, nil +} + +func (m *ManagerRelayState) container(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) (*Container, error) { + sid, err := m.sid(ctx, w, r, name) + if err != nil { + return nil, err + } + + container, err := m.dr.ContinuityPersister().GetContinuitySession(ctx, sid) + + if err != nil { + _ = x.SessionUnsetKey(w, r, m.dc.ContinuityCookieManager(ctx), CookieName, name) + } + + if errors.Is(err, sqlcon.ErrNoRows) { + return nil, errors.WithStack(ErrNotResumable.WithDebugf("Resumable ID from RelayState could not be found in the datastore: %+v", err)) + } else if err != nil { + return nil, err + } + + return container, err +} + +func (m ManagerRelayState) Abort(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) error { + sid, err := m.sid(ctx, w, r, name) + if errors.Is(err, &ErrNotResumable) { + // We do not care about an error here + return nil + } else if err != nil { + return err + } + + if err := x.SessionUnsetKey(w, r, m.dc.ContinuityCookieManager(ctx), CookieName, name); err != nil { + return err + } + + if err := m.dr.ContinuityPersister().DeleteContinuitySession(ctx, sid); err != nil && !errors.Is(err, sqlcon.ErrNoRows) { + return errors.WithStack(err) + } + + return nil +} diff --git a/driver/registery_default_saml.go b/driver/registery_default_saml.go new file mode 100644 index 000000000000..c201047fc21d --- /dev/null +++ b/driver/registery_default_saml.go @@ -0,0 +1,11 @@ +package driver + +import "github.com/ory/kratos/selfservice/flow/saml" + +func (m *RegistryDefault) SAMLHandler() *saml.Handler { + if m.selfserviceSAMLHandler == nil { + m.selfserviceSAMLHandler = saml.NewHandler(m) + } + + return m.selfserviceSAMLHandler +} diff --git a/driver/registry_default.go b/driver/registry_default.go index 4288d12affdf..47c4c0f20c7f 100644 --- a/driver/registry_default.go +++ b/driver/registry_default.go @@ -37,11 +37,13 @@ import ( "github.com/ory/kratos/hash" "github.com/ory/kratos/schema" "github.com/ory/kratos/selfservice/flow/recovery" + "github.com/ory/kratos/selfservice/flow/saml" "github.com/ory/kratos/selfservice/flow/settings" "github.com/ory/kratos/selfservice/flow/verification" "github.com/ory/kratos/selfservice/hook" "github.com/ory/kratos/selfservice/strategy/link" "github.com/ory/kratos/selfservice/strategy/profile" + samlstrategy "github.com/ory/kratos/selfservice/strategy/saml/strategy" "github.com/ory/kratos/x" "github.com/cenkalti/backoff" @@ -99,6 +101,9 @@ type RegistryDefault struct { continuityManager continuity.Manager + x.RelayStateProvider + session.ManagementProvider + schemaHandler *schema.Handler sessionHandler *session.Handler @@ -121,6 +126,8 @@ type RegistryDefault struct { selfserviceLoginHandler *login.Handler selfserviceLoginRequestErrorHandler *login.ErrorHandler + selfserviceSAMLHandler *saml.Handler + selfserviceSettingsHandler *settings.Handler selfserviceSettingsErrorHandler *settings.ErrorHandler selfserviceSettingsExecutor *settings.HookExecutor @@ -153,6 +160,7 @@ func (m *RegistryDefault) Audit() *logrusx.Logger { func (m *RegistryDefault) RegisterPublicRoutes(ctx context.Context, router *x.RouterPublic) { m.LoginHandler().RegisterPublicRoutes(router) + m.SAMLHandler().RegisterPublicRoutes(router) m.RegistrationHandler().RegisterPublicRoutes(router) m.LogoutHandler().RegisterPublicRoutes(router) m.SettingsHandler().RegisterPublicRoutes(router) @@ -282,6 +290,7 @@ func (m *RegistryDefault) selfServiceStrategies() []interface{} { m.selfserviceStrategies = []interface{}{ password2.NewStrategy(m), oidc.NewStrategy(m), + samlstrategy.NewStrategy(m), profile.NewStrategy(m), link.NewStrategy(m), totp.NewStrategy(m), @@ -616,12 +625,25 @@ func (m *RegistryDefault) Courier(ctx context.Context) courier.Courier { } func (m *RegistryDefault) ContinuityManager() continuity.Manager { - if m.continuityManager == nil { + // If m.continuityManager is nil or not a continuity.ManagerCookie + switch m.continuityManager.(type) { + case *continuity.ManagerCookie: + default: m.continuityManager = continuity.NewManagerCookie(m) } return m.continuityManager } +func (m *RegistryDefault) RelayStateContinuityManager() continuity.Manager { + // If m.continuityManager is nil or not a continuity.ManagerRelayState + switch m.continuityManager.(type) { + case *continuity.ManagerRelayState: + default: + m.continuityManager = continuity.NewManagerRelayState(m, m) + } + return m.continuityManager +} + func (m *RegistryDefault) ContinuityPersister() continuity.Persister { return m.persister } diff --git a/driver/registry_default_test.go b/driver/registry_default_test.go index 54524c8b6b71..8dc0b8991eea 100644 --- a/driver/registry_default_test.go +++ b/driver/registry_default_test.go @@ -686,7 +686,7 @@ func TestDefaultRegistry_AllStrategies(t *testing.T) { _, reg := internal.NewFastRegistryWithMocks(t) t.Run("case=all login strategies", func(t *testing.T) { - expects := []string{"password", "oidc", "totp", "webauthn", "lookup_secret"} + expects := []string{"password", "saml", "oidc", "totp", "webauthn", "lookup_secret"} s := reg.AllLoginStrategies() require.Len(t, s, len(expects)) for k, e := range expects { diff --git a/embedx/config.schema.json b/embedx/config.schema.json index f2c4ef9696ab..ffbba5f75a52 100644 --- a/embedx/config.schema.json +++ b/embedx/config.schema.json @@ -347,6 +347,213 @@ } } }, + "selfServiceSAMLProvider": { + "type": "object", + "properties": { + "id": { + "title":"ID of the IdentityProvider", + "type": "string", + "examples": [ + "activedirectory1" + ] + }, + "label": { + "title": "Optional string which will be used when generating labels for UI buttons.", + "type": "string", + "examples": [ + "Microsoft Active Directory" + ] + }, + "public_cert_path": { + "title": "Public Certificate Path", + "description": "The Public Certificate for your SAML Messages", + "type": "string", + "format": "uri", + "examples": [ + "file://path/to/cert", + "https://foo.bar.com/path/to/cert" + ] + }, + "private_key_path": { + "title": "Private Key Path", + "description": "The Private Key for your SAML Messages", + "type": "string", + "format": "uri", + "examples": [ + "file://path/to/key" + ] + }, + "mapper_url": { + "title": "Jsonnet Mapper URL", + "description": "The URL where the jsonnet source is located for mapping the provider's data to Ory Kratos data.", + "type": "string", + "format": "uri", + "examples": [ + "file://path/to/oidc.jsonnet", + "https://foo.bar.com/path/to/oidc.jsonnet", + "base64://bG9jYWwgc3ViamVjdCA9I..." + ] + }, + "idp_information": { + "type": "object", + "properties": { + "idp_metadata_url": { + "title": "IDP Metadata URL", + "description": "The URL of the metadata of the IDP", + "type": "string", + "examples": [ + "https://path/to/metadata" + ] + }, + "idp_certificate_path": { + "title": "IDP Certificate Path", + "description": "The path to the certificate of the IDP", + "type": "string", + "examples": [ + "file://path/to/certificate", + "https://foo.bar.com/path/to/certificate" + ] + }, + "idp_logout_url": { + "title": "IDP Logout URL", + "description": "The URL of the Single Log Out (SLO) API of the IDP", + "type": "string", + "examples": [ + "https://path/to/logout" + ] + }, + "idp_sso_url": { + "title": "IDP SSO URL", + "description": "The URL of the SSO Handler at the IDP", + "type": "string", + "examples": [ + "https://path/to/sso" + ] + }, + "idp_entity_id": { + "title": "The EntityID of the IDP", + "description": "It is a unique identifier representing the IDP in saml requests", + "type": "string", + "examples": [ + "https://samltest.id/saml/idp" + ] + } + }, + "allOf": [ + { + "if": { + "properties": { + "idp_metadata_url": { + "const": {} + } + } + }, + "then": { + "required": [ + "idp_logout_url", + "idp_certificate_path", + "idp_entity_id" + ] + }, + "else":{ + "properties": { + "idp_certificate_path": { + "const": {} + }, + "idp_logout_url": { + "const": {} + }, + "idp_entity_id":{ + "const":{} + }, + "idp_sso_url":{ + "const":{} + } + } + } + } + ] + }, + "attributes_map": { + "type": "object", + "properties": { + "id": { + "title": "ID", + "description": "The name of the IDP SAML Assertion attribute that will represent the user ID on Kratos", + "type": "string", + "examples": [ + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn" + ] + }, + "firstname": { + "title": "Firstname", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's firstname on Kratos", + "type": "string", + "examples": [ + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" + ] + }, + "lastname": { + "title": "Lastname", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's lastname on Kratos", + "type": "string", + "examples": [ + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname" + ] + }, + "nickname": { + "title": "Nickname", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's username on Kratos", + "type": "string" + }, + "gender": { + "title": "Gender", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's gender on Kratos", + "type": "string" + }, + "birthdate": { + "title": "Birthdate", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's birthdate on Kratos", + "type": "string" + }, + "picture": { + "title": "Picture", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's picture on Kratos", + "type": "string" + }, + "email": { + "title": "Email", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's email on Kratos", + "type": "string", + "examples": [ + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ] + }, + "roles": { + "title": "Roles", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's roles on Kratos", + "type": "string", + "examples" : [ + "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + ] + }, + "phone_number": { + "title": "Phone Number", + "description": "The name of the IDP SAML Assertion attribute that will represent the user's phone number on Kratos", + "type": "string" + } + } + } + }, + "additionalProperties": false, + "required": [ + "id", + "label", + "public_cert_path", + "private_key_path", + "mapper_url" + ] + }, "selfServiceOIDCProvider": { "type": "object", "properties": { @@ -806,6 +1013,9 @@ "oidc": { "$ref": "#/definitions/selfServiceAfterRegistrationMethod" }, + "saml": { + "$ref": "#/definitions/selfServiceAfterRegistrationMethod" + }, "hooks": { "$ref": "#/definitions/selfServiceHooks" } @@ -1430,6 +1640,35 @@ ] } }, + "saml": { + "type": "object", + "title": "Specify SAML configuration", + "showEnvVarBlockForObject": true, + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enables SAML Authentication Method", + "default": false + }, + "config": { + "type": "object", + "additionalProperties": false, + "properties": { + "providers": { + "title": "SAML Provider", + "description": "All information required to implement a SAML authentication", + "type": "array", + "items": { + "$ref": "#/definitions/selfServiceSAMLProvider" + } + } + } + + + } + } + }, "oidc": { "type": "object", "title": "Specify OpenID Connect and OAuth2 Configuration", diff --git a/go.mod b/go.mod index e5581b1c1bbc..246b4a870058 100644 --- a/go.mod +++ b/go.mod @@ -23,12 +23,14 @@ require ( github.com/Masterminds/sprig/v3 v3.0.0 github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 github.com/avast/retry-go/v3 v3.1.1 + github.com/beevik/etree v1.1.0 github.com/bradleyjkemp/cupaloy/v2 v2.6.0 github.com/bwmarrin/discordgo v0.23.0 github.com/bxcodec/faker/v3 v3.3.1 github.com/cenkalti/backoff v2.2.1+incompatible github.com/coreos/go-oidc v2.2.1+incompatible github.com/cortesi/modd v0.0.0-20210323234521-b35eddab86cc + github.com/crewjam/saml v0.4.6 github.com/davecgh/go-spew v1.1.1 github.com/davidrjonas/semver-cli v0.0.0-20190116233701-ee19a9a0dda6 github.com/dgraph-io/ristretto v0.1.0 @@ -98,6 +100,7 @@ require ( golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f golang.org/x/tools v0.1.11 + gotest.tools v2.2.0+incompatible ) require ( @@ -136,6 +139,7 @@ require ( github.com/cortesi/moddwatch v0.0.0-20210222043437-a6aaad86a36e // indirect github.com/cortesi/termlog v0.0.0-20210222042314-a1eec763abec // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/crewjam/httperr v0.2.0 // indirect github.com/docker/cli v20.10.14+incompatible // indirect github.com/docker/distribution v2.8.1+incompatible // indirect github.com/docker/docker v20.10.9+incompatible // indirect @@ -184,6 +188,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/btree v1.0.1 // indirect github.com/google/certificate-transparency-go v1.1.2-0.20210511102531-373a877eec92 // indirect + github.com/google/go-cmp v0.5.7 // indirect github.com/google/go-querystring v1.0.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/gorilla/css v1.0.0 // indirect @@ -227,6 +232,7 @@ require ( github.com/magiconair/properties v1.8.6 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/markbates/hmax v1.0.0 // indirect + github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.12 // indirect @@ -260,6 +266,7 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/rjeczalik/notify v0.0.0-20181126183243-629144ba06a1 // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect + github.com/russellhaering/goxmldsig v1.1.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/seatgeek/logrus-gelf-formatter v0.0.0-20210414080842-5b05eb8ff761 // indirect github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect diff --git a/go.sum b/go.sum index 784fa0e272ac..907ba31961d2 100644 --- a/go.sum +++ b/go.sum @@ -231,6 +231,8 @@ github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAm github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= +github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= +github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -454,6 +456,10 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo= +github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3pglZ5oH4= +github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4= +github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A= github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ= @@ -468,6 +474,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidrjonas/semver-cli v0.0.0-20190116233701-ee19a9a0dda6 h1:VzPvKOw28XJ77PYwOq5gAqvFB4gk6gst0HxxiW8kfZQ= github.com/davidrjonas/semver-cli v0.0.0-20190116233701-ee19a9a0dda6/go.mod h1:+6FzxsSbK4oEuvdN06Jco8zKB2mQqIB6UduZdd0Zesk= +github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4= github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0= github.com/devigned/tab v0.1.1/go.mod h1:XG9mPq0dFghrYvoBF3xdRrJzSTX1b7IQrvaL9mzjeJY= github.com/dgraph-io/ristretto v0.0.1/go.mod h1:T40EBc7CJke8TkpiYfGGKAeFjSaxuFXhuXRyumBd6RE= @@ -1271,6 +1278,8 @@ github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCn github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= +github.com/mattermost/xml-roundtrip-validator v0.1.0 h1:RXbVD2UAl7A7nOTR4u7E3ILa4IbtvKBHw64LDsmu9hU= +github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxqpJpWWUiPNr5H3O8eDgGV9gT5To= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -1624,6 +1633,8 @@ github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/russellhaering/goxmldsig v1.1.1 h1:vI0r2osGF1A9PLvsGdPUAGwEIrKa4Pj5sesSBsebIxM= +github.com/russellhaering/goxmldsig v1.1.1/go.mod h1:gM4MDENBQf7M+V824SGfyIUVFWydB7n0KkEubVJl+Tw= github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1851,6 +1862,7 @@ github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +github.com/zenazn/goji v1.0.1/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= github.com/zmap/rc2 v0.0.0-20131011165748-24b9757f5521/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE= github.com/zmap/zcertificate v0.0.0-20180516150559-0e3d58b1bac4/go.mod h1:5iU54tB79AMBcySS0R2XIyZBAVmeHranShAFELYx7is= diff --git a/identity/credentials.go b/identity/credentials.go index 025abd59480b..7bd72caeeee1 100644 --- a/identity/credentials.go +++ b/identity/credentials.go @@ -67,6 +67,7 @@ const ( CredentialsTypeTOTP CredentialsType = "totp" CredentialsTypeLookup CredentialsType = "lookup_secret" CredentialsTypeWebAuthn CredentialsType = "webauthn" + CredentialsTypeSAML CredentialsType = "saml" ) const ( diff --git a/internal/httpclient/.openapi-generator/FILES b/internal/httpclient/.openapi-generator/FILES index 53993154b1db..816cbf306f91 100644 --- a/internal/httpclient/.openapi-generator/FILES +++ b/internal/httpclient/.openapi-generator/FILES @@ -48,6 +48,7 @@ docs/SelfServiceRecoveryFlow.md docs/SelfServiceRecoveryFlowState.md docs/SelfServiceRecoveryLink.md docs/SelfServiceRegistrationFlow.md +docs/SelfServiceSamlUrl.md docs/SelfServiceSettingsFlow.md docs/SelfServiceSettingsFlowState.md docs/SelfServiceVerificationFlow.md @@ -139,6 +140,7 @@ model_self_service_recovery_flow.go model_self_service_recovery_flow_state.go model_self_service_recovery_link.go model_self_service_registration_flow.go +model_self_service_saml_url.go model_self_service_settings_flow.go model_self_service_settings_flow_state.go model_self_service_verification_flow.go diff --git a/internal/httpclient/README.md b/internal/httpclient/README.md index 37a9fb01a3a3..6781c3bc0f63 100644 --- a/internal/httpclient/README.md +++ b/internal/httpclient/README.md @@ -111,6 +111,7 @@ Class | Method | HTTP request | Description *V0alpha2Api* | [**InitializeSelfServiceRecoveryFlowWithoutBrowser**](docs/V0alpha2Api.md#initializeselfservicerecoveryflowwithoutbrowser) | **Get** /self-service/recovery/api | Initialize Recovery Flow for APIs, Services, Apps, ... *V0alpha2Api* | [**InitializeSelfServiceRegistrationFlowForBrowsers**](docs/V0alpha2Api.md#initializeselfserviceregistrationflowforbrowsers) | **Get** /self-service/registration/browser | Initialize Registration Flow for Browsers *V0alpha2Api* | [**InitializeSelfServiceRegistrationFlowWithoutBrowser**](docs/V0alpha2Api.md#initializeselfserviceregistrationflowwithoutbrowser) | **Get** /self-service/registration/api | Initialize Registration Flow for APIs, Services, Apps, ... +*V0alpha2Api* | [**InitializeSelfServiceSamlFlowForBrowsers**](docs/V0alpha2Api.md#initializeselfservicesamlflowforbrowsers) | **Get** /self-service/methods/saml/auth | Initialize Registration Flow for APIs, Services, Apps, ... *V0alpha2Api* | [**InitializeSelfServiceSettingsFlowForBrowsers**](docs/V0alpha2Api.md#initializeselfservicesettingsflowforbrowsers) | **Get** /self-service/settings/browser | Initialize Settings Flow for Browsers *V0alpha2Api* | [**InitializeSelfServiceSettingsFlowWithoutBrowser**](docs/V0alpha2Api.md#initializeselfservicesettingsflowwithoutbrowser) | **Get** /self-service/settings/api | Initialize Settings Flow for APIs, Services, Apps, ... *V0alpha2Api* | [**InitializeSelfServiceVerificationFlowForBrowsers**](docs/V0alpha2Api.md#initializeselfserviceverificationflowforbrowsers) | **Get** /self-service/verification/browser | Initialize Verification Flow for Browser Clients @@ -171,6 +172,7 @@ Class | Method | HTTP request | Description - [SelfServiceRecoveryFlowState](docs/SelfServiceRecoveryFlowState.md) - [SelfServiceRecoveryLink](docs/SelfServiceRecoveryLink.md) - [SelfServiceRegistrationFlow](docs/SelfServiceRegistrationFlow.md) + - [SelfServiceSamlUrl](docs/SelfServiceSamlUrl.md) - [SelfServiceSettingsFlow](docs/SelfServiceSettingsFlow.md) - [SelfServiceSettingsFlowState](docs/SelfServiceSettingsFlowState.md) - [SelfServiceVerificationFlow](docs/SelfServiceVerificationFlow.md) diff --git a/internal/httpclient/api/openapi.yaml b/internal/httpclient/api/openapi.yaml index ebc48c690bc1..92fe0eea8fbc 100644 --- a/internal/httpclient/api/openapi.yaml +++ b/internal/httpclient/api/openapi.yaml @@ -1267,6 +1267,51 @@ paths: summary: Create a Logout URL for Browsers tags: - v0alpha2 + /self-service/methods/saml/auth: + get: + description: |- + This endpoint initiates a registration flow for API clients such as mobile devices, smart TVs, and so on. + + If a valid provided session cookie or session token is provided, a 400 Bad Request error + will be returned unless the URL query parameter `?refresh=true` is set. + + To fetch an existing registration flow call `/self-service/registration/flows?flow=`. + + You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server + Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make + you vulnerable to a variety of CSRF attacks. + + In the case of an error, the `error.id` of the JSON response body can be one of: + + `session_already_available`: The user is already signed in. + `security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred. + + This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...). + + More information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration). + operationId: initializeSelfServiceSamlFlowForBrowsers + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/selfServiceRegistrationFlow' + description: selfServiceRegistrationFlow + "400": + content: + application/json: + schema: + $ref: '#/components/schemas/jsonError' + description: jsonError + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/jsonError' + description: jsonError + summary: Initialize Registration Flow for APIs, Services, Apps, ... + tags: + - v0alpha2 /self-service/recovery: post: description: |- @@ -4071,6 +4116,24 @@ components: - type - ui type: object + selfServiceSamlUrl: + properties: + saml_acs_url: + description: |- + SamlAcsURL is a post endpoint to handle SAML Response + + format: uri + type: string + saml_metadata_url: + description: |- + SamlMetadataURL is a get endpoint to get the metadata + + format: uri + type: string + required: + - saml_acs_url + - saml_metadata_url + type: object selfServiceSettingsFlow: description: |- This flow is used when an identity wants to update settings diff --git a/internal/httpclient/docs/SelfServiceSamlUrl.md b/internal/httpclient/docs/SelfServiceSamlUrl.md new file mode 100644 index 000000000000..c7f22694c63c --- /dev/null +++ b/internal/httpclient/docs/SelfServiceSamlUrl.md @@ -0,0 +1,72 @@ +# SelfServiceSamlUrl + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**SamlAcsUrl** | **string** | SamlAcsURL is a post endpoint to handle SAML Response format: uri | +**SamlMetadataUrl** | **string** | SamlMetadataURL is a get endpoint to get the metadata format: uri | + +## Methods + +### NewSelfServiceSamlUrl + +`func NewSelfServiceSamlUrl(samlAcsUrl string, samlMetadataUrl string, ) *SelfServiceSamlUrl` + +NewSelfServiceSamlUrl instantiates a new SelfServiceSamlUrl object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewSelfServiceSamlUrlWithDefaults + +`func NewSelfServiceSamlUrlWithDefaults() *SelfServiceSamlUrl` + +NewSelfServiceSamlUrlWithDefaults instantiates a new SelfServiceSamlUrl object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetSamlAcsUrl + +`func (o *SelfServiceSamlUrl) GetSamlAcsUrl() string` + +GetSamlAcsUrl returns the SamlAcsUrl field if non-nil, zero value otherwise. + +### GetSamlAcsUrlOk + +`func (o *SelfServiceSamlUrl) GetSamlAcsUrlOk() (*string, bool)` + +GetSamlAcsUrlOk returns a tuple with the SamlAcsUrl field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetSamlAcsUrl + +`func (o *SelfServiceSamlUrl) SetSamlAcsUrl(v string)` + +SetSamlAcsUrl sets SamlAcsUrl field to given value. + + +### GetSamlMetadataUrl + +`func (o *SelfServiceSamlUrl) GetSamlMetadataUrl() string` + +GetSamlMetadataUrl returns the SamlMetadataUrl field if non-nil, zero value otherwise. + +### GetSamlMetadataUrlOk + +`func (o *SelfServiceSamlUrl) GetSamlMetadataUrlOk() (*string, bool)` + +GetSamlMetadataUrlOk returns a tuple with the SamlMetadataUrl field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetSamlMetadataUrl + +`func (o *SelfServiceSamlUrl) SetSamlMetadataUrl(v string)` + +SetSamlMetadataUrl sets SamlMetadataUrl field to given value. + + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/internal/httpclient/docs/V0alpha2Api.md b/internal/httpclient/docs/V0alpha2Api.md index 1dbbfcc10d52..53e7633d733f 100644 --- a/internal/httpclient/docs/V0alpha2Api.md +++ b/internal/httpclient/docs/V0alpha2Api.md @@ -29,6 +29,7 @@ Method | HTTP request | Description [**InitializeSelfServiceRecoveryFlowWithoutBrowser**](V0alpha2Api.md#InitializeSelfServiceRecoveryFlowWithoutBrowser) | **Get** /self-service/recovery/api | Initialize Recovery Flow for APIs, Services, Apps, ... [**InitializeSelfServiceRegistrationFlowForBrowsers**](V0alpha2Api.md#InitializeSelfServiceRegistrationFlowForBrowsers) | **Get** /self-service/registration/browser | Initialize Registration Flow for Browsers [**InitializeSelfServiceRegistrationFlowWithoutBrowser**](V0alpha2Api.md#InitializeSelfServiceRegistrationFlowWithoutBrowser) | **Get** /self-service/registration/api | Initialize Registration Flow for APIs, Services, Apps, ... +[**InitializeSelfServiceSamlFlowForBrowsers**](V0alpha2Api.md#InitializeSelfServiceSamlFlowForBrowsers) | **Get** /self-service/methods/saml/auth | Initialize Registration Flow for APIs, Services, Apps, ... [**InitializeSelfServiceSettingsFlowForBrowsers**](V0alpha2Api.md#InitializeSelfServiceSettingsFlowForBrowsers) | **Get** /self-service/settings/browser | Initialize Settings Flow for Browsers [**InitializeSelfServiceSettingsFlowWithoutBrowser**](V0alpha2Api.md#InitializeSelfServiceSettingsFlowWithoutBrowser) | **Get** /self-service/settings/api | Initialize Settings Flow for APIs, Services, Apps, ... [**InitializeSelfServiceVerificationFlowForBrowsers**](V0alpha2Api.md#InitializeSelfServiceVerificationFlowForBrowsers) | **Get** /self-service/verification/browser | Initialize Verification Flow for Browser Clients @@ -1745,6 +1746,67 @@ No authorization required [[Back to README]](../README.md) +## InitializeSelfServiceSamlFlowForBrowsers + +> SelfServiceRegistrationFlow InitializeSelfServiceSamlFlowForBrowsers(ctx).Execute() + +Initialize Registration Flow for APIs, Services, Apps, ... + + + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "./openapi" +) + +func main() { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.V0alpha2Api.InitializeSelfServiceSamlFlowForBrowsers(context.Background()).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.InitializeSelfServiceSamlFlowForBrowsers``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `InitializeSelfServiceSamlFlowForBrowsers`: SelfServiceRegistrationFlow + fmt.Fprintf(os.Stdout, "Response from `V0alpha2Api.InitializeSelfServiceSamlFlowForBrowsers`: %v\n", resp) +} +``` + +### Path Parameters + +This endpoint does not need any parameter. + +### Other Parameters + +Other parameters are passed through a pointer to a apiInitializeSelfServiceSamlFlowForBrowsersRequest struct via the builder pattern + + +### Return type + +[**SelfServiceRegistrationFlow**](SelfServiceRegistrationFlow.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## InitializeSelfServiceSettingsFlowForBrowsers > SelfServiceSettingsFlow InitializeSelfServiceSettingsFlowForBrowsers(ctx).ReturnTo(returnTo).Execute() diff --git a/internal/httpclient/model_self_service_saml_url.go b/internal/httpclient/model_self_service_saml_url.go new file mode 100644 index 000000000000..3194edbb4031 --- /dev/null +++ b/internal/httpclient/model_self_service_saml_url.go @@ -0,0 +1,138 @@ +/* + * Ory Kratos API + * + * Documentation for all public and administrative Ory Kratos APIs. Public and administrative APIs are exposed on different ports. Public APIs can face the public internet without any protection while administrative APIs should never be exposed without prior authorization. To protect the administative API port you should use something like Nginx, Ory Oathkeeper, or any other technology capable of authorizing incoming requests. + * + * API version: 1.0.0 + * Contact: hi@ory.sh + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package client + +import ( + "encoding/json" +) + +// SelfServiceSamlUrl struct for SelfServiceSamlUrl +type SelfServiceSamlUrl struct { + // SamlAcsURL is a post endpoint to handle SAML Response format: uri + SamlAcsUrl string `json:"saml_acs_url"` + // SamlMetadataURL is a get endpoint to get the metadata format: uri + SamlMetadataUrl string `json:"saml_metadata_url"` +} + +// NewSelfServiceSamlUrl instantiates a new SelfServiceSamlUrl object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSelfServiceSamlUrl(samlAcsUrl string, samlMetadataUrl string) *SelfServiceSamlUrl { + this := SelfServiceSamlUrl{} + this.SamlAcsUrl = samlAcsUrl + this.SamlMetadataUrl = samlMetadataUrl + return &this +} + +// NewSelfServiceSamlUrlWithDefaults instantiates a new SelfServiceSamlUrl object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSelfServiceSamlUrlWithDefaults() *SelfServiceSamlUrl { + this := SelfServiceSamlUrl{} + return &this +} + +// GetSamlAcsUrl returns the SamlAcsUrl field value +func (o *SelfServiceSamlUrl) GetSamlAcsUrl() string { + if o == nil { + var ret string + return ret + } + + return o.SamlAcsUrl +} + +// GetSamlAcsUrlOk returns a tuple with the SamlAcsUrl field value +// and a boolean to check if the value has been set. +func (o *SelfServiceSamlUrl) GetSamlAcsUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.SamlAcsUrl, true +} + +// SetSamlAcsUrl sets field value +func (o *SelfServiceSamlUrl) SetSamlAcsUrl(v string) { + o.SamlAcsUrl = v +} + +// GetSamlMetadataUrl returns the SamlMetadataUrl field value +func (o *SelfServiceSamlUrl) GetSamlMetadataUrl() string { + if o == nil { + var ret string + return ret + } + + return o.SamlMetadataUrl +} + +// GetSamlMetadataUrlOk returns a tuple with the SamlMetadataUrl field value +// and a boolean to check if the value has been set. +func (o *SelfServiceSamlUrl) GetSamlMetadataUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.SamlMetadataUrl, true +} + +// SetSamlMetadataUrl sets field value +func (o *SelfServiceSamlUrl) SetSamlMetadataUrl(v string) { + o.SamlMetadataUrl = v +} + +func (o SelfServiceSamlUrl) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if true { + toSerialize["saml_acs_url"] = o.SamlAcsUrl + } + if true { + toSerialize["saml_metadata_url"] = o.SamlMetadataUrl + } + return json.Marshal(toSerialize) +} + +type NullableSelfServiceSamlUrl struct { + value *SelfServiceSamlUrl + isSet bool +} + +func (v NullableSelfServiceSamlUrl) Get() *SelfServiceSamlUrl { + return v.value +} + +func (v *NullableSelfServiceSamlUrl) Set(val *SelfServiceSamlUrl) { + v.value = val + v.isSet = true +} + +func (v NullableSelfServiceSamlUrl) IsSet() bool { + return v.isSet +} + +func (v *NullableSelfServiceSamlUrl) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSelfServiceSamlUrl(val *SelfServiceSamlUrl) *NullableSelfServiceSamlUrl { + return &NullableSelfServiceSamlUrl{value: val, isSet: true} +} + +func (v NullableSelfServiceSamlUrl) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSelfServiceSamlUrl) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/persistence/sql/migrations/sql/2022080818000000000_identity_credentials_types_saml.down.sql b/persistence/sql/migrations/sql/2022080818000000000_identity_credentials_types_saml.down.sql new file mode 100644 index 000000000000..baacd751eade --- /dev/null +++ b/persistence/sql/migrations/sql/2022080818000000000_identity_credentials_types_saml.down.sql @@ -0,0 +1 @@ +DELETE FROM identity_credential_types WHERE name = 'saml'; diff --git a/persistence/sql/migrations/sql/2022080818000000000_identity_credentials_types_saml.up.sql b/persistence/sql/migrations/sql/2022080818000000000_identity_credentials_types_saml.up.sql new file mode 100644 index 000000000000..b58c212cb0d3 --- /dev/null +++ b/persistence/sql/migrations/sql/2022080818000000000_identity_credentials_types_saml.up.sql @@ -0,0 +1 @@ +INSERT INTO identity_credential_types (id, name) SELECT 'ff5a1823-8b47-4255-860f-4b70ed122740', 'saml' WHERE NOT EXISTS ( SELECT * FROM identity_credential_types WHERE name = 'saml'); diff --git a/selfservice/flow/saml/handler.go b/selfservice/flow/saml/handler.go new file mode 100644 index 000000000000..55f5c3406ccf --- /dev/null +++ b/selfservice/flow/saml/handler.go @@ -0,0 +1,330 @@ +package saml + +import ( + "bytes" + "context" + "crypto/rsa" + "crypto/tls" + "crypto/x509" + "encoding/pem" + "io/ioutil" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + "github.com/crewjam/saml/samlsp" + "github.com/julienschmidt/httprouter" + + "github.com/ory/kratos/driver/config" + "github.com/ory/kratos/selfservice/errorx" + + samlidp "github.com/crewjam/saml" + samlstrategy "github.com/ory/kratos/selfservice/strategy/saml" + + "github.com/ory/kratos/session" + "github.com/ory/kratos/x" + "github.com/ory/x/decoderx" + "github.com/ory/x/jsonx" +) + +const ( + RouteSamlMetadata = "/self-service/methods/saml/metadata" + RouteSamlLoginInit = "/self-service/methods/saml/auth" // Redirect to the IDP + RouteSamlAcs = "/self-service/methods/saml/acs" +) + +var ErrNoSession = errors.New("saml: session not present") +var samlMiddleware *samlsp.Middleware + +var ContinuityKey = "ory_kratos_continuity" + +type ( + handlerDependencies interface { + x.WriterProvider + x.CSRFProvider + session.ManagementProvider + session.PersistenceProvider + errorx.ManagementProvider + config.Provider + } + HandlerProvider interface { + LogoutHandler() *Handler + } + Handler struct { + d handlerDependencies + dx *decoderx.HTTP + } +) + +type SessionData struct { + SessionID string +} + +func NewHandler(d handlerDependencies) *Handler { + return &Handler{ + d: d, + dx: decoderx.NewHTTP(), + } +} + +func (h *Handler) RegisterPublicRoutes(router *x.RouterPublic) { + + h.d.CSRFHandler().IgnorePath(RouteSamlLoginInit) + h.d.CSRFHandler().IgnorePath(RouteSamlAcs) + + router.GET(RouteSamlMetadata, h.serveMetadata) + router.GET(RouteSamlLoginInit, h.loginWithIdp) +} + +// Handle /selfservice/methods/saml/metadata +func (h *Handler) serveMetadata(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + config := h.d.Config(r.Context()) + if samlMiddleware == nil { + if err := h.instantiateMiddleware(*config); err != nil { + h.d.SelfServiceErrorManager().Forward(r.Context(), w, r, err) + } + } + + samlMiddleware.ServeMetadata(w, r) +} + +// swagger:route GET /self-service/methods/saml/auth v0alpha2 initializeSelfServiceSamlFlowForBrowsers +// +// Initialize Authentication Flow for SAML (Either the login or the register) +// +// If you already have a session, it will redirect you to the main page. +// +// Schemes: http, https +// +// Responses: +// 200: selfServiceRegistrationFlow +// 400: jsonError +// 500: jsonError +func (h *Handler) loginWithIdp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + // Middleware is a singleton so we have to verify that it exists + if samlMiddleware == nil { + config := h.d.Config(r.Context()) + if err := h.instantiateMiddleware(*config); err != nil { + h.d.SelfServiceErrorManager().Forward(r.Context(), w, r, err) + } + } + + conf := h.d.Config(r.Context()) + + // We have to get the SessionID from the cookie to inject it into the context to ensure continuity + cookie, err := r.Cookie("ory_kratos_continuity") + if err != nil { + h.d.SelfServiceErrorManager().Forward(r.Context(), w, r, err) + } + body, _ := ioutil.ReadAll(r.Body) + r2 := r.Clone(context.WithValue(r.Context(), ContinuityKey, cookie.Value)) + r2.Body = ioutil.NopCloser(bytes.NewReader(body)) + *r = *r2 + + // Checks if the user already have an active session + if e := new(session.ErrNoActiveSessionFound); errors.As(e, &e) { + // No session exists yet, we start the auth flow and create the session + samlMiddleware.HandleStartAuthFlow(w, r) + } else { + // A session already exist, we redirect to the main page + http.Redirect(w, r, conf.SelfServiceBrowserDefaultReturnTo().Path, http.StatusTemporaryRedirect) + } +} + +func DestroyMiddlewareIfExists() { + if samlMiddleware != nil { + samlMiddleware = nil + } +} + +func (h *Handler) instantiateMiddleware(config config.Config) error { + // Create a SAMLProvider object from the config file + var c samlstrategy.ConfigurationCollection + conf := config.SelfServiceStrategy("saml").Config + if err := jsonx. + NewStrictDecoder(bytes.NewBuffer(conf)). + Decode(&c); err != nil { + return errors.Wrapf(err, "Unable to decode config %v", string(conf)) + } + + // Key pair to encrypt and sign SAML requests + keyPair, err := tls.LoadX509KeyPair(strings.Replace(c.SAMLProviders[len(c.SAMLProviders)-1].PublicCertPath, "file://", "", 1), strings.Replace(c.SAMLProviders[len(c.SAMLProviders)-1].PrivateKeyPath, "file://", "", 1)) + if err != nil { + return err + } + keyPair.Leaf, err = x509.ParseCertificate(keyPair.Certificate[0]) + if err != nil { + return err + } + + var idpMetadata *samlidp.EntityDescriptor + + // We check if the metadata file is provided + if c.SAMLProviders[len(c.SAMLProviders)-1].IDPInformation["idp_metadata_url"] != "" { + + metadataURL := c.SAMLProviders[len(c.SAMLProviders)-1].IDPInformation["idp_metadata_url"] + // The metadata file is provided + if strings.HasPrefix(metadataURL, "file://") { + metadataURL = strings.Replace(metadataURL, "file://", "", 1) + + metadataPlainText, err := ioutil.ReadFile(metadataURL) + if err != nil { + return err + } + + idpMetadata, err = samlsp.ParseMetadata([]byte(metadataPlainText)) + if err != nil { + return err + } + + } else { + idpMetadataURL, err := url.Parse(metadataURL) + if err != nil { + return err + } + // Parse the content of metadata file into a Golang struct + idpMetadata, err = samlsp.FetchMetadata(context.Background(), http.DefaultClient, *idpMetadataURL) + if err != nil { + return err + } + } + + } else { + + // The metadata file is not provided + // So were are creating a minimalist IDP metadata based on what is provided by the user on the config file + entityIDURL, err := url.Parse(c.SAMLProviders[len(c.SAMLProviders)-1].IDPInformation["idp_entity_id"]) + if err != nil { + return err + } + + // The IDP SSO URL + IDPSSOURL, err := url.Parse(c.SAMLProviders[len(c.SAMLProviders)-1].IDPInformation["idp_sso_url"]) + if err != nil { + return err + } + + // The IDP Logout URL + IDPlogoutURL, err := url.Parse(c.SAMLProviders[len(c.SAMLProviders)-1].IDPInformation["idp_logout_url"]) + if err != nil { + return err + } + + // The certificate of the IDP + certificate, err := ioutil.ReadFile(strings.Replace(c.SAMLProviders[len(c.SAMLProviders)-1].IDPInformation["idp_certificate_path"], "file://", "", 1)) + if err != nil { + return err + } + + // We parse it into a x509.Certificate object + IDPCertificate, err := MustParseCertificate(certificate) + if err != nil { + return err + } + + // Because the metadata file is not provided, we need to simulate an IDP to create artificial metadata from the data entered in the conf file + tempIDP := samlidp.IdentityProvider{ + Key: nil, + Certificate: IDPCertificate, + Logger: nil, + MetadataURL: *entityIDURL, + SSOURL: *IDPSSOURL, + LogoutURL: *IDPlogoutURL, + } + + // Now we assign our reconstructed metadata to our SP + idpMetadata = tempIDP.Metadata() + } + + // The main URL + rootURL, err := url.Parse(config.SelfServiceBrowserDefaultReturnTo().String()) + if err != nil { + return err + } + + // Here we create a MiddleWare to transform Kratos into a Service Provider + samlMiddleWare, err := samlsp.New(samlsp.Options{ + URL: *rootURL, + Key: keyPair.PrivateKey.(*rsa.PrivateKey), + Certificate: keyPair.Leaf, + IDPMetadata: idpMetadata, + SignRequest: true, + // We have to replace the ContinuityCookie by using RelayState. We will pass the SessionID (uuid) of Kratos through RelayState + RelayStateFunc: func(w http.ResponseWriter, r *http.Request) string { + ctx := r.Context() + cipheredCookie, ok := ctx.Value(ContinuityKey).(string) + if !ok { + _, err := w.Write([]byte("No SessionID in current context")) + if err != nil { + errors.New("Error while writing the SessionID problem") + } + return "" + } + return cipheredCookie + }, + }) + if err != nil { + return err + } + + var publicUrlString = config.SelfPublicURL().String() + + // Sometimes there is an issue with double slash into the url so we prevent it + // Crewjam library use default route for ACS and metadat but we want to overwrite them + RouteSamlAcsWithSlash := RouteSamlAcs + if publicUrlString[len(publicUrlString)-1] != '/' { + + u, err := url.Parse(publicUrlString + RouteSamlAcsWithSlash) + if err != nil { + return err + } + samlMiddleWare.ServiceProvider.AcsURL = *u + + } else if publicUrlString[len(publicUrlString)-1] == '/' { + + publicUrlString = publicUrlString[:len(publicUrlString)-1] + u, err := url.Parse(publicUrlString + RouteSamlAcsWithSlash) + if err != nil { + return err + } + samlMiddleWare.ServiceProvider.AcsURL = *u + } + + // Crewjam library use default route for ACS and metadata but we want to overwrite them + metadata, err := url.Parse(publicUrlString + RouteSamlMetadata) + if err != nil { + return err + } + samlMiddleWare.ServiceProvider.MetadataURL = *metadata + + // The EntityID in the AuthnRequest is the Metadata URL + samlMiddleWare.ServiceProvider.EntityID = samlMiddleWare.ServiceProvider.MetadataURL.String() + + // The issuer format is unspecified + samlMiddleWare.ServiceProvider.AuthnNameIDFormat = samlidp.UnspecifiedNameIDFormat + + samlMiddleware = samlMiddleWare + + return nil +} + +func GetMiddleware() (*samlsp.Middleware, error) { + if samlMiddleware == nil { + return nil, errors.Errorf("The MiddleWare for SAML is null (Probably due to a backward step)") + } + return samlMiddleware, nil +} + +func MustParseCertificate(pemStr []byte) (*x509.Certificate, error) { + b, _ := pem.Decode(pemStr) + if b == nil { + return nil, errors.Errorf("Cannot find the next PEM formatted block") + } + cert, err := x509.ParseCertificate(b.Bytes) + if err != nil { + return nil, err + } + return cert, nil +} diff --git a/selfservice/flow/saml/helpertest/helpertest.go b/selfservice/flow/saml/helpertest/helpertest.go new file mode 100644 index 000000000000..42ded4a23459 --- /dev/null +++ b/selfservice/flow/saml/helpertest/helpertest.go @@ -0,0 +1,203 @@ +package helpertest + +import ( + "crypto" + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "encoding/pem" + "encoding/xml" + "io/ioutil" + "net/http" + "net/http/cookiejar" + "net/http/httptest" + "testing" + "time" + + "github.com/beevik/etree" + crewjamsaml "github.com/crewjam/saml" + "github.com/crewjam/saml/samlsp" + "github.com/crewjam/saml/xmlenc" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" + "gotest.tools/golden" + + "github.com/ory/kratos/driver/config" + "github.com/ory/kratos/identity" + "github.com/ory/kratos/internal" + "github.com/ory/kratos/internal/testhelpers" + samlhandler "github.com/ory/kratos/selfservice/flow/saml" + "github.com/ory/kratos/selfservice/strategy/saml" + samlstrategy "github.com/ory/kratos/selfservice/strategy/saml" + samlstrat "github.com/ory/kratos/selfservice/strategy/saml/strategy" + "github.com/ory/kratos/x" +) + +var TimeNow = func() time.Time { return time.Now().UTC() } +var RandReader = rand.Reader + +func NewSAMLProvider( + t *testing.T, + kratos *httptest.Server, + id, label string, +) samlstrategy.Configuration { + + return samlstrategy.Configuration{ + ID: id, + Label: label, + PublicCertPath: "secret", + PrivateKeyPath: "/", + Mapper: "file://./stub/oidc.hydra.jsonnet", + //IDPMetadataURL: "", + //IDPSSOURL: "", + } +} + +func ViperSetProviderConfig(t *testing.T, conf *config.Config, SAMLProvider ...samlstrategy.Configuration) { + conf.MustSet(config.ViperKeySelfServiceStrategyConfig+"."+string(identity.CredentialsTypeSAML)+".config", &samlstrategy.ConfigurationCollection{SAMLProviders: SAMLProvider}) + conf.MustSet(config.ViperKeySelfServiceStrategyConfig+"."+string(identity.CredentialsTypeSAML)+".enabled", true) +} + +func NewClient(t *testing.T, jar *cookiejar.Jar) *http.Client { + if jar == nil { + j, err := cookiejar.New(nil) + jar = j + require.NoError(t, err) + } + return &http.Client{ + Jar: jar, + CheckRedirect: func(req *http.Request, via []*http.Request) error { + if len(via) >= 20 { + for k, v := range via { + t.Logf("Failed with redirect (%d): %s", k, v.URL.String()) + } + return errors.New("stopped after 20 redirects") + } + return nil + }, + } +} + +// AssertSystemError asserts an error ui response +func AssertSystemError(t *testing.T, errTS *httptest.Server, res *http.Response, body []byte, code int, reason string) { + require.Contains(t, res.Request.URL.String(), errTS.URL, "%s", body) + + assert.Equal(t, int64(code), gjson.GetBytes(body, "code").Int(), "%s", body) + assert.Contains(t, gjson.GetBytes(body, "reason").String(), reason, "%s", body) +} + +func mustParseCertificate(pemStr []byte) *x509.Certificate { + b, _ := pem.Decode(pemStr) + if b == nil { + panic("cannot parse PEM") + } + cert, err := x509.ParseCertificate(b.Bytes) + if err != nil { + panic(err) + } + return cert +} + +func mustParsePrivateKey(pemStr []byte) crypto.PrivateKey { + b, _ := pem.Decode(pemStr) + if b == nil { + panic("cannot parse PEM") + } + k, err := x509.ParsePKCS1PrivateKey(b.Bytes) + if err != nil { + panic(err) + } + return k +} + +func InitMiddleware(t *testing.T, idpInformation map[string]string) (*samlsp.Middleware, *samlstrat.Strategy, *httptest.Server, error) { + conf, reg := internal.NewFastRegistryWithMocks(t) + + strategy := samlstrat.NewStrategy(reg) + errTS := testhelpers.NewErrorTestServer(t, reg) + routerP := x.NewRouterPublic() + routerA := x.NewRouterAdmin() + ts, _ := testhelpers.NewKratosServerWithRouters(t, reg, routerP, routerA) + + attributesMap := make(map[string]string) + attributesMap["id"] = "mail" + attributesMap["firstname"] = "givenName" + attributesMap["lastname"] = "sn" + attributesMap["email"] = "mail" + + // Initiates the service provider + ViperSetProviderConfig( + t, + conf, + NewSAMLProvider(t, ts, "samlProviderTestID", "samlProviderTestLabel"), + saml.Configuration{ + ID: "samlProviderTestID", + Label: "samlProviderTestLabel", + PublicCertPath: "file://testdata/myservice.cert", + PrivateKeyPath: "file://testdata/myservice.key", + Mapper: "file://testdata/saml.jsonnet", + AttributesMap: attributesMap, + IDPInformation: idpInformation, + }, + ) + + conf.MustSet(config.ViperKeySelfServiceRegistrationEnabled, true) + testhelpers.SetDefaultIdentitySchema(conf, "file://testdata/registration.schema.json") + conf.MustSet(config.HookStrategyKey(config.ViperKeySelfServiceRegistrationAfter, + identity.CredentialsTypeSAML.String()), []config.SelfServiceHook{{Name: "session"}}) + + t.Logf("Kratos Public URL: %s", ts.URL) + t.Logf("Kratos Error URL: %s", errTS.URL) + + // Instantiates the MiddleWare + _, err := NewClient(t, nil).Get(ts.URL + "/self-service/methods/saml/metadata") + require.NoError(t, err) + middleware, err := samlhandler.GetMiddleware() + require.NoError(t, err) + middleware.ServiceProvider.Key = mustParsePrivateKey(golden.Get(t, "key.pem")).(*rsa.PrivateKey) + middleware.ServiceProvider.Certificate = mustParseCertificate(golden.Get(t, "cert.pem")) + + return middleware, strategy, ts, err +} + +func InitMiddlewareWithMetadata(t *testing.T, metadataURL string) (*samlsp.Middleware, *samlstrat.Strategy, *httptest.Server, error) { + idpInformation := make(map[string]string) + idpInformation["idp_metadata_url"] = metadataURL + + return InitMiddleware(t, idpInformation) +} + +func InitMiddlewareWithoutMetadata(t *testing.T, idpSsoUrl string, idpEntityId string, + idpCertifiatePath string, idpLogoutUrl string) (*samlsp.Middleware, *samlstrat.Strategy, *httptest.Server, error) { + + idpInformation := make(map[string]string) + idpInformation["idp_sso_url"] = idpSsoUrl + idpInformation["idp_entity_id"] = idpEntityId + idpInformation["idp_certificate_path"] = idpCertifiatePath + idpInformation["idp_logout_url"] = idpLogoutUrl + + return InitMiddleware(t, idpInformation) +} + +func GetAndDecryptAssertion(t *testing.T, samlResponseFile string, key *rsa.PrivateKey) (*crewjamsaml.Assertion, error) { + // Load saml response test file + samlResponse, err := ioutil.ReadFile(samlResponseFile) + require.NoError(t, err) + + // Decrypt saml response assertion + doc := etree.NewDocument() + err = doc.ReadFromBytes(samlResponse) + require.NoError(t, err) + responseEl := doc.Root() + el := responseEl.FindElement("//EncryptedAssertion/EncryptedData") + plaintextAssertion, err := xmlenc.Decrypt(key, el) + require.NoError(t, err) + + assertion := &crewjamsaml.Assertion{} + err = xml.Unmarshal(plaintextAssertion, assertion) + require.NoError(t, err) + + return assertion, err +} diff --git a/selfservice/flow/saml/test/handler_test.go b/selfservice/flow/saml/test/handler_test.go new file mode 100644 index 000000000000..0af00023e473 --- /dev/null +++ b/selfservice/flow/saml/test/handler_test.go @@ -0,0 +1,92 @@ +package saml_test + +import ( + "io/ioutil" + "testing" + + samlhandler "github.com/ory/kratos/selfservice/flow/saml" + "github.com/stretchr/testify/require" + + helpertest "github.com/ory/kratos/selfservice/flow/saml/helpertest" + "gotest.tools/assert" +) + +func TestInitMiddleWareWithMetadata(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + middleWare, _, _, err := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + require.NoError(t, err) + assert.Check(t, middleWare != nil) + assert.Check(t, middleWare.ServiceProvider.IDPMetadata != nil) + assert.Check(t, middleWare.ServiceProvider.MetadataURL.Path == "/self-service/methods/saml/metadata") + assert.Check(t, middleWare.ServiceProvider.IDPMetadata.EntityID == "https://idp.testshib.org/idp/shibboleth") +} + +func TestInitMiddleWareWithoutMetadata(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + middleWare, _, _, err := helpertest.InitMiddlewareWithoutMetadata(t, + "https://samltest.id/idp/profile/SAML2/Redirect/SSO", + "https://samltest.id/saml/idp", + "file://testdata/samlkratos.crt", + "https://samltest.id/idp/profile/SAML2/Redirect/SSO") + + require.NoError(t, err) + assert.Check(t, middleWare != nil) + assert.Check(t, middleWare.ServiceProvider.IDPMetadata != nil) + assert.Check(t, middleWare.ServiceProvider.MetadataURL.Path == "/self-service/methods/saml/metadata") + assert.Check(t, middleWare.ServiceProvider.IDPMetadata.EntityID == "https://samltest.id/saml/idp") +} + +func TestGetMiddleware(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + middleWare, err := samlhandler.GetMiddleware() + + require.NoError(t, err) + assert.Check(t, middleWare != nil) + assert.Check(t, middleWare.ServiceProvider.IDPMetadata != nil) + assert.Check(t, middleWare.ServiceProvider.MetadataURL.Path == "/self-service/methods/saml/metadata") + assert.Check(t, middleWare.ServiceProvider.IDPMetadata.EntityID == "https://idp.testshib.org/idp/shibboleth") +} + +func TestMustParseCertificate(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + certificate, err := ioutil.ReadFile("testdata/samlkratos.crt") + require.NoError(t, err) + + cert, err := samlhandler.MustParseCertificate(certificate) + + require.NoError(t, err) + assert.Check(t, cert.Issuer.Country[0] == "AU") + assert.Check(t, cert.Issuer.Organization[0] == "Internet Widgits Pty Ltd") + assert.Check(t, cert.Issuer.Province[0] == "Some-State") + assert.Check(t, cert.Subject.Country[0] == "AU") + assert.Check(t, cert.Subject.Organization[0] == "Internet Widgits Pty Ltd") + assert.Check(t, cert.Subject.Province[0] == "Some-State") + assert.Check(t, cert.NotBefore.String() == "2022-02-21 11:08:20 +0000 UTC") + assert.Check(t, cert.NotAfter.String() == "2023-02-21 11:08:20 +0000 UTC") + assert.Check(t, cert.SerialNumber.String() == "485646075402096403898806020771481121115125312047") +} diff --git a/selfservice/flow/saml/test/metadata_test.go b/selfservice/flow/saml/test/metadata_test.go new file mode 100644 index 000000000000..7545034d7157 --- /dev/null +++ b/selfservice/flow/saml/test/metadata_test.go @@ -0,0 +1,127 @@ +package saml_test + +import ( + "encoding/xml" + "io" + "io/ioutil" + "net/http" + "reflect" + "testing" + + samlhandler "github.com/ory/kratos/selfservice/flow/saml" + helpertest "github.com/ory/kratos/selfservice/flow/saml/helpertest" + + samltesthelpers "github.com/ory/kratos/selfservice/flow/saml/helpertest" + + "github.com/stretchr/testify/require" + "gotest.tools/assert" + is "gotest.tools/assert/cmp" +) + +type Metadata struct { + XMLName xml.Name `xml:"EntityDescriptor"` + Text string `xml:",chardata"` + Xmlns string `xml:"xmlns,attr"` + ValidUntil string `xml:"validUntil,attr"` + EntityID string `xml:"entityID,attr"` + SPSSODescriptor struct { + Text string `xml:",chardata"` + Xmlns string `xml:"xmlns,attr"` + ValidUntil string `xml:"validUntil,attr"` + ProtocolSupportEnumeration string `xml:"protocolSupportEnumeration,attr"` + AuthnRequestsSigned string `xml:"AuthnRequestsSigned,attr"` + WantAssertionsSigned string `xml:"WantAssertionsSigned,attr"` + KeyDescriptor []struct { + Text string `xml:",chardata"` + Use string `xml:"use,attr"` + KeyInfo struct { + Text string `xml:",chardata"` + Xmlns string `xml:"xmlns,attr"` + X509Data struct { + Text string `xml:",chardata"` + Xmlns string `xml:"xmlns,attr"` + X509Certificate struct { + Text string `xml:",chardata"` + Xmlns string `xml:"xmlns,attr"` + } `xml:"X509Certificate"` + } `xml:"X509Data"` + } `xml:"KeyInfo"` + EncryptionMethod []struct { + Text string `xml:",chardata"` + Algorithm string `xml:"Algorithm,attr"` + } `xml:"EncryptionMethod"` + } `xml:"KeyDescriptor"` + SingleLogoutService struct { + Text string `xml:",chardata"` + Binding string `xml:"Binding,attr"` + Location string `xml:"Location,attr"` + ResponseLocation string `xml:"ResponseLocation,attr"` + } `xml:"SingleLogoutService"` + AssertionConsumerService []struct { + Text string `xml:",chardata"` + Binding string `xml:"Binding,attr"` + Location string `xml:"Location,attr"` + Index string `xml:"index,attr"` + } `xml:"AssertionConsumerService"` + } `xml:"SPSSODescriptor"` +} + +func TestXmlMetadataExist(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + _, _, ts, err := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + assert.NilError(t, err) + res, _ := samltesthelpers.NewClient(t, nil).Get(ts.URL + "/self-service/methods/saml/metadata") + + assert.Check(t, is.Equal(http.StatusOK, res.StatusCode)) + assert.Check(t, is.Equal("application/samlmetadata+xml", + res.Header.Get("Content-type"))) +} + +func TestXmlMetadataValues(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + _, _, ts, err := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + res, _ := samltesthelpers.NewClient(t, nil).Get(ts.URL + "/self-service/methods/saml/metadata") + body, _ := io.ReadAll(res.Body) + + assert.Check(t, is.Equal(http.StatusOK, res.StatusCode)) + assert.Check(t, is.Equal("application/samlmetadata+xml", + res.Header.Get("Content-type"))) + + expectedMetadata, err := ioutil.ReadFile("./testdata/expected_metadata.xml") + assert.NilError(t, err) + + // The string is parse to a struct + var expectedStructMetadata Metadata + err = xml.Unmarshal(expectedMetadata, &expectedStructMetadata) + require.NoError(t, err) + + var obtainedStructureMetadata Metadata + err = xml.Unmarshal(body, &obtainedStructureMetadata) + require.NoError(t, err) + + // We delete data that is likely to change naturally + expectedStructMetadata.SPSSODescriptor.AssertionConsumerService[0].Location = "" + expectedStructMetadata.SPSSODescriptor.AssertionConsumerService[1].Location = "" + obtainedStructureMetadata.SPSSODescriptor.AssertionConsumerService[0].Location = "" + obtainedStructureMetadata.SPSSODescriptor.AssertionConsumerService[1].Location = "" + expectedStructMetadata.ValidUntil = "" + expectedStructMetadata.SPSSODescriptor.ValidUntil = "" + obtainedStructureMetadata.ValidUntil = "" + obtainedStructureMetadata.SPSSODescriptor.ValidUntil = "" + expectedStructMetadata.EntityID = "" + obtainedStructureMetadata.EntityID = "" + + assert.Check(t, reflect.DeepEqual(expectedStructMetadata, obtainedStructureMetadata)) +} diff --git a/selfservice/flow/saml/test/testdata/cert.pem b/selfservice/flow/saml/test/testdata/cert.pem new file mode 100644 index 000000000000..52667ef39ff2 --- /dev/null +++ b/selfservice/flow/saml/test/testdata/cert.pem @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJV +UzELMAkGA1UECAwCR0ExDDAKBgNVBAoMA2ZvbzESMBAGA1UEAwwJbG9jYWxob3N0 +MB4XDTEzMTAwMjAwMDg1MVoXDTE0MTAwMjAwMDg1MVowPDELMAkGA1UEBhMCVVMx +CzAJBgNVBAgMAkdBMQwwCgYDVQQKDANmb28xEjAQBgNVBAMMCWxvY2FsaG9zdDCB +nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1PMHYmhZj308kWLhZVT4vOulqx/9 +ibm5B86fPWwUKKQ2i12MYtz07tzukPymisTDhQaqyJ8Kqb/6JjhmeMnEOdTvSPmH +O8m1ZVveJU6NoKRn/mP/BD7FW52WhbrUXLSeHVSKfWkNk6S4hk9MV9TswTvyRIKv +Rsw0X/gfnqkroJcCAwEAATANBgkqhkiG9w0BAQUFAAOBgQCMMlIO+GNcGekevKgk +akpMdAqJfs24maGb90DvTLbRZRD7Xvn1MnVBBS9hzlXiFLYOInXACMW5gcoRFfeT +QLSouMM8o57h0uKjfTmuoWHLQLi6hnF+cvCsEFiJZ4AbF+DgmO6TarJ8O05t8zvn +OwJlNCASPZRH/JmF8tX0hoHuAQ== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/selfservice/flow/saml/test/testdata/expected_metadata.xml b/selfservice/flow/saml/test/testdata/expected_metadata.xml new file mode 100644 index 000000000000..05039766f75f --- /dev/null +++ b/selfservice/flow/saml/test/testdata/expected_metadata.xml @@ -0,0 +1,25 @@ + + + + + + MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJVUzELMAkGA1UECAwCR0ExDDAKBgNVBA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AAOBgQCMMlIO+GNcGekevKgkakpMdAqJfs24maGb90DvTLbRZRD7Xvn1MnVBBS9hzlXiFLYOInXACMW5gcoRFfeTQLSouMM8o57h0uKjfTmuoWHLQLi6hnF+cvCsEFiJZ4AbF+DgmO6TarJ8O05t8zvnOwJlNCASPZRH/JmF8tX0hoHuAQ== + + + + + + + + \ No newline at end of file diff --git a/selfservice/flow/saml/test/testdata/idp_saml_metadata.xml b/selfservice/flow/saml/test/testdata/idp_saml_metadata.xml new file mode 100644 index 000000000000..dcaf7f051dae --- /dev/null +++ b/selfservice/flow/saml/test/testdata/idp_saml_metadata.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + testshib.org + + TestShib Test IdP + TestShib IdP. Use this as a source of attributes + for your test SP. + https://www.testshib.org/testshibtwo.jpg + + + + + + MIIEDjCCAvagAwIBAgIBADANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzEV + MBMGA1UECBMMUGVubnN5bHZhbmlhMRMwEQYDVQQHEwpQaXR0c2J1cmdoMREwDwYD + VQQKEwhUZXN0U2hpYjEZMBcGA1UEAxMQaWRwLnRlc3RzaGliLm9yZzAeFw0wNjA4 + MzAyMTEyMjVaFw0xNjA4MjcyMTEyMjVaMGcxCzAJBgNVBAYTAlVTMRUwEwYDVQQI + EwxQZW5uc3lsdmFuaWExEzARBgNVBAcTClBpdHRzYnVyZ2gxETAPBgNVBAoTCFRl + c3RTaGliMRkwFwYDVQQDExBpZHAudGVzdHNoaWIub3JnMIIBIjANBgkqhkiG9w0B + AQEFAAOCAQ8AMIIBCgKCAQEArYkCGuTmJp9eAOSGHwRJo1SNatB5ZOKqDM9ysg7C + yVTDClcpu93gSP10nH4gkCZOlnESNgttg0r+MqL8tfJC6ybddEFB3YBo8PZajKSe + 3OQ01Ow3yT4I+Wdg1tsTpSge9gEz7SrC07EkYmHuPtd71CHiUaCWDv+xVfUQX0aT + NPFmDixzUjoYzbGDrtAyCqA8f9CN2txIfJnpHE6q6CmKcoLADS4UrNPlhHSzd614 + kR/JYiks0K4kbRqCQF0Dv0P5Di+rEfefC6glV8ysC8dB5/9nb0yh/ojRuJGmgMWH + gWk6h0ihjihqiu4jACovUZ7vVOCgSE5Ipn7OIwqd93zp2wIDAQABo4HEMIHBMB0G + A1UdDgQWBBSsBQ869nh83KqZr5jArr4/7b+QazCBkQYDVR0jBIGJMIGGgBSsBQ86 + 9nh83KqZr5jArr4/7b+Qa6FrpGkwZzELMAkGA1UEBhMCVVMxFTATBgNVBAgTDFBl + bm5zeWx2YW5pYTETMBEGA1UEBxMKUGl0dHNidXJnaDERMA8GA1UEChMIVGVzdFNo + aWIxGTAXBgNVBAMTEGlkcC50ZXN0c2hpYi5vcmeCAQAwDAYDVR0TBAUwAwEB/zAN + BgkqhkiG9w0BAQUFAAOCAQEAjR29PhrCbk8qLN5MFfSVk98t3CT9jHZoYxd8QMRL + I4j7iYQxXiGJTT1FXs1nd4Rha9un+LqTfeMMYqISdDDI6tv8iNpkOAvZZUosVkUo + 93pv1T0RPz35hcHHYq2yee59HJOco2bFlcsH8JBXRSRrJ3Q7Eut+z9uo80JdGNJ4 + /SJy5UorZ8KazGj16lfJhOBXldgrhppQBb0Nq6HKHguqmwRfJ+WkxemZXzhediAj + Geka8nz8JjwxpUjAiSWYKLtJhGEaTqCYxCCX2Dw+dOTqUzHOZ7WKv4JXPK5G/Uhr + 8K/qhmFT2nIQi538n6rVYLeWj8Bbnl+ev0peYzxFyF5sQA== + + + + + + + + + + + + urn:mace:shibboleth:1.0:nameIdentifier + urn:oasis:names:tc:SAML:2.0:nameid-format:transient + + + + + + + + + + + + MIIEDjCCAvagAwIBAgIBADANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzEV + MBMGA1UECBMMUGVubnN5bHZhbmlhMRMwEQYDVQQHEwpQaXR0c2J1cmdoMREwDwYD + VQQKEwhUZXN0U2hpYjEZMBcGA1UEAxMQaWRwLnRlc3RzaGliLm9yZzAeFw0wNjA4 + MzAyMTE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0Nq6HKHguqmwRfJ+WkxemZXzhediAj + Geka8nz8JjwxpUjAiSWYKLtJhGEaTqCYxCCX2Dw+dOTqUzHOZ7WKv4JXPK5G/Uhr + 8K/qhmFT2nIQi538n6rVYLeWj8Bbnl+ev0peYzxFyF5sQA== + + + + + + + + + + + + urn:mace:shibboleth:1.0:nameIdentifier + urn:oasis:names:tc:SAML:2.0:nameid-format:transient + + + TestShib Two Identity Provider + TestShib Two + http://www.testshib.org/testshib-two/ + + + Nate + Klingenstein + ndk@internet2.edu + + \ No newline at end of file diff --git a/selfservice/flow/saml/test/testdata/key.pem b/selfservice/flow/saml/test/testdata/key.pem new file mode 100644 index 000000000000..48284dac33a1 --- /dev/null +++ b/selfservice/flow/saml/test/testdata/key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXgIBAAKBgQDU8wdiaFmPfTyRYuFlVPi866WrH/2JubkHzp89bBQopDaLXYxi +3PTu3O6Q/KaKxMOFBqrInwqpv/omOGZ4ycQ51O9I+Yc7ybVlW94lTo2gpGf+Y/8E +PsVbnZaFutRctJ4dVIp9aQ2TpLiGT0xX1OzBO/JEgq9GzDRf+B+eqSuglwIDAQAB +AoGBAMuy1eN6cgFiCOgBsB3gVDdTKpww87Qk5ivjqEt28SmXO13A1KNVPS6oQ8SJ +CT5Azc6X/BIAoJCURVL+LHdqebogKljhH/3yIel1kH19vr4E2kTM/tYH+qj8afUS +JEmArUzsmmK8ccuNqBcllqdwCZjxL4CHDUmyRudFcHVX9oyhAkEA/OV1OkjM3CLU +N3sqELdMmHq5QZCUihBmk3/N5OvGdqAFGBlEeewlepEVxkh7JnaNXAXrKHRVu/f/ +fbCQxH+qrwJBANeQERF97b9Sibp9xgolb749UWNlAdqmEpmlvmS202TdcaaT1msU +4rRLiQN3X9O9mq4LZMSVethrQAdX1whawpkCQQDk1yGf7xZpMJ8F4U5sN+F4rLyM +Rq8Sy8p2OBTwzCUXXK+fYeXjybsUUMr6VMYTRP2fQr/LKJIX+E5ZxvcIyFmDAkEA +yfjNVUNVaIbQTzEbRlRvT6MqR+PTCefC072NF9aJWR93JimspGZMR7viY6IM4lrr +vBkm0F5yXKaYtoiiDMzlOQJADqmEwXl0D72ZG/2KDg8b4QZEmC9i5gidpQwJXUc6 +hU+IVQoLxRq0fBib/36K9tcrrO5Ba4iEvDcNY+D8yGbUtA== +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/selfservice/flow/saml/test/testdata/myservice.cert b/selfservice/flow/saml/test/testdata/myservice.cert new file mode 100755 index 000000000000..a815f8f44742 --- /dev/null +++ b/selfservice/flow/saml/test/testdata/myservice.cert @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDITCCAgmgAwIBAgIUAKe3G3G4JRoPJDbHcFfUC0M1vUwwDQYJKoZIhvcNAQEL +BQAwIDEeMBwGA1UEAwwVbXlzZXJ2aWNlLmV4YW1wbGUuY29tMB4XDTIxMTIyODEw +MTcxOFoXDTIyMTIyODEwMTcxOFowIDEeMBwGA1UEAwwVbXlzZXJ2aWNlLmV4YW1w +bGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA456eHhpbTabo +JD9IurVIakdb4Y1CtM1cWEgeDB/owu+h13pqj+wk/1AlFUNIYKfzJNmP+CoJv5pS +vUeJaMdA7vKUCHPMY7SNoZdaX0eGV4Z9Q7Q6pSkV+heoamojl+Lq9VIVvWnz4ra9 +3xjvJJ4bACyIz7k9u32jAb+v3Rh3axVlPfYJqCx0gU+tcMxb/Lc7HH7ynAjFGc4N +iG7qOqE2nmzRanKw4dMJhkzhNyFQbqtd4DmEzV70XixyztxmbENVfNdvOrCc34/e +JR4q7w5YEGMwUIPip7/zz/itqsrk0x4/VF1lExMOihf8dfYnqdF3+SdywoBf5UC4 +AUyFS/3FgQIDAQABo1MwUTAdBgNVHQ4EFgQUdG+6zhMmsR2yenGz22Iacjeh6BUw +HwYDVR0jBBgwFoAUdG+6zhMmsR2yenGz22Iacjeh6BUwDwYDVR0TAQH/BAUwAwEB +/zANBgkqhkiG9w0BAQsFAAOCAQEAU5eJKGCBsJpMgL6AgrtpY47iT2KtIkeiI5RC +L+2z2pORG2jFzvY+3kcYA+Nj7EwVyBGmn2lL2JCgk3Qr1YsO4IMJ6sZYbDi6I1SR +z14QMYDRWqPY7VoyqiDzdIS9ENWm80gCG4BChSMtEtN2kmjdTOM++Cr4LY/LLhM4 +9aSNfXHTx4kklP1VVc8dGWw+bFtzZUeP6O+ssrFhcse4V6DoQAxYSU4MAAjePhAP +0IS2I3sSzLe/LCsJMPZv0r1q8YQCGBrijAXSnQiu8KFh8hEQusxilIZV9XPDGB98 +EwTT5cbtUtOIbrZ6kdBs49O27xCTymaIuysidFtywwTaDdrc1g== +-----END CERTIFICATE----- diff --git a/selfservice/flow/saml/test/testdata/myservice.key b/selfservice/flow/saml/test/testdata/myservice.key new file mode 100755 index 000000000000..e7b461f2f228 --- /dev/null +++ b/selfservice/flow/saml/test/testdata/myservice.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDjnp4eGltNpugk +P0i6tUhqR1vhjUK0zVxYSB4MH+jC76HXemqP7CT/UCUVQ0hgp/Mk2Y/4Kgm/mlK9 +R4lox0Du8pQIc8xjtI2hl1pfR4ZXhn1DtDqlKRX6F6hqaiOX4ur1UhW9afPitr3f +GO8knhsALIjPuT27faMBv6/dGHdrFWU99gmoLHSBT61wzFv8tzscfvKcCMUZzg2I +buo6oTaebNFqcrDh0wmGTOE3IVBuq13gOYTNXvReLHLO3GZsQ1V81286sJzfj94l +HirvDlgQYzBQg+Knv/PP+K2qyuTTHj9UXWUTEw6KF/x19iep0Xf5J3LCgF/lQLgB +TIVL/cWBAgMBAAECggEAAn9H/s6NN+Hf5B3pn1rDy56yzFuvYqpqG/HWmo1zEUht +vx5xstiFY2OutHgDgEP3b+0PHkrfxoFb7QWu5T5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L720 +mTIhl2AzTJ1VMWoqUIHtGxhaIC3zhDjAaTMHZNDXFU78hPOhcBPtKikh3Hj2bfGG +TK1KTG49VMcWHmYJhJXwVevKAg== +-----END PRIVATE KEY----- diff --git a/selfservice/flow/saml/test/testdata/registration.schema.json b/selfservice/flow/saml/test/testdata/registration.schema.json new file mode 100644 index 000000000000..c7005d87ce8d --- /dev/null +++ b/selfservice/flow/saml/test/testdata/registration.schema.json @@ -0,0 +1,16 @@ +{ + "$id": "https://example.com/registration.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Person", + "type": "object", + "properties": { + "traits": { + "type": "object", + "properties": { + "bar": { + "type": "string" + } + } + } + } +} diff --git a/selfservice/flow/saml/test/testdata/saml.jsonnet b/selfservice/flow/saml/test/testdata/saml.jsonnet new file mode 100644 index 000000000000..87103e26bc6b --- /dev/null +++ b/selfservice/flow/saml/test/testdata/saml.jsonnet @@ -0,0 +1,17 @@ +local claims = { + email_verified: false +} + std.extVar('claims'); + +{ + identity: { + traits: { + // Allowing unverified email addresses enables account + // enumeration attacks, especially if the value is used for + // e.g. verification or as a password login identifier. + // + // Therefore we only return the email if it (a) exists and (b) is marked verified + // by Discord. + [if "email" in claims && claims.email_verified then "email" else null]: claims.email, + }, + }, +} \ No newline at end of file diff --git a/selfservice/flow/saml/test/testdata/samlkratos.crt b/selfservice/flow/saml/test/testdata/samlkratos.crt new file mode 100755 index 000000000000..3dfdeb703e1c --- /dev/null +++ b/selfservice/flow/saml/test/testdata/samlkratos.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDazCCAlOgAwIBAgIUVREfiVXf4z/hq8AsbyNnkuWn6i8wDQYJKoZIhvcNAQEL +BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM +GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMjAyMjExMTA4MjBaFw0yMzAy +MjExMTA4MjBaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw +HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQCjvij3wZV+OhbEbwcs7cpc1hGR+uK4Y0y/ItHkAqlV +ddl+D28iDJeHci4LA8XmG0loFMTxdC9PG5t4ewn8G18+EeYRV0K3BMMWfxrO6ibG +z1ElTxQvVSw9tgPpjIgZqL8Qso8UO1ji98yoPhqP77F29pCNqiHrKJI1c52OCPHq +NBCZa76DmCGcXKAwRQaTo+tig6HJ1/3qCLGq57O396mQRFvjB535mceLzKSpFHsh +45beytXiBjTkvOEmNIUGVKIidXxqDtuTHz5QqhHTHMSsFH8cT648sSB9K9jPZ6ai +VCq5z/McyaYFlb/wt7PApJTSRjU0Any4876eBca59ca/AgMBAAGjUzBRMB0GA1Ud +DgQWBBQml5ORluABegdU+rLlpn++esD9fjAfBgNVHSMEGDAWgBQml5ORluABegdU ++rLlpn++esD9fjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCL +X5bpRKtMY7FsPtMsO/KBz5GT7P6aqe8pS0m3uXap6KkQwxa2wyyyH+in6uds8Sxm +bsdsGpSpCfGQCMqmu0yCjhfwI8nFA6q1YxLNgmx7kEIAQQQG2+jZJE7adXzSk2vT +tiNQ55mfiO9Wv+JpaB7ldAX3Q+O2uqVLJG/NlvC3ZAq0FXMyeitddLYSmEE0xrcM +QTB7vb7LpZk7Owa2UJ2VcQyZcxLWMonikIg4u3ALHGR0SvEgMwGhWr354RDGLYSO +Ii5O1foUR1O71jffr7CgELauyz3AXv6PNYLkyOCQP5gNB2NEMLJBRn5U4IhCHKzD +t1/BujsTuZV5r6aj3J9+ +-----END CERTIFICATE----- diff --git a/selfservice/strategy/saml/error.go b/selfservice/strategy/saml/error.go new file mode 100644 index 000000000000..ab984670e1a0 --- /dev/null +++ b/selfservice/strategy/saml/error.go @@ -0,0 +1,16 @@ +package saml + +import "github.com/ory/herodot" + +var ( + ErrScopeMissing = herodot.ErrBadRequest. + WithError("authentication failed because a required scope was not granted"). + WithReason(`Unable to finish because one or more permissions were not granted. Please retry and accept all permissions.`) + + ErrIDTokenMissing = herodot.ErrBadRequest. + WithError("authentication failed because id_token is missing"). + WithReason(`Authentication failed because no id_token was returned. Please accept the "openid" permission and try again.`) + + ErrAPIFlowNotSupported = herodot.ErrBadRequest.WithError("API-based flows are not supported for this method"). + WithReason("SAML SignIn and Registeration are only supported for flows initiated using the Browser endpoint.") +) diff --git a/selfservice/strategy/saml/provider.go b/selfservice/strategy/saml/provider.go new file mode 100644 index 000000000000..8be02aa28cb7 --- /dev/null +++ b/selfservice/strategy/saml/provider.go @@ -0,0 +1,43 @@ +package saml + +import ( + "context" + + "github.com/crewjam/saml/samlsp" + + "github.com/ory/kratos/driver/config" + "github.com/ory/kratos/x" +) + +type Provider interface { + Claims(ctx context.Context, config *config.Config, SAMLAttribute samlsp.Attributes) (*Claims, error) + Config() *Configuration +} + +type Claims struct { + Issuer string `json:"iss,omitempty"` + Subject string `json:"sub,omitempty"` + Name string `json:"name,omitempty"` + GivenName string `json:"given_name,omitempty"` + FamilyName string `json:"family_name,omitempty"` + LastName string `json:"last_name,omitempty"` + MiddleName string `json:"middle_name,omitempty"` + Nickname string `json:"nickname,omitempty"` + PreferredUsername string `json:"preferred_username,omitempty"` + Profile string `json:"profile,omitempty"` + Picture string `json:"picture,omitempty"` + Website string `json:"website,omitempty"` + Email string `json:"email,omitempty"` + EmailVerified x.ConvertibleBoolean `json:"email_verified,omitempty"` + Gender string `json:"gender,omitempty"` + Birthdate string `json:"birthdate,omitempty"` + Zoneinfo string `json:"zoneinfo,omitempty"` + Locale string `json:"locale,omitempty"` + PhoneNumber string `json:"phone_number,omitempty"` + PhoneNumberVerified bool `json:"phone_number_verified,omitempty"` + UpdatedAt int64 `json:"updated_at,omitempty"` + HD string `json:"hd,omitempty"` + Team string `json:"team,omitempty"` + Roles []string `json:"roles,omitempty"` + Groups []string `json:"groups,omitempty"` +} diff --git a/selfservice/strategy/saml/provider_config.go b/selfservice/strategy/saml/provider_config.go new file mode 100644 index 000000000000..6020ccef2b15 --- /dev/null +++ b/selfservice/strategy/saml/provider_config.go @@ -0,0 +1,33 @@ +package saml + +type Configuration struct { + // ID is the provider's ID + ID string `json:"id"` + + // Label represents an optional label which can be used in the UI generation. + Label string `json:"label"` + + // Represent the path of the certificate of your application + PublicCertPath string `json:"public_cert_path"` + + // Represent the path of the private key of your application + PrivateKeyPath string `json:"private_key_path"` + + // It is a map where you have to name the attributes contained in the SAML response to associate them with their value + AttributesMap map[string]string `json:"attributes_map"` + + // Information about the IDP like the sso url, slo url, entiy ID, metadata url + IDPInformation map[string]string `json:"idp_information"` + + // Mapper specifies the JSONNet code snippet + // It can be either a URL (file://, http(s)://, base64://) or an inline JSONNet code snippet. + Mapper string `json:"mapper_url"` +} + +type ConfigurationCollection struct { + SAMLProviders []Configuration `json:"providers"` +} + +func (c ConfigurationCollection) Provider(id string, label string) (Provider, error) { + return NewProviderSAML(id, label, &c.SAMLProviders[len(c.SAMLProviders)-1]), nil +} diff --git a/selfservice/strategy/saml/provider_saml.go b/selfservice/strategy/saml/provider_saml.go new file mode 100644 index 000000000000..f9b4e273c912 --- /dev/null +++ b/selfservice/strategy/saml/provider_saml.go @@ -0,0 +1,66 @@ +package saml + +import ( + "bytes" + "context" + + "github.com/crewjam/saml/samlsp" + "github.com/ory/kratos/driver/config" + "github.com/ory/x/jsonx" + "github.com/pkg/errors" +) + +type ProviderSAML struct { + id string + label string + config *Configuration +} + +func NewProviderSAML( + id string, + label string, + config *Configuration, +) *ProviderSAML { + return &ProviderSAML{ + id: id, + label: label, + config: config, + } +} + +// Translate attributes from saml asseryion into kratos claims +func (d *ProviderSAML) Claims(ctx context.Context, config *config.Config, attributeSAML samlsp.Attributes) (*Claims, error) { + + var c ConfigurationCollection + + conf := config.SelfServiceStrategy("saml").Config + if err := jsonx. + NewStrictDecoder(bytes.NewBuffer(conf)). + Decode(&c); err != nil { + return nil, errors.Wrapf(err, "Unable to decode config %v", string(conf)) + } + + providerSAML := c.SAMLProviders[len(c.SAMLProviders)-1] + + claims := &Claims{ + Issuer: "saml", + Subject: attributeSAML.Get(providerSAML.AttributesMap["id"]), + Name: attributeSAML.Get(providerSAML.AttributesMap["firstname"]), + LastName: attributeSAML.Get(providerSAML.AttributesMap["lastname"]), + Nickname: attributeSAML.Get(providerSAML.AttributesMap["nickname"]), + Gender: attributeSAML.Get(providerSAML.AttributesMap["gender"]), + Birthdate: attributeSAML.Get(providerSAML.AttributesMap["birthdate"]), + Picture: attributeSAML.Get(providerSAML.AttributesMap["picture"]), + Email: attributeSAML.Get(providerSAML.AttributesMap["email"]), + Roles: attributeSAML[providerSAML.AttributesMap["roles"]], + Groups: attributeSAML[providerSAML.AttributesMap["groups"]], + PhoneNumber: attributeSAML.Get(providerSAML.AttributesMap["phone_number"]), + EmailVerified: true, + } + + return claims, nil +} + +func (d *ProviderSAML) Config() *Configuration { + return d.config +} diff --git a/selfservice/strategy/saml/strategy/.schema/link.schema.json b/selfservice/strategy/saml/strategy/.schema/link.schema.json new file mode 100644 index 000000000000..95c72b83ed18 --- /dev/null +++ b/selfservice/strategy/saml/strategy/.schema/link.schema.json @@ -0,0 +1,17 @@ +{ + "$id": "file://.schema/login.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "csrf_token": { + "type": "string" + }, + "samlProvider": { + "type": "string", + "minLength": 1 + }, + "traits": { + "description": "DO NOT DELETE THIS FIELD. This field will be overwritten in login.go's and registration.go's decoder() method. Do not add anything to this field as it has no effect." + } + } +} diff --git a/selfservice/strategy/saml/strategy/.schema/settings.schema.json b/selfservice/strategy/saml/strategy/.schema/settings.schema.json new file mode 100644 index 000000000000..3cac10cea831 --- /dev/null +++ b/selfservice/strategy/saml/strategy/.schema/settings.schema.json @@ -0,0 +1,19 @@ +{ + "$id": "file://.schema/settings.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "link": { + "type": "string" + }, + "csrf_token": { + "type": "string" + }, + "unlink": { + "type": "string" + }, + "traits": { + "description": "This field will be overwritten in registration.go's decoder() method. Do not add anything to this field as it has no effect." + } + } +} diff --git a/selfservice/strategy/saml/strategy/const.go b/selfservice/strategy/saml/strategy/const.go new file mode 100644 index 000000000000..e578913b1427 --- /dev/null +++ b/selfservice/strategy/saml/strategy/const.go @@ -0,0 +1,5 @@ +package strategy + +const ( + sessionName = "ory_kratos_saml_auth_code_session" +) diff --git a/selfservice/strategy/saml/strategy/schema.go b/selfservice/strategy/saml/strategy/schema.go new file mode 100644 index 000000000000..92ac527c5d00 --- /dev/null +++ b/selfservice/strategy/saml/strategy/schema.go @@ -0,0 +1,8 @@ +package strategy + +import ( + _ "embed" +) + +//go:embed .schema/link.schema.json +var linkSchema []byte diff --git a/selfservice/strategy/saml/strategy/strategy.go b/selfservice/strategy/saml/strategy/strategy.go new file mode 100644 index 000000000000..93b2508aa4f7 --- /dev/null +++ b/selfservice/strategy/saml/strategy/strategy.go @@ -0,0 +1,471 @@ +package strategy + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/crewjam/saml" + "github.com/crewjam/saml/samlsp" + "github.com/gofrs/uuid" + "github.com/julienschmidt/httprouter" + "github.com/pkg/errors" + "github.com/tidwall/gjson" + + "github.com/ory/herodot" + "github.com/ory/kratos/text" + "github.com/ory/kratos/ui/container" + "github.com/ory/kratos/ui/node" + + "github.com/go-playground/validator/v10" + + "github.com/ory/x/decoderx" + "github.com/ory/x/fetcher" + "github.com/ory/x/jsonx" + + "github.com/ory/kratos/continuity" + "github.com/ory/kratos/driver/config" + "github.com/ory/kratos/hash" + "github.com/ory/kratos/identity" + "github.com/ory/kratos/selfservice/errorx" + "github.com/ory/kratos/selfservice/flow" + "github.com/ory/kratos/selfservice/flow/login" + + "github.com/ory/kratos/selfservice/flow/registration" + samlflow "github.com/ory/kratos/selfservice/flow/saml" + "github.com/ory/kratos/selfservice/flow/settings" + "github.com/ory/kratos/selfservice/strategy" + samlstrategy "github.com/ory/kratos/selfservice/strategy/saml" + "github.com/ory/kratos/session" + "github.com/ory/kratos/x" +) + +const ( + RouteBase = "/self-service/methods/saml" + + RouteAcs = RouteBase + "/acs" + RouteAuth = RouteBase + "/auth" +) + +var _ identity.ActiveCredentialsCounter = new(Strategy) + +type registrationStrategyDependencies interface { + x.LoggingProvider + x.WriterProvider + x.CSRFTokenGeneratorProvider + x.CSRFProvider + + config.Provider + + continuity.ManagementProvider + continuity.ManagementProviderRelayState + + errorx.ManagementProvider + hash.HashProvider + + registration.HandlerProvider + registration.HooksProvider + registration.ErrorHandlerProvider + registration.HookExecutorProvider + registration.FlowPersistenceProvider + + login.HooksProvider + login.ErrorHandlerProvider + login.HookExecutorProvider + login.FlowPersistenceProvider + login.HandlerProvider + + settings.FlowPersistenceProvider + settings.HookExecutorProvider + settings.HooksProvider + settings.ErrorHandlerProvider + + identity.PrivilegedPoolProvider + identity.ValidationProvider + + session.HandlerProvider + session.ManagementProvider +} + +func (s *Strategy) ID() identity.CredentialsType { + return identity.CredentialsTypeSAML +} + +func (s *Strategy) D() registrationStrategyDependencies { + return s.d +} + +func (s *Strategy) NodeGroup() node.UiNodeGroup { + return node.SAMLGroup +} + +func uid(provider, subject string) string { + return fmt.Sprintf("%s:%s", provider, subject) +} + +func isForced(req interface{}) bool { + f, ok := req.(interface { + IsForced() bool + }) + return ok && f.IsForced() +} + +type Strategy struct { + d registrationStrategyDependencies + f *fetcher.Fetcher + v *validator.Validate + hd *decoderx.HTTP +} + +type authCodeContainer struct { + FlowID string `json:"flow_id"` + State string `json:"state"` + Traits json.RawMessage `json:"traits"` +} + +func NewStrategy(d registrationStrategyDependencies) *Strategy { + return &Strategy{ + d: d, + f: fetcher.NewFetcher(), + v: validator.New(), + hd: decoderx.NewHTTP(), + } +} + +// We indicate here that when the ACS endpoint receives a POST request, we call the handleCallback method to process it +func (s *Strategy) setRoutes(r *x.RouterPublic) { + wrappedHandleCallback := strategy.IsDisabled(s.d, s.ID().String(), s.handleCallback) + if handle, _, _ := r.Lookup("POST", RouteAcs); handle == nil { + r.POST(RouteAcs, wrappedHandleCallback) + } // ACS SUPPORT +} + +// Get possible SAML Request IDs +func GetPossibleRequestIDs(r *http.Request, m samlsp.Middleware) []string { + possibleRequestIDs := []string{} + if m.ServiceProvider.AllowIDPInitiated { + possibleRequestIDs = append(possibleRequestIDs, "") + } + + trackedRequests := m.RequestTracker.GetTrackedRequests(r) + for _, tr := range trackedRequests { + possibleRequestIDs = append(possibleRequestIDs, tr.SAMLRequestID) + } + + return possibleRequestIDs +} + +// Retrieves the user's attributes from the SAML Assertion +func (s *Strategy) GetAttributesFromAssertion(assertion *saml.Assertion) (map[string][]string, error) { + + if assertion == nil { + return nil, errors.New("The assertion is nil") + } + + attributes := map[string][]string{} + + for _, attributeStatement := range assertion.AttributeStatements { + for _, attr := range attributeStatement.Attributes { + claimName := attr.Name + for _, value := range attr.Values { + attributes[claimName] = append(attributes[claimName], value.Value) + } + } + } + + return attributes, nil +} + +func (s *Strategy) validateFlow(ctx context.Context, r *http.Request, rid uuid.UUID) (flow.Flow, error) { + if x.IsZeroUUID(rid) { + return nil, errors.WithStack(herodot.ErrBadRequest.WithReason("The session cookie contains invalid values and the flow could not be executed. Please try again.")) + } + + if ar, err := s.d.RegistrationFlowPersister().GetRegistrationFlow(ctx, rid); err == nil { + if ar.Type != flow.TypeBrowser { + return ar, samlstrategy.ErrAPIFlowNotSupported + } + + if err := ar.Valid(); err != nil { + return ar, err + } + return ar, nil + } + + if ar, err := s.d.LoginFlowPersister().GetLoginFlow(ctx, rid); err == nil { + if ar.Type != flow.TypeBrowser { + return ar, samlstrategy.ErrAPIFlowNotSupported + } + + if err := ar.Valid(); err != nil { + return ar, err + } + return ar, nil + } + + ar, err := s.d.SettingsFlowPersister().GetSettingsFlow(ctx, rid) + if err == nil { + if ar.Type != flow.TypeBrowser { + return ar, samlstrategy.ErrAPIFlowNotSupported + } + + sess, err := s.d.SessionManager().FetchFromRequest(ctx, r) + if err != nil { + return ar, err + } + + if err := ar.Valid(sess); err != nil { + return ar, err + } + return ar, nil + } + + return ar, err // this must return the error +} + +func (s *Strategy) alreadyAuthenticated(w http.ResponseWriter, r *http.Request, req interface{}) bool { + // we assume an error means the user has no session + if _, err := s.d.SessionManager().FetchFromRequest(r.Context(), r); err == nil { + if _, ok := req.(*settings.Flow); ok { + // ignore this if it's a settings flow + } else if !isForced(req) { + http.Redirect(w, r, s.d.Config(r.Context()).SelfServiceBrowserDefaultReturnTo().String(), http.StatusSeeOther) + return true + } + } + + return false +} + +func (s *Strategy) validateCallback(w http.ResponseWriter, r *http.Request) (flow.Flow, *authCodeContainer, error) { + var cntnr authCodeContainer + if _, err := s.d.RelayStateContinuityManager().Continue(r.Context(), w, r, sessionName, continuity.WithPayload(&cntnr)); err != nil { + return nil, nil, err + } + + req, err := s.validateFlow(r.Context(), r, x.ParseUUID(cntnr.FlowID)) + if err != nil { + return nil, &cntnr, err + } + + if r.URL.Query().Get("error") != "" { + return req, &cntnr, errors.WithStack(herodot.ErrBadRequest.WithReasonf(`Unable to complete SAML flow because the SAML Provider returned error "%s": %s`, r.URL.Query().Get("error"), r.URL.Query().Get("error_description"))) + } + + return req, &cntnr, nil +} + +// Handle /selfservice/methods/saml/acs | Receive SAML response, parse the attributes and start auth flow +func (s *Strategy) handleCallback(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + + pid := ps.ByName("provider") + + if err := r.ParseForm(); err != nil { + s.d.SelfServiceErrorManager().Forward(r.Context(), w, r, s.handleError(w, r, nil, pid, nil, err)) + } + + req, _, err := s.validateCallback(w, r) + if err != nil { + if req != nil { + s.forwardError(w, r, s.handleError(w, r, req, pid, nil, err)) + // TODO add flow param to s.handleError + // s.forwardError(w, r, req, s.handleError(w, r, req, pid, nil, err)) + } else { + s.d.SelfServiceErrorManager().Forward(r.Context(), w, r, s.handleError(w, r, nil, pid, nil, err)) + } + return + } + + m, err := samlflow.GetMiddleware() + if err != nil { + s.forwardError(w, r, err) + } + + // We get the possible SAML request IDs + possibleRequestIDs := GetPossibleRequestIDs(r, *m) + assertion, err := m.ServiceProvider.ParseResponse(r, possibleRequestIDs) + if err != nil { + s.forwardError(w, r, err) + } + + // We get the user's attributes from the SAML Response (assertion) + attributes, err := s.GetAttributesFromAssertion(assertion) + if err != nil { + s.forwardError(w, r, err) + return + } + + // We get the provider information from the config file + provider, err := s.Provider(r.Context()) + if err != nil { + s.forwardError(w, r, err) + return + } + + // We translate SAML Attributes into claims (To create an identity we need these claims) + claims, err := provider.Claims(r.Context(), s.d.Config(r.Context()), attributes) + if err != nil { + s.forwardError(w, r, err) + return + } + + switch a := req.(type) { + case *login.Flow: + // Now that we have the claims and the provider, we have to decide if we log or register the user + if ff, err := s.processLoginOrRegister(w, r, a, provider, claims); err != nil { + if ff != nil { + s.forwardError(w, r, err) + } + s.forwardError(w, r, err) + } + return + } +} + +func (s *Strategy) forwardError(w http.ResponseWriter, r *http.Request, err error) { + s.d.LoginFlowErrorHandler().WriteFlowError(w, r, nil, s.NodeGroup(), err) +} + +// Return the SAML Provider +func (s *Strategy) Provider(ctx context.Context) (samlstrategy.Provider, error) { + c, err := s.Config(ctx) + if err != nil { + return nil, err + } + + provider, err := c.Provider(c.SAMLProviders[len(c.SAMLProviders)-1].ID, c.SAMLProviders[len(c.SAMLProviders)-1].Label) + if err != nil { + return nil, err + } + + return provider, nil +} + +// Translate YAML Config file into a SAML Provider struct +func (s *Strategy) Config(ctx context.Context) (*samlstrategy.ConfigurationCollection, error) { + var c samlstrategy.ConfigurationCollection + + conf := s.d.Config(ctx).SelfServiceStrategy(string(s.ID())).Config + if err := jsonx. + NewStrictDecoder(bytes.NewBuffer(conf)). + Decode(&c); err != nil { + s.d.Logger().WithError(err).WithField("config", conf) + return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Unable to decode SAML Identity Provider configuration: %s", err)) + } + + return &c, nil +} + +func (s *Strategy) populateMethod(r *http.Request, c *container.Container, message func(provider string) *text.Message) error { + conf, err := s.Config(r.Context()) + if err != nil { + return err + } + + // does not need sorting because there is only one field + c.SetCSRF(s.d.GenerateCSRFToken(r)) + AddProviders(c, conf.SAMLProviders, message) + + return nil +} + +func (s *Strategy) handleError(w http.ResponseWriter, r *http.Request, f flow.Flow, provider string, traits []byte, err error) error { + switch rf := f.(type) { + case *login.Flow: + return err + case *registration.Flow: + // Reset all nodes to not confuse users. + // This is kinda hacky and will probably need to be updated at some point. + + rf.UI.Nodes = node.Nodes{} + + // Adds the "Continue" button + rf.UI.SetCSRF(s.d.GenerateCSRFToken(r)) + AddProvider(rf.UI, provider, text.NewInfoRegistrationContinue()) + + if traits != nil { + ds, err := s.d.Config(r.Context()).DefaultIdentityTraitsSchemaURL() + if err != nil { + return err + } + + traitNodes, err := container.NodesFromJSONSchema(r.Context(), node.SAMLGroup, ds.String(), "", nil) + if err != nil { + return err + } + + rf.UI.Nodes = append(rf.UI.Nodes, traitNodes...) + rf.UI.UpdateNodeValuesFromJSON(traits, "traits", node.SAMLGroup) + } + + return err + case *settings.Flow: + return err + } + + return err +} + +func (s *Strategy) CountActiveCredentials(cc map[identity.CredentialsType]identity.Credentials) (count int, err error) { + for _, c := range cc { + if c.Type == s.ID() && gjson.ValidBytes(c.Config) { + var conf CredentialsConfig + if err = json.Unmarshal(c.Config, &conf); err != nil { + return 0, errors.WithStack(err) + } + + for _, ider := range c.Identifiers { + parts := strings.Split(ider, ":") + if len(parts) != 2 { + continue + } + + if parts[0] == conf.Providers[0].Provider && parts[1] == conf.Providers[0].Subject && len(conf.Providers[0].Subject) > 1 && len(conf.Providers[0].Provider) > 1 { + count++ + } + + } + } + } + return +} + +func (s *Strategy) CountActiveFirstFactorCredentials(cc map[identity.CredentialsType]identity.Credentials) (count int, err error) { + for _, c := range cc { + if c.Type == s.ID() && gjson.ValidBytes(c.Config) { + // TODO MANAGE THIS + var conf identity.CredentialsOIDC + if err = json.Unmarshal(c.Config, &conf); err != nil { + return 0, errors.WithStack(err) + } + + for _, ider := range c.Identifiers { + parts := strings.Split(ider, ":") + if len(parts) != 2 { + continue + } + + for _, prov := range conf.Providers { + if parts[0] == prov.Provider && parts[1] == prov.Subject && len(prov.Subject) > 1 && len(prov.Provider) > 1 { + count++ + } + } + } + } + } + return +} + +func (s *Strategy) CountActiveMultiFactorCredentials(cc map[identity.CredentialsType]identity.Credentials) (count int, err error) { + return 0, nil +} + +func (s *Strategy) CompletedAuthenticationMethod(ctx context.Context) session.AuthenticationMethod { + return session.AuthenticationMethod{ + Method: s.ID(), + AAL: identity.AuthenticatorAssuranceLevel1, + } +} diff --git a/selfservice/strategy/saml/strategy/strategy_auth.go b/selfservice/strategy/saml/strategy/strategy_auth.go new file mode 100644 index 000000000000..b04bea371291 --- /dev/null +++ b/selfservice/strategy/saml/strategy/strategy_auth.go @@ -0,0 +1,66 @@ +package strategy + +import ( + "errors" + "net/http" + + "github.com/ory/kratos/identity" + "github.com/ory/kratos/selfservice/flow" + "github.com/ory/kratos/selfservice/flow/login" + samlsp "github.com/ory/kratos/selfservice/strategy/saml" + "github.com/ory/x/sqlcon" +) + +// Handle SAML Assertion and process to either login or register +func (s *Strategy) processLoginOrRegister(w http.ResponseWriter, r *http.Request, loginFlow *login.Flow, provider samlsp.Provider, claims *samlsp.Claims) (*flow.Flow, error) { + + // This is a check to see if the user exists in the database + i, c, err := s.d.PrivilegedIdentityPool().FindByCredentialsIdentifier(r.Context(), identity.CredentialsTypeSAML, uid(provider.Config().ID, claims.Subject)) + + if err != nil { + // ErrNoRows is returned when a SQL SELECT statement returns no rows. + if errors.Is(err, sqlcon.ErrNoRows) { + + // The user doesn't net existe yet so we register him + registerFlow, err := s.d.RegistrationHandler().NewRegistrationFlow(w, r, flow.TypeBrowser) + if err != nil { + if i == nil { + return nil, s.handleError(w, r, registerFlow, provider.Config().ID, nil, err) + } else { + return nil, s.handleError(w, r, registerFlow, provider.Config().ID, i.Traits, err) + } + } + + if err = s.processRegistration(w, r, registerFlow, provider, claims); err != nil { + if i == nil { + return nil, s.handleError(w, r, registerFlow, provider.Config().ID, nil, err) + } else { + return nil, s.handleError(w, r, registerFlow, provider.Config().ID, i.Traits, err) + } + } + + return nil, nil + + } else { + return nil, err + } + } else { + // The user already exist in database so we log him + // loginFlow, err := s.d.LoginHandler().NewLoginFlow(w, r, flow.TypeBrowser) + if err != nil { + if i == nil { + return nil, s.handleError(w, r, loginFlow, provider.Config().ID, nil, err) + } else { + return nil, s.handleError(w, r, loginFlow, provider.Config().ID, i.Traits, err) + } + } + if _, err = s.processLogin(w, r, loginFlow, provider, c, i, claims); err != nil { + if i == nil { + return nil, s.handleError(w, r, loginFlow, provider.Config().ID, nil, err) + } else { + return nil, s.handleError(w, r, loginFlow, provider.Config().ID, i.Traits, err) + } + } + return nil, nil + } +} diff --git a/selfservice/strategy/saml/strategy/strategy_login.go b/selfservice/strategy/saml/strategy/strategy_login.go new file mode 100644 index 000000000000..775e0f71d709 --- /dev/null +++ b/selfservice/strategy/saml/strategy/strategy_login.go @@ -0,0 +1,139 @@ +package strategy + +import ( + "bytes" + "encoding/json" + "net/http" + "time" + + "github.com/ory/herodot" + "github.com/ory/kratos/continuity" + "github.com/ory/kratos/identity" + "github.com/ory/kratos/selfservice/flow" + "github.com/ory/kratos/selfservice/flow/login" + "github.com/ory/kratos/selfservice/flow/registration" + handler "github.com/ory/kratos/selfservice/flow/saml" + samlsp "github.com/ory/kratos/selfservice/strategy/saml" + "github.com/ory/kratos/session" + "github.com/ory/kratos/text" + "github.com/ory/kratos/ui/node" + "github.com/ory/kratos/x" + "github.com/pkg/errors" +) + +// Implement the interface +var _ login.Strategy = new(Strategy) + +//Call at the creation of Kratos, when Kratos implement all authentication routes +func (s *Strategy) RegisterLoginRoutes(r *x.RouterPublic) { + s.setRoutes(r) +} + +// SubmitSelfServiceLoginFlowWithSAMLMethodBody is used to decode the login form payload +// when using the saml method. +// +// swagger:model SubmitSelfServiceLoginFlowWithSAMLMethodBody +type SubmitSelfServiceLoginFlowWithSAMLMethodBody struct { + // The provider to register with + // + // required: true + Provider string `json:"samlProvider"` + + // The CSRF Token + CSRFToken string `json:"csrf_token"` + + // Method to use + // + // This field must be set to `oidc` when using the oidc method. + // + // required: true + Method string `json:"method"` + + // The identity traits. This is a placeholder for the registration flow. + Traits json.RawMessage `json:"traits"` +} + +//Login and give a session to the user +func (s *Strategy) processLogin(w http.ResponseWriter, r *http.Request, a *login.Flow, provider samlsp.Provider, c *identity.Credentials, i *identity.Identity, claims *samlsp.Claims) (*registration.Flow, error) { + + var o CredentialsConfig + if err := json.NewDecoder(bytes.NewBuffer(c.Config)).Decode(&o); err != nil { + return nil, s.handleError(w, r, a, provider.Config().ID, nil, errors.WithStack(herodot.ErrInternalServerError.WithReason("The password credentials could not be decoded properly").WithDebug(err.Error()))) + } + + sess := session.NewInactiveSession() //creation of an inactive session + sess.CompletedLoginFor(s.ID(), identity.AuthenticatorAssuranceLevel1) //Add saml to the Authentication Method References + + if err := s.d.LoginHookExecutor().PostLoginHook(w, r, node.SAMLGroup, a, i, sess); err != nil { + return nil, s.handleError(w, r, a, provider.Config().ID, nil, err) + } + + return nil, nil +} + +func (s *Strategy) Login(w http.ResponseWriter, r *http.Request, f *login.Flow, ss *session.Session) (i *identity.Identity, err error) { + if err := login.CheckAAL(f, identity.AuthenticatorAssuranceLevel1); err != nil { + return nil, err + } + + var p SubmitSelfServiceLoginFlowWithSAMLMethodBody + if err := s.newLinkDecoder(&p, r); err != nil { + return nil, s.handleError(w, r, f, "", nil, errors.WithStack(herodot.ErrBadRequest.WithDebug(err.Error()).WithReasonf("Unable to parse HTTP form request: %s", err.Error()))) + } + + var pid = p.Provider // this can come from both url query and post body + if pid == "" { + return nil, errors.WithStack(flow.ErrStrategyNotResponsible) + } + + if err := flow.MethodEnabledAndAllowed(r.Context(), s.ID().String(), s.ID().String(), s.d); err != nil { + return nil, s.handleError(w, r, f, pid, nil, err) + } + + req, err := s.validateFlow(r.Context(), r, f.ID) + if err != nil { + return nil, s.handleError(w, r, f, pid, nil, err) + } + + if s.alreadyAuthenticated(w, r, req) { + return + } + + state := x.NewUUID().String() + if err := s.d.RelayStateContinuityManager().Pause(r.Context(), w, r, sessionName, + continuity.WithPayload(&authCodeContainer{ + State: state, + FlowID: f.ID.String(), + Traits: p.Traits, + }), + continuity.WithLifespan(time.Minute*30)); err != nil { + return nil, s.handleError(w, r, f, pid, nil, err) + } + + f.Active = s.ID() + if err = s.d.LoginFlowPersister().UpdateLoginFlow(r.Context(), f); err != nil { + return nil, s.handleError(w, r, f, pid, nil, errors.WithStack(herodot.ErrInternalServerError.WithReason("Could not update flow").WithDebug(err.Error()))) + } + + if x.IsJSONRequest(r) { + s.d.Writer().WriteError(w, r, flow.NewBrowserLocationChangeRequiredError(handler.RouteSamlLoginInit)) + } else { + + http.Redirect(w, r, handler.RouteSamlLoginInit, http.StatusSeeOther) + } + + return nil, errors.WithStack(flow.ErrCompletedByStrategy) +} + +func (s *Strategy) PopulateLoginMethod(r *http.Request, requestedAAL identity.AuthenticatorAssuranceLevel, l *login.Flow) error { + if l.Type != flow.TypeBrowser { + return nil + } + + // This strategy can only solve AAL1 + if requestedAAL > identity.AuthenticatorAssuranceLevel1 { + return nil + } + + return s.populateMethod(r, l.UI, text.NewInfoLoginWith) +} diff --git a/selfservice/strategy/saml/strategy/strategy_registration.go b/selfservice/strategy/saml/strategy/strategy_registration.go new file mode 100644 index 000000000000..9d3d93e080ad --- /dev/null +++ b/selfservice/strategy/saml/strategy/strategy_registration.go @@ -0,0 +1,167 @@ +package strategy + +import ( + "bytes" + "context" + "encoding/json" + "net/http" + + "github.com/google/go-jsonnet" + "github.com/ory/kratos/driver/config" + "github.com/ory/kratos/identity" + "github.com/ory/x/decoderx" + "github.com/pkg/errors" + + "github.com/ory/kratos/selfservice/flow" + "github.com/ory/kratos/selfservice/flow/registration" + samlsp "github.com/ory/kratos/selfservice/strategy/saml" + "github.com/ory/kratos/text" + + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" + + "github.com/ory/kratos/x" +) + +//################# +// This file contains all the methods and functions allowing the registration of a user. +//################# + +// Implement the interface +var _ registration.Strategy = new(Strategy) + +//Call at the creation of Kratos, when Kratos implement all authentication routes +func (s *Strategy) RegisterRegistrationRoutes(r *x.RouterPublic) { + s.setRoutes(r) +} + +func (s *Strategy) GetRegistrationIdentity(r *http.Request, ctx context.Context, provider samlsp.Provider, claims *samlsp.Claims, logsEnabled bool) (*identity.Identity, error) { + // Fetch fetches the file contents from the mapper file. + jn, err := s.f.Fetch(provider.Config().Mapper) + if err != nil { + return nil, err + } + + var jsonClaims bytes.Buffer + if err := json.NewEncoder(&jsonClaims).Encode(claims); err != nil { + return nil, err + } + + // Identity Creation + i := identity.NewIdentity(config.DefaultIdentityTraitsSchemaID) + + vm := jsonnet.MakeVM() + vm.ExtCode("claims", jsonClaims.String()) + evaluated, err := vm.EvaluateAnonymousSnippet(provider.Config().Mapper, jn.String()) + if err != nil { + return nil, err + } else if traits := gjson.Get(evaluated, "identity.traits"); !traits.IsObject() { + i.Traits = []byte{'{', '}'} + if logsEnabled { + s.d.Logger(). + WithRequest(r). + WithField("Provider", provider.Config().ID). + WithSensitiveField("saml_claims", claims). + WithField("mapper_jsonnet_output", evaluated). + WithField("mapper_jsonnet_url", provider.Config().Mapper). + Error("SAML Jsonnet mapper did not return an object for key identity.traits. Please check your Jsonnet code!") + } + } else { + i.Traits = []byte(traits.Raw) + } + + if logsEnabled { + s.d.Logger(). + WithRequest(r). + WithField("saml_provider", provider.Config().ID). + WithSensitiveField("saml_claims", claims). + WithSensitiveField("mapper_jsonnet_output", evaluated). + WithField("mapper_jsonnet_url", provider.Config().Mapper). + Debug("SAML Jsonnet mapper completed.") + + s.d.Logger(). + WithRequest(r). + WithField("saml_provider", provider.Config().ID). + WithSensitiveField("identity_traits", i.Traits). + WithSensitiveField("mapper_jsonnet_output", evaluated). + WithField("mapper_jsonnet_url", provider.Config().Mapper). + Debug("Merged form values and SAML Jsonnet output.") + } + + // Verify the identity + if err := s.d.IdentityValidator().Validate(ctx, i); err != nil { + return i, err + } + + // Create new uniq credentials identifier for user is database + creds, err := NewCredentialsForSAML(claims.Subject, provider.Config().ID) + if err != nil { + return i, err + } + + // Set the identifiers to the identity + i.SetCredentials(s.ID(), *creds) + + return i, nil +} + +func (s *Strategy) processRegistration(w http.ResponseWriter, r *http.Request, a *registration.Flow, provider samlsp.Provider, claims *samlsp.Claims) error { + + i, err := s.GetRegistrationIdentity(r, r.Context(), provider, claims, true) + if err != nil { + if i == nil { + return s.handleError(w, r, a, provider.Config().ID, nil, err) + } else { + return s.handleError(w, r, a, provider.Config().ID, i.Traits, err) + } + } + + if err := s.d.RegistrationExecutor().PostRegistrationHook(w, r, identity.CredentialsTypeSAML, a, i); err != nil { + return s.handleError(w, r, a, provider.Config().ID, i.Traits, err) + } + + return nil +} + +// Method not used but necessary to implement the interface +func (s *Strategy) PopulateRegistrationMethod(r *http.Request, f *registration.Flow) error { + if f.Type != flow.TypeBrowser { + return nil + } + + return s.populateMethod(r, f.UI, text.NewInfoRegistrationWith) +} + +func (s *Strategy) newLinkDecoder(p interface{}, r *http.Request) error { + ds, err := s.d.Config(r.Context()).DefaultIdentityTraitsSchemaURL() + if err != nil { + return err + } + + raw, err := sjson.SetBytes(linkSchema, "properties.traits.$ref", ds.String()+"#/properties/traits") + if err != nil { + return errors.WithStack(err) + } + + compiler, err := decoderx.HTTPRawJSONSchemaCompiler(raw) + if err != nil { + return errors.WithStack(err) + } + + if err := s.hd.Decode(r, &p, compiler, + decoderx.HTTPKeepRequestBody(true), + decoderx.HTTPDecoderSetValidatePayloads(false), + decoderx.HTTPDecoderUseQueryAndBody(), + decoderx.HTTPDecoderAllowedMethods("POST", "GET"), + decoderx.HTTPDecoderJSONFollowsFormFormat(), + ); err != nil { + return errors.WithStack(err) + } + + return nil +} + +// Method not used but necessary to implement the interface +func (s *Strategy) Register(w http.ResponseWriter, r *http.Request, f *registration.Flow, i *identity.Identity) (err error) { + return nil +} diff --git a/selfservice/strategy/saml/strategy/test/strategy_test.go b/selfservice/strategy/saml/strategy/test/strategy_test.go new file mode 100644 index 000000000000..88d4d8931fe1 --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/strategy_test.go @@ -0,0 +1,191 @@ +package strategy_test + +import ( + "bytes" + "context" + "encoding/json" + "regexp" + "testing" + + "github.com/ory/kratos/identity" + samlhandler "github.com/ory/kratos/selfservice/flow/saml" + helpertest "github.com/ory/kratos/selfservice/flow/saml/helpertest" + samlstrategy "github.com/ory/kratos/selfservice/strategy/saml/strategy" + "github.com/stretchr/testify/require" + + "gotest.tools/assert" + gotest "gotest.tools/assert" + is "gotest.tools/assert/cmp" +) + +func TestGetAndDecryptAssertion(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + middleware, _, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + assertion, err := helpertest.GetAndDecryptAssertion(t, "./testdata/SP_SamlResponse.xml", middleware.ServiceProvider.Key) + + require.NoError(t, err) + assert.Check(t, assertion != nil) +} + +func TestGetAttributesFromAssertion(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + middleware, strategy, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + assertion, _ := helpertest.GetAndDecryptAssertion(t, "./testdata/SP_SamlResponse.xml", middleware.ServiceProvider.Key) + + mapAttributes, err := strategy.GetAttributesFromAssertion(assertion) + + require.NoError(t, err) + assert.Check(t, mapAttributes["urn:oid:0.9.2342.19200300.100.1.1"][0] == "myself") + assert.Check(t, mapAttributes["urn:oid:1.3.6.1.4.1.5923.1.1.1.1"][0] == "Member") + assert.Check(t, mapAttributes["urn:oid:1.3.6.1.4.1.5923.1.1.1.1"][1] == "Staff") + assert.Check(t, mapAttributes["urn:oid:1.3.6.1.4.1.5923.1.1.1.6"][0] == "myself@testshib.org") + assert.Check(t, mapAttributes["urn:oid:2.5.4.4"][0] == "And I") + assert.Check(t, mapAttributes["urn:oid:1.3.6.1.4.1.5923.1.1.1.9"][0] == "Member@testshib.org") + assert.Check(t, mapAttributes["urn:oid:1.3.6.1.4.1.5923.1.1.1.9"][1] == "Staff@testshib.org") + assert.Check(t, mapAttributes["urn:oid:2.5.4.42"][0] == "Me Myself") + assert.Check(t, mapAttributes["urn:oid:1.3.6.1.4.1.5923.1.1.1.7"][0] == "urn:mace:dir:entitlement:common-lib-terms") + assert.Check(t, mapAttributes["urn:oid:2.5.4.3"][0] == "Me Myself And I") + assert.Check(t, mapAttributes["urn:oid:2.5.4.20"][0] == "555-5555") + + t.Log(mapAttributes) +} + +func TestCreateAuthRequest(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + middleware, _, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + authReq, err := middleware.ServiceProvider.MakeAuthenticationRequest("https://samltest.id/idp/profile/SAML2/Redirect/SSO", "saml.HTTPPostBinding", "saml.HTTPPostBinding") + require.NoError(t, err) + + matchACS, err := regexp.MatchString(`http://127.0.0.1:\d{5}/self-service/methods/saml/acs`, authReq.AssertionConsumerServiceURL) + require.NoError(t, err) + gotest.Check(t, matchACS) + + matchMetadata, err := regexp.MatchString(`http://127.0.0.1:\d{5}/self-service/methods/saml/metadata`, authReq.Issuer.Value) + require.NoError(t, err) + gotest.Check(t, matchMetadata) + + gotest.Check(t, is.Equal(authReq.Destination, "https://samltest.id/idp/profile/SAML2/Redirect/SSO")) +} + +func TestProvider(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + _, strategy, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + provider, err := strategy.Provider(context.Background()) + require.NoError(t, err) + gotest.Check(t, provider != nil) + gotest.Check(t, provider.Config().ID == "samlProviderTestID") + gotest.Check(t, provider.Config().Label == "samlProviderTestLabel") +} + +func TestConfig(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + _, strategy, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + config, err := strategy.Config(context.Background()) + require.NoError(t, err) + gotest.Check(t, config != nil) + gotest.Check(t, len(config.SAMLProviders) == 2) + gotest.Check(t, config.SAMLProviders[0].ID == "samlProviderTestID") + gotest.Check(t, config.SAMLProviders[0].Label == "samlProviderTestLabel") +} + +func TestID(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + _, strategy, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + id := strategy.ID() + gotest.Check(t, id == "saml") +} + +func TestCountActiveCredentials(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + _, strategy, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + mapCredentials := make(map[identity.CredentialsType]identity.Credentials) + + var b bytes.Buffer + err := json.NewEncoder(&b).Encode(samlstrategy.CredentialsConfig{ + Providers: []samlstrategy.ProviderCredentialsConfig{ + { + Subject: "testUserID", + Provider: "saml", + }}, + }) + require.NoError(t, err) + + mapCredentials[identity.CredentialsTypeSAML] = identity.Credentials{ + Type: identity.CredentialsTypeSAML, + Identifiers: []string{"saml:testUserID"}, + Config: b.Bytes(), + } + + count, err := strategy.CountActiveCredentials(mapCredentials) + require.NoError(t, err) + gotest.Check(t, count == 1) +} + +func TestGetRegistrationIdentity(t *testing.T) { + if testing.Short() { + t.Skip() + } + + samlhandler.DestroyMiddlewareIfExists() + + middleware, strategy, _, _ := helpertest.InitMiddlewareWithMetadata(t, + "file://testdata/idp_saml_metadata.xml") + + provider, _ := strategy.Provider(context.Background()) + assertion, _ := helpertest.GetAndDecryptAssertion(t, "./testdata/SP_SamlResponse.xml", middleware.ServiceProvider.Key) + attributes, _ := strategy.GetAttributesFromAssertion(assertion) + claims, _ := provider.Claims(context.Background(), strategy.D().Config(context.Background()), attributes) + + i, err := strategy.GetRegistrationIdentity(nil, context.Background(), provider, claims, false) + require.NoError(t, err) + gotest.Check(t, i != nil) +} diff --git a/selfservice/strategy/saml/strategy/test/testdata/SP_IDPMetadata.xml b/selfservice/strategy/saml/strategy/test/testdata/SP_IDPMetadata.xml new file mode 100644 index 000000000000..dcaf7f051dae --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/SP_IDPMetadata.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + testshib.org + + TestShib Test IdP + TestShib IdP. Use this as a source of attributes + for your test SP. + https://www.testshib.org/testshibtwo.jpg + + + + + + MIIEDjCCAvagAwIBAgIBADANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzEV + MBMGA1UECBMMUGVubnN5bHZhbmlhMRMwEQYDVQQHEwpQaXR0c2J1cmdoMREwDwYD + VQQKEwhUZXN0U2hpYjEZMBcGA1UEAxMQaWRwLnRlc3RzaGliLm9yZzAeFw0wNjA4 + MzAyMTEyMjVaFw0xNjA4MjcyMTEyMjVaMGcxCzAJBgNVBAYTAlVTMRUwEwYDVQQI + EwxQZW5uc3lsdmFuaWExEzARBgNVBAcTClBpdHRzYnVyZ2gxETAPBgNVBAoTCFRl + c3RTaGliMRkwFwYDVQQDExBpZHAudGVzdHNoaWIub3JnMIIBIjANBgkqhkiG9w0B + AQEFAAOCAQ8AMIIBCgKCAQEArYkCGuTmJp9eAOSGHwRJo1SNatB5ZOKqDM9ysg7C + yVTDClcpu93gSP10nH4gkCZOlnESNgttg0r+MqL8tfJC6ybddEFB3YBo8PZajKSe + 3OQ01Ow3yT4I+Wdg1tsTpSge9gEz7SrC07EkYmHuPtd71CHiUaCWDv+xVfUQX0aT + NPFmDixzUjoYzbGDrtAyCqA8f9CN2txIfJnpHE6q6CmKcoLADS4UrNPlhHSzd614 + kR/JYiks0K4kbRqCQF0Dv0P5Di+rEfefC6glV8ysC8dB5/9nb0yh/ojRuJGmgMWH + gWk6h0ihjihqiu4jACovUZ7vVOCgSE5Ipn7OIwqd93zp2wIDAQABo4HEMIHBMB0G + A1UdDgQWBBSsBQ869nh83KqZr5jArr4/7b+QazCBkQYDVR0jBIGJMIGGgBSsBQ86 + 9nh83KqZr5jArr4/7b+Qa6FrpGkwZzELMAkGA1UEBhMCVVMxFTATBgNVBAgTDFBl + bm5zeWx2YW5pYTETMBEGA1UEBxMKUGl0dHNidXJnaDERMA8GA1UEChMIVGVzdFNo + aWIxGTAXBgNVBAMTEGlkcC50ZXN0c2hpYi5vcmeCAQAwDAYDVR0TBAUwAwEB/zAN + BgkqhkiG9w0BAQUFAAOCAQEAjR29PhrCbk8qLN5MFfSVk98t3CT9jHZoYxd8QMRL + I4j7iYQxXiGJTT1FXs1nd4Rha9un+LqTfeMMYqISdDDI6tv8iNpkOAvZZUosVkUo + 93pv1T0RPz35hcHHYq2yee59HJOco2bFlcsH8JBXRSRrJ3Q7Eut+z9uo80JdGNJ4 + /SJy5UorZ8KazGj16lfJhOBXldgrhppQBb0Nq6HKHguqmwRfJ+WkxemZXzhediAj + Geka8nz8JjwxpUjAiSWYKLtJhGEaTqCYxCCX2Dw+dOTqUzHOZ7WKv4JXPK5G/Uhr + 8K/qhmFT2nIQi538n6rVYLeWj8Bbnl+ev0peYzxFyF5sQA== + + + + + + + + + + + + urn:mace:shibboleth:1.0:nameIdentifier + urn:oasis:names:tc:SAML:2.0:nameid-format:transient + + + + + + + + + + + + MIIEDjCCAvagAwIBAgIBADANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzEV + MBMGA1UECBMMUGVubnN5bHZhbmlhMRMwEQYDVQQHEwpQaXR0c2J1cmdoMREwDwYD + VQQKEwhUZXN0U2hpYjEZMBcGA1UEAxMQaWRwLnRl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 + /SJy5UorZ8KazGj16lfJhOBXldgrhppQBb0Nq6HKHguqmwRfJ+WkxemZXzhediAj + Geka8nz8JjwxpUjAiSWYKLtJhGEaTqCYxCCX2Dw+dOTqUzHOZ7WKv4JXPK5G/Uhr + 8K/qhmFT2nIQi538n6rVYLeWj8Bbnl+ev0peYzxFyF5sQA== + + + + + + + + + + + + urn:mace:shibboleth:1.0:nameIdentifier + urn:oasis:names:tc:SAML:2.0:nameid-format:transient + + + TestShib Two Identity Provider + TestShib Two + http://www.testshib.org/testshib-two/ + + + Nate + Klingenstein + ndk@internet2.edu + + \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/SP_SamlResponse.xml b/selfservice/strategy/saml/strategy/test/testdata/SP_SamlResponse.xml new file mode 100644 index 000000000000..f5dbc10766ab --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/SP_SamlResponse.xml @@ -0,0 +1,38 @@ + + + https://idp.testshib.org/idp/shibboleth + + + + + + + + + + + + + + MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJVUzELMAkGA1UE +CAwCR0ExDDAKBgNVBAoMA2ZvbzESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTEzMTAwMjAwMDg1MVoX +DTE0MTAwMjAwMDg1MVowPDELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkdBMQwwCgYDVQQKDANmb28x +EjAQBgNVBAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1PMHYmhZj308 +kWLhZVT4vOulqx/9ibm5B86fPWwUKKQ2i12MYtz07tzukPymisTDhQaqyJ8Kqb/6JjhmeMnEOdTv +SPmHO8m1ZVveJU6NoKRn/mP/BD7FW52WhbrUXLSeHVSKfWkNk6S4hk9MV9TswTvyRIKvRsw0X/gf +nqkroJcCAwEAATANBgkqhkiG9w0BAQUFAAOBgQCMMlIO+GNcGekevKgkakpMdAqJfs24maGb90Dv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RLfwZCYd5mZoxtBhNBWvY3ZOVD/21dIUlQanG1n6RygbmAwCHnIB4c7EH2CBYEMDToRQuAuIssviIfdaJglwDgHbLWKNUVDOdqeclBNZjfQfVXbVukPk8DfWLqj9pD4xAOzDeVQcdmg2aLvNKgpZsWs4d+6GlKrpS7qEGvoBkIFh/cVY7DMYrt/JXYuF6DpwB+HbfnuDFc2p47SPNhnmt/ez6/DACBPQ+tgpyWYXUsiviGSp72JNTzd8uFJJZNeKUJZw1c0UTjxdwigh5tL/hWhPl48DY937zymSr1xVqC3RV6wSIpuplH+hss/rsRPAp1/TfxvhJuFsoPbW0586y9YzqEHT4FUu6WSRy0gMJLP2sLqiiZXZ6kPicXsW7M55mV3ugbGQjB7YS7EVqsQzvJTiQbOlcPqwoKK7DTqaeCOXd8kH1tNoe7hjx/UNNdLQQ7IhrJIzxqTTgwcXYMCxhoezDsIHReTIymsHPkCurfteTQcbfwoKN5E9zC2hINOPmhAxLvONzaLXQGMqofuTbFshkB4eUj8U4vBCNp+60iCLnibt4rPuyoWKEHWBYa6FfIykxVKuXkfcb64dCdGCWjv7x1XqkbpHxQB80qhipoSo244pyhIsN91ASu1Q7L75LxGXibY3jb0Y4KZ5zIWsH4kVlvPhangohDO1J9gmL9inGr9hy5BHTQiMcktGoUgOIbFJ72381vYpPxn3ngBbp48mVZd0w6xV8RBaqR3l7CxI9vvMAPYPoXBB18ERoZypza8mAlzv2QxIkNGuRzFENh1SXegBfN7eiazZnwnhbyeMghJpnXzfvHACyjkdH3shRYcJ+oMiOSpInGxm/hxFQxHJZA0Ft/lza + + + + \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/TestSPCanHandleOneloginResponse_response b/selfservice/strategy/saml/strategy/test/testdata/TestSPCanHandleOneloginResponse_response new file mode 100644 index 000000000000..1031d30218df --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/TestSPCanHandleOneloginResponse_response @@ -0,0 +1 @@ +PHNhbWxwOlJlc3BvbnNlIHht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strategy/saml/strategy/test/testdata/cert.pem b/selfservice/strategy/saml/strategy/test/testdata/cert.pem new file mode 100644 index 000000000000..52667ef39ff2 --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/cert.pem @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJV +UzELMAkGA1UECAwCR0ExDDAKBgNVBAoMA2ZvbzESMBAGA1UEAwwJbG9jYWxob3N0 +MB4XDTEzMTAwMjAwMDg1MVoXDTE0MTAwMjAwMDg1MVowPDELMAkGA1UEBhMCVVMx +CzAJBgNVBAgMAkdBMQwwCgYDVQQKDANmb28xEjAQBgNVBAMMCWxvY2FsaG9zdDCB +nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1PMHYmhZj308kWLhZVT4vOulqx/9 +ibm5B86fPWwUKKQ2i12MYtz07tzukPymisTDhQaqyJ8Kqb/6JjhmeMnEOdTvSPmH +O8m1ZVveJU6NoKRn/mP/BD7FW52WhbrUXLSeHVSKfWkNk6S4hk9MV9TswTvyRIKv +Rsw0X/gfnqkroJcCAwEAATANBgkqhkiG9w0BAQUFAAOBgQCMMlIO+GNcGekevKgk +akpMdAqJfs24maGb90DvTLbRZRD7Xvn1MnVBBS9hzlXiFLYOInXACMW5gcoRFfeT +QLSouMM8o57h0uKjfTmuoWHLQLi6hnF+cvCsEFiJZ4AbF+DgmO6TarJ8O05t8zvn +OwJlNCASPZRH/JmF8tX0hoHuAQ== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/idp_saml_metadata.xml b/selfservice/strategy/saml/strategy/test/testdata/idp_saml_metadata.xml new file mode 100644 index 000000000000..dcaf7f051dae --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/idp_saml_metadata.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + testshib.org + + TestShib Test IdP + TestShib IdP. Use this as a source of attributes + for your test SP. + https://www.testshib.org/testshibtwo.jpg + + + + + + MIIEDjCCAvagAwIBAgIBADANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzEV + MBMGA1UECBMMUGVubnN5bHZhbmlhMRMwEQYDVQQHEwpQaXR0c2J1cmdoMREwDwYD + VQQKEwhUZXN0U2hpYjEZMBcGA1UEAxMQaWRwLnRlc3RzaGliLm9yZzAeFw0wNjA4 + MzAyMTEyMjVaFw0xNjA4MjcyMTEyMjVaMGcxCzAJBgNVBAYTAlVTMRUwEwYDVQQI + EwxQZW5uc3lsdmFuaWExEzARBgNVBAcTClBpdHRzYnVyZ2gxETAPBgNVBAoTCFRl + c3RTaGliMRkwFwYDVQQDExBpZHAudGVzdHNoaWIub3JnMIIBIjANBgkqhkiG9w0B + AQEFAAOCAQ8AMIIBCgKCAQEArYkCGuTmJp9eAOSGHwRJo1SNatB5ZOKqDM9ysg7C + yVTDClcpu93gSP10nH4gkCZOlnESNgttg0r+MqL8tfJC6ybddEFB3YBo8PZajKSe + 3OQ01Ow3yT4I+Wdg1tsTpSge9gEz7SrC07EkYmHuPtd71CHiUaCWDv+xVfUQX0aT + NPFmDixzUjoYzbGDrtAyCqA8f9CN2txIfJnpHE6q6CmKcoLADS4UrNPlhHSzd614 + kR/JYiks0K4kbRqCQF0Dv0P5Di+rEfefC6glV8ysC8dB5/9nb0yh/ojRuJGmgMWH + gWk6h0ihjihqiu4jACovUZ7vVOCgSE5Ipn7OIwqd93zp2wIDAQABo4HEMIHBMB0G + A1UdDgQWBBSsBQ869nh83KqZr5jArr4/7b+QazCBkQYDVR0jBIGJMIGGgBSsBQ86 + 9nh83KqZr5jArr4/7b+Qa6FrpGkwZzELMAkGA1UEBhMCVVMxFTATBgNVBAgTDFBl + bm5zeWx2YW5pYTETMBEGA1UEBxMKUGl0dHNidXJnaDERMA8GA1UEChMIVGVzdFNo + aWIxGTAXBgNVBAMTEGlkcC50ZXN0c2hpYi5vcmeCAQAwDAYDVR0TBAUwAwEB/zAN + BgkqhkiG9w0BAQUFAAOCAQEAjR29PhrCbk8qLN5MFfSVk98t3CT9jHZoYxd8QMRL + I4j7iYQxXiGJTT1FXs1nd4Rha9un+LqTfeMMYqISdDDI6tv8iNpkOAvZZUosVkUo + 93pv1T0RPz35hcHHYq2yee59HJOco2bFlcsH8JBXRSRrJ3Q7Eut+z9uo80JdGNJ4 + /SJy5UorZ8KazGj16lfJhOBXldgrhppQBb0Nq6HKHguqmwRfJ+WkxemZXzhediAj + Geka8nz8JjwxpUjAiSWYKLtJhGEaTqCYxCCX2Dw+dOTqUzHOZ7WKv4JXPK5G/Uhr + 8K/qhmFT2nIQi538n6rVYLeWj8Bbnl+ev0peYzxFyF5sQA== + + + + + + + + + + + + urn:mace:shibboleth:1.0:nameIdentifier + urn:oasis:names:tc:SAML:2.0:nameid-format:transient + + + + + + + + + + + + MIIEDjCCAvagAwIBAgIBADANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzEV + MBMGA1UECBMMUGVubnN5bHZhbmlhMRMwEQYDVQQHEwpQaXR0c2J1cmdoMREwDwYD + VQQKEwhUZXN0U2hpYjEZMBcGA1UEAxMQaWRwLnRlc3RzaGliLm9yZzAeFw0wNjA4 + MzAyMTEyMjVaFw0xNjA4MjcyMTEyMjVaMGcxCzAJBgNVBAYTAlVTMRUwEwYDVQQI + EwxQZW5uc3lsdmFuaWExEzARBgNVBAcTClBpdHRzYnVyZ2gxETAPBgNVBAoTCFRl + c3RTaGliMRkwFwYDVQQDExBpZHAudGVzdHNoaWIub3JnMIIBIjANBgkqhkiG9w0B + AQEFAAOCAQ8AMIIBCgKCAQEArYkCGuTmJp9eAOSGHwRJo1SNatB5ZOKqDM9ysg7C + yVTDClcpu93gSP10nH4gkCZOlnESNgttg0r+MqL8tfJC6ybddEFB3YBo8PZajKSe + 3OQ01Ow3yT4I+Wdg1tsTpSge9gEz7SrC07EkYmHuPtd71CHiUaCWDv+xVfUQX0aT + NPFmDixzUjoYzbGDrtAyCqA8f9CN2txIfJnpHE6q6CmKcoLADS4UrNPlhHSzd614 + kR/JYiks0K4kbRqCQF0Dv0P5Di+rEfefC6glV8ysC8dB5/9nb0yh/ojRuJGmgMWH + gWk6h0ihjihqiu4jACovUZ7vVOCgSE5Ipn7OIwqd93zp2wIDAQABo4HEMIHBMB0G + A1UdDgQWBBSsBQ869nh83KqZr5jArr4/7b+QazCBkQYDVR0jBIGJMIGGgBSsBQ86 + 9nh83KqZr5jArr4/7b+Qa6FrpGkwZzELMAkGA1UEBhMCVVMxFTATBgNVBAgTDFBl + bm5zeWx2YW5pYTETMBEGA1UEBxMKUGl0dHNidXJnaDERMA8GA1UEChMIVGVzdFNo + aWIxGTAXBgNVBAMTEGlkcC50ZXN0c2hpYi5vcmeCAQAwDAYDVR0TBAUwAwEB/zAN + BgkqhkiG9w0BAQUFAAOCAQEAjR29PhrCbk8qLN5MFfSVk98t3CT9jHZoYxd8QMRL + I4j7iYQxXiGJTT1FXs1nd4Rha9un+LqTfeMMYqISdDDI6tv8iNpkOAvZZUosVkUo + 93pv1T0RPz35hcHHYq2yee59HJOco2bFlcsH8JBXRSRrJ3Q7Eut+z9uo80JdGNJ4 + /SJy5UorZ8KazGj16lfJhOBXldgrhppQBb0Nq6HKHguqmwRfJ+WkxemZXzhediAj + Geka8nz8JjwxpUjAiSWYKLtJhGEaTqCYxCCX2Dw+dOTqUzHOZ7WKv4JXPK5G/Uhr + 8K/qhmFT2nIQi538n6rVYLeWj8Bbnl+ev0peYzxFyF5sQA== + + + + + + + + + + + + urn:mace:shibboleth:1.0:nameIdentifier + urn:oasis:names:tc:SAML:2.0:nameid-format:transient + + + TestShib Two Identity Provider + TestShib Two + http://www.testshib.org/testshib-two/ + + + Nate + Klingenstein + ndk@internet2.edu + + \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/key.pem b/selfservice/strategy/saml/strategy/test/testdata/key.pem new file mode 100644 index 000000000000..48284dac33a1 --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXgIBAAKBgQDU8wdiaFmPfTyRYuFlVPi866WrH/2JubkHzp89bBQopDaLXYxi +3PTu3O6Q/KaKxMOFBqrInwqpv/omOGZ4ycQ51O9I+Yc7ybVlW94lTo2gpGf+Y/8E +PsVbnZaFutRctJ4dVIp9aQ2TpLiGT0xX1OzBO/JEgq9GzDRf+B+eqSuglwIDAQAB +AoGBAMuy1eN6cgFiCOgBsB3gVDdTKpww87Qk5ivjqEt28SmXO13A1KNVPS6oQ8SJ +CT5Azc6X/BIAoJCURVL+LHdqebogKljhH/3yIel1kH19vr4E2kTM/tYH+qj8afUS +JEmArUzsmmK8ccuNqBcllqdwCZjxL4CHDUmyRudFcHVX9oyhAkEA/OV1OkjM3CLU +N3sqELdMmHq5QZCUihBmk3/N5OvGdqAFGBlEeewlepEVxkh7JnaNXAXrKHRVu/f/ +fbCQxH+qrwJBANeQERF97b9Sibp9xgolb749UWNlAdqmEpmlvmS202TdcaaT1msU +4rRLiQN3X9O9mq4LZMSVethrQAdX1whawpkCQQDk1yGf7xZpMJ8F4U5sN+F4rLyM +Rq8Sy8p2OBTwzCUXXK+fYeXjybsUUMr6VMYTRP2fQr/LKJIX+E5ZxvcIyFmDAkEA +yfjNVUNVaIbQTzEbRlRvT6MqR+PTCefC072NF9aJWR93JimspGZMR7viY6IM4lrr +vBkm0F5yXKaYtoiiDMzlOQJADqmEwXl0D72ZG/2KDg8b4QZEmC9i5gidpQwJXUc6 +hU+IVQoLxRq0fBib/36K9tcrrO5Ba4iEvDcNY+D8yGbUtA== +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/myservice.cert b/selfservice/strategy/saml/strategy/test/testdata/myservice.cert new file mode 100755 index 000000000000..a815f8f44742 --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/myservice.cert @@ -0,0 +1,19 @@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GB98 +EwTT5cbtUtOIbrZ6kdBs49O27xCTymaIuysidFtywwTaDdrc1g== +-----END CERTIFICATE----- diff --git a/selfservice/strategy/saml/strategy/test/testdata/myservice.key b/selfservice/strategy/saml/strategy/test/testdata/myservice.key new file mode 100755 index 000000000000..e7b461f2f228 --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/myservice.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDjnp4eGltNpugk +P0i6tUhqR1vhjUK0zVxYSB4MH+jC76HXemqP7CT/UCUVQ0hgp/Mk2Y/4Kgm/mlK9 +R4lox0Du8pQIc8xjtI2hl1pfR4ZXhn1DtDqlKRX6F6hqaiOX4ur1UhW9afPitr3f +GO8knhsALIjPuT27faMBv6/dGHdrFWU99gmoLHSBT61wzFv8tzscfvKcCMUZzg2I +buo6oTaebNFqcrDh0wmGTOE3IVBuq13gOYTNXvReLHLO3GZsQ1V81286sJzfj94l +HirvDlgQYzBQg+Knv/PP+K2qyuTTHj9UXWUTEw6KF/x19iep0Xf5J3LCgF/lQLgB +TIVL/cWBAgMBAAECggEAAn9H/s6NN+Hf5B3pn1rDy56yzFuvYqpqG/HWmo1zEUht +vx5xstiFY2OutHgDgEP3b+0PHkrfxoFb7QWu5T5iYPy6UQlsMZ/WefJeJHN1btpj +321Hw24a9p5x05EMiOsNZtmasXRLH66fkKYGYaF2bF8QtS60Fa2AL1G6DTPqg3s4 +T+ijNYPr1xUk5GSh8Ea0DjLhzL6WgSHj+eBKgfEdYPDlOaQaYQuV2OJg9JyqxV6h +/Fa1HDc6RgpIhalLhP+9OqhSr9vmXSzEidzu+WTQSPpabwlVIae30Qh8XT9bYF5v +TElDXv5e5FwFmIJTnhAHyGlpnJ3KzaEHkmGbAxLOQQKBgQD2P4++d0WzrugKnfpz +hMpIVwk4jl1l2LUe3LoKEtF85lj6NjmvUNEPfJ0MIwKAjQYZ9AJWgCPP2/kjDBRv +dwwtSDIjFf79y810MNTGhAKv8nf7Lf5tSiJbvWgwtiiqF/ivUlxOKL9jqc6qj2s9 +psFoPOSAHQz6NqNpGyNza/7+CQKBgQDsojNWLJUXVzeUCMCzF+tn8lgs1aGrjHB7 +ZMHpr5nZCBdXjAzZR6yQH653Fa3OzNnVjq8CiO1ZdvbwW/KgVUHB4Mb/4kJ0Uxbm +WOF7zQjsMleoABFTi5mCcSqEK+u1qnrG8Ful9L6F8WhP7mdDmRXQM3f9rG2NDb1H +/OJuj/LpuQKBgQDK0+31Z069QtsUK62oSv9G+JG6yOC7S/Vbt1lxhLCSnTU620FG +W13n0K+W2JtuATq+U9M9JozY4ApkyMVoTnl0LtxFNA/1QlI3WyVXYlLIVAJpnSfN +I1wLjoZsYQ47lEUdO8yWAFAsqih1Km6duGXkEwvvTn5q9mhA4b6giprc6QKBgQCR +knMcd068ziXdxsitJHDoQHkoE8BiZYIpFuIIHcP6dPTPIdQhsusguqy8i7Sh/Pmh +XCaj25KQMBRX52jKY8iROfOSJSIWp6r1yAXnAEqV655rNqdyCvZD/dRW/SIDXz4q +tmDbJkYy5kDys0oJltqJe7A8eV/nn2UrLRIrTBj22QKBgQCFMmXVRqRje9k0Aqfe +KGYYCEPzeFzY4PzufwoOyhsGkLCwKthf43jXjWy53+u82Od1oKiNCjIhQHOtL720 +mTIhl2AzTJ1VMWoqUIHtGxhaIC3zhDjAaTMHZNDXFU78hPOhcBPtKikh3Hj2bfGG +TK1KTG49VMcWHmYJhJXwVevKAg== +-----END PRIVATE KEY----- diff --git a/selfservice/strategy/saml/strategy/test/testdata/registration.schema.json b/selfservice/strategy/saml/strategy/test/testdata/registration.schema.json new file mode 100644 index 000000000000..c7005d87ce8d --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/registration.schema.json @@ -0,0 +1,16 @@ +{ + "$id": "https://example.com/registration.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Person", + "type": "object", + "properties": { + "traits": { + "type": "object", + "properties": { + "bar": { + "type": "string" + } + } + } + } +} diff --git a/selfservice/strategy/saml/strategy/test/testdata/saml.jsonnet b/selfservice/strategy/saml/strategy/test/testdata/saml.jsonnet new file mode 100644 index 000000000000..87103e26bc6b --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/saml.jsonnet @@ -0,0 +1,17 @@ +local claims = { + email_verified: false +} + std.extVar('claims'); + +{ + identity: { + traits: { + // Allowing unverified email addresses enables account + // enumeration attacks, especially if the value is used for + // e.g. verification or as a password login identifier. + // + // Therefore we only return the email if it (a) exists and (b) is marked verified + // by Discord. + [if "email" in claims && claims.email_verified then "email" else null]: claims.email, + }, + }, +} \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/saml_response.xml b/selfservice/strategy/saml/strategy/test/testdata/saml_response.xml new file mode 100644 index 000000000000..22ea0920a014 --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/saml_response.xml @@ -0,0 +1,11 @@ +https://idp.testshib.org/idp/shibbolethMIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJVUzELMAkGA1UE +CAwCR0ExDDAKBgNVBAoMA2ZvbzESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTEzMTAwMjAwMDg1MVoX +DTE0MTAwMjAwMDg1MVowPDELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkdBMQwwCgYDVQQKDANmb28x +EjAQBgNVBAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1PMHYmhZj308 +kWLhZVT4vOulqx/9ibm5B86fPWwUKKQ2i12MYtz07tzukPymisTDhQaqyJ8Kqb/6JjhmeMnEOdTv +SPmHO8m1ZVveJU6NoKRn/mP/BD7FW52WhbrUXLSeHVSKfWkNk6S4hk9MV9TswTvyRIKvRsw0X/gf +nqkroJcCAwEAATANBgkqhkiG9w0BAQUFAAOBgQCMMlIO+GNcGekevKgkakp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Pe5vkqRLfwZCYd5mZoxtBhNBWvY3ZOVD/21dIUlQanG1n6RygbmAwCHnIB4c7EH2CBYEMDToRQuAuIssviIfdaJglwDgHbLWKNUVDOdqeclBNZjfQfVXbVukPk8DfWLqj9pD4xAOzDeVQcdmg2aLvNKgpZsWs4d+6GlKrpS7qEGvoBkIFh/cVY7DMYrt/JXYuF6DpwB+HbfnuDFc2p47SPNhnmt/ez6/DACBPQ+tgpyWYXUsiviGSp72JNTzd8uFJJZNeKUJZw1c0UTjxdwigh5tL/hWhPl48DY937zymSr1xVqC3RV6wSIpuplH+hss/rsRPAp1/TfxvhJuFsoPbW0586y9YzqEHT4FUu6WSRy0gMJLP2sLqiiZXZ6kPicXsW7M55mV3ugbGQjB7YS7EVqsQzvJTiQbOlcPqwoKK7DTqaeCOXd8kH1tNoe7hjx/UNNdLQQ7IhrJIzxqTTgwcXYMCxhoezDsIHReTIymsHPkCurfteTQcbfwoKN5E9zC2hINOPmhAxLvONzaLXQGMqofuTbFshkB4eUj8U4vBCNp+60iCLnibt4rPuyoWKEHWBYa6FfIykxVKuXkfcb64dCdGCWjv7x1XqkbpHxQB80qhipoSo244pyhIsN91ASu1Q7L75LxGXibY3jb0Y4KZ5zIWsH4kVlvPhangohDO1J9gmL9inGr9hy5BHTQiMcktGoUgOIbFJ72381vYpPxn3ngBbp48mVZd0w6xV8RBaqR3l7CxI9vvMAPYPoXBB18ERoZypza8mAlzv2QxIkNGuRzFENh1SXegBfN7eiazZnwnhbyeMghJpnXzfvHACyjkdH3shRYcJ+oMiOSpInGxm/hxFQxHJZA0Ft/lza \ No newline at end of file diff --git a/selfservice/strategy/saml/strategy/test/testdata/samlkratos.crt b/selfservice/strategy/saml/strategy/test/testdata/samlkratos.crt new file mode 100755 index 000000000000..3dfdeb703e1c --- /dev/null +++ b/selfservice/strategy/saml/strategy/test/testdata/samlkratos.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDazCCAlOgAwIBAgIUVREfiVXf4z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1foUR1O71jffr7CgELauyz3AXv6PNYLkyOCQP5gNB2NEMLJBRn5U4IhCHKzD +t1/BujsTuZV5r6aj3J9+ +-----END CERTIFICATE----- diff --git a/selfservice/strategy/saml/strategy/types.go b/selfservice/strategy/saml/strategy/types.go new file mode 100644 index 000000000000..e201e2e76e85 --- /dev/null +++ b/selfservice/strategy/saml/strategy/types.go @@ -0,0 +1,63 @@ +package strategy + +import ( + "bytes" + "encoding/json" + + "github.com/ory/kratos/identity" + "github.com/ory/kratos/selfservice/strategy/saml" + "github.com/ory/kratos/text" + "github.com/ory/kratos/ui/container" + "github.com/ory/kratos/ui/node" + "github.com/ory/kratos/x" + "github.com/ory/x/stringsx" + + "github.com/pkg/errors" +) + +type CredentialsConfig struct { + Providers []ProviderCredentialsConfig `json:"providers"` +} + +//Create an uniq identifier for user in database. Its look like "id + the id of the saml provider" +func NewCredentialsForSAML(subject string, provider string) (*identity.Credentials, error) { + var b bytes.Buffer + if err := json.NewEncoder(&b).Encode(CredentialsConfig{ + Providers: []ProviderCredentialsConfig{ + { + Subject: subject, + Provider: provider, + }}, + }); err != nil { + return nil, errors.WithStack(x.PseudoPanic. + WithDebugf("Unable to encode password options to JSON: %s", err)) + } + + return &identity.Credentials{ + Type: identity.CredentialsTypeSAML, + Identifiers: []string{uid(provider, subject)}, + Config: b.Bytes(), + }, nil +} + +func AddProviders(c *container.Container, providers []saml.Configuration, message func(provider string) *text.Message) { + for _, p := range providers { + AddProvider(c, p.ID, message( + stringsx.Coalesce(p.Label, p.ID))) + } +} + +func AddProvider(c *container.Container, providerID string, message *text.Message) { + c.GetNodes().Append( + node.NewInputField("samlProvider", providerID, node.SAMLGroup, node.InputAttributeTypeSubmit).WithMetaLabel(message), + ) +} + +type ProviderCredentialsConfig struct { + Subject string `json:"subject"` + Provider string `json:"samlProvider"` +} + +type FlowMethod struct { + *container.Container +} diff --git a/spec/api.json b/spec/api.json index b085802095cd..d7c28b3a905a 100755 --- a/spec/api.json +++ b/spec/api.json @@ -1036,6 +1036,23 @@ ], "type": "object" }, + "selfServiceSamlUrl": { + "properties": { + "saml_acs_url": { + "description": "SamlAcsURL is a post endpoint to handle SAML Response\n\nformat: uri", + "type": "string" + }, + "saml_metadata_url": { + "description": "SamlMetadataURL is a get endpoint to get the metadata\n\nformat: uri", + "type": "string" + } + }, + "required": [ + "saml_metadata_url", + "saml_acs_url" + ], + "type": "object" + }, "selfServiceSettingsFlow": { "description": "This flow is used when an identity wants to update settings\n(e.g. profile data, passwords, ...) in a selfservice manner.\n\nWe recommend reading the [User Settings Documentation](../self-service/flows/user-settings)", "properties": { @@ -3802,6 +3819,48 @@ ] } }, + "/self-service/methods/saml/auth": { + "get": { + "description": "This endpoint initiates a registration flow for API clients such as mobile devices, smart TVs, and so on.\n\nIf a valid provided session cookie or session token is provided, a 400 Bad Request error\nwill be returned unless the URL query parameter `?refresh=true` is set.\n\nTo fetch an existing registration flow call `/self-service/registration/flows?flow=\u003cflow_id\u003e`.\n\nYou MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server\nPages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make\nyou vulnerable to a variety of CSRF attacks.\n\nIn the case of an error, the `error.id` of the JSON response body can be one of:\n\n`session_already_available`: The user is already signed in.\n`security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred.\n\nThis endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).\n\nMore information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).", + "operationId": "initializeSelfServiceSamlFlowForBrowsers", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/selfServiceRegistrationFlow" + } + } + }, + "description": "selfServiceRegistrationFlow" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/jsonError" + } + } + }, + "description": "jsonError" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/jsonError" + } + } + }, + "description": "jsonError" + } + }, + "summary": "Initialize Registration Flow for APIs, Services, Apps, ...", + "tags": [ + "v0alpha2" + ] + } + }, "/self-service/recovery": { "post": { "description": "Use this endpoint to complete a recovery flow. This endpoint\nbehaves differently for API and browser flows and has several states:\n\n`choose_method` expects `flow` (in the URL query) and `email` (in the body) to be sent\nand works with API- and Browser-initiated flows.\nFor API clients and Browser clients with HTTP Header `Accept: application/json` it either returns a HTTP 200 OK when the form is valid and HTTP 400 OK when the form is invalid.\nand a HTTP 303 See Other redirect with a fresh recovery flow if the flow was otherwise invalid (e.g. expired).\nFor Browser clients without HTTP Header `Accept` or with `Accept: text/*` it returns a HTTP 303 See Other redirect to the Recovery UI URL with the Recovery Flow ID appended.\n`sent_email` is the success state after `choose_method` for the `link` method and allows the user to request another recovery email. It\nworks for both API and Browser-initiated flows and returns the same responses as the flow in `choose_method` state.\n`passed_challenge` expects a `token` to be sent in the URL query and given the nature of the flow (\"sending a recovery link\")\ndoes not have any API capabilities. The server responds with a HTTP 303 See Other redirect either to the Settings UI URL\n(if the link was valid) and instructs the user to update their password, or a redirect to the Recover UI URL with\na new Recovery Flow ID which contains an error message that the recovery link was invalid.\n\nMore information can be found at [Ory Kratos Account Recovery Documentation](../self-service/flows/account-recovery).", diff --git a/spec/swagger.json b/spec/swagger.json index 3bab3006bcd5..94ff214628cb 100755 --- a/spec/swagger.json +++ b/spec/swagger.json @@ -1265,6 +1265,40 @@ } } }, + "/self-service/methods/saml/auth": { + "get": { + "description": "This endpoint initiates a registration flow for API clients such as mobile devices, smart TVs, and so on.\n\nIf a valid provided session cookie or session token is provided, a 400 Bad Request error\nwill be returned unless the URL query parameter `?refresh=true` is set.\n\nTo fetch an existing registration flow call `/self-service/registration/flows?flow=\u003cflow_id\u003e`.\n\nYou MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server\nPages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make\nyou vulnerable to a variety of CSRF attacks.\n\nIn the case of an error, the `error.id` of the JSON response body can be one of:\n\n`session_already_available`: The user is already signed in.\n`security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred.\n\nThis endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).\n\nMore information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).", + "schemes": [ + "http", + "https" + ], + "tags": [ + "v0alpha2" + ], + "summary": "Initialize Registration Flow for APIs, Services, Apps, ...", + "operationId": "initializeSelfServiceSamlFlowForBrowsers", + "responses": { + "200": { + "description": "selfServiceRegistrationFlow", + "schema": { + "$ref": "#/definitions/selfServiceRegistrationFlow" + } + }, + "400": { + "description": "jsonError", + "schema": { + "$ref": "#/definitions/jsonError" + } + }, + "500": { + "description": "jsonError", + "schema": { + "$ref": "#/definitions/jsonError" + } + } + } + } + }, "/self-service/recovery": { "post": { "description": "Use this endpoint to complete a recovery flow. This endpoint\nbehaves differently for API and browser flows and has several states:\n\n`choose_method` expects `flow` (in the URL query) and `email` (in the body) to be sent\nand works with API- and Browser-initiated flows.\nFor API clients and Browser clients with HTTP Header `Accept: application/json` it either returns a HTTP 200 OK when the form is valid and HTTP 400 OK when the form is invalid.\nand a HTTP 303 See Other redirect with a fresh recovery flow if the flow was otherwise invalid (e.g. expired).\nFor Browser clients without HTTP Header `Accept` or with `Accept: text/*` it returns a HTTP 303 See Other redirect to the Recovery UI URL with the Recovery Flow ID appended.\n`sent_email` is the success state after `choose_method` for the `link` method and allows the user to request another recovery email. It\nworks for both API and Browser-initiated flows and returns the same responses as the flow in `choose_method` state.\n`passed_challenge` expects a `token` to be sent in the URL query and given the nature of the flow (\"sending a recovery link\")\ndoes not have any API capabilities. The server responds with a HTTP 303 See Other redirect either to the Settings UI URL\n(if the link was valid) and instructs the user to update their password, or a redirect to the Recover UI URL with\na new Recovery Flow ID which contains an error message that the recovery link was invalid.\n\nMore information can be found at [Ory Kratos Account Recovery Documentation](../self-service/flows/account-recovery).", @@ -3463,6 +3497,23 @@ } } }, + "selfServiceSamlUrl": { + "type": "object", + "required": [ + "saml_metadata_url", + "saml_acs_url" + ], + "properties": { + "saml_acs_url": { + "description": "SamlAcsURL is a post endpoint to handle SAML Response\n\nformat: uri", + "type": "string" + }, + "saml_metadata_url": { + "description": "SamlMetadataURL is a get endpoint to get the metadata\n\nformat: uri", + "type": "string" + } + } + }, "selfServiceSettingsFlow": { "description": "This flow is used when an identity wants to update settings\n(e.g. profile data, passwords, ...) in a selfservice manner.\n\nWe recommend reading the [User Settings Documentation](../self-service/flows/user-settings)", "type": "object", diff --git a/ui/node/node.go b/ui/node/node.go index 4856f6d8e9e7..36b87fb0119b 100644 --- a/ui/node/node.go +++ b/ui/node/node.go @@ -39,6 +39,7 @@ const ( DefaultGroup UiNodeGroup = "default" PasswordGroup UiNodeGroup = "password" OpenIDConnectGroup UiNodeGroup = "oidc" + SAMLGroup UiNodeGroup = "saml" ProfileGroup UiNodeGroup = "profile" LinkGroup UiNodeGroup = "link" TOTPGroup UiNodeGroup = "totp" diff --git a/x/provider.go b/x/provider.go index d6311c54adf3..dd54485e9ebf 100644 --- a/x/provider.go +++ b/x/provider.go @@ -26,6 +26,11 @@ type CookieProvider interface { ContinuityCookieManager(ctx context.Context) sessions.StoreExact } +type RelayStateProvider interface { + RelayStateManager(ctx context.Context) sessions.StoreExact + ContinuityRelayStateManager(ctx context.Context) sessions.StoreExact +} + type TracingProvider interface { Tracer(ctx context.Context) *otelx.Tracer } diff --git a/x/relaystate.go b/x/relaystate.go new file mode 100644 index 000000000000..a28c97024d58 --- /dev/null +++ b/x/relaystate.go @@ -0,0 +1,51 @@ +package x + +import ( + "net/http" + + "github.com/gorilla/sessions" + "github.com/pkg/errors" +) + +// SessionGetRelayState returns a string of the content of the relaystate for the current session. +func SessionGetStringRelayState(r *http.Request, s sessions.StoreExact, id string, key interface{}) (string, error) { + + cipherRelayState := r.PostForm.Get("RelayState") + if cipherRelayState == "" { + return "", errors.New("The RelayState is empty or not exists") + } + + // Reconstructs the cookie from the ciphered value + continuityCookie := &http.Cookie{ + Name: id, + Value: cipherRelayState, + MaxAge: 300, + } + + r2 := r.Clone(r.Context()) + r2.AddCookie(continuityCookie) + + check := func(v map[interface{}]interface{}) (string, error) { + vv, ok := v[key] + if !ok { + return "", errors.Errorf("key %s does not exist in cookie: %+v", key, id) + } else if vvv, ok := vv.(string); !ok { + return "", errors.Errorf("value of key %s is not of type string in cookie", key) + } else { + return vvv, nil + } + } + + var exactErr error + sessionCookie, err := s.GetExact(r2, id, func(s *sessions.Session) bool { + _, exactErr = check(s.Values) + return exactErr == nil + }) + if err != nil { + return "", err + } else if exactErr != nil { + return "", exactErr + } + + return check(sessionCookie.Values) +}