I try to send messages to icq via jabber-transport. I tried to use code from this answer
XMPP transport to another protocol, but I got this message:
DEBUG -- : SENDING:
<message to='12345#icq.jabber.blahblah.ru' xmlns='jabber:client'><body>test
message from robot</body></message>
=> nil
DEBUG -- : RECEIVED:
<message from='12345#icq.jabber.blahblah.ru' to='myjit#blahblah.ru/83076
14161416233482839674' type='error'><error code='401' type='auth'><not-authorized
xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:n
s:xmpp-stanzas'>Error. You must log into the transport before sending messages.<
/text></error><body>test message from robot</body></message>
Please explain me: What am I doing wrong? Thanks in advance.
Here's my code
require 'rubygems'
require 'xmpp4r/client'
include Jabber
Jabber.debug = true
jid = JID::new('myjit#blahblah.ru')
pass = 'pwd'
server = 'jabber.blahblah.ru'
port = '5223'
subj = 'Nagios notification'
user = '12345#icq.jabber.blahblah.ru'
text = 'AAAA AAAA AAAA'
cl = Jabber::Client::new(jid)
cl.use_ssl = true
cl.connect(server,port)
cl.auth(pass)
#connect to transport
reg=Jabber::Iq.new_register "54321", "pwd2"
reg.to="icq.jabber.blahblah.ru"
cl.send reg
mes = Message::new(user,text)
cl.send(mes)
cl.close()
Updated code:
cl.connect(server,port)
cl.auth(pass)
# sending initial presence
p = Jabber::Presence.new
cl.send p
mes = Message::new(user,text)
mes.type = :chat
cl.send(mes)
cl.close()
returns:
D, [2014-11-18T19:01:35.986182 #8084] DEBUG -- : SENDING:
<presence xmlns='jabber:client'/>
=> nil
irb(main):027:0> D, [2014-11-18T19:01:36.048980 #8084] DEBUG -- : RECEIVED:
<presence from='icq.jabber.blahblah.ru' to='myjit#blahblah.ru' type='subscri
be'><status/></presence>
and still doesnt work
You only need to register transport only first time, then you need to send initial presence after session creation.
Related
I have a project to complete in Ruby involving TLS v.1.3. I want to optimize requests and thus use "early data". I'm using a package called tttls1.3 and the client works until I send early data to the server. What's even more wired is that a request with early data goes through and I get a response from the server but immediately after the reply (response message) an alert 20 (Bad Record MAC) is received. I went so far that I even go and recalculate the "client-finished" message which seemed suspicious but it looks correct.
What could be the problem? Is there a TCP or other issue I could check?
Here's an example:
require 'socket'
require 'tttls1.3'
settings2 = {
alpn: ['http/1.1'],
supported_groups: [TTTLS13::NamedGroup::SECP256R1],
cipher_suites: [TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384],
check_certificate_status: false,
}
settings1 = {
alpn: ['http/1.1'],
supported_groups: [TTTLS13::NamedGroup::SECP256R1],
cipher_suites: [TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384],
check_certificate_status: false,
process_new_session_ticket: lambda do |nst, rms, cs|
return if Time.now.to_i - nst.timestamp > nst.ticket_lifetime
settings2[:ticket] = nst.ticket
settings2[:resumption_master_secret] = rms
settings2[:psk_cipher_suite] = cs
settings2[:ticket_nonce] = nst.ticket_nonce
settings2[:ticket_age_add] = nst.ticket_age_add
settings2[:ticket_timestamp] = nst.timestamp
end
}
# REQUEST
socket = TCPSocket.new("ssltest.louis.info", 443)
client = TTTLS13::Client.new(socket, "ssltest.louis.info", settings1)
client.connect
client.write("GET / HTTP/1.1\r\n")
client.write("Host: ssltest.louis.info\r\n")
client.write("\r\n\r\n")
client.read
client.close
socket.close
sleep(1)
# RESUMPTION
socket = TCPSocket.new("ssltest.louis.info", 443)
client = TTTLS13::Client.new(socket, "ssltest.louis.info", settings2)
client.early_data("HEAD / HTTP/1.1\r\nHost: ssltest.louis.info\r\n\r\n\r\n")
client.connect
p client.read
p client.read
p client.read
p client.read
Original issue: https://github.com/thekuwayama/tttls1.3/issues/48
It turned out that the Connection: close header must be present in the request. It must be the remote server implementation specific.
When i am creating secure connection.
Getting error follows as,
OpenSSL::SSL::SSLError: certificate verify failed
connect at org/jruby/ext/openssl/SSLSocket.java:266
Getting error on line : #ssl_socket.connect
sample code :
#socket = TCPSocket.new(#uri.host, #port)
#ssl_context = OpenSSL::SSL::SSLContext.new
#ssl_context.cert = OpenSSL::X509::Certificate.new(File.open("certificate.crt"))
#ssl_context.key = OpenSSL::PKey::RSA.new(File.open("certificate.key"))
#ssl_context.ssl_version = :TLSv1_2_client
#ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
#ssl_socket = OpenSSL::SSL::SSLSocket.new(#socket, #ssl_context)
#ssl_socket.sync_close = true
#ssl_socket.connect
any help on it, why am i getting such error on line #ssl_socket.connect
My aim is to connect with secure websocket.
I would like understand the data format of Freeswitch ESL library method getBody and also from the ESl how to get the media bugs list on channel issuing the command api uuid_buglist .
My concern is that I can issue the command but how to read the data that comes out is my problem.
Please help.
esl_event_get_body() is a very simple wrapper function that returns event->body from an event.
To get the reply from your cmd you should use handle.last_sr_event->body after using esl_send_recv(&handle, cmd)
you can see my open source project, it is a auto dial project:
https://github.com/nwaycn/nway_ac
here is plain the message of hangup
con = ESLconnection(fs_ip, fs_esl_port, fs_esl_auth)
if con.connected():
thread.start_new_thread(AutoCall,(1,1))
e = con.events('plain','CHANNEL_HANGUP_COMPLETE')
while True:
ee = con.recvEvent()
#print ee
if ee:
my_number = ee.getHeader('Caller-Caller-ID-Number')
dest_number = ee.getHeader('Caller-Destination-Number')
SetNumberIdle(dest_number)
con.disconnect();
here is to call a phone
def CallOut(dial_string,call_number):
con = ESLconnection(fs_ip, fs_esl_port, fs_esl_auth)
if con.connected():
e = con.api(dial_string)
SetNumberBusy(call_number)
print e.getBody()
else:
print 'not Connected'
con.disconnect();
I'm trying to send a BitTorrent handshake to a peer but it's not working. Can someone figure out what I'm doing wrong? len is supposed to come back with something, but it's currently nil.
require 'bencode'
require 'digest/sha1'
file = File.open('./python.torrent').read
info_hash = Digest::SHA1.hexdigest(a['info'].bencode)
# Here's what parsed_response['peers'] returns:
# [{"ip"=>"8.19.35.234", "peer id"=>"-lt0C20-\x90\xE0\xE6\x0E\xD0\x8A\xE5\xA2\xF2b(!",
# "port"=>9898}]
peer_id = parsed_response['peers'].first['peer id']
send_string = "\023BitTorrent protocol\0\0\0\0\0\0\0\0" << info_hash << peer_id
# ip and port are my current internet ip and 6881 respectively
client = TCPSocket.new ip, port
# What I'm sending over
client.send("\023BitTorrent protocol\0\0\0\0\0\0\0\0" << info_hash << peer_id, 0)
len = client.recv(1)
puts len
Here's what send_string looks like in the end:
While having handshake from your side,
PeerID used should be yours , not of the other side.
So your message should look like this :
peer_id = "-MY0001-123456654321"
client.send("\023BitTorrent protocol\0\0\0\0\0\0\0\0" << info_hash << peer_id, 0)
If you are developing your own bit-torrent client then you can have your own format for peer id following standards mentioned by bit-torrent protocol.
You can read more about peer id here:
https://wiki.theory.org/BitTorrentSpecification#peer_id
If you have any confusion in future , start any bittorrent client and follow wire-shark packets. You will understand, where you are making mistake.
I am attaching a sample handshake message here :
Here "-KS0001-123456654321" is peerid for my bittorrent client.
I cant write ruby.
This is python code:
send_string = chr(19)+"BitTorrent Protocol"+8*chr(0)+info_hash+peer_id
jid = Jabber::JID.new('....#jabber.ru')
j = Jabber::Client.new(jid)
j.connect
j.auth('12345')
if i trying to send message through transport it responds to me
SENDING:
<message to='2....3#icq.proc.ru' xmlns='jabber:client'><body>hi!</body></message>
=> nil
ruby-1.9.2-p290 :106 > RECEIVED:
<message from='2...3#icq.proc.ru' to='....#jabber.ru/38185266013242853702144' type='error'><error code='401' type='auth'><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error. You must log into the transport before sending messages.</text></error><body>hi!</body></message>
PROCESSING:
<message from='2....3#icq.proc.ru' to='do-not-replay.perekup.net#jabber.ru/38185266013242853702144' type='error' xmlns='jabber:client'><error code='401' type='auth'><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error. You must log into the transport before sending messages.</text></error><body>hi!</body></message> (Jabber::Message)
but:
iq = Jabber::Iq.new(:set)
query = Jabber::IqQuery.new
query.add_namespace('jabber:iq:auth')
query.add(REXML::Element.new('username').add_text("6...6"))
query.add(REXML::Element.new('password').add_text('F...1'))
iq.add(query)
iq.to = 'icq.proc.ru'
iq
j.send iq
SENDING:
<iq to='icq.proc.ru' type='set' xmlns='jabber:client'><query xmlns='jabber:iq:authenticate'><username>6....6</username><password>F....1</password></query></iq>
=> nil
ruby-1.9.2-p290 :105 > RECEIVED:
<iq from='icq.proc.ru' to='...#jabber.ru/38185266013242853702144' type='error'><error code='501' type='cancel'><feature-not-implemented/></error></iq>
PROCESSING:
<iq from='icq.proc.ru' to='...#jabber.ru/38185266013242853702144' type='error' xmlns='jabber:client'><error code='501' type='cancel'><feature-not-implemented/></error></iq> (Jabber::Iq)
i cant use Iq.new_authset_digest(jid, session_id, password) because i cant get session_id parameter
what am I doing wrong?
jid = Jabber::JID.new('user')
client = Jabber::Client.new(jid)
client.connect('54.187.67.96',5222)
client.auth('password')
client.send(Jabber::Presence.new.set_show(:chat).set_status('Rails!'))
puts "Hurray...!! Connected..!!"
# Send an Instant Message.
body = 'Hello from Rails'
to_jid = Jabber::JID.new('user')
message = Jabber::Message::new(to_jid, body).set_type(:normal).set_id('1')
client.send(message)