Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature that generate mac in ISO8583 Crypto PreProcessor UI based on specific fields #87

Open
mehrdad2000 opened this issue Apr 9, 2024 · 6 comments

Comments

@mehrdad2000
Copy link

mehrdad2000 commented Apr 9, 2024

Hi
Would you please add feature that generate mac in ISO8583 Crypto PreProcessor UI based on specific fields.

E.g. fields: 0,2,11,12,47
concat these fields and based on these fields generate mac.

Any idea?
Thanks

@mehrdad2000 mehrdad2000 changed the title feature that add generate mac in ISO8583 Crypto PreProcessor UI base on specific fields feature that generate mac in ISO8583 Crypto PreProcessor UI base on specific fields Apr 9, 2024
@mehrdad2000 mehrdad2000 changed the title feature that generate mac in ISO8583 Crypto PreProcessor UI base on specific fields feature that generate mac in ISO8583 Crypto PreProcessor UI based on specific fields Apr 9, 2024
@tilln tilln added the enhancement New feature or request label Apr 12, 2024
@tilln
Copy link
Owner

tilln commented Apr 12, 2024

Hi @mehrdad2000

Thanks for bringing this up.
I had not been aware there are messaging specs out there with MACs of only parts of the message.

Here is a work-around you can try:
Under your "ISO8583 Sampler", use a JSR223 PreProcessor with code like the below which should work assuming you include only "top-level" fields.

Note this avoids creating multiple instances of the MAC key and SecurityModule by caching a closure in a JMeter variable.

if (!vars.getObject('addMac')) {
    def macKey = new javax.crypto.spec.SecretKeySpec(
        org.jpos.iso.ISOUtil.hex2byte('1A1A1A1A1A1A1A1A1A1A1A1A1A1A1A1A'), 'ISO9797ALG3')
    def ssm = new nz.co.breakpoint.jmeter.iso8583.SecurityModule()

    vars.putObject('addMac', { sampler ->
        def msg = sampler.getRequest()
        def p = msg.getPackager()

        def bytes = [0,2,11,12,47].collect {
            p.getFieldPackager(it).pack(msg.getComponent(it))
        }.flatten() as byte[]

        sampler.addField('64', ssm.generateMAC(bytes, macKey, macKey.getAlgorithm()))
    })
}
vars.getObject('addMac').call(sampler)

Implementing this properly may be a bit more complicated to deal with the more general case of nested/subfields.

@mehrdad2000
Copy link
Author

mehrdad2000 commented Apr 13, 2024

@tilln I try this but encounter with strange issue, I just want to concat these fields "data", but seems after packed add size of first field in start of "bytes", so i change this line from this:

            p.getFieldPackager(it).pack(msg.getComponent(it))

to this:

          msg.getComponent(it).getValue().getBytes()

after that field 11,37 are not same as what generate by sampler! all other part of message same!
seems not use of field 11,37 sampler value and instead generate new one!

image

FYI1: these fields generate by random function ${__Random(111111111111,999999999999,)}

FYI2: for debug issue add this line:

        log.info("bytes as text=${new String(bytes)}");  // Log bytes as text

@tilln
Copy link
Owner

tilln commented Apr 14, 2024

@mehrdad2000

I have experienced this issue myself after upgrading to JMeter v5.6 where JMeter seems to evaluate function expressions such as ${__Random()} multiple times.
This apparently happens when a sampler property that contains a function is accessed more than once.

However, it is not an issue with this plugin.

The attached script demonstrates this with a single HTTP Sampler: jmeter-regression-v5.6.jmx.txt

Running this with -Lorg.apache.jmeter.functions=DEBUG will show that the function is invoked once with JMeter v5.5 but multiple times as of v5.6

I have not had time to investigate or log a JMeter bug so feel free to do that.

As a work-around you can assign the random function output to a JMeter variable first and put that variable in the sampler.

@tilln
Copy link
Owner

tilln commented Apr 14, 2024

Before implementing this feature, I would need to understand what options to consider, such as list of input fields, how they are supposed to be combined to form the input bytes for the MAC calculation, e.g. packed by the packager or not, padded or not, with or without length and/or tag prefixes, etc.

As there are so many variations (and I don't know all of them yet) I think it may be easier to use some custom code as the above than to capture all the options in the "ISO8583 Crypto PreProcessor" configuration. Happy to make changes to expose additional methods to access the Sampler and/or Preprocessor instances/properties.

@mehrdad2000
Copy link
Author

mehrdad2000 commented Apr 14, 2024

@tilln
1-ok thanks report jmeter issue here
2-I just need to use pure data of these fields without any padding or prefix etc.
3-i'm using 5.6.2 currently do you try 5.6.3? latest version of jmeter has this this issue?

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants