Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

MatriXz
New Contributor

HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

Hi

Im using Visa Direct, and trying to implement the HelloWorld.cs functionality into my MVC Core project, to test it out on my site. 

The line when you call:

var certificate = new X509Certificate2(certificatePath, certificatePassword);

throws an exception: "System.Security.Cryptography.CryptographicException: 'The system cannot find the path specified.'"

I put the cert.pem file into my project under a custom folder called Utils. and set the path to point at that like this: "~/Utils/cert.pem". 

What am I doing wrong? 

6 REPLIES 6
SyedSa
Community Moderator

Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

Hi @MatriXz, Thank you for reaching out. One of our agents will look into this and get back to you soon. Until then, if any community members know a solution, please feel free to reply to this thread.

API_Managers
Visa Developer Support Specialist

Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

Hi @MatriXz,

 

To further investigate, please provide the following information:

1. End Point
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body

You can find the x-correlation-id in the response header.




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

MatriXz
New Contributor

Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

Hi,

I honestly have no idea what to reply here.

 

I think the endpoint is: "https://sandbox.api.visa.com/vdp/helloworld", it works perfectly in postman, using the same credentials, certificates etc.

 

In my project i created a simple button that calls this controller method:

[HttpPost]

public ActionResult BuyRows(string rowData) {
var visa = new Visa();
var response = visa.DoMutualAuthCall("vdp/helloworld", "GET", null, null, null);
return Json(response);
}

 

The class Visa is a copy paste of the Helloworld.cs file from your sample code collection. Slightly changed the logging method, and filled in the username etc. 

 

This is the code: 

screenshot of issue.JPG

As you can see I get an unhandled exception when it comes to this line. The request hasnt even been done yet. Hope its possible to read the screenshot. 

MatriXz
New Contributor

Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

Using some Copilot assistance I figured out what the problem was.. Its the Absolute path of the Cert.Pem file location that was the issue..

Solution:

string certificatePath = Path.Combine(Directory.GetCurrentDirectory(), "Utils", "cert.pem");

 

However, now I am getting to the request.GetResponse() part. Im getting an error 400 (bad request)

 

Details i know:

Url: "https://sandbox.api.visa.com/vdp/helloworld"

Method: "GET"

 

I call this method like this:

new Visa().DoMutualAuthCall("vdp/helloworld", "GET", null, null, null);

 

Any idea what I am doing wrong ?

All Searches say that something is not correct in the request.Header, or url is incorrect. But its copied from the documentation, and works in postman, so not that imo. 

API_Managers
Visa Developer Support Specialist

Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

HI @MatriXz,

 

HTTP STATUS HTTP CODE CAUSE/RESOLUTION

BAD REQUEST

400

This error could be due to a variety of reasons.

Check for the following:

  • The url has a space after the ?.
  • Whitespace issues, in general, anywhere in the url.
  • Ideally the following fields need to be checked for correctness:
    •  URL
    •  Query params

Or

  • The API endpoint you are trying to use only supports Two-Way SSL authentication. Please ensure you are not using any other token type.

Or

  • Invalid input found in the request payload.

 




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

vrm
Helper

Re: HelloWorld.cs with Mutual Auth throws error in X509Certificate2 call

hi @MatriXz 

i'm using node js to connect to VISA network. one thing i forgot in the first try, was including username and password in headers. in nodejs it is as follows:

'Authorization': 'Basic ' + new Buffer(userId + ':' + password).toString('base64')
this must be present in headers section. maybe you are facing the same issue

 

nobody is perfect