51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/omniauth/strategies/raven.rb', line 51
def callback_phase
return fail!("null_response") if request.params['WLS-Response'] == ""
wls_response = request.params['WLS-Response'].to_s
ver, status, msg, issue, id, url, principal, auth, sso, life, params, kid, sig = wls_response.split('!')
return fail!("invalid_protocol_version") unless ver == options[:raven_opt][:version]
return fail!("mismatched urls", Exception.new("url: " + url + " vs callback: " + callback_url) ) unless url == callback_url.split('?').first
issuetime = timeforRFC3339( issue )
skew = issuetime - Time.now
return fail!("time_skew") unless skew.abs < options[:raven_opt][:max_skew]
return fail!(:invalid_response, Exception.new("No raven interaction took place, but it was requested") ) if ( options[:raven_opt][:iact] == 'yes' && auth == "" )
if @match_response_and_request
response_id = unescape( params )
request_id = session['request_id']
return fail!("mismatched_response", Exception.new("req_id:" + request_id + " vs resp_id:" + response_id) ) unless request_id == response_id
end
if status == '200'
publickey = OmniAuth.raven_pubkey
return fail!("invalid_keyno") unless kid == OmniAuth.raven_keyno
length_to_drop = -(sig.length + kid.length + 3)
signedbit = wls_response[ 0 .. length_to_drop]
return fail!("mismatched_signature") unless publickey.verify( OpenSSL::Digest::SHA1.new, Base64.decode64(sig.tr('-._','+/=')), signedbit)
@name = principal
@email = principal+"@cam.ac.uk"
super
else
return fail!(:invalid_credentials, Exception.new("Raven status:" + status) )
end
end
|