HttpGet with HTTPS : SSLPeerUnverifiedException

Note: Do not do this in production code, use http instead, or the actual self signed public key as suggested above. On HttpClient 4.xx: import static org.junit.Assert.assertEquals; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.junit.Test; public class HttpClientTrustingAllCertsTest { … Read more

Getting “Handshake failed…unexpected packet format” when using WebClient.UploadFile() with “https” when the server has a valid SSL certificate

You have to make sure the port you are connecting to is port 443 instead of port 80. Example of explicitly setting the port to be used in the URL: var request = (HttpWebRequest) WebRequest.Create(“https://example.com:443/”); request.Method = “GET”; request.UserAgent = “example/1.0”; request.Accept = “*/*”; request.Host = “example.com”; var resp = (HttpWebResponse) request.GetResponse();

How to make Sinatra work over HTTPS/SSL?

this seems to do it for me: require ‘sinatra/base’ require ‘webrick’ require ‘webrick/https’ require ‘openssl’ CERT_PATH = ‘/opt/myCA/server/’ webrick_options = { :Port => 8443, :Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG), :DocumentRoot => “/ruby/htdocs”, :SSLEnable => true, :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE, :SSLCertificate => OpenSSL::X509::Certificate.new( File.open(File.join(CERT_PATH, “my-server.crt”)).read), :SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open(File.join(CERT_PATH, “my-server.key”)).read), :SSLCertName => [ [ “CN”,WEBrick::Utils::getservername ] ] } … Read more

Nginx does redirect, not proxy

You have to use the proxy_redirect to handle the redirection. Sets the text that should be changed in the “Location” and “Refresh” header fields of a proxied server response. Suppose a proxied server returned the header field “Location:https://myserver/uri/”. The directive will rewrite this string to “Location: http://nginx_server:8080/uri/”. Example: proxy_redirect https://myserver/ http://nginx_server:8080/; Source: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect

how to check SSL certificate expiration date programmatically in Java

How to parse the expiration date from the certificate Cast it to an X509Certificate and call getNotAfter(). How to determine the certificate chain, eg, the github certificate with chains You’ve got it. That’s what the Certificate[] array is, as it says in the Javadoc. How did i know which certificate to get the expiration date … Read more

Configuring MAMP for SSL

If you’re using MAMP 3 or 4 the instructions are slightly different. Here’s what worked for me, starting from a fresh install of MAMP 3.0.5 on Mavericks without Pro. Update: Still works on Yosemite after fixing Apache as described in this answer. Further Update: Comments suggest this still works at least through MAMP 5.4. Generate … Read more

Importing self-signed cert into Docker’s JRE cacert is not recognized by the service

Hence imported the self-signed certificate of HTTPS external URL into Docker container’s JRE cacert keystore. No: you need to import it into the Docker image from which you run your container. Importing it into the container would only create a temporary writable data layer, which will be discarded when you restart your container. Something like … Read more