How to set MAC in bitmap but value in field

380 views
Skip to first unread message

Bjarne Henriksen

unread,
Dec 10, 2013, 8:06:49 AM12/10/13
to jpos-...@googlegroups.com
Hi

I need to calculate the mac for a message.
But I'm struckling a bit as the bitmap has to include mac field but no value should be set on the field.

How do I do that?

Best regards
Bjarne


Alejandro Revilla

unread,
Dec 10, 2013, 8:32:10 AM12/10/13
to jPOS Users

In the implementations I’ve been involved, I solved the problem by setting the MAC fields with a dummy place holder, and then adjusting it in an ISOFilter.

i.e. the filter would use code like this:

    public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt)
        throws VetoException
    {
        try {
            m.set (128, sm.generateEDE_MAC (generateMockImage(channel, m), tak));
        } catch (ISOException e) {
            evt.addMessage (e);
            throw new VetoException (e);
        }
        return m;
    }

    private byte[] generateMockImage (ISOChannel channel, ISOMsg m)
        throws ISOException
    {
        byte[] msg = m.pack();

        int offset = 4 + (m.getMaxField() > 64 ? 16 : 8);

        ByteBuffer buf = ByteBuffer.allocate (msg.length - offset);
        buf.put (msg, offset, msg.length - offset);

        return buf.array();

    }

Hope this helps.

--
@apr


--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/cd023b7d-8919-4f5f-80f7-54316c27ef3f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bjarne Henriksen

unread,
Dec 10, 2013, 9:09:40 AM12/10/13
to jpos-...@googlegroups.com
Alejandro,

thanks for your quick reply:)

The way I read your code your mock-method returns method without mac and without bitmap.
I need the message without the mac but with the bitmap and the mac-bit set.

But your solution made me think a little, and I think I can do it by packing the message and copy the byte array excluding the last 4 (for this implementation) bytes:)


/Bjarne

Alejandro Revilla

unread,
Dec 10, 2013, 10:21:37 AM12/10/13
to jPOS Users

But your solution made me think a little, and I think I can do it by packing the message and copy the byte array excluding the last 4 (for this implementation) bytes:)

Exactly. You set a dummy MAC field so that jPOS properly sets the bitmap, then you don’t take that last part into account when computing the MAC. Good luck!




--
@apr


chhil

unread,
Dec 10, 2013, 10:31:12 AM12/10/13
to jpos-users
Just curious, why cant we set the mac field as an empty string, this would set the bitmap.
Calculate the MAC and then put it in that field.

-chhil


Alejandro Revilla

unread,
Dec 10, 2013, 10:49:02 AM12/10/13
to jPOS Users
Your approach could do if you trick the packager into using IF_NOP, but if we have a say 8-bytes binary field packager, I'm afraid the empty string approach wouldn't work.

But your idea is good Murtuza, perhaps we can change IFB_BINARY to accept a configuration parameter, or create a new binary field packager that could produce no output for a zero-length byte array.


--
@apr


chhil

unread,
Dec 10, 2013, 10:56:59 AM12/10/13
to jpos-users

On Tue, Dec 10, 2013 at 9:49 AM, Alejandro Revilla <a...@jpos.org> wrote:
create a new binary field packager that could produce no output for a zero-length byte array.


I like this approach.

luo...@peacesoft.net

unread,
Apr 13, 2016, 11:10:43 PM4/13/16
to jPOS Users
What about we change the BITMAP manually?
Ex: if the field is 64, which is in the last byte of bitmap, then change the 9th byte ( we count 2 bytes of MIT )

packedMsg[9] = (byte) (packedMsg[9] ^ 0x01); 

Alejandro Revilla

unread,
Apr 14, 2016, 9:06:37 PM4/14/16
to jPOS Users
You can set a dummy value (i.e. 8 zeroes), compute MAC (excluding the last 8 bytes), and then properly set that field.




--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages