saml_camel 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71f94da315b31aec73381b73e58fb6bb1a6fd3eb
4
- data.tar.gz: '08d80cedc906fb1cb14ceaa008a796a9bee802c5'
3
+ metadata.gz: 9587f9aa4978c5bfc1ff83fd93490b77cfada4a0
4
+ data.tar.gz: d005f8ba385cd0443baeda86c668d002c7907857
5
5
  SHA512:
6
- metadata.gz: 62891d7a9e63252a869314de2d06fc919646eb7b5a9f5b005b3d15d53bee9091514e9126ba6dd94daac2909fac9adff83eb6e3d31e1050a930183413643d9fce
7
- data.tar.gz: 30cc191cb55e6a66cc192327d201365450e48beb0d76ca62d683d910ecfcbdec2b1c8faf0f4040c052d1c072357543e55b76d00167d5cb770577825d4e558806
6
+ metadata.gz: 012d8b91632f47e689f385cb1de8f82e7e99696579e11491ce94e54de0823f0b56f727bd25b5e748cc1c288db6debaf57f2aa5df3d7b83a3ffdc1a20514b779a
7
+ data.tar.gz: de3c6af5a1395e1a44502b9f85101f8e42d238362443ff7826037ec96d783712329ae028370365b2b514f4f338287e04247a3e906ae1b0dd04ac0e4bb8e2817e
@@ -7,7 +7,10 @@ module SamlCamel::SamlHelpers
7
7
 
8
8
  #this generates a call to the idp, which will then be returned to the consume action the in saml_contorller
9
9
  def saml_request(host_request)
10
+ relay_state = SecureRandom.base64.chomp.gsub( /\n/, '' ) #set relay state to secure against replay attack
11
+ session[:relay_state] = relay_state
10
12
  request = OneLogin::RubySaml::Authrequest.new
13
+
11
14
  secure_cookie = (Rails.env == "development" || Rails.env == "test") ? false : true
12
15
  cookies.encrypted[:saml_camel_redirect] = {
13
16
  value: host_request.url,
@@ -15,7 +18,21 @@ module SamlCamel::SamlHelpers
15
18
  httponly: true
16
19
  }
17
20
 
18
- redirect_to(request.create(SamlCamel::Transaction.saml_settings))
21
+ cookies.encrypted[:saml_camel_relay] = {
22
+ value: relay_state,
23
+ secure: secure_cookie,
24
+ httponly: true
25
+ }
26
+
27
+ saml_request = request.create(SamlCamel::Transaction.saml_settings) + "&RelayState=#{relay_state}"
28
+ redirect_to(saml_request)
29
+ end
30
+
31
+
32
+ def valid_relay_state(param_relay_state)
33
+ stored_relay = cookies.encrypted[:saml_camel_relay]
34
+ cookies.delete :saml_camel_relay
35
+ param_relay_state == stored_relay
19
36
  end
20
37
 
21
38
 
@@ -13,7 +13,9 @@ module SamlCamel
13
13
  end
14
14
 
15
15
  def consume
16
+ raise "Invalid RelayState" unless valid_relay_state(params[:RelayState])
16
17
  redirect_path = cookies.encrypted[:saml_camel_redirect]
18
+
17
19
  cookies.delete :saml_camel_redirect
18
20
  response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], :settings => saml_settings)
19
21
  response.settings = saml_settings
@@ -38,7 +40,12 @@ module SamlCamel
38
40
  rescue => e
39
41
  session[:saml_success] = false
40
42
  SamlCamel::Logging.auth_failure(e)
41
- redirect_to main_app.try('root_path')
43
+ redirect_to action: "failure", locals:{errors: e}
44
+ end
45
+
46
+ def failure
47
+ @error = params[:locals][:errors]
48
+ # byebug
42
49
  end
43
50
 
44
51
  def logout
@@ -46,12 +53,11 @@ module SamlCamel
46
53
  session[:saml_attributes] = nil
47
54
  session[:sp_session] = nil
48
55
 
49
- return_url = SamlCamel::Transaction.logout #this methods logs the user out of the IDP, and returns a url to be redirected to
50
- redirect_to return_url
56
+ # return_url = SamlCamel::Transaction.logout #this methods logs the user out of the IDP, and returns a url to be redirected to
57
+ redirect_to "https://shib.oit.duke.edu/cgi-bin/logout.pl"
51
58
  end
52
59
 
53
60
  def attr_check
54
-
55
61
  end
56
62
 
57
63
 
@@ -7,16 +7,22 @@ module SamlCamel
7
7
  def self.successfull_auth(saml_attrs)
8
8
  logger = Logger.new("log/saml.log")
9
9
  logger.info("#{saml_attrs[PRIMARY_ID]} has succesfully authenticated.")
10
+ rescue
11
+ logger.debug("Unknown Error During successfull_auth logging. Check PRIMARY_ID configured in settings.json and that user has attribute.")
10
12
  end
11
13
 
