How to use Ruby's xmpp library behind a HTTP proxy - ruby

I want to use to the xmpp4r gem to send notifications to gtalk from my Rails app. However I am behind a HTTP proxy and hence cannot use regular jabber. Also, xmpp4r supports HTTPBind but it seems gtalk does not. So is there a way to use HTTPBind with gtalk?

Use proxifier http://rubygems.org/gems/proxifier.
If your proxy is configured on the environment already (ex. by setting the environment variable http_proxy) you can simply add the following two lines to your code.
require "proxifier"
require "proxifier/env"
This enhances the used TCPSocket to support connection via proxy.
xmpp4rproxifier

Related

Ruby Sockets via proxy

Is is possible to use Socks5 proxy when communicating over Ruby Socket?
I need to communicate with a Modbus device from a fixed IP. As my Rails app is hosted on Heroku, I'm thinking about using IPBurger addon to get the fixed IP. The addon gives me a Socks5/HTTP and HTTPS proxies. The Modbus library I want to use (RModbus) is build using Sockets:
https://github.com/rmodbus/rmodbus/blob/master/lib/rmodbus/tcp.rb
I'm considering forking the library and making the necessary changes to be able to pass the proxy details to it. How can I define a proxy in the Ruby Socket? What are my other options?

TLS-PSK over TOR python

I am currently trying to create a "TOR version" of a service I created, running with TLS. I want to perform mutual authentication of both parties ; client and server.
I thought about using TLS-PSK over TOR, which would gives me the properties I desire, especially eavesdropping prevention.
I wanted to use the socket library and to double wrap a socket instance using first the ssl library then to do the same thing with TOR, but it looks like there is no library existing allowing me to do the second wrapping.
Do you have any idea about existing libraries allowing me to do something like that ?

Enabling HTTPS with Rack, Puma and Sinatra?

I have a Ruby web application built with Sinatra, Rack and Puma. I'm using Sinatra to implement the controllers (MVC pattern), each handling a different route, and each controller class extends Sinatra::Base. I'd like to enable TLS so that all connections to the server are served over HTTPS.
My Rack config.ru looks like:
require 'sinatra'
require 'rack'
# Start my database ...
run Rack::URLMap.new(
'/api/foo' => FooController.new,
'/api/bar' => BarController.new
)
Puma is picked up automatically by Rack.
How do I enable HTTPS? To start, I'm happy to use a self-signed certificate, but how can I configure the server with a valid cert? None of this seems well-documented at all, which I find quite frustrating. Am I overlooking an option I can just set at the top-level in my Rack config file, something like set :ssl => true maybe?
Similar yet fruitless SO posts:
How to make Sinatra work over HTTPS/SSL?
How to enable SSL for a standalone Sinatra app?
Since you mentioned that you use Puma, you can find this in their docs:
Need a bit of security? Use SSL sockets!
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
In production deployments a dedicated load balancer (e.g. nginx, HAProxy, AWS ELB) is usually responsible for SSL termination, and forwards plain HTTP traffic to application servers over the internal network. These heavy duty web servers are usually much faster, more stable, and better audited.

Ruby MITM proxy

I'm searching for some examples on how to write a proxy in Ruby that supports HTTPS. I have a simple proxy implemented with Webricks HTTPProxyServer, but I noticed, that HTTPS traffic is just tunneling (as it should ;) ). But I want to record the content with VCR (regarding my question here VCRProxy: Record PhantomJS ajax calls with VCR inside Capybara) and as long the content is only tunnled through, VCR can't record it.
So I was thinking of writing the proxy as a man-in-the-middle, generate SSL certificates on the fly (I don't care about certificate errors, its just for testing), and then I would be able to record the content / playback it later.
So if somebody has a good ressource from how to start, or a tutorial or a gist, please let me know.
PS: I have already seen this questions, but they don't provide any further stuff (and it need to be in ruby):
Man in the Middle (MITM) proxy with HTTPS support
How do I write a simple HTTPS proxy server in Ruby?
Help with HTTP Intercepting Proxy in Ruby?
An old question, but for the sake of completeness here goes another answer.
I've implemented a HTTP/HTTPS interception proxy in Ruby, the project is hosted in github.
The project is new, so it's not (yet) as mature as Python's mitmproxy, but it supports HTTPS with certificates generation on-the-fly.
There's an excellent MITM proxy in Python aptly named mitmproxy. The netlib library by the author does the tricks and mitmproxy uses it.
The codebase isn't large and it shouldn't be hard to go through it given that you know Ruby.

IMAP server implementation in Ruby EventMachine

I am looking for IMAP server protocol implementation in Ruby EventMachine.
Can someone advice a library or share some source code?
I don't know of any existing IMAP server in ruby but depending on your needs there is another approach you could use: setup a full fledged imap C server but instead of binding it to an external port you bind it on localhost and put an eventmachine process between it and the clients. This way you can intercept/modify commands you care about and let the other pass through.
Without knowing more about what you want to do it is hard to give a more relevant answer.

Resources