4

I have been trying to log in to a Betfair account following these steps and using this source code. This works fine and I am returned a session key, however if I try to repeat the steps to get a session key in another project I receive a "CERT_AUTH_REQUIRED" error, implying that there is something wrong with the client certificate I am sending with my request.

Odder still, if I create another project that references the working Betfair project and get this new project to simply run the Program.Main method in the Betfair project I get the "CERT_AUTH_REQUIRED" message again?

When the Betfair application is the Launch project for the solution it works, but if I set the second project that launches the betfair console app as the startup project it doesn't return a success response (although the code runs fine and goes through all the same steps, it is just the web response that fails).

Does anyone have any idea why this might be?

PeterJ
  • 3,705
  • 28
  • 51
  • 71
mark_h
  • 5,233
  • 4
  • 36
  • 52

2 Answers2

2

I managed to get that code working for non-interactive log ins. I did make this change though. It sounds vaguely familiar as I remember having that error.

    private WebRequestHandler getWebRequestHandlerWithCert(string certFilename)
    {
        var cert = new X509Certificate2(certFilename, "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
        var clientHandler = new WebRequestHandler();
        clientHandler.ClientCertificates.Add(cert);
        return clientHandler;
    }
Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87
  • 1
    Thanks @Robsedgwick, for me all I needed was the X509KeyStorageFlags.Exportable flag, but I still definitely regard this as the answer! – mark_h Apr 25 '17 at 19:05
0

Another thing that I've just found can cause the same error is if you enter an export password during the step below. That may have changed since you created your key because it marks it as exportable so I didn't need to add X509KeyStorageFlags.Exportable in the code:

openssl pkcs12 -export -in client-2048.crt -inkey client-2048.key -out client-2048.p12

I assumed the export password was what the sample application was prompting for but it wasn't so the export password should be left blank.

PeterJ
  • 3,705
  • 28
  • 51
  • 71