Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I accept the SSL certificates when connecting using F#?

Tags:

http

ssl

f#

I tried to connect to a HTTPS page. In C# i can write a line that asks C# to connect to HTTPS easily with the line

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

How do I adapt this to f#?

open System.Net
open System.IO

let url = "https://..."

let mutable request = HttpWebRequest.Create(url)
request.Method <- "GET"  
request.ContentType <- "multipart/form-data"

ServicePointManager.ServerCertificateValidationCallback = fun -> true ???? 

let mutable resp = request.GetResponse()

let fn =
    for i = 1 to 10 do
        request <- WebRequest.Create(url)
        resp <- request.GetResponse()
like image 235
unj2 Avatar asked Jul 25 '11 19:07

unj2


People also ask

How do I connect my SSL certificate?

Under Install and Manage SSL for your site (HTTPS), click Manage SSL Sites. Scroll down to the Install an SSL Website and click Browse Certificates. Select the certificate that you want to activate and click Use Certificate. This will auto-fill the fields for the certificate.

What does accept all SSL certificates mean?

Yes, it means that it will accept all (as in, regardless of issuer) SSL certificates, even if they are from an untrusted Certificate Authority. You could use this if you didn't care who your messages were going to but wanted them secure.


1 Answers

ServicePointManager.ServerCertificateValidationCallback <-
  System.Net.Security.RemoteCertificateValidationCallback(fun _ _ _ _ -> true)

The following works too:

System.Net.ServicePointManager.ServerCertificateValidationCallback <- 
  (fun _ _ _ _ -> true) //four underscores (and seven years ago?)

RemoteCertificateValidationCallback has the following signature:

public delegate bool RemoteCertificateValidationCallback(
    Object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors
)

Since pattern matching occurs for function arguments, and you're ignoring all four parameters, you can substitute the wildcard pattern (underscore) for each, which is an idiomatic way to indicate a parameter is unused.

like image 160
Daniel Avatar answered Sep 21 '22 06:09

Daniel