DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Gateway script to read TLS info

  • 1.  Gateway script to read TLS info

    Posted 07/21/20 05:09 AM

    Hi

    I am trying to read TLS info from service variable and exact TLS version information. I am able to do this using XSLT. But when I am read this variable using gateway script getVar, the response is in ojbect. I am unable to parse this and extract TLS version information. Any help??



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: Gateway script to read TLS info

    Posted 07/21/20 01:57 PM

    Log the object, eg. with JSON.stringify() and show the log entry. Then tell which part of that you want to get.



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: Gateway script to read TLS info

    Posted 07/21/20 02:59 PM

    Hello Herman.

    Logs are truncated but similar to this.

    {"tls-info":

    {"version":{"$":"TLSv1.2"},

    "cipher":{"$":"ECDHE-RSA-AES256-GCM-SHA384"},

    "peer-certficate":{"$":"MIICGjC...uah00="},

    "sni-extension":{"$":"bob-hardware.com"},

    "session-id":{"$":"base64_ID"}

    }

    }




    #DataPower
    #Support
    #SupportMigration


  • 4.  RE: Gateway script to read TLS info

    Posted 07/21/20 03:00 PM

    Hello Herman.

    Logs are truncated but similar to this.

    {"tls-info":

    {"version":{"$":"TLSv1.2"},

    "cipher":{"$":"ECDHE-RSA-AES256-GCM-SHA384"},

    "peer-certficate":{"$":"MIICGjC...uah00="},

    "sni-extension":{"$":"bob-hardware.com"},

    "session-id":{"$":"base64_ID"}

    }

    }



    #DataPower
    #Support
    #SupportMigration


  • 5.  RE: Gateway script to read TLS info

    Posted 07/21/20 03:03 PM

    I am trying to extract TLSv1.2 from below string



    #DataPower
    #Support
    #SupportMigration


  • 6.  RE: Gateway script to read TLS info

    Posted 07/21/20 03:53 PM

    If the object is stored in "obj" variable, you get it with:

    obj.tls-info.version.$



    #DataPower
    #Support
    #SupportMigration


  • 7.  RE: Gateway script to read TLS info

    Posted 07/21/20 04:06 PM

    Tried it. But no luck

    var tls = service.getVarr('var://service/tls-info');

    console.error('tls info'+JSON.stringify(tls));

    //above statement printed TLS json in logs

    hm.current.set ('TLSVersion', tls.tls-info.version.$);

    this is failing with error

    GatewayScript processing Error 'ReferenceError: Info is not defined'



    #DataPower
    #Support
    #SupportMigration


  • 8.  RE: Gateway script to read TLS info

    Posted 07/21/20 04:06 PM

    Tried it. But no luck

    var tls = service.getVarr('var://service/tls-info');

    console.error('tls info'+JSON.stringify(tls));

    //above statement printed TLS json in logs

    hm.current.set ('TLSVersion', tls.tls-info.version.$);

    this is failing with error

    GatewayScript processing Error 'ReferenceError: Info is not defined'



    #DataPower
    #Support
    #SupportMigration


  • 9.  RE: Gateway script to read TLS info

    Posted 07/22/20 12:39 PM

    OK, then

    var tls = service.getVarr('var://service/tls-info');

    reads a string.

    Please use

    var tls = JSON.parse(service.getVarr('var://service/tls-info'));

    instead.



    #DataPower
    #Support
    #SupportMigration


  • 10.  RE: Gateway script to read TLS info

    Posted 07/22/20 02:31 PM

    Hi Herman

    I am having issues with this too.

    var tls = JSON.parse(service.getVar('var://service/tls-info'));

    hm.current.set ('TLSVersion', tls.tls-info.version.$);

    Error:

    Gateway script processing Error. 'Syntax Error : Unexpected token o in JSON at position '1'




    #DataPower
    #Support
    #SupportMigration


  • 11.  RE: Gateway script to read TLS info

    Posted 08/26/20 10:05 PM

    Hi

    Can someone help with the XSLT to capture and log the TLS version and cipher

    I am trying to do the below and it doesnt work

    <xsl:variable name="tlsinfo">

    <xsl:copy-of select="dp:variable('var://service/tls-info')"/>

    </xsl:variable>

    <dp:set-variable name="'var://context/TLS/info'" value="$tlsinfo"/>

    <dp:set-variable name="'var://context/TLS/version'" value="$tlsinfo/tls-info/version"/>

    <dp:set-variable name="'var://context/TLS/cipher'" value="$tlsinfo/tls-info/cipher"/>

    Basically I am trying to save it a context seperately and log it seperately .

    Thanks



    #DataPower
    #Support
    #SupportMigration