Secure Transport send with pinned public key snippet

This snippet illustrates Secure Transport. It performs the following actions:

  • Create a new instance of secure transport with server public key
  • Send an HTTP request and get a response

Please refer to the API definition:

         
    // TODO change server PK
    var publicKey = "-----BEGIN PUBLIC KEY-----\n" +
        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2swYYzD99BcjGlZ+W988\n" +
        "bDjkcbd4kdS8odhM+KhDtgPpTSEHCIjaWC9mOSm9BXiLnTjoBbdqfnGk5sRgprDv\n" +
        "gOSJKA+eJdbtg/OtppHHmMlCGDUUna2YRpIuT8rxh0PBFpVXLVDviS2Aelet8u5f\n" +
        "a9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6cJmTM386DGXHKTubU1XupGc1V3sjs\n" +
        "0l44U+VcT4wt/lAjNvxm5suOpDkZALeVAjmRCw7+OC7RHQWa9k0+bw8HHa8sHo9g\n" +
        "OeL6NlMTOdReJivbPagUvTLrGAMoUgRx5aszPeE4uwc2hGKceeoWMPRfwCvocWvk\n" +
        "+QIDAQAB\n" +
        "-----END PUBLIC KEY-----\n";

    // create the Transport Secure instance
    intel.security.secureTransport.open( {url: "https://software.intel.com/en-us/app-security-api/api", serverKey: publicKey} )
    
    // send the request
    .then (function (transportInstanceID) {
            // send the HTTPS request
            return intel.security.secureTransport.sendRequest( {instanceID: transportInstanceID, requestBody: "data to send"} );
    })
    
    // process the response
    .then (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:
        // the response status in 'responseHttpStatus'
        // the response body in 'responseBody'
        // the response header in 'responseHeader'
        
        // we can use those in our code.
        doSomethingAfterReceiveWithKeyPinning(response);
    })

    .catch (function(error) {
        console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);
    });
        
For more complete information about compiler optimizations, see our Optimization Notice.