OpenSSL
bio_*
, evp_*
, rsa_*
, dsa_*
, pem_*
, asn1_*
, x509_*
).ssl_ctx_use_certificate
, ssl_ctx_use_privatekey
).subject_alt_name
, ext_usage
, usage
).issuer_name
, subject_name
, Generate certificate requires it.MITM
OpenSSL::SSL::Socket::Client
.OpenSSL::SSL::Socket::Server
.require "base64"
require "carton"
require "cherry"
# This is a simple design, please do not use it directly.
def handle_client(context, client : Carton::Socket)
return client.close unless request = client.request_payload
STDOUT.puts [client]
case {client.tunnel_mode, client.traffic_type}
when {true, Carton::Traffic::HTTPS}
client = MITM::Server.upgrade client, request, context
buffer = uninitialized UInt8[4096_i32]
length = client.read buffer.to_slice
puts String.new buffer.to_slice[0_i32, length]
end
client.close
end
# Durian
servers = [] of Tuple(Socket::IPAddress, Durian::Protocol)
servers << Tuple.new Socket::IPAddress.new("8.8.8.8", 53_i32), Durian::Protocol::UDP
servers << Tuple.new Socket::IPAddress.new("1.1.1.1", 53_i32), Durian::Protocol::UDP
resolver = Durian::Resolver.new servers
resolver.ip_cache = Durian::Resolver::Cache::IPAddress.new
# Carton
tcp_server = TCPServer.new "0.0.0.0", 1234_i32
carton = Carton::Server.new tcp_server, resolver
carton.authentication = Carton::Authentication::None
carton.client_timeout = Carton::TimeOut.new
carton.remote_timeout = Carton::TimeOut.new
certificate = Base64.decode_string "Something..."
private_key = Base64.decode_string "Something..."
context = MITM::Context.new certificate, private_key
# Authentication (Optional)
# carton.authentication = Carton::Authentication::Basic
# carton.on_auth = ->(user_name : String, password : String) do
# STDOUT.puts [user_name, password]
# Carton::Verify::Pass
# end
loop do
socket = carton.accept?
spawn do
next unless client = socket
next unless client = carton.process client
handle_client context, client
end
end
Simple HTTP Client
Add this to your application's shard.yml:
dependencies:
cherry:
github: 636f7374/cherry.cr
$ git clone https://github.com/636f7374/cherry.cr.git
$ make test
Name | Creator | Maintainer | Contributor |
---|---|---|---|
636f7374 | √ | √ | |
datanoise | √ |