# SSL communication with Mechanize

**URL:** <https://www.ruby-forum.com/t/ssl-communication-with-mechanize/192162>\
**Category:** Ruby\
**Created:** [July 25, 2010, 11:40am UTC](https://www.ruby-forum.com/t/ssl-communication-with-mechanize/192162 "2010-07-25T11:40:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![poseid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@poseid](https://www.ruby-forum.com/u/poseid)\
**Post date:** [July 25, 2010, 11:40am UTC](https://www.ruby-forum.com/t/ssl-communication-with-mechanize/192162/1 "2010-07-25T11:40:48Z")

</div>

In a network with SSL protection, I can work with http by using:

http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE

However, trying to use Mechanize:

irb(main):033:0\> login\_page = agent.get(url)  
OpenSSL::SSL::SSLError: SSL\_connect returned=1 errno=0 state=SSLv3  
read server certificate B: certificate verify failed  
from /opt/local/lib/ruby/1.8/net/http.rb:586:in `connect' from /opt/local/lib/ruby/1.8/net/http.rb:586:in`connect’  
from /opt/local/lib/ruby/1.8/net/http.rb:553:in `do_start' from /opt/local/lib/ruby/1.8/net/http.rb:548:in`start’

How would I approach my agent class to find the attributes on SSL.

agent.methods  
=\> [“to\_yaml\_style”, “inspect”, “post\_connect\_hooks”, “open\_timeout”,  
“transact”, “tap”, “conditional\_requests=”, “redirection\_limit”,  
“clone”, “submit”, “public\_methods”, “object\_id”, “ **send** ”,  
“open\_timeout=”, “redirect\_ok”, “instance\_variable\_defined?”,  
“redirection\_limit=”, “proxy\_user”, “freeze”, “equal?”, “max\_history”,  
“key”, “delete”, “cert”, “follow\_redirect?”, “extend”, “get”,  
“redirect\_ok=”, “follow\_meta\_refresh”, “send”,  
“pretty\_print\_instance\_variables”, “request\_with\_entity”, “methods”,  
“max\_history=”, “set\_proxy”, “key=”, “read\_timeout”, “cert=”, “hash”,  
“follow\_meta\_refresh=”, “request\_headers”, “dup”, “click”,  
“instance\_variables”, “to\_enum”, “cookies”, “read\_timeout=”,  
“gzip\_enabled”, “pretty\_print\_inspect”, “to\_yaml”, “request\_headers=”,  
“html\_parser”, “log”, “eql?”, “to\_yaml\_properties”, “gzip\_enabled=”,  
“verify\_callback”, “id”, “instance\_eval”, “pretty\_inspect”,  
“html\_parser=”, “log=”, “singleton\_methods”, “user\_agent”,  
“verify\_callback=”, “proxy\_addr”, “pass”, “taint”,  
“instance\_variable\_get”, “frozen?”, “enum\_for”, “auth”, “user\_agent=”,  
“keep\_alive\_time”, “display”, “instance\_of?”, “history”, “visited?”,  
“pass=”, “method”, “to\_a”, “pre\_connect\_hooks”, “visited\_page”,  
“keep\_alive\_time=”, “history\_added”, “instance\_exec”, “type”, “page”,  
“head”, “protected\_methods”, “watch\_for\_set”, “==”, “history\_added=”,  
“proxy\_pass”, “===”, “post”, “instance\_variable\_set”,  
“watch\_for\_set=”, “keep\_alive”, “respond\_to?”, “kind\_of?”, “put”,  
“pluggable\_parser”, “to\_s”, “cookie\_jar”, “pretty\_print\_cycle”,  
“taguri”, “keep\_alive=”, “scheme\_handlers”, “class”, “get\_file”,  
“private\_methods”, “=~”, “tainted?”, “ **id** ”, “cookie\_jar=”,  
“ca\_file”, “back”, “taguri=”, “current\_page”, “scheme\_handlers=”,  
“proxy\_port”, “untaint”, “nil?”, “ca\_file=”, “conditional\_requests”,  
“pretty\_print”, “user\_agent\_alias=”, “basic\_auth”, “is\_a?”]

---

<div class="post-metadata">

**Author:** ![poseid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@poseid](https://www.ruby-forum.com/u/poseid)\
**Post date:** [July 25, 2010, 12:27pm UTC](https://www.ruby-forum.com/t/ssl-communication-with-mechanize/192162/2 "2010-07-25T12:27:37Z")

</div>

On Sun, Jul 25, 2010 at 10:40 AM, poseid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> In a network with SSL protection, I can work with http by using:
> 
> http.verify\_mode = OpenSSL::SSL::VERIFY\_NONE
> 
> However, trying to use Mechanize:
> 
> How would I approach my agent class to find the attributes on SSL.

It might help if you were more clear in stating what it is that you want  
to  
achieve,  
or what your specific problem is.

Some of the most comprehensive discussion on SSL in Ruby was discussed  
on  
Ola B.'s blog: [http://olabini.com](http://olabini.com) (and his older  
[http://olabini.blogspot.com](http://olabini.blogspot.com) -  
useful articles on both). There are many code examples, as well as a  
great  
writeup  
(for any language) on the fundamentals of security/cryptography.

For instance VERIFY\_NONE is almost never what you want to do in a secure  
environment - its basically the same thing as ‘trust all certificates’.  
If  
you  
want to use VERIFY\_PEER you need to have a local keystore, where you  
import  
cacerts (certificates from certificate authorities) that you can verify  
your  
sites  
certificates against.

Also note, that there are alternative HTTP clients, some like  
Http-client,  
Httparty,  
Resourceful etc. Which might handle SSL better, or in a more transparent  
way.

---

<div class="post-metadata">

**Author:** ![poseid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@poseid](https://www.ruby-forum.com/u/poseid)\
**Post date:** [July 25, 2010, 6:16pm UTC](https://www.ruby-forum.com/t/ssl-communication-with-mechanize/192162/3 "2010-07-25T18:16:27Z")

</div>

On Jul 25, 12:18 pm, Richard C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Also note, that there are alternative HTTP clients, some like Http-client,  
> Httparty,  
> Resourceful etc. Which might handle SSL better, or in a more transparent  
> way.

Thanks for providing the references. I’ll need to check these.
