C# cert_auth_required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fossystem1
    Junior Member
    • Jun 2014
    • 5

    #1

    C# cert_auth_required

    Hello, Support,
    please advise me:
    use follow code on c# to login in betfair but got error CERT_AUTH_REQUIRED. Where is my bug?
    Thanks



    try
    {
    const string postData = "username=myusername&password=mypassw";
    System.Security.Cryptography.X509Certificates.X509 Certificate2 x509certificate = new System.Security.Cryptography.X509Certificates.X509 Certificate2("C:\\OpenSSL-Win32\\bin\\client-2048.pem", "xxxx"); //------ where xxxx - password was mentioned in process of ssl-key generation
    /*
    Country Name (2 letter code) [AU]:GB
    State or Province Name (full name) [Some-State]:London
    Locality Name (eg, city) []:London
    Organization Name (eg, company) [Internet Widgits Pty Ltd]:myname
    Organizational Unit Name (eg, section) []:trader
    Common Name (e.g. server FQDN or YOUR name) []:myname
    Email Address []:myemail@myemail.com

    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:xxxx
    An optional company name []:myname

    */

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://identitysso-api.betfair.com/api/certlogin");
    request.UseDefaultCredentials = true;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.Headers.Add("X-Application", appkey);
    request.ClientCertificates.Add(x509certificate);
    request.Accept = "*/*";
    request.Proxy = null;
    using (Stream stream = request.GetRequestStream())
    {
    using (StreamWriter writer = new StreamWriter(stream, Encoding.Default))
    {
    writer.Write(postData);
    }
    }
    using (Stream stream = ((HttpWebResponse)request.GetResponse()).GetRespon seStream())
    {
    using (StreamReader reader = new StreamReader(stream, Encoding.Default))
    {
    var jsonResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<Logi nResponse>(reader.ReadToEnd());
    if (jsonResponse.loginStatus == "SUCCESS")
    {
    //saveSession(jsonResponse.sessionToken);
    bool loginSucceeded = true;
    }
    else
    {
    System.Media.SystemSounds.Exclamation.Play();
    }
    }
    }
    }
    catch (System.Exception ex)
    {
    System.Media.SystemSounds.Exclamation.Play();
    //MessageBox.Show(ex.ToString(), "Login ERROR");
    }
  • fossystem1
    Junior Member
    • Jun 2014
    • 5

    #2
    Problem solved: .p12 should be used instead .pem

    Comment

    • Javeid_UK_2.
      Junior Member
      • Jul 2014
      • 5

      #3
      Still no luck with the bot login

      Originally posted by fossystem1 View Post
      Problem solved: .p12 should be used instead .pem
      Hi fossystem1,

      I'm trying to do the same thing as you were and I'm still getting a CERT_AUTH_REQUIRED error.

      I've followed the tutorial at https://api.developer.betfair.com/se...28bot%29+login, and I've also, as you suggested, generated the .pfx (or .p12) file with openssl's "pkcs12" command, but I still get that error.

      I've tried to make an encrypted POST request with curl, specifying the certificate and key files (separately) on the command line and I can get the session token successfully, so it shouldn't be something wrong with my key and/or cert.

      Have you got any idea what might be wrong here? Has anybody else?

      Comment

      • Javeid_UK_2.
        Junior Member
        • Jul 2014
        • 5

        #4
        Apparently, either I failed to follow the instructions to generate a cert using openssl or there is something wrong with the instructions, since after trying to generate a new cert with the Windows GUI tool it works.

        The two certs I generated seem to differ in some fundamental ways, such as the intended use, which probably means that .NET refused to use the first one to authenticate an HTTPS client connection even though I had correctly told it to use it.

        Comment

        • superpunter888
          Junior Member
          • Oct 2013
          • 1

          #5
          &quot;CERT_AUTH_REQUIRED&quot; Error

          I encounter the same error.
          I tried to use both PEM and p12 extension but still encounter the same error.

          Comment

          Working...
          X