This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Add other method to utils.js in Sentinel SDK fro write new colector.

I want implement hash funkcion fore create SHA-1  SHA-2  MDP from string

There is implemented SAH-1 hash but this does not work.

it is implemented  in utils.js by this funkcion:

/**
 * This method calculates the one-way hash of an input string, and returns the hash.
 * This method is used to calculate the one-way hash of an input string, which can then be used to ensure that strings are not modified,
 * for anonymization, or for any other purpose for which hashes are useful.
 * At this time, the only supported hash algorithm is SHA-1, but parameters are supplied for future extensions.
 * @example
 * var string="This is my messge.";
 * var hash=string.hash();
 * @addon
 * @param {String} format  Output format for the hash ('HEX' or 'B64' for hex (default) and base64, respectively)
 * @param {String} algo  Algorithm to be used to calculate the hash value ('SHA-1' is the default, and only supported method at this time)
 * @return {String} A string representing the hash value calculated from the source string.
 */
String.prototype.hash = function(format, algo) {
        if (typeof format == "undefined" || format != "B64") { format = "HEX"; }
        algo = "SHA-1";
        var hashobj = new jsSHA(this, "ASCII");  // UTF-8?
        return hashobj.getHash(format);
        // return hashobj.getHash(algo, format); // reserved for future extensions
};

But this does not work it cannot find jsSHA

My question if somebody know:

- What engine is use for interpret java script in Sentinel

- How it is  include java script from directory (How it is implemented " load, include ... does not work")

./current/sdk/2011.1/common/

to work together.

- There is  jsSHA implementation in file sha1.js    

- I want to fix hash function to work and add future extension for ssh-2

Thx.

Tags:

  • 0  

    Sentinel uses the Rhino JavaScript Engine http://mozilla.github.io/rhino/

    Are you using the latest SDK 2019.1r1 (https://marketplace.microfocus.com/arcsight/content/sdk)? IIRC the hash function does not use jsSHA anymore.

    Norbert

  • 0 in reply to   

    Hi thank you  I use latest SDK 2019.1r1.  It is there some  possibility to use  some working implemantation of crypto function and add it to SDK core function. (I meen expect to write hash function from scratch) .

    - Do you  How Sentinel implement include some new js file   from core function in SDK.

    I know that there is create zip file from all  source in SDK and for example utils.js and other js file are included and method in this file are available for release.js code. 

    But how I can add some my newfunction,js to core SDK function to be available for  release.js (How is done mecahizm of include in sentinel)?

    One method is rewrite utills.js and ad  new function directly in this one In my copy of SDK (All other build it will be available) But I want to split it to my file and this method innew  file I will call from new function in utills.js but I do not know how  to make it available. (something like include load ..)

    Thx

  • Suggested Answer

    0   in reply to 

    Hi,

    seems that utils.js/hash() is limited to SHA-1 and HEX output.

    /**
     * This method calculates the one-way hash of an input string, and returns the hash.
     * This method is used to calculate the one-way hash of an input string, which can then be used to ensure that strings are not modified,
     * for anonymization, or for any other purpose for which hashes are useful.
     * At this time, the only supported hash algorithm is SHA-1, but parameters are supplied for future extensions.
     * @example
     * var string="This is my messge.";
     * var hash=string.hash();
     * @addon
     * @param {String} format  Output format for the hash ('HEX' or 'B64' for hex (default) and base64, respectively)
     * @param {String} algo  Algorithm to be used to calculate the hash value ('SHA-1' is the default, and only supported method at this time)
     * @return {String} A string representing the hash value calculated from the source string.
     */
    String.prototype.hash = function(formatalgo) {
        if (typeof format == "undefined" || format != "B64") { format = "HEX"; }
        algo = "SHA-1";
        
        if(format == "HEX"){
            var messageDigest = new MessageDigest(algo);
            var hash = messageDigest.getChecksum(this);
            return hash;
        }
        //TODO enhance the java class MessageDigest to return base64 hash values also OR change the jsdoc of this function for parameter - format to only have one option namely, HEX.
        
    };

    The MessageDigest class in the current SDK is a wrapper around java.security.MessageDigest. So you should be able to use any algorithm that the JVM implements if you use it directly.

    If you want new common code to be included in multiple collectors you can drop the the .js into current\sdk\common\Collector\src\:

    "Including these common resources is very simple — simply list the file in the files.include file that is part of every Collector as part of the template. You can review the set of files that are available in the //current/sdk/common/Collector/src directory; open each file to see what it does. Any files you wish you use you just list on a single line, comma-separated, in files.include."

  • Verified Answer

    +1

    Yes SHA1 and HEX output is OK for me but problem is that this has does not work anymore and I want to fix it or replace it with something else. 

    I want extent hash in utils.js which is delivered with SDK

    It is possible to use  to use call of java library but this is not nice way

    and it is necessary implement strig function getBytes. (which create something like (116, 101, 115, 116, 46, 109, 101, 115, 115, 97, 103, 101] from string)

    Implementation like:

    p=java.security.MessageDigest

    md=p.getInstance("SHA-1"); //or I can use other algorithm for example SHA-256 

    text = "Text to hash, cryptographically. 26";

    tex2=getBytes(text)

    md.update(tex2)

    out=java.math.BigInteger(mp)

    ........

    and transfer out to HEX. I will need to write again string method (I do not know how to use I js script metod from Java)

    In the end, I fix it in utils.j

    /**
     * This method calculates the one-way hash of an input string, and returns the hash.
     * This method is used to calculate the one-way hash of an input string, which can then be used to ensure that strings are not modified,
     * for anonymization, or for any other purpose for which hashes are useful.
     * At this time, the only supported hash algorithm is SHA-1, but parameters are supplied for future extensions.
     * @example
     * var string="This is my messge.";
     * var hash=string.hash();
     * @addon
     * @param {String} format  Output format for the hash ('HEX' or 'B64' for hex (default) and base64, respectively)
     * @param {String} algo  Algorithm to be used to calculate the hash value ('SHA-1' is the default, and only supported method at this time)
     * @return {String} A string representing the hash value calculated from the source string.
     */
    String.prototype.hash = function(format, algo) {
            if (typeof format == "undefined" || format != "B64") { format = "HEX"; }
            algo = "SHA-1";
            var sha_ob = new jsSHA(algo, 'TEXT');
            sha_ob.setHMACKey(this, 'TEXT');
            return  sha_ob.getHMAC('HEX');
            // return hashobj.getHash(algo, format); // reserved for future extensions
    };


    /**

    I download latest version of sha1.js    from https://github.com/Caligatio/jsSHA/tree/master/dist

    Now it work after compile colector

    In collector, I use  this function this way in release.js

    var ToHashString="Something to hash"

    if (ToHashString) { e.CustomerVar54=ToHashString.hash()};

    I do not know if it is corect fix but it work.

    Also I still, I do not know what is in the rhino engine of sentinel responsible for collect al js file together there is one big file main.script but I do not know what is the process how it is in runtime created.