HTTPS connection

I am having a problem connecting to HTTPS. My program use to need to
connect through HTTP but now we have made a change and need to connect
using HTTPS. Is there anyone out there that could be of assistance?

old code:
def initialize(host = “isac-qa.cbc.local”, port = 5203)
@connection = Net::HTTP.new(host, port)
end

have tried this but it does not work:
def initialize(host = “172.31.3.97”, port = 8080)
@connection = Net::HTTP.new(host, port)
@connection.use_ssl = true
@connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
end

Thanks for the help.

On Feb 18, 2009, at 1:26 PM, Bob S. wrote:

I am having a problem connecting to HTTPS. My program use to need to
connect through HTTP but now we have made a change and need to connect
using HTTPS. Is there anyone out there that could be of assistance?

old code:
def initialize(host = “isac-qa.cbc.local”, port = 5203)
@connection = Net::HTTP.new(host, port)
end

have tried this but it does not work:

require ‘net/https’

and use Net::HTTPS.new perhaps?

Rob B. http://agileconsultingllc.com
[email protected]

Rob B. wrote:

require ‘net/https’

and use Net::HTTPS.new perhaps?

Rob B. http://agileconsultingllc.com
[email protected]

i already had ‘net/https’

i changed it to use HTTPS.new but get the following error

‘unititialized constant Net::HTTPS’

Rob B. wrote:

Sorry, so do I! But what do you get with:

connection = Net::HTTP.new(“172.31.3.97”, 8080)
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER

connection.get ‘/’

Is the response a 200 OK? Or some error about the:
OpenSSL::SSL::SSLError: certificate verify failed

Or something else?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I get the ‘OpenSSL::SSL::SSLError: certificate verify failed’ error

On Feb 18, 2009, at 2:51 PM, Bob S. wrote:

i changed it to use HTTPS.new but get the following error

‘unititialized constant Net::HTTPS’

Sorry, so do I! But what do you get with:

connection = Net::HTTP.new(“172.31.3.97”, 8080)
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER

connection.get ‘/’

Is the response a 200 OK? Or some error about the:
OpenSSL::SSL::SSLError: certificate verify failed

Or something else?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Rob B. wrote:

On Feb 18, 2009, at 3:17 PM, Bob S. wrote:

OpenSSL::SSL::SSLError: certificate verify failed

Or something else?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I get the ‘OpenSSL::SSL::SSLError: certificate verify failed’ error

Does it work with OpenSSL::SSL::VERIFY_NONE

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I think I’m getting pass the connection issues, but I’m not getting data
back. I should be getting some xml returned but nothing is there. I’m
not sure if you would be able to help on that or is there a different
way to connect then what you have shown above?

On Feb 18, 2009, at 3:17 PM, Bob S. wrote:

OpenSSL::SSL::SSLError: certificate verify failed

Or something else?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I get the ‘OpenSSL::SSL::SSLError: certificate verify failed’ error

Does it work with OpenSSL::SSL::VERIFY_NONE

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

On Feb 18, 2009, at 3:53 PM, Bob S. wrote:

[email protected]
[email protected]

I think I’m getting pass the connection issues, but I’m not getting
data
back. I should be getting some xml returned but nothing is there. I’m
not sure if you would be able to help on that or is there a different
way to connect then what you have shown above?

Posted via http://www.ruby-forum.com/.

Note, this is real code in my answer. Try putting real code it your
follow-up questions, too.

irb> google = Net::HTTP.new(‘google.com’,443)
=> #<Net::HTTP google.com:443 open=false>
irb> google.use_ssl = true
=> true
irb> google.verify_mode = OpenSSL::SSL::VERIFY_NONE
=> 0
irb> resp = google.get “/”
=> #<Net::HTTPFound 302 Found readbody=true>
irb> puts resp.body

302 Moved

302 Moved

The document has moved here. => nil irb> resp.each_header do |name,value| ?> puts "%s : %s"%[name,value] irb> end connection : Close content-type : text/html; charset=UTF-8 date : Wed, 18 Feb 2009 21:52:34 GMT server : GFE/1.3 content-length : 218 location : http://www.google.com => {"connection"=>["Close"], "content-type"=>["text/html; charset=UTF-8"], "date"=>["Wed, 18 Feb 2009 21:52:34 GMT"], "server"=>["GFE/1.3"], "content-length"=>["218"], "location"=>["http://www.google.com "]}

Without seeing the code you’re trying or the actual response that
comes back, I have to just guess.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Without seeing the code you’re trying or the actual response that
comes back, I have to just guess.

-Rob

the program I’m working on was developed by someone else and is
extremely over complicated but I will try to explain it here.

Part 1 - in my C-suite
def setup
startup
vru = Regression::ISAC::VRU.new
vru.fraud_alert(“AlertPlacement”, “INITIAL_FRAUD”,
@consumer.consumer_id, @consumer.first_name, @consumer.last_name,
@consumer.ssn, @consumer.dob, @consumer.address,
@consumer.city,@consumer.state, @consumer.zip)
@event = Regression::ISAC::Event.new(@user_isac_ie, EVENT_TYPE,
@consumer, vru.get_event_id)
end

