Layer7 API Management

 View Only
  • 1.  Signing a hash string with Gateway

    Posted May 24, 2022 03:00 PM
    Hi,

    I need to call an API that have a security process that i need to do, with the Datapower i have done with the code above in XSL:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" 
        extension-element-prefixes="dp" exclude-result-prefixes="dp"
        version="1.0">
        <xsl:template match="/">
            <xsl:variable name="input-xml" select="."/>
            
            <xsl:variable name="sign-algorithm">
                <xsl:text>http://www.w3.org/2001/04/xmldsig-more#rsa-sha256</xsl:text>
            </xsl:variable>
            
            <xsl:variable name="hash-algorithm">
                <xsl:text>http://www.w3.org/2001/04/xmlenc#sha256</xsl:text>
            </xsl:variable>
           
            <xsl:variable name="certKey" select="dp:variable('var://context/jwt/cerKey')"/>
    		<xsl:variable name="cerKey" select="concat('name:', $certKey)"/>
    		
            <xsl:variable name="hash-signedinfo" select="dp:hash($hash-algorithm, dp:variable('var://context/jwt/arquivoRequest'))"/>
            <xsl:message> Inicio Assinar msg </xsl:message>
            <xsl:variable name="signed-data">
                <xsl:value-of select="dp:sign($sign-algorithm, $hash-signedinfo, $cerKey)"/>
            </xsl:variable>
            <xsl:message> Fim Assinar msg </xsl:message>
            <SignatureValue>
                <xsl:value-of select="$signed-data"/>
            </SignatureValue>
    		<dp:set-variable name="'var://context/jwt/arquivoRequest'" value="$signed-data"/>
    		<xsl:copy-of select="$signed-data"/>
        </xsl:template>
    </xsl:stylesheet>
    
    ​



    But now i need to do the same thing with Broadcom Gateway i see that i can hash the string with the assertions "Generate Security Hash" using SHA-256.
    My problem is that i dont know how to sign that hash with the certificate using RSA SHA 256, i have read somewhere to use Enconde JWT assertion but i dont want to create a JWT i need to sign the hash string, how can i do it?


  • 2.  RE: Signing a hash string with Gateway

    Posted May 24, 2022 04:17 PM
    The hash encryption assertion doesn't support asymmetric key. Only symmetric SHA, HMAC, and MD5 algorithms are supported.

    If you really want to use the asymmetric key on symmetric assertion, then I can think of custom policy development but ultimately your solution will look like symmetric key. You could use a custom assertion from Broadcom (Asymmetric Key Encryption/Decryption Assertion) that decrypts the encrypted fields or object and then you can compare the results stored in your API service.

    Check with Broadcom support if they provide custom assertion to this issue.




  • 3.  RE: Signing a hash string with Gateway

    Posted May 30, 2022 01:55 PM
    Hi,

    Thats not exactly what i meen, i need to SIGN a string not ENCRYPT it.
    is a way to sign strings in the gateway? or only jwts are possible to sign?


  • 4.  RE: Signing a hash string with Gateway

    Broadcom Employee
    Posted May 30, 2022 03:34 PM
    The Gateway can sign a JWT using JWS via the Encode JSON Web Token assertion and it can sign an XML element using XMLDSIG via the (Non-SOAP) Sign XML Element or the Sign Element assertion for SOAP messages. There is no way to sign an arbitrary string in the Gateway that I am aware.

    Since generating a signature requires access to a private key (a signature is just the hash of the data that is encrypted using the private key) this can only be done using a modular assertion. I don't think the custom assertion API allows access to the private keys.

    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------



  • 5.  RE: Signing a hash string with Gateway

    Posted Jun 09, 2022 02:44 AM

    I know this does not answer the question but the gateway does have "Symmetric Key Encryption/Decryption" as an add-on you have to request.

    You could wrap your value in XML and use the Sign Element assertion