SBell607510 (Community Member) asked a question.

How do you call a Veracode API endpoint from Java?

I am trying to delete sandboxes created during unit test of an automation utility that we wrote. Because the deleteSandbox function has not yet been added to the Veracode API Wrapper, I need to call the deleteSandbox.do endpoint. The documentation on this is thin. From what I have seen I need to implement HMAC signing in order to authenticate to the API. However, the documentation falls short on exactly how to do this. Does anyone have an example or can point me to one?


  • Hi @SBell607510 (Community Member)​ 

     

    Do you need to use Java? I think a simpler solution is to use HTTPie which has built-in Veracode HMAC. See this link and example run of mine below for details on HTTPie. This can be run from a windows/linux command/bash window or called from a bat/sh script. Let me know if this is helps you.

     

    https://help.veracode.com/r/c_httpie_tool

     

    $ http --auth-type=veracode_hmac POST https://analysiscenter.veracode.com/api/5.0/deletesandbox.do "sandbox_id==2116601"

    HTTP/1.1 200 OK

    Cache-Control: no-cache, no-store

    Content-Encoding: gzip

    Content-Length: 247

    Content-Type: text/xml

    Date: Thu, 30 Jul 2020 13:18:13 GMT

    Expires: Thu, 01 Jan 1970 00:00:00 GMT

    Pragma: no-cache

    Server:

    Set-Cookie: JSESSIONID=8247800EE9D3E33B11A9EC14DB783515; Domain=.analysiscenter.veracode.com; Path=/; Secure; HttpOnly

     

    <?xml version="1.0" encoding="UTF-8"?>

     

    <sandboxlist xmlns:xsi="http&#x3a;&#x2f;&#x2f;www.w3.org&#x2f;2001&#x2f;XMLSchema-instance" xmlns="https&#x3a;&#x2f;&#x2f;analysiscenter.veracode.com&#x2f;schema&#x2f;4.0&#x2f;sandboxlist" xsi:schemaLocation="https&#x3a;&#x2f;&#x2f;analysiscenter.veracode.com&#x2f;schema&#x2f;4.0&#x2f;sandboxlist https&#x3a;&#x2f;&#x2f;analysiscenter.veracode.com&#x2f;resource&#x2f;4.0&#x2f;sandboxlist.xsd" sandboxlist_version="1.0" account_id="68629" app_id="778032"></sandboxlist>

    Expand Post
  • SBell607510 (Community Member)

    Thank you for the response. Unfortunately I do need to use Java. We wrote a Java wrapper around the Veracode wrapper to automate some tasks in our pipeline to automatically create application profiles if the specified app doesn't exist, and do the same for sandboxes. I wrote a set of unit tests to test our code, which is creating test profiles and sandboxes, and I need to clean those up in the post test area. I already have that working for application profiles as those can be deleted through the Veracode Java wrapper. However, I need to do the same for sandboxes. The only way I can get away from Java would be to rewrite our wrapper in Python or something.

    Expand Post
    • Hi @SBell607510 (Community Member)​ 

       

      I spent some time modifying the Veracode HMAC Java examle code on the help center to do a POST request to the platform needed for deletesandbox.do api call. The java examples are only for GET requests. There is a little more involved for a POST. I attached main.java and HmacRequestSigner.java here. If you haven't already, you'll need to import the Veracode HMAC signing library to your project for the examples to work . You'll have to add your API ID/KEY to the code and your scanbox_ID. I pointed this out in the code. I ran the code in Eclipse running JDK 1.0.8_191 and was able to delete one of my sandboxes. Here is an example of the XML output .

       

      <?xml version="1.0" encoding="UTF-8"?>

       

      <sandboxlist xmlns:xsi="http&#x3a;&#x2f;&#x2f;www.w3.org&#x2f;2001&#x2f;XMLSchema-instance" xmlns="https&#x3a;&#x2f;&#x2f;analysiscenter.veracode.com&#x2f;schema&#x2f;4.0&#x2f;sandboxlist" xsi:schemaLocation="https&#x3a;&#x2f;&#x2f;analysiscenter.veracode.com&#x2f;schema&#x2f;4.0&#x2f;sandboxlist https&#x3a;&#x2f;&#x2f;analysiscenter.veracode.com&#x2f;resource&#x2f;4.0&#x2f;sandboxlist.xsd" sandboxlist_version="1.0" account_id="68629" app_id="778032"></sandboxlist>

       

      I just wanted to add that this is not an official Veraode example but since I got it working I wanted to share. You could always review it and modify it to your specification. Let me know if you get this code working. If not, submit a case to support@veracode.com to troubleshoot further.

       

      Regards

       

      Andy

      Expand Post

Topics (3)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.