– the vru.get_event_id and vru.fraud_alert calls this next portion
Part 2 - in my VRU class

def get_tag_data(tag_name)
return
@xml_content[(@xml_content.index("<#{tag_name}>")+2+tag_name.length)…@xml_content.index("</#{tag_name}>")]
end

def initialize(host = “172.31.3.97”, port = 8080)
@connection = Net::HTTP.new(host, port)
@connection.use_ssl = true
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
@connection.get ‘/’
end

def get_event_id
return get_tag_data(“eventId”)
end

– vru.fraud_alert calls the initialize and then goes to create my https
alert string. The changes you showed me, I think, got me pass the SSL
issues but now I can not get the other portions to work. I need to get
the XML back from the request so that I can take information from the
tag of ‘eventId’
– vru.get_event_id is calling the get_event_id which then

The error that I am getting as of right now is
NoMethodError: undefined method +' for nil:NilClass c:\ruby\qa\isac\regression suite\regression\isac\vru.rb:40:inget_tag_data’
c:\ruby\qa\isac\regression suite\regression\isac\vru.rb:80:in
get_event_id' C:/ruby/QA/ISAC/Regression Suite/ALRT/Valid_Consumer/Concurrency.rb:27:insetup’

I think this is all that you would need. Please let me know if there is
anything else I need to help you help me.

Thanks

On Feb 19, 2009, at 7:27 AM, Bob S. wrote:

startup
vru = Regression::ISAC::VRU.new

You’re initialize gets called as part of the behavior of .new right
here.

vru.fraud_alert(“AlertPlacement”, “INITIAL_FRAUD”,
@consumer.consumer_id, @consumer.first_name, @consumer.last_name,
@consumer.ssn, @consumer.dob, @consumer.address,
@consumer.city,@consumer.state, @consumer.zip)

Why pass all those attributes separately? (not that it really changes
anything)

@event = Regression::ISAC::Event.new(@user_isac_ie, EVENT_TYPE,
@consumer, vru.get_event_id)
(Except that you pass @consumer here.)

end
Ooh, you really should use XPath selectors here or parse the data with
Hpricot or Nokogiri or even REXML.

def initialize(host = “172.31.3.97”, port = 8080)
@connection = Net::HTTP.new(host, port)
@connection.use_ssl = true
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
Did you mean to save the response here?
@response =
@connection.get ‘/’
end

Or otherwise show where @xml_content gets set?

– vru.get_event_id is calling the get_event_id which then

The error that I am getting as of right now is
NoMethodError: undefined method +' for nil:NilClass c:\ruby\qa\isac\regression suite\regression\isac\vru.rb:40:in get_tag_data’
c:\ruby\qa\isac\regression suite\regression\isac\vru.rb:80:in
get_event_id' C:/ruby/QA/ISAC/Regression Suite/ALRT/Valid_Consumer/Concurrency.rb:27:in setup’

If you look at the docs for String#index, you’ll see that the result
is nil when the parameter string is not found:
irb> “hello, world!”.index(‘a’)
=> nil

I think this is all that you would need. Please let me know if there
is
anything else I need to help you help me.

Thanks

Have you tried to use any of this manually from an irb session? You
should at least be able to get the “readonly” parts working there (or
find out what error-checking you need–like failed method calls).

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I have tried to do this with the irb and here is what I am getting:

C:\ruby>irb
irb(main):001:0> require ‘net/https’
=> true
irb(main):002:0> @connection = Net::HTTP.new(“172.31.3.97”, 8080)
=> #<Net::HTTP 172.31.3.97:8080 open=false>
irb(main):003:0> @connection.use_ssl = true
=> true
irb(main):004:0> @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
=> 0
irb(main):005:0> @connection.get(“myRequestString”)
=> #<Net::HTTPVersionNotSupported 505 HTTP Version Not Supported
readbody=true>
irb(main):006:0>

anyone have any idea why I would be getting the 505 error. I only
required https not http so I dont understand what is going on here. I
have been searching for help on this error but cant seem to find any
real good explainations or ideas on how to fix it.

Also if I am doing something wrong with the irb pointers in that area
would be helpful too because I have never used the irb.

On Feb 19, 2009, at 2:58 PM, Bob S. wrote:

=> 0
Also if I am doing something wrong with the irb pointers in that area
would be helpful too because I have never used the irb.

Posted via http://www.ruby-forum.com/.

What happens if you hit this URL in a browser:

https://172.31.3.97:8080/

Particularly, one that will let you see the details like Firefox with
the Firebug add-on.

Or (if you have these tools on you Windows):

telnet 172.31.3.97 8080
GET / HTTP/1.0

(hit return twice after the GET… line)

telnet 172.31.3.97 8080
GET / HTTP/1.1
Host: 172.31.3.97

(two returns after the Host:… line)

You need to take baby steps. Test OUTSIDE the code when you can and
then you’ll know what the response should be.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

What happens if you hit this URL in a browser:

https://172.31.3.97:8080/
I get to the our JBoss console

Particularly, one that will let you see the details like Firefox with
the Firebug add-on.

Or (if you have these tools on you Windows):

I do not have access to Telnet

telnet 172.31.3.97 8080
GET / HTTP/1.0