using ruby Net::HTTP with self signed certificates

307 views
Skip to first unread message

Craig White

unread,
Jan 29, 2008, 12:04:16 PM1/29/08
to Ruby on Rails: Talk
Probably more of a ruby question than a rails question but I am trying
to retrieve a file from my web server that requires ssl but uses a self
signed certificate.

Looking through all of the documentation at
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html
and
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html

I don't see any way that I could do something equivalent to like wget...

wget -no-check-certificate https://myserver/myfile.txt

Is there any way to accomplish this with net/http or do I have to
execute a shell wget and open the file locally?

Craig

Craig White

unread,
Jan 29, 2008, 3:23:56 PM1/29/08
to rubyonra...@googlegroups.com
----
OK, I think I have this solved but I'm hamstrung by a '?' in the URL...

in console...

>> url.path =
"/horde/kronolith/ics.php?c=5be410ec5238fc93c1f66b1a935365c9"
URI::InvalidComponentError: bad component(expected absolute path
component): /horde/kronolith/ics.php?c=5be410ec5238fc93c1f66b1a935365c9
from /usr/lib/ruby/1.8/uri/generic.rb:475:in `check_path'
from /usr/lib/ruby/1.8/uri/generic.rb:495:in `path='
from (irb):354
from :0

and if I substitute %3F for the ? it will accept the 'path'...
>> url.path = "/horde/kronolith/ics.php%
3Fc=5be410ec5238fc93c1f66b1a935365c9"
=> "/horde/kronolith/ics.php%3Fc=5be410ec5238fc93c1f66b1a935365c9"

but it doesn't work
>> res = Net::HTTP.new(url.host, 443)
=> #<Net::HTTP my_server:443 open=false>
>> res.use_ssl=true
=> true
>> res.verify_mode = OpenSSL::SSL::VERIFY_NONE
=> 0
>> ret=res.start {|http| http.request(req)}
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true>

nor does this URL work with wget...

wget --no-check-certificate
https://craig:*****@my_server//horde/kronolith/ics.php%
3Fc=5be410ec5238fc93c1f66b1a935365c9
--13:06:07--
https://craig:*password*@my_server//horde/kronolith/ics.php%
3Fc=5be410ec5238fc93c1f66b1a935365c9
=> `ics.php?c=5be410ec5238fc93c1f66b1a935365c9.1'
Resolving my_server... 192.168.3.5
Connecting to my_server|192.168.3.5|:443... connected.
WARNING: Certificate verification error for my_server: self signed
certificate
HTTP request sent, awaiting response... 404 Not Found
13:06:07 ERROR 404: Not Found.

of course with a ? instead of %3F, it works

How does one use net/http (net/https) with URL's that have a ?

?

Craig

Reply all
Reply to author
Forward
0 new messages