Verify self-signed TLS certificate for HTTPS in Ruby


Ashima Sood

How to use SSL certificate verification (using password parameter in URL) in RUBY's GET Request? ->

require 'net/https'
require 'uri'

uri = URI.parse(ARGV[0] || 'https://example.com?password=my_password')

http = Net::HTTP.new(uri.host, uri.port)

if uri.scheme == "https" 

    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    http.ca_file=File.join(File.dirname(__FILE__),
             "/Users/me/Desktop/demp.pem")
end

http.start do
    http.request_get(uri.path) do |res|

print res.body

end

end

-> output

SSL_connect return=1 errno=0 status=error: certificate verification failed (self-signed certificate in certificate chain) (OpenSSL::SSL::SSLError)

Ashima Sood

This worked for me.

require 'net/http'
require 'net/https'
require 'openssl'
require 'uri'
require 'json'


ContentURI = URI.parse("example.com")
@cert_raw = File.read('cert.pem')
TestDataPath = '.'

req = Net::HTTP::Get.new(ContentURI.path)
https = Net::HTTP.new(ContentURI.host, ContentURI.port)
https.use_ssl = true
https.cert = OpenSSL::X509::Certificate.new(@cert_raw)
https.key = OpenSSL::PKey::RSA.new(@cert_raw)
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
resp = https.start { |cx| cx.request(req) }
p resp
p resp.body

Related


Verify self-signed TLS certificate for HTTPS in Ruby

Ashima Sood How to use SSL certificate verification (using password parameter in URL) in RUBY's GET Request? -> require 'net/https' require 'uri' uri = URI.parse(ARGV[0] || 'https://example.com?password=my_password') http = Net::HTTP.new(uri.host, uri.port)

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

TLS with self-signed certificate

Zapp I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server cert i

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

Https iOS with self signed certificate

Michael 67 I have a server with a self signed certificate. I want to connect device to server via https form. I heard I had to accept this connection. but I do not know. I have a self signed certificate as it is a test server. But I want to access it in https

Https iOS with self signed certificate

Michael 67 I have a server with a self signed certificate. I want to connect device to server via https form. I heard I had to accept this connection. but I do not know. I have a self signed certificate as it is a test server. But I want to access it in https

Https iOS with self signed certificate

Michael 67 I have a server with a self signed certificate. I want to connect device to server via https form. I heard I had to accept this connection. but I do not know. I have a self signed certificate as it is a test server. But I want to access it in https

Verify self-signed certificate for LDAPS connection

Anant Gupta I want to establish a secure ldap connection (ldaps) from a Linux (Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux) client to a Windows 2012 server to change user passwords while active directory, via php. For this, I created a self-sig

How to verify self-signed certificate?

Eugen Konkov I Net::Jabber::Clientused to send messages via XMPP a lot. The server I'm connecting to uses a self-signed certificate: DEBUG: .../IO/Socket/SSL.pm:2853: new ctx 45728400 DEBUG: .../IO/Socket/SSL.pm:1540: start handshake DEBUG: .../IO/Socket/SSL.p

Verify self-signed certificate for LDAPS connection

Anant Gupta I want to establish a secure ldap connection (ldaps) from a Linux (Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux) client to a Windows 2012 server to change user passwords while active directory, via php. For this, I created a self-sig

Verify self-signed certificate for LDAPS connection

Anant Gupta I want to establish a secure ldap connection (ldaps) from a Linux (Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux) client to a Windows 2012 server to change user passwords while active directory, via php. For this, I created a self-sig

Verify self-signed certificate for LDAPS connection

Anant Gupta I want to establish a secure ldap connection (ldaps) from a Linux (Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux) client to a Windows 2012 server to change user passwords while active directory, via php. For this, I created a self-sig

How to verify self-signed certificate?

Eugen Konkov I Net::Jabber::Clientused to send messages via XMPP a lot. The server I'm connecting to uses a self-signed certificate: DEBUG: .../IO/Socket/SSL.pm:2853: new ctx 45728400 DEBUG: .../IO/Socket/SSL.pm:1540: start handshake DEBUG: .../IO/Socket/SSL.p

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Self-signed server certificate for Postfix TLS

Tufel I'm trying to create a self-signed server certificate for Postfix users: thufir@dur:~$ thufir@dur:~$ sudo ./tls.script Error opening Private Key 3073578684:error:02001002:system library:fopen:No such file or directory:bss_file.c:398:fopen('','r') 3073

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Self-signed server certificate for Postfix TLS

Tufel I'm trying to create a self-signed server certificate for Postfix users: thufir@dur:~$ thufir@dur:~$ sudo ./tls.script Error opening Private Key 3073578684:error:02001002:system library:fopen:No such file or directory:bss_file.c:398:fopen('','r') 3073

egit with self-signed certificate, https

Hubidubi : I want to use a git repo accessible via https, the Https server has a self signed certificate. When trying to clone a repository using eclipse + egit, I always get the error: https://host/path : cannot open git-upload-pack sun.security.validator.Val

egit with self-signed certificate, https

Hubidubi : I want to use a git repo accessible via https, the Https server has a self signed certificate. When trying to clone a repository using eclipse + egit, I always get the error: https://host/path : cannot open git-upload-pack sun.security.validator.Val

ktor client https request with self signed certificate

Jay Yanez I have a Ktor server application (REST API) with a self signed certificate. From the browser (after the warning and confirmation) it works fine, port 80 redirects to 8443. However, if I try this from the Ktor Apache Client: fun main(args: Array<Strin

egit with self-signed certificate, https

Hubidubi : I want to use a git repo accessible via https, the Https server has a self signed certificate. When trying to clone a repository using eclipse + egit, I always get the error: https://host/path : cannot open git-upload-pack sun.security.validator.Val

ktor client https request with self signed certificate

Jay Yanez I have a Ktor server application (REST API) with a self signed certificate. From the browser (after the warning and confirmation) it works fine, port 80 redirects to 8443. However, if I try this from the Ktor Apache Client: fun main(args: Array<Strin