Class: Vines::Stream::Server::AuthMethod
- Inherits:
-
Vines::Stream::State
- Object
- Vines::Stream::State
- Vines::Stream::Server::AuthMethod
- Defined in:
- lib/vines/stream/server/auth_method.rb
Constant Summary collapse
- PROCEED =
%Q{<proceed xmlns="#{NAMESPACES[:tls]}"/>}.freeze
- FAILURE =
%Q{<failure xmlns="#{NAMESPACES[:tls]}"/>}.freeze
Constants included from Node
Instance Attribute Summary
Attributes inherited from Vines::Stream::State
Instance Method Summary collapse
-
#initialize(stream, success = AuthRestart) ⇒ AuthMethod
constructor
A new instance of AuthMethod.
- #node(node) ⇒ Object
Methods inherited from Vines::Stream::State
Methods included from Node
body?, namespace, stream?, to_stanza
Methods included from Log
Constructor Details
#initialize(stream, success = AuthRestart) ⇒ AuthMethod
Returns a new instance of AuthMethod.
12 13 14 |
# File 'lib/vines/stream/server/auth_method.rb', line 12 def initialize(stream, success=AuthRestart) super end |
Instance Method Details
#node(node) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vines/stream/server/auth_method.rb', line 16 def node(node) if dialback_verify?(node) id, from, to = %w[id from to].map {|a| node[a] } key = node.text outbound_stream = stream.router.stream_by_id(id) unless outbound_stream && outbound_stream.state.is_a?(Stream::Server::Outbound::AuthDialbackResult) stream.write(%Q{<db:verify from="#{to}" to=#{from} id=#{id} type="error"><error type="cancel"><item-not-found xmlns="#{NAMESPACES[:stanzas]}" /></error></db:verify>}) return end secret = outbound_stream.state.dialback_secret type = Kit.dialback_key(secret, from, to, id) == key ? VALID_TYPE : INVALID_TYPE stream.write(%Q{<db:verify from="#{to}" to="#{from}" id="#{id}" type="#{type}" />}) stream.close_connection_after_writing elsif starttls?(node) if stream.encrypt? stream.write(PROCEED) stream.encrypt stream.reset advance else stream.write(FAILURE) stream.write('</stream:stream>') stream.close_connection_after_writing end elsif dialback_result?(node) begin Vines::Stream::Server.start(stream.config, node[FROM], node[TO], true) do || if # will be closed in outbound/authoritative.rb .write("<db:verify from='#{node[TO]}' id='#{stream.id}' to='#{node[FROM]}'>#{node.text}</db:verify>") end end # We need to be discoverable for the dialback connection stream.router << stream rescue StanzaErrors::RemoteServerNotFound => e stream.write("<db:result from='#{node[TO]}' to='#{node[FROM]}' " \ "type='error'><error type='cancel'><item-not-found " \ "xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></db:result>") stream.close_connection_after_writing end else raise StreamErrors::NotAuthorized end end |