Skip to content

Instantly share code, notes, and snippets.

@tvon

tvon/SSLPoke.java

Last active Aug 29, 2015
Embed
What would you like to do?
JRuby/Java SSL issue
% jruby ssl-test.rb https://example.com # not the actual command, I ran with our internal hostname in the source as with others
OpenSSL::SSL::SSLError: certificate verify failed
connect at org/jruby/ext/openssl/SSLSocket.java:180
connect at /opt/rubies/jruby-1.7.16.1/lib/ruby/1.9/net/http.rb:799
timeout at org/jruby/ext/timeout/Timeout.java:104
connect at /opt/rubies/jruby-1.7.16.1/lib/ruby/1.9/net/http.rb:799
do_start at /opt/rubies/jruby-1.7.16.1/lib/ruby/1.9/net/http.rb:755
start at /opt/rubies/jruby-1.7.16.1/lib/ruby/1.9/net/http.rb:744
(root) at ssl-test.rb:8
#! /usr/bin/env ruby
require 'net/https'
require 'uri'
uri = URI.parse(ARGV[0] || 'https://example.com/')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start {
http.request_get(uri.path) {|res|
print res.body
}
}
% java SSLPoke example.com 443
Successfully connected
# from: https://gist.github.com/4ndrej/4547029
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));
InputStream in = sslsocket.getInputStream();
OutputStream out = sslsocket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
System.out.println("Successfully connected");
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
tvon@foo % java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
tvon@foo % jruby -version
jruby 1.7.16.1 (1.9.3p392) 2014-10-28 4e93f31 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_25-b17 +jit [darwin-x86_64]
NameError: undefined local variable or method `rsion' for main:Object
(root) at -e:1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment