-
Notifications
You must be signed in to change notification settings - Fork 0
New provisioning format #43
Comments
New provisioning format: UPDATEDAll byte-orders is token = version(UnsignedByte:1)+expireDate(UnsignedInt:4)+cryptomoduleId(UnsignedByte:1)+seed(Byte:20)+name(Byte:6-50)+bankId(UnsignedByte:1)
token += checksum(token, length=4)
token = encrypt(token)
token = hexlify(token) // Convert to hex-string: 0-9a-f Example:
|
@pylover Thanks. Would you please put a mock-up token in hex format and each field values? I want to write a test based on this token. |
@pylover Where is IV? We need IV if you used CBC mode. |
Yes. Usually, we freeze our random function to return always the same result for IV, to pass our tests: def encrypt(self, data):
cipher = AESCipher(
self.secret,
random=cryptohelpers.random # Frozen
)
return cipher.encrypt(data) Is it ok to deliver these frozen bytes to you for testing purposes? |
class AESCipher(Cipher):
def __init__(self, key, random=os.urandom):
self.bs = 16
self.key = key
self.random = random
def encrypt(self, raw):
raw = self._pad(raw)
iv = self.random(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return iv + cipher.encrypt(raw)
def decrypt(self, enc):
iv = enc[:AES.block_size]
cipher = AES.new(self.key, AES.MODE_CBC, iv)
result = self._unpad(cipher.decrypt(enc[AES.block_size:]))
if not result.strip():
raise ValueError()
return result
def _pad(self, s):
remaining_bytes = len(s) % self.bs
padding_bytes = self.bs - remaining_bytes
return s + padding_bytes * bytes([padding_bytes])
@staticmethod
def _unpad(s):
return s[:-ord(s[len(s)-1:])]
|
A real-world example
After bundling:
After adding checksum
After encrypt with
|
@EhsanMashhadi please use this script: to ensure eveything is working: https://github.com/Carrene/mobile-token-isc/blob/master/production/test-script.sh |
@pylover Where is the IV in your provisioning format? Would you please add it to your table above? |
Please check my recent comment:
It will prepended to the token. |
Would you please add hex format of the result (last value) here too? |
@pylover Would you please describe your checksum calculation?
What does this code do? |
A real-world example(UPDATED after #78, Carrene/lion#14 token = version(UnsignedByte:1)+expireDate(UnsignedInt:4)+cryptomoduleId(UnsignedByte:1)+length(UnsignedByte:1)+timeInterval(UnsignedByte:1)+seed(Byte:20)+name(Byte:6-50)
token += checksum(token, length=4)
token = encrypt(token)
token = hexlify(token) // Convert to hex-string: 0-9a-f
After bundling:
After adding checksum
After encrypt with
|
The server is ready. Please test it by: #! /usr/bin/env bash
set -e
shopt -s expand_aliases
alias curl="curl -i -s --insecure"
HOST="192.168.1.57"
AGAMA="https://$HOST"
WOLF="http://$HOST:81"
LION="http://$HOST"
PHONE="98912145175"
UDID="2b6f0cc904d137be2e1730235f5664094b831186"
echo -n "Claiming device..."
curl -XCLAIM -s $AGAMA/apiv1/devices -F"phone=$PHONE" \
-F"udid=$UDID" 2>&1 > /dev/null
echo
echo "done"
echo -n "Finding last activation token..."
ACTIVATION_CODE=`curl $AGAMA | tail -n1 | cut -d',' -f2`
echo "done: $ACTIVATION_CODE"
echo -n "Bidning the device..."
curl -XBIND -s $AGAMA/apiv1/devices -F"phone=$PHONE" \
-F"udid=$UDID" \
-F"name=MytestDevice" \
-F"activationCode=$ACTIVATION_CODE"
echo
echo -n "Ensuring a token..."
curl 192.168.1.57:81/apiv1/tokens -XENSURE -F"phone=$PHONE" \
-F"name=MiladSibil" -F"cryptomoduleId=1" -F"expireDate=1572264891"
echo
echo "done"
|
|
The server just reply with phone = "192.168.1.57" otherwise I get {"stackTrace":"Traceback (most recent call last):\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/application.py\", line 108, in __call__\n response_body = self.__root__(*remaining_paths)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/restfulpy\/controllers.py\", line 21, in __call__\n return super().__call__(*remaining_paths)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/controllers.py\", line 110, in __call__\n return self._serve_handler(handler, remaining_paths)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/controllers.py\", line 104, in _serve_handler\n return handler(*remaining_paths, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/controllers.py\", line 110, in __call__\n return self._serve_handler(handler, remaining_paths)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/controllers.py\", line 104, in _serve_handler\n return handler(*remaining_paths, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/wolf\/controllers.py\", line 57, in __call__\n return super().__call__(*remaining_paths)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/controllers.py\", line 110, in __call__\n return self._serve_handler(handler, remaining_paths)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/controllers.py\", line 104, in _serve_handler\n return handler(*remaining_paths, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/decorators.py\", line 133, in wrapper\n result = func(*args, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/nanohttp\/validation.py\", line 313, in wrapper\n return func(*args, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/restfulpy\/orm\/models.py\", line 250, in wrapper\n result = func(*args, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/restfulpy\/orm\/__init__.py\", line 84, in wrapper\n result = func(*args, **kwargs)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/wolf\/controllers.py\", line 110, in ensure\n result['provisioning'] = token.provision(phone)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/wolf\/models.py\", line 114, in provision\n encrypted_binary = LionClient().encrypt(phone, binary, checksum=4)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/wolf\/backends.py\", line 47, in encrypt\n dict(data=data, checksumLength=checksum)\n File \"\/usr\/local\/lib\/python3.6\/site-packages\/wolf\/backends.py\", line 34, in _request\n raise SSMInternalError()\nwolf.exceptions.SSMInternalError: 802 SSM internal error\n"} |
This issue migrated to #86 |
We need to add version and checksum elements.
The text was updated successfully, but these errors were encountered: