ciam-es 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ciam-es.gemspec +1 -1
- data/lib/ciam/ruby-saml/authrequest.rb +0 -1
- data/lib/ciam/ruby-saml/logout_request.rb +8 -10
- data/lib/ciam/ruby-saml/logout_response.rb +51 -31
- data/lib/ciam/ruby-saml/response.rb +6 -1
- data/lib/ciam/ruby-saml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c80df6472d22b7b301cc4cb8947380d8f8bd8d281baeb1277f646393e86595a
|
4
|
+
data.tar.gz: 990ce44721bc98af1881030a10272a486680054e801e87bca74e0d6eddf0454b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed091145eb483be7d4c5ece184b3e2ff674bb1778b756bd7b96a4a3e30087e7cf18df02811a72d6f138edd9fa89f653e06a33c5d8f6d6563742797f8d7d554e
|
7
|
+
data.tar.gz: 074e0d01c85fa224e1c4bd74c41ae3cfb9421ceff6d8fb025e9b2bc46f6464847c453e00ee3a074504a16f60804b1c840feaf94586c935d03fdd27ecebc3b0dd
|
data/ciam-es.gemspec
CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'ciam-es'
|
5
|
-
s.version = '0.0
|
5
|
+
s.version = '0.1.0'
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Fabiano Pavan"]
|
@@ -37,7 +37,6 @@ module Ciam::Saml
|
|
37
37
|
root.attributes['Version'] = "2.0"
|
38
38
|
#root.attributes['ProtocolBinding'] = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
|
39
39
|
root.attributes['AttributeConsumingServiceIndex'] = @settings.assertion_consumer_service_index
|
40
|
-
root.attributes['ForceAuthn'] = "true"
|
41
40
|
#root.attributes['IsPassive'] = "false"
|
42
41
|
#usato AssertionConsumerServiceURL e ProtocolBinding in alternativa, pag 8 regole tecniche
|
43
42
|
root.attributes['AssertionConsumerServiceIndex'] = @settings.attribute_consuming_service_index
|
@@ -41,26 +41,24 @@ module Ciam::Saml
|
|
41
41
|
request_doc.context[:attribute_quote] = :quote
|
42
42
|
|
43
43
|
|
44
|
-
root = request_doc.add_element "samlp:LogoutRequest", { "xmlns:samlp" => PROTOCOL }
|
44
|
+
root = request_doc.add_element "samlp:LogoutRequest", { "xmlns:samlp" => PROTOCOL, "xmlns:saml" => ASSERTION }
|
45
45
|
root.attributes['ID'] = @transaction_id
|
46
46
|
root.attributes['IssueInstant'] = @issue_instant
|
47
47
|
root.attributes['Version'] = "2.0"
|
48
48
|
root.attributes['Destination'] = @settings.single_logout_destination
|
49
49
|
|
50
|
-
issuer = root.add_element "
|
51
|
-
issuer.attributes['Format'] = "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
|
52
|
-
|
53
|
-
#per la federazione trentina qui ci vanno i metadati...
|
54
|
-
issuer.text = @settings.idp_metadata
|
50
|
+
issuer = root.add_element "saml:Issuer"#, { "xmlns:saml2" => ASSERTION }
|
51
|
+
#issuer.attributes['Format'] = "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
|
52
|
+
issuer.text = @settings.issuer
|
55
53
|
|
56
|
-
name_id = root.add_element "
|
54
|
+
name_id = root.add_element "saml:NameID"#, { "xmlns:saml2" => ASSERTION }
|
57
55
|
name_id.attributes['Format'] = "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
|
58
56
|
name_id.attributes['NameQualifier'] = @settings.idp_name_qualifier
|
59
57
|
name_id.text = opt[:name_id]
|
60
58
|
# I believe the rest of these are optional
|
61
|
-
if @settings && @settings.sp_name_qualifier
|
62
|
-
|
63
|
-
end
|
59
|
+
# if @settings && @settings.sp_name_qualifier
|
60
|
+
# name_id.attributes["SPNameQualifier"] = @settings.sp_name_qualifier
|
61
|
+
# end
|
64
62
|
if opt[:session_index]
|
65
63
|
session_index = root.add_element "samlp:SessionIndex" #, { "xmlns:samlp" => PROTOCOL }
|
66
64
|
session_index.text = opt[:session_index]
|
@@ -5,13 +5,15 @@ require "rexml/document"
|
|
5
5
|
module Ciam
|
6
6
|
module Saml
|
7
7
|
class LogoutResponse
|
8
|
-
|
8
|
+
include Coding
|
9
9
|
include Request
|
10
10
|
ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"
|
11
11
|
PROTOCOL = "urn:oasis:names:tc:SAML:2.0:protocol"
|
12
12
|
DSIG = "http://www.w3.org/2000/09/xmldsig#"
|
13
13
|
|
14
|
-
|
14
|
+
attr_accessor :settings
|
15
|
+
|
16
|
+
def initialize( options = { } )
|
15
17
|
opt = { :response => nil, :settings => nil }.merge(options)
|
16
18
|
# We've recieved a LogoutResponse from the IdP
|
17
19
|
if opt[:response]
|
@@ -32,7 +34,7 @@ module Ciam
|
|
32
34
|
if opt[:settings]
|
33
35
|
@settings = opt[:settings]
|
34
36
|
end
|
35
|
-
|
37
|
+
end
|
36
38
|
|
37
39
|
# Create a LogoutResponse to to the IdP's LogoutRequest
|
38
40
|
# (For IdP initiated SLO)
|
@@ -42,70 +44,85 @@ module Ciam
|
|
42
44
|
:status => "urn:oasis:names:tc:SAML:2.0:status:Success",
|
43
45
|
:extra_parameters => nil }.merge(options)
|
44
46
|
return nil if opt[:transaction_id].nil?
|
45
|
-
|
46
|
-
|
47
|
+
response_doc = Ciam::XMLSecurityNew::Document.new
|
48
|
+
response_doc.context[:attribute_quote] = :quote
|
49
|
+
|
47
50
|
uuid = "_" + UUID.new.generate
|
48
51
|
time = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
|
49
|
-
root =
|
52
|
+
root = response_doc.add_element "saml2p:LogoutResponse", { "xmlns:saml2p" => PROTOCOL }
|
50
53
|
root.attributes['ID'] = uuid
|
51
54
|
root.attributes['IssueInstant'] = time
|
52
55
|
root.attributes['Version'] = "2.0"
|
56
|
+
root.attributes['Destination'] = @settings.single_logout_destination
|
53
57
|
# Just convenient naming to accept both names as InResponseTo
|
54
58
|
if opt[:transaction_id]
|
55
59
|
root.attributes['InResponseTo'] = opt[:transaction_id]
|
56
60
|
elsif opt[:in_response_to]
|
57
61
|
root.attributes['InResponseTo'] = opt[:in_response_to]
|
58
62
|
end
|
59
|
-
if opt[:status]
|
60
|
-
status = root.add_element "saml2p:Status"
|
61
|
-
status_code = status.add_element "saml2p:StatusCode", {
|
62
|
-
"Value" => opt[:status]
|
63
|
-
}
|
64
|
-
end
|
65
63
|
if @settings && @settings.issuer
|
66
64
|
issuer = root.add_element "saml:Issuer", {
|
67
65
|
"xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion"
|
68
66
|
}
|
69
67
|
issuer.text = @settings.issuer
|
70
68
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
|
70
|
+
response_doc << REXML::XMLDecl.new("1.0", "UTF-8")
|
71
|
+
#sign logout_response
|
72
|
+
cert = @settings.get_cert(@settings.sp_cert)
|
73
|
+
|
74
|
+
# embed signature
|
75
|
+
if @settings.metadata_signed && @settings.sp_private_key && @settings.sp_cert
|
76
|
+
private_key = @settings.get_sp_key
|
77
|
+
response_doc.sign_document(private_key, cert)
|
78
|
+
end
|
74
79
|
|
75
|
-
|
80
|
+
if opt[:status]
|
81
|
+
status = root.add_element "saml2p:Status"
|
82
|
+
status_code = status.add_element "saml2p:StatusCode", {
|
83
|
+
"Value" => opt[:status]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
Logging.debug "Created LogoutResponse:\n #{response_doc}"
|
76
88
|
|
89
|
+
return response_doc.to_s
|
90
|
+
|
77
91
|
end
|
92
|
+
|
78
93
|
# function to return the created request as an XML document
|
79
94
|
def to_xml
|
80
95
|
text = ""
|
81
96
|
@response.write(text, 1)
|
82
97
|
return text
|
83
98
|
end
|
99
|
+
|
84
100
|
def to_s
|
85
101
|
@response.to_s
|
86
102
|
end
|
87
103
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
104
|
+
def issuer
|
105
|
+
element = REXML::XPath.first(@response, "/p:LogoutResponse/a:Issuer", {
|
106
|
+
"p" => PROTOCOL, "a" => ASSERTION} )
|
107
|
+
return nil if element.nil?
|
108
|
+
element.text
|
109
|
+
end
|
94
110
|
|
95
|
-
|
111
|
+
def in_response_to
|
96
112
|
element = REXML::XPath.first(@response, "/p:LogoutResponse", {
|
97
113
|
"p" => PROTOCOL })
|
98
114
|
return nil if element.nil?
|
99
|
-
|
100
|
-
|
115
|
+
element.attributes["InResponseTo"]
|
116
|
+
end
|
101
117
|
|
102
|
-
|
118
|
+
def success?
|
103
119
|
element = REXML::XPath.first(@response, "/p:LogoutResponse/p:Status/p:StatusCode", {
|
104
120
|
"p" => PROTOCOL })
|
105
121
|
return false if element.nil?
|
106
|
-
|
107
|
-
|
108
|
-
|
122
|
+
element.attributes["Value"] == "urn:oasis:names:tc:SAML:2.0:status:Success"
|
123
|
+
|
124
|
+
end
|
125
|
+
|
109
126
|
def is_valid?
|
110
127
|
validate(soft = true)
|
111
128
|
end
|
@@ -113,6 +130,7 @@ module Ciam
|
|
113
130
|
def validate!
|
114
131
|
validate( soft = false )
|
115
132
|
end
|
133
|
+
|
116
134
|
def validate( soft = true )
|
117
135
|
return false if @response.nil?
|
118
136
|
# Skip validation with a failed response if we don't have settings
|
@@ -123,10 +141,12 @@ module Ciam
|
|
123
141
|
|
124
142
|
end
|
125
143
|
|
126
|
-
|
144
|
+
protected
|
145
|
+
|
127
146
|
def document
|
128
147
|
REXML::Document.new(@response)
|
129
148
|
end
|
130
|
-
|
149
|
+
|
150
|
+
end
|
131
151
|
end
|
132
152
|
end
|
@@ -98,8 +98,13 @@ module Ciam
|
|
98
98
|
parse_time(node, "SessionNotOnOrAfter")
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
102
101
|
|
102
|
+
def session_index
|
103
|
+
@session_index ||= begin
|
104
|
+
node = REXML::XPath.first(document, "/p:Response/a:Assertion/a:AuthnStatement", { "p" => PROTOCOL, "a" => ASSERTION })
|
105
|
+
node.attributes["SessionIndex"] unless node.blank?
|
106
|
+
end
|
107
|
+
end
|
103
108
|
|
104
109
|
# Checks the status of the response for a "Success" code
|
105
110
|
def success?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ciam-es
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabiano Pavan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: canonix
|