Topic
19 replies Latest Post - ‏2011-12-03T18:47:44Z by HermannSW
dp_admin
dp_admin
23 Posts
ACCEPTED ANSWER

Pinned topic How to decode the base64 encode result from SOMA export

‏2010-12-15T17:12:24Z |
Hi all,

If I export the configuration (using SOMA) as a XML format, then I can succesfully decode the base64 encode result. But if I export it as ZIP format, then the result of the decoding is not correct. How can we decode the base64 result if we export it as ZIP format?
Updated on 2011-12-03T18:47:44Z at 2011-12-03T18:47:44Z by HermannSW
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T17:53:25Z  in response to dp_admin
    There are lot of base64 decode online tools available, you can do the decode using tools.
    • dp_admin
      dp_admin
      23 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2010-12-15T18:00:39Z  in response to SystemAdmin
      Kumar,

      Yes, I did that and it worked when I exported the configuration with XML format. But when I exported using ZIP format, then the result decode text is not clear text. If I export it as ZIP format, do we have to unzip it and then decode it?
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T18:09:57Z  in response to dp_admin
    When you do the export of the objects you get the export.zip , in that you will get export.xml file. Try to open the file using any XML editor like XML tidy or notepad++ which will have list of all the objects you have imported.

    While doing the export with SOMA , you will have base64 enocoded value and that value you paste in the import script.

    Hope this helps,
    Kumar
    • dp_admin
      dp_admin
      23 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2010-12-15T18:26:17Z  in response to SystemAdmin
      Kumar,

      I was exporting using SOMA. If the format of export is either ZIP or XML, I can import the objects succesfully. Now If the format is XML, then if I decode the base64 encode result, then decode result is in clear text. But if the format is ZIP and the decode result is not in clear text.
      I know if it works for XML, then it should work for ZIP also. But its not. What am I missing here?
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T19:02:04Z  in response to dp_admin
    While doing the export using SOMA , you will get the base64 encoded value, which is not in clear test, to decode the base64 encode value use perl module or do it online , there are tools available to do base64 encoding.
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T19:04:37Z  in response to dp_admin
    Can you upload your export soma script as well as the xml file.
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T19:27:40Z  in response to dp_admin
    You are not specifying the name the of classes you want to import.

    like this
    <dp:object name="xml1" class="XMLFirewallService" ref-objects="true" ref-files="true"/>
    <dp:object name="xml2" class="XMLFirewallService" ref-objects="true" ref-files="true"/>
    <dp:object name="xml3" class="XMLFirewallService" ref-objects="true" ref-files="true"/>
    <dp:object name="xml4" class="XMLFirewallService" ref-objects="true" ref-files="true"/>

    and other objects and there class you want to export mention that too.. I am thinking all the default objects are also getting exported..
    • dp_admin
      dp_admin
      23 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2010-12-15T20:22:05Z  in response to SystemAdmin
      Kumar,

      The problem is not with importing. It is when I decode the base64 encoded content if I use the ZIP FORMAT.

      Let me explain more specifically. If export with ZIP format, the encode result is something like UEsDBAoAAAAAAOVkjz0AAAAAAAAAAAAAAAAHABUAZHA...........

      and when I decode this, the result is PKåd=..........(not in clear text)

      If I export with XML format, the encode result is something like
      PGRhdGFwb3dlci1jb25maWd1cmF0aW9uIH..............

      and the decode result is
      <datapower-configuration..................(in clear text).

      So for XML format its working, but not for ZIP format.
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T20:30:26Z  in response to dp_admin
    What firmware are you using ?

    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14535524&#14535524

    read the previous thread , i never had any problem using format as ZIP using SOMA ..
    • dp_admin
      dp_admin
      23 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2010-12-15T20:43:24Z  in response to SystemAdmin
      I am using 3.8.1.6

      When I export using SOMA, I can see a export.zip in the export directory and the results are the way I had expected. Its only with the decoding?
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T20:49:04Z  in response to dp_admin
    Its pretty latest firmware you are using ..
    My suggestion to you is

    --> To do the export using SOMA, then you will get the <dp:file>base64 file <dp:file>.

    --> copy the base64 encoded value and paste in the import SOMA script and check whether you are able to see the desire objects .
    • dp_admin
      dp_admin
      23 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2010-12-15T20:57:47Z  in response to SystemAdmin
      Kumar,

      Yes, I can see the desired objects by using both formats. I want to decode the file and save it, so that it can be review it later. It seems like I have to open a PMR.
  • JBrennan
    JBrennan
    77 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2010-12-15T21:31:20Z  in response to dp_admin
    WHat are you using to decode the response from the SOMA request? If you are using a DataPower extension function decode()then this makes sense. This is for decoding a non-binary string. There is another extension function binary-decode() that is used for decoding binary data.

    If you are decoding this via another method (openssl, etc) then I have never had success with that. DataPower does not format the base64 encoding properly so these tools cannot decode it. I have had to reformat the string to 64 character lines.
    • dp_admin
      dp_admin
      23 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2010-12-15T22:01:35Z  in response to JBrennan
      I have used both online tool and perl script. I will use the datapower functions and see how it turns out. But I still wonder, why does it work with XML format?. Thanks for the response.
    • samanderson
      samanderson
      172 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2011-12-03T07:14:28Z  in response to JBrennan
      Hi Jim,

      I want to pass through same stuff.. Can you pls. help me get the snippet for xslt using extension function binary decode for which result is the output of soma containing base64 in tag.

      Is it equivalent to the one u do in xml export or can I compare it that way ?
    • samanderson
      samanderson
      172 Posts
      ACCEPTED ANSWER

      Re: How to decode the base64 encode result from SOMA export

      ‏2011-12-03T07:15:48Z  in response to JBrennan
      has any one had luck with openssl. what needs to be done exactly for this ?/
  • HermannSW
    HermannSW
    4129 Posts
    ACCEPTED ANSWER

    Re: How to decode the base64 encode result from SOMA export

    ‏2011-12-03T18:47:44Z  in response to dp_admin
    > ...
    > If you are decoding this via another method (openssl, etc) then I have never had success with that.
    > DataPower does not format the base64 encoding properly so these tools cannot decode it.
    >
    not properly for these tools, yes, but I do not know of any general requirement that a base64 string has to be split at any length.

    There are requirements for specific protocols, eg. the maximum MIME line length is 76 characters:
    http://en.wikipedia.org/wiki/Base64#MIME

    But the DataPower response to do-export SOMA call is XML, not MIME, and so DataPower does nothing wrong here.

    > I have had to reformat the string to 64 character lines.
    >

    OK, find below 3 different approaches on how you can decode the base64 string from DataPower response:
    ...<dp:file>***base64 string***</dp:file>...
    First, we need a simple sample response.
    My first ever SOMA export is for XML FW service "10sec" from default domain by this request:
    
    <soapenv:Envelope xmlns:soapenv=
    "http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <dp:request xmlns:dp=
    "http://www.datapower.com/schemas/management" domain=
    "default"> <dp:do-export format=
    "ZIP" all-files=
    "false"> <dp:object name=
    "10sec" class=
    "XMLFirewallService" ref-objects=
    "true" ref-files=
    "true"/> </dp:do-export> </dp:request> </soapenv:Body> </soapenv:Envelope>
    

    (see section 3.2.13 in WebSphere DataPower SOA Appliance: The XML Management Interface)

    You can send the SOMA request any way you like, I use doSoma tool for this:
    
    $ doSoma admin export.xml dp3-l3:5550 >e Enter host password 
    
    for user 
    'admin': $
    

    Now you can see 3 different approaches (there are abitrary many more of course):
    • if you are working under Unix/Linux or Cygwin under Windows, then "sed", "tail" and "base64" commands do the job
    • you may use below PERL one-liner to achieve the same result
    • and finally stylesheet dec.xsl does the same via coproc2nonxml service.

    If you are interested in the explanations you may find then below.
    
    $ sed 
    "s/^.*<dp:file>\(.*\)<\/dp:file>.*$/\1/g" e | tail -1 | base64 -id >f $ $ perl -MMIME::Base64 -ne 
    's/^.*<dp:file>(.*)<\/dp:file>.*$/\1/g; print decode_base64($_) if 2..2' e >g $ $ coproc2 dec.xsl e http:
    //dp3-l3:2224 -s >h $ $ ll ? -rw-rw-r--. 1 stammw stammw 687891 Dec  3 18:57 e -rw-rw-r--. 1 stammw stammw 515694 Dec  3 18:57 f -rw-rw-r--. 1 stammw stammw 515694 Dec  3 18:57 g -rw-r--r--. 1 stammw stammw 515694 Dec  3 18:58 h $ $ diff f g $ diff f h $ $ unzip -l f Archive:  f Length      Date    Time    Name ---------  ---------- -----   ---- 0  12-03-2011 18:50   dp-aux/  6819  12-03-2011 18:50   dp-aux/basetypes.xml 3952672  12-03-2011 18:50   dp-aux/drMgmt.xml 5684  12-03-2011 18:50   dp-aux/map-dmz.xsl 7285  12-03-2011 18:50   dp-aux/management.xsl 21368  12-03-2011 18:50   dp-aux/SchemaUtil.xsl 194598  12-03-2011 18:50   dp-aux/clixform.xsl 0  12-03-2011 18:50   local/  1477  12-03-2011 18:50   local/10sec.xsl 9350  12-03-2011 18:50   export.xml ---------                     ------- 4199253                     10 files $
    

    The "sed" statement extracts the <dp:file> base64 string.
    Because there are two line of input "tail" just selects the base64 string.
    "base64 -d" commnand does the base64 decoding.
    
    $ sed 
    "s/^.*<dp:file>\(.*\)<\/dp:file>.*$/\1/g" e | tail -1 | base64 -d >f $
    

    (whenever you need to decode base64 strings ontaining whitespace you may want to use "base64 -id")

    The PERL one-liner is basically the same solution as the previous one.
    Using module "MIME::Base64" by -M option provides "decode_base64()" function.
    Finally the 2nd line of input is selected by "...($_) if 2..2".
    
    $ perl -MMIME::Base64 -ne 
    's/^.*<dp:file>(.*)<\/dp:file>.*$/\1/g; print decode_base64($_) if 2..2' e >g $
    


    Last, but not least, the DataPower solution.
    Stylesheet dec.xsl does the same the previous solutions did:
    
    <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" xmlns:man=
    "http://www.datapower.com/schemas/management" extension-element-prefixes=
    "dp" > <dp:output-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/> <xsl:template match=
    "/"> <object> <message> <xsl:value-of select=
    "dp:binary-decode(/*/*/man:response/man:file)"/> </message> </object> </xsl:template> </xsl:stylesheet>
    

    (see http://www-01.ibm.com/support/docview.wss?uid=swg27022977 for the details on how to return binaryNode result of dp:binary-decode() )

     
    Hermann<myXsltBlog/>