I'm implementing a Mobile Server client using the Mobile Protocol docs but it's not clear how to extract the IV and Key from the PublicKey returned by the server for AES encryption of the username and password, does anyone have a complete example?

I’m referencing these 2 docs, which seem to contradict each other in terms of which bytes should be included in the IV and Key:

https://doc.developer.milestonesys.com/mipsdkmobile/reference/protocols/mobile_logon.html

https://doc.developer.milestonesys.com/mipsdkmobile/reference/protocols/mobile_appendix.html

Seeing a snippet of the server-side code may also help.

Hello Tom,

Let me clarify something - Mobile server does not return the actual public key for encryption. It returns, in this value, its version of the key that needs to be combine with the version of the client in order to have the real public key. For more details you can check the wiki - https://en.wikipedia.org/wiki/Diffie–Hellman_key_exchange

If you have already the public key containing the client and server version then you need to CryptoJS.enc.hex.parse as it is shown in the document here: https://doc.developer.milestonesys.com/mipsdkmobile/reference/protocols/mobile_logon.html . Then take the most significant (first) 16 bytes from the parsed string and this is your iv that can be used to encrypt other strings.

I hope this helps. If you have any other questions feel free to share them with us.

Hi Teodor, thanks for that. I do understand that the key returned by the server is used to generate the shared secret, which is then used to AES encrypt the username and password.

I think the challenge I have is that I’m doing this in Ruby, so the available libraries and default endianness are different.

I have now found the mobile SDK source code (e.g. https://doc.developer.milestonesys.com/mipsdkmobile/reference/WebSDKdoc/Lib_security_DiffieHellman.js.html) so I’ve got a reference implementation to work against. Although there are still a few inconsistencies between the docs and the code.

I’ll let you know how I get on, and ask follow up questions here if I get stuck again.