Skip to content

Commit 662ffcb

Browse files
committed
Shibboleth SLO Session match fix. Fixes #11
1 parent a760c53 commit 662ffcb

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
### v0.8.4
4+
5+
+ Shibboleth Single Logout session match related fix. Uptake `esaml v3.3.0`.
6+
37
### v0.8.3
48

59
+ Generates SP metadata XML that passes XSD validation

lib/samly/auth_handler.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Samly.AuthHandler do
33

44
require Logger
55
import Plug.Conn
6-
alias Samly.{Assertion, IdpData, Helper, State}
6+
alias Samly.{Assertion, IdpData, Helper, State, Subject}
77

88
import Samly.RouterUtil, only: [ensure_sp_uris_set: 2, send_saml_request: 5, redirect: 3]
99

@@ -105,8 +105,10 @@ defmodule Samly.AuthHandler do
105105
nameid = get_session(conn, "samly_nameid")
106106

107107
case State.get_by_nameid(nameid) do
108-
{^nameid, %Assertion{idp_id: ^idp_id}} ->
109-
{idp_signout_url, req_xml_frag} = Helper.gen_idp_signout_req(sp, idp_rec, nameid)
108+
{^nameid, %Assertion{idp_id: ^idp_id, authn: authn, subject: subject}} ->
109+
session_index = Map.get(authn, "session_index", "")
110+
subject_rec = Subject.to_rec(subject)
111+
{idp_signout_url, req_xml_frag} = Helper.gen_idp_signout_req(sp, idp_rec, subject_rec, session_index)
110112

111113
State.delete(nameid)
112114
relay_state = State.gen_id()

lib/samly/helper.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ defmodule Samly.Helper do
4949

5050
def gen_idp_signin_req(sp, idp_metadata) do
5151
idp_signin_url = Esaml.esaml_idp_metadata(idp_metadata, :login_location)
52-
xml_frag = :esaml_sp.generate_authn_request(idp_signin_url, sp)
52+
# TODO: Expose an config
53+
name_format = 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'
54+
xml_frag = :esaml_sp.generate_authn_request(idp_signin_url, sp, name_format)
5355
{idp_signin_url, xml_frag}
5456
end
5557

56-
def gen_idp_signout_req(sp, idp_metadata, nameid) do
58+
def gen_idp_signout_req(sp, idp_metadata, subject_rec, session_index) do
5759
idp_signout_url = Esaml.esaml_idp_metadata(idp_metadata, :logout_location)
58-
xml_frag = :esaml_sp.generate_logout_request(idp_signout_url, nameid, sp)
60+
xml_frag = :esaml_sp.generate_logout_request(idp_signout_url, session_index, subject_rec, sp)
5961
{idp_signout_url, xml_frag}
6062
end
6163

lib/samly/subject.ex

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ defmodule Samly.Subject do
1111
alias Samly.Esaml
1212

1313
defstruct name: "",
14+
name_qualifier: :undefined,
15+
sp_name_qualifier: :undefined,
16+
name_format: :undefined,
1417
confirmation_method: :bearer,
1518
notonorafter: ""
1619

1720
@type t :: %__MODULE__{
1821
name: String.t(),
22+
name_qualifier: :undefined | String.t(),
23+
sp_name_qualifier: :undefined | String.t(),
24+
name_format: :undefined | String.t(),
1925
confirmation_method: atom,
2026
notonorafter: String.t()
2127
}
@@ -24,14 +30,38 @@ defmodule Samly.Subject do
2430
def from_rec(subject_rec) do
2531
Esaml.esaml_subject(
2632
name: name,
33+
name_qualifier: name_qualifier,
34+
sp_name_qualifier: sp_name_qualifier,
35+
name_format: name_format,
2736
confirmation_method: confirmation_method,
2837
notonorafter: notonorafter
2938
) = subject_rec
3039

3140
%__MODULE__{
3241
name: name |> List.to_string(),
42+
name_qualifier: to_string_or_undefined(name_qualifier),
43+
sp_name_qualifier: to_string_or_undefined(sp_name_qualifier),
44+
name_format: to_string_or_undefined(name_format),
3345
confirmation_method: confirmation_method,
3446
notonorafter: notonorafter |> List.to_string()
3547
}
3648
end
49+
50+
@doc false
51+
def to_rec(subject) do
52+
Esaml.esaml_subject(
53+
name: String.to_charlist(subject.name),
54+
name_qualifier: from_string_or_undefined(subject.name_qualifier),
55+
sp_name_qualifier: from_string_or_undefined(subject.sp_name_qualifier),
56+
name_format: from_string_or_undefined(subject.name_format),
57+
confirmation_method: subject.confirmation_method,
58+
notonorafter: String.to_charlist(subject.notonorafter)
59+
)
60+
end
61+
62+
defp to_string_or_undefined(:undefined), do: :undefined
63+
defp to_string_or_undefined(s) when is_list(s), do: List.to_string(s)
64+
65+
defp from_string_or_undefined(:undefined), do: :undefined
66+
defp from_string_or_undefined(s) when is_binary(s), do: String.to_charlist(s)
3767
end

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Samly.Mixfile do
22
use Mix.Project
33

4-
@version "0.8.3"
4+
@version "0.8.4"
55
@description "SAML SP SSO made easy"
66
@source_url "https://github.com/handnot2/samly"
77

@@ -29,7 +29,7 @@ defmodule Samly.Mixfile do
2929
defp deps() do
3030
[
3131
{:plug, "~> 1.4"},
32-
{:esaml, "~> 3.2"},
32+
{:esaml, "~> 3.3"},
3333
{:sweet_xml, "~> 0.6"},
3434
{:ex_doc, "~> 0.18", only: :dev},
3535
{:inch_ex, "~> 0.5", only: :docs}

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%{"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
22
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
3-
"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], [], "hexpm"},
4-
"esaml": {:hex, :esaml, "3.2.0", "fa728c705a6f3212c59a8f78861b3083e0db93b44cd377851eb5656c5a35542c", [:rebar3], [{:cowboy, "1.1.2", [hex: :cowboy, repo: "hexpm", optional: false]}], "hexpm"},
3+
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
4+
"esaml": {:hex, :esaml, "3.3.0", "9b675c1201ef2d60e53cf5603a20560e1a688acc128bf0de476812919e4d2c52", [:rebar3], [{:cowboy, "1.1.2", [hex: :cowboy, repo: "hexpm", optional: false]}], "hexpm"},
55
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
66
"inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
77
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"},

0 commit comments

Comments
 (0)