12
14
  def self.auth_failure(error_context)
13
15
  logger = Logger.new("log/saml.log")
14
16
  logger.error("An error occured during authentication. #{error_context}")
17
+ rescue
18
+ logger.debug("Unknown Error During auth_failure logging.")
15
19
  end
16
20
 
17
21
  def self.logout(saml_attrs)
18
22
  logger = Logger.new("log/saml.log")
19
23
  logger.info("#{saml_attrs[PRIMARY_ID]} has succesfully logged out.")
24
+ rescue
25
+ logger.debug("Unknown error logging user logout. Most likely anonymous user clicked a logout button.")
20
26
  end
21
27
 
22
28
  end
@@ -46,29 +46,6 @@ module SamlCamel
46
46
  mapped_attributes
47
47
  end
48
48
 
49
- #currently duke specifc
50
- #TODO use the regular idp based logout
51
- #TODO httponly should always be set to true on cookies
52
- #TODO securure should be set to true in non dev environments (ht
53
- #TODO look at metadata file import,validate via cert
54
-
55
- def self.logout
56
- url = URI("https://shib.oit.duke.edu/cgi-bin/logout.pl")
57
-
58
- http = Net::HTTP.new(url.host, url.port)
59
- http.use_ssl = true
60
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
61
-
62
- request = Net::HTTP::Post.new(url)
63
- request["authorization"] = 'Basic c29hcC5pZG1zLm9pdDowRGFvdXU2Y1g4MEJ1Vkg2QlFaaA=='
64
- request["content-type"] = 'application/x-www-form-urlencoded'
65
- request["cache-control"] = 'no-cache'
66
- request.body = "logoutWithoutPrompt=1"
67
-
68
- response = http.request(request)
69
-
70
- logout_return = SP_SETTINGS["settings"]["logout_return_url"]
71
- end
72
49
 
73
50
  end
74
51
  end
@@ -0,0 +1,2 @@
1
+ <h1>Failure in SAML Response</h1>
2
+ <h3><%= @error %></h3>
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  SamlCamel::Engine.routes.draw do
2
2
  get "/" => "saml#index"
3
3
  get "/attributes" => 'saml#attr_check'
4
+ get "/failure" => 'saml#failure'
4
5
  post "/consumeSaml" => "saml#consume"
5
6
  post "/logout" => "saml#logout"
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module SamlCamel
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -10,6 +10,7 @@ namespace :saml_camel do
10
10
  cert = generate_cert(key)
11
11
  settings = generate_saml_settings.to_json
12
12
 
13
+
13
14
  #TODO pull in specified idp certificate
14
15
  # idp_cert = File.read("saml/idp_certs/#{ENV['idp']}.crt") if ENV['idp']
15
16
  idp_cert = """MIIEWjCCA0KgAwIBAgIJAP1rB/FjRgy6MA0GCSqGSIb3DQEBBQUAMHsxCzAJBgNV
@@ -46,6 +47,7 @@ tA6SX0infqNRyPRNJK+bnQd1yOP4++tjD/lAPE+5tiD/waI3fArt43ZE/qp7pYMS
46
47
  File.open("#{Rails.root}/saml/#{e}/saml_key.key","w+") {|f| f.write(key) }
47
48
  File.open("#{Rails.root}/saml/#{e}/idp_certificate.crt","w+") {|f| f.write(idp_cert) }
48
49
  File.open("#{Rails.root}/saml/#{e}/settings.json","w+") {|f| f.write(settings) }
50
+ File.open('.gitignore', 'a') { |f| f.write("saml/#{e}/saml_key.key\n") }
49
51
  end
50
52
  else
51
53
  dir = "#{Rails.root}/saml/#{specified_env}"
@@ -54,6 +56,7 @@ tA6SX0infqNRyPRNJK+bnQd1yOP4++tjD/lAPE+5tiD/waI3fArt43ZE/qp7pYMS
54
56
  File.open("#{Rails.root}/saml/#{specified_env}/saml_key.key","w+") {|f| f.write(key) }
55
57
  File.open("#{Rails.root}/saml/#{specified_env}/idp_certificate.crt","w+") {|f| f.write(idp_cert) }
56
58
  File.open("#{Rails.root}/saml/#{specified_env}/settings.json","w+") {|f| f.write(settings) }
59
+ File.open('.gitignore', 'a') { |f| f.write("saml/#{specified_env}/saml_key.key") }
57
60
  end
58
61
  end
59
62
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saml_camel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Danai Adkisson '
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -91,6 +91,7 @@ files:
91
91
  - app/models/saml_camel/transaction.rb
92
92
  - app/views/layouts/saml_camel/application.html.erb
93
93
  - app/views/saml_camel/saml/attr_check.html.erb
94
+ - app/views/saml_camel/saml/failure.html.erb
94
95
  - config/routes.rb
95
96
  - lib/saml_camel.rb
96
97
  - lib/saml_camel/engine.rb