×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    25

    Calculation of MAC in the WSP header

    Hi Traud,

    In the S40 OMA client Provisioning doc, page 36 of Appendix B, the MAC value is mentioned as "4430453033344330383634453545373244464541
    3645334234333032324133324232333941463736"

    Could you please explain how this was arrived at? What was the bootstrap document in this case and what was the pin considered?

    Also is the MAC always based on the SHA-1 algorithm or could it also be based on the MD5 algorithm? (This is because the SyncML server I am using uses md5 authentication.

    Regards,
    Vinay

  2. #2
    Registered User
    Join Date
    Aug 2008
    Posts
    25

    Re: Calculation of MAC in the WSP header

    Hi,

    Could anyone get back to me on this; calculation of MAC value in the WSP header of a binary message.

    -Vinay

  3. #3
    Registered User
    Join Date
    Aug 2004
    Location
    Hyderabad,India
    Posts
    808

    Re: Calculation of MAC in the WSP header

    hi,

    MAC is calculated as below

    Get MAC value of WBXML(converted as string) using HmacSHA1(20 bytes) and transcode it into HEX format(40 chars).

    Again get hex string of above HEX format which will not give 80 chars string.

    All the best.

    Regards,
    Sudhakar
    Regards,
    Sudhakar

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    25

    Re: Calculation of MAC in the WSP header

    Hi Sudhakar, Theoretically I understood that. But could you please explain this with the example in the S40 client provisioning document. Could you point out what was the WBXML data used to generate the MAC? Because when I used the WBXML data shown in the doc with a user pin of 1234, I did not receive the MAC value shown: "4430453033344330383634453545373244464541
    3645334234333032324133324232333941463736"

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    3

    Re: Calculation of MAC in the WSP header

    Hi,

    Sorry to hijack your thread but I'm trying to do the same thing and have problems generating the mac when I use a PIN. I understand the principal of what I'm supposed to do but am having problems generating the MAC

    I'm using PHP as my dev language and am not sure exactly what should be the input into the hmac function

    So I have

    hash_hmac('sha1', $wbxml, $pin);

    Does anyone know what format the wbxml and pin should be in i.e. hex (0x030x01...), hex as string (0301...) or should they be in another format?

  6. #6
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,104
    In question 9, the Nokia document mentions a third-party tool (for Windows). I recommend to start with that. Its result must be converted into hex than.

    2sents, the authentication mechanism of your OMA SyncML DS server has nothing to do with the MAC header of your configuration SMS.

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    25

    Re: Calculation of MAC in the WSP header

    Thank you Traud. I think I missed converting the result of 'HashCalc' back to Hex.
    But what is the key that was used in the example?

  8. #8
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,104
    If I recall correctly, it is 1234. Are you sure you removed all line endings and saved the WBXML as binary and not in its hex presentation?

  9. #9
    Registered User
    Join Date
    Aug 2008
    Posts
    25

    Re: Calculation of MAC in the WSP header

    Hi Traud,

    After repeated attempts, I am unable to calculate the MAC according to the S40 client provisioning document. I would request for your guidance on a step to step basis. Below is what I did:

    1. I considered the below XML:

    <?xml version="1.0"?>
    <!DOCTYPE wap-provisioningdoc PUBLIC "-//WAPFORUM//DTD PROV 1.0//EN" “http://www.wapforum.org/DTD/prov.dtd">
    <wap-provisioningdoc version="1.0">
    <characteristic type="NAPDEF">
    <parm name="NAPID" value="inet"/>
    <parm name="NAME" value="InternetNAPDEF"/>
    <parm name="BEARER" value="GSM-GPRS"/>
    <parm name="NAP-ADDRESS" value="internet"/>
    <parm name="NAP-ADDRTYPE" value="APN"/>
    <parm name="INTERNET"/>
    </characteristic>
    <characteristic type="APPLICATION">
    <parm name="APPID" value="w2"/>
    <parm name="TO-NAPID" value="inet"/>
    <characteristic type="RESOURCE">
    <parm name="URI" value="http://wap.krak.dk"/>
    <parm name="STARTPAGE"/>
    </characteristic>
    </characteristic>
    <characteristic type="BOOTSTRAP">
    <parm name="NAME" value="Sonofon Browser"/>
    </characteristic>
    </wap-provisioningdoc>

    2. I converted this into WbXML as below:

    030B6A05 696E6574 00C54601 C6550187 ..j. inet ..F. .U..
    11068300 01870706 03496E74 65726E65 .... .... .Int erne
    744E4150 44454600 01871006 AB018708 tNAP DEF. .... ....
    0603696E 7465726E 65740001 87090689 ..in tern et.. ....
    01871401 01C60001 55018736 00000603 .... .... U..6 ....
    77320001 87220683 0001C600 01590187 w2.. .".. .... .Y..
    3A000006 03687474 703A2F2F 7761702E :... .htt p:// wap.
    6B72616B 2E646B00 01871C01 0101C656 krak .dk. .... ...V
    01870706 03536F6E 6F666F6E 2042726F .... .Son ofon Bro
    77736572 00010101 wser ....
    Series

    3. I saved this wbxml as a binary file (i.e. as a example.wbxml file itself)

    4. I used SlavaSoft's HashCalc

    5. With the example.wbxml file as my data input, and with a key of 1234 in text string, I generated the SHA 1 MAC as: 2df4234ad69b6c63a1d2680625211d2abf221213

    6. I converted this into Hex as: 32646634323334616436396236633633613164323638303632353231316432616266323231323133

    Now this is nowhere close to what the S40 document mentions the MAC as which is 4430453033344330383634453545373244464541
    3645334234333032324133324232333941463736

    Could you please tell me how I can calculate MAC?

    Regards,
    2sent

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    18

    Re: Calculation of MAC in the WSP header

    If you're using java ..

    Code:
    public static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
    
    byte[] getMac(byte[] data, String key){
      byte[] result;
      byte[] keyBytes = key.getBytes();
    
      javax.crypto.spec.SecretKeySpec signingKey = new javax.crypto.spec.SecretKeySpec(keyBytes, HMAC_SHA1_ALGORITHM);
      javax.crypto.Mac mac = javax.crypto.Mac.getInstance(HMAC_SHA1_ALGORITHM);
      mac.init(signingKey);
      byte[] rawHmac = mac.doFinal(data);
      byte[] k_result = rawHmac;
      if(k_result != null){
         result = String.copyValueOf(org.apache.commons.codec.binary.Hex.encodeHex(k_result)).getBytes();
      }
      
      return result;
    }
    Give that a go, hope it helps

    er the data passwed is the wbxml in byte[] and the key is the pin you want
    Last edited by Balmark; 2009-05-25 at 12:35.

  11. #11
    Registered User
    Join Date
    Aug 2008
    Posts
    25

    Re: Calculation of MAC in the WSP header

    Thank You Balmark.
    Do you also have the Java code to convert xml to WbXML? I would like that since my current java implementation using the kxml library is not giving the desired output. I presume the kxml library is not complete.
    Could you help me out here?

    Regards,
    Vinay

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    18

    Re: Calculation of MAC in the WSP header

    Not sure I'd be any help, atm what I've done, I dont have alot of confidence in.. demo + time pressure thing

    just ran through the kxmlparser and generated hex based on tag/attrib/value arrays

    like tag list is like for the nokia ericsson standard:
    TAG_TABLE = new Hashtable<String, String>();
    TAG_TABLE.put("characteristic-list", "05");
    TAG_TABLE.put("characteristic", "06");
    TAG_TABLE.put("parm", "07");

    for parsing,
    have 2 page attribute lists (ie. 2 seperate tables, 1 for page1, 1 for page2 )and a value list
    (if the attrib is on page 2, you've to add some hex to tell the wbxml decoder on the phone its working off page 1, then when you go back to page 1, another tag to tell it its no longer on page 2)

    no idea if it works for most cases.. I've havent catered for any different versions (could just throw in dif tables for each version)

Similar Threads

  1. Recording in Amr Format
    By losym in forum Symbian Media (Closed)
    Replies: 12
    Last Post: 2009-03-26, 06:41
  2. OMA OTA Settings - WSP Header?
    By wanner in forum OMA DM/DS/CP
    Replies: 2
    Last Post: 2009-03-05, 09:24
  3. WAP upload / Content-Type header is lost at WAP gateway
    By rabai in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2004-02-24, 11:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •