Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_M_1
Beginner
43 Views

App security API with Public Key

I am trying to do a simple connect using a public key to my server. I am unable to connect. The error thrown is: "Fail, error code is: 16, error message is: Server not accessible error"

The following is my code snippet:

var publicKey = "-----BEGIN PUBLIC KEY-----\n" +
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlqSzFh5jWW/BzWfeS5gX\n" +
"5MjCnCZaZ/AFmo7RLou8lV3Ue6Pjdpqcf3T9Ul9X5Cj1TPq5mzAleo5DR8il+7mp\n" +
"tWLZ5SqTNB3N40E9UtN6dqVky7rCvU6/rDEH+BOydBFDTP02j78gdD/tneuZnVT3\n" +
"TMV9fSiqX5CdunyzLc8gaVtpr1c1VoGH641z7+0VRmsl9iIuxQu1Vgt8QojioOr0\n" +
"/pH8O7sTlobKf7rbuwKKP7xxU2zNWXqHE7IZWhbKo0zmB9MDH1YmxCAnGup7gvPD\n" +
"sxOWjp5JTGV8clEYr4f0KgvnvCCIarRliEFfdSnYYKlafoOx4KSc75tN69nONQYn\n" +
"QQIDAQAB\n" +
"-----END PUBLIC KEY-----\n";

// options for the transport creation call 
var openOptions = {
    url: "https://104.155.25.147:8181/DeliveryReport/privatewealth/register",
    serverKey: publicKey
};

// create the Transport Secure instance
intel.security.secureTransport.open(
    function(instanceID) {

        // options for the request send.
        var sendRequestOptions = {
            instanceID: instanceID,
            requestBody: "data to send"
        };

        // send the HTTPS request
        intel.security.secureTransport.sendRequest(
            function(response) {

                // assign response HTTP status
                var responseHttpStatus = response.responseHttpStatus;

                // assign response body
                var responseBody = response.responseBody;

                // assign response header
                var responseHeader = response.responseHeader;

                /*
                now we have the following items:
                * Transport Secure instance ID at 'transportInstanceId'
                * the response body at 'responseBody'
                * the response header at 'responseHeader'

                we can use it in our code.
                */
                console.log("response"+response);
                doSomethingAfterReceiveWithKeyPinning(response);

            },
            failCallback,
            sendRequestOptions);
    },
    failCallback,
    openOptions);


function failCallback(error) {
    console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);
}

 

Tags (2)
0 Kudos
1 Reply
PaulF_IntelCorp
Employee
43 Views

Are you getting this error from a built app or from the Emulator or Debug tabs? If from a built app you might need to update the whitelist settings for your app, on the Projects tab.

Reply