Skip to content

Instantly share code, notes, and snippets.

@pezra
pezra / ssl-weirdness.md
Last active October 9, 2016 19:55
SSL weirdness

SSL connections from ruby are unable to verify a cert that curl and openssl are able to. Below i use the same cert.pem file for both curl and ruby but get different outcomes.

In irb:

> irb(main):004:0> http = Net::HTTP.new("localhost", 4000) 
> irb(main):006:0> http.use_ssl = true 
> irb(main):007:0> http.cert_store = OpenSSL::X509::Store.new 
> irb(main):008:0> http.cert_store.add_file('/usr/local/etc/openssl/cert.pem') 
> irb(main):009:0> http.request_get("/") 
> OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed 

background

There is a node

$ knife search node  "name:N-T-DROPT-POST-01"
1 items found

Node Name:   N-T-DROPT-POST-01
Environment: dit
$ knife search -c $KNIFE_CONF node "name:N-T-DROPT-POST-01"
1 items found
Node Name: N-T-DROPT-POST-01
Environment: dit
FQDN: N-T-DROPT-POST-01.comverge.com
IP: 10.154.114.46
Run List:
Roles:
Recipes:
# This class takes a job, and maybe does it.
# Usage `Slacker.maybe(probability: 0.1) { something() }
class Slacker
# Probability should be a float between 0 and 1.
def self.maybe(probability:)
raise "Slacker needs a job to skip out on." unless block_given?
yield if rand() < probability
end
def self.often(&block)
class Account
include HalRepresentation
property :name, String
association :members, array_of(User), rel: "http://example.com/api/rels/members"
end
a = Account.get('http://example.com/accounts/42')
a.name = "New name"
class MyResource
include Spinal::Resource
representation :simple, :media_types => [:ufe, :ssj, :myxml] , :direction => :in_and_out do |rep|
rep.attribute :foo
rep.attribute :bar, :required => true
end
repesentation :html, :parent => :simple, :direction => :out do |rep|
rep.attribute :current_user
class MyResource
include Spinal::Resource
representation :json, :direction => :in_and_out do |rep|
rep.attribute :foo
rep.attribute :bar, :required => true
end
representation :url_encoded_form_data, :direction => :in do |rep|
rep.attribute :foo
require 'ostruct'
class Keister::App
class DatabasesResource
include Spinal::Resource
resource '/databases'
def get
@databases = [OpenStruct.new(:created_at => Time.now.utc, :updated_at => Time.now.utc)]
require 'ostruct'
class Keister::App
class DatabasesResource
include Spinal::Resource
resource '/databases'
def get
@databases = [OpenStruct.new(:created_at => Time.now.utc, :updated_at => Time.now.utc)]
{
href: "http://example.com/databases/1",
_type: "Database",
name: "test_db",
server_hostname: "betabox.mongomachine.com",
server_port: 27017,
account_href: "http://example.com/accounts/1",
authorized_users_href: "http://example.com/authorized_users",
storage_stats_href: "http://example.com/database/1/storage_stats",
request_stats_href: "http://example.com/database/1/request_stats",