# Looking for good Ruby OpenSSL TLS docs

**URL:** <https://www.ruby-forum.com/t/looking-for-good-ruby-openssl-tls-docs/192889>\
**Category:** Ruby\
**Created:** [August 7, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/looking-for-good-ruby-openssl-tls-docs/192889 "2010-08-07T18:38:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_DSGifford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@Aaron\_DSGifford](https://www.ruby-forum.com/u/Aaron_DSGifford)\
**Post date:** [August 7, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/looking-for-good-ruby-openssl-tls-docs/192889/1 "2010-08-07T18:38:52Z")

</div>

Hi,

I’ve got a custom TCP protocol that currently runs plaintext/cleartext  
to which I want to add something akin to SMTP’s STARTTLS. The scripts  
use Ruby’s TCPSockets. The protocol will for the most part remain  
unencrypted, but when client or server requests that TLS begin, I need  
to take the existing TCPSocket and initiate TLS over it.

So… any pointers to good Ruby OpenSSL docs? The Rdocs my searches  
have found thus far are SEVERELY lacking in anything useful. And  
searches for Ruby TLS or SSL stuff turns up only preexisting  
protocols, no details about how to interact at a TCPSocket level. My  
next step will be to install a few of the libraries I have found and  
delve into their source. (But of course I’d MUCH prefer to read  
written documentation online if possible, or in combination with my  
source code perusal.)

And I do need to preserve the non-blocking nature of my existing code  
(which uses IO.select).

Thanks!

Aaron out.

---

<div class="post-metadata">

**Author:** ![Aaron\_DSGifford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@Aaron\_DSGifford](https://www.ruby-forum.com/u/Aaron_DSGifford)\
**Post date:** [August 8, 2010, 2:30am UTC](https://www.ruby-forum.com/t/looking-for-good-ruby-openssl-tls-docs/192889/2 "2010-08-08T02:30:39Z")

</div>

On Aug 7, 11:28 am, “Aaron D. Gifford” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I’ve got a custom TCP protocol that currently runs plaintext/cleartext  
> to which I want to add something akin to SMTP’s STARTTLS. The scripts  
> use Ruby’s TCPSockets. The protocol will for the most part remain  
> unencrypted, but when client or server requests that TLS begin, I need  
> to take the existing TCPSocket and initiate TLS over it.
> 
> So… any pointers to good Ruby OpenSSL docs?

Ruby’s openssl is a very basic wrapper around the OpenSSL library and  
I haven’t found much good documentation for either.

I’d first look in the samples that come with the Ruby source code. In  
the source distribution, check out sample/openssl/echo\_cli.rb and  
echo\_svr.rb. The server uses a TCPSocket, but between the example and  
the TCPSocket code, it shouldn’t be hard to work out what to do.

Jeremy

---

<div class="post-metadata">

**Author:** ![Aaron\_DSGifford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@Aaron\_DSGifford](https://www.ruby-forum.com/u/Aaron_DSGifford)\
**Post date:** [August 8, 2010, 2:38am UTC](https://www.ruby-forum.com/t/looking-for-good-ruby-openssl-tls-docs/192889/3 "2010-08-08T02:38:16Z")

</div>

On Sat, Aug 7, 2010 at 6:30 PM, yermej [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote

> Ruby’s openssl is a very basic wrapper around the OpenSSL library and  
> I haven’t found much good documentation for either.
> 
> I’d first look in the samples that come with the Ruby source code. In  
> the source distribution, check out sample/openssl/echo\_cli.rb and  
> echo\_svr.rb. The server uses a TCPSocket, but between the example and  
> the TCPSocket code, it shouldn’t be hard to work out what to do.
> 
> Jeremy

Thanks for the tip, Jeremy! I was going to go source-code digging  
anyway, and now you’ve given me a good starting place.

Aaron out.

---

<div class="post-metadata">

**Author:** ![Aaron\_DSGifford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@Aaron\_DSGifford](https://www.ruby-forum.com/u/Aaron_DSGifford)\
**Post date:** [August 9, 2010, 11:01am UTC](https://www.ruby-forum.com/t/looking-for-good-ruby-openssl-tls-docs/192889/4 "2010-08-09T11:01:21Z")

</div>

Aaron D. Gifford wrote:

> I’ve got a custom TCP protocol that currently runs plaintext/cleartext  
> to which I want to add something akin to SMTP’s STARTTLS. The scripts  
> use Ruby’s TCPSockets. The protocol will for the most part remain  
> unencrypted, but when client or server requests that TLS begin, I need  
> to take the existing TCPSocket and initiate TLS over it.

I wrote ruby-ldapserver some years ago, and I wrote code which does  
exactly that. Shouldn’t be too hard to extract it.

IIRC, an OpenSSL socket duck-types a normal socket in most ways, so you  
can just wrap the socket in an OpenSSL object. I would imagine you  
couldn’t #select on it though, but would have to #select on the  
underlying socket instead.

(I was using threads, so #select compatibility wasn’t a requirement)

HTH,

Brian.
