aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-06-06 20:49:57 +0200
committerHarald Welte <laforge@osmocom.org>2023-06-08 17:29:46 +0200
commit75e31c5d5b5b20a669772f5c44e4416bfc79b5aa (patch)
treee70a4bb8cf1e0f3a05ac34248c4eac38f9022122 /tests
parent19b4a971e9405d047324922a160d0a976115c5ea (diff)
test_ota: Add one first OTA SMS AES128 unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ota.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test_ota.py b/tests/test_ota.py
index 277f178..c58a69d 100644
--- a/tests/test_ota.py
+++ b/tests/test_ota.py
@@ -4,6 +4,69 @@ import unittest
from pySim.utils import h2b, b2h
from pySim.ota import *
+# pre-defined SPI values for use in test cases below
+SPI_CC_POR_CIPHERED_CC = {
+ 'counter':'no_counter',
+ 'ciphering':True,
+ 'rc_cc_ds': 'cc',
+ 'por_in_submit':False,
+ 'por_shall_be_ciphered':True,
+ 'por_rc_cc_ds': 'cc',
+ 'por': 'por_required'
+ }
+
+SPI_CC_POR_UNCIPHERED_CC = {
+ 'counter':'no_counter',
+ 'ciphering':True,
+ 'rc_cc_ds': 'cc',
+ 'por_in_submit':False,
+ 'por_shall_be_ciphered':False,
+ 'por_rc_cc_ds': 'cc',
+ 'por': 'por_required'
+}
+
+SPI_CC_POR_UNCIPHERED_NOCC = {
+ 'counter':'no_counter',
+ 'ciphering':True,
+ 'rc_cc_ds': 'cc',
+ 'por_in_submit':False,
+ 'por_shall_be_ciphered':False,
+ 'por_rc_cc_ds': 'no_rc_cc_ds',
+ 'por': 'por_required'
+}
+
+
+class Test_SMS_AES128(unittest.TestCase):
+ tar = h2b('B00011')
+ """Test the OtaDialectSms for AES128 algorithms."""
+ def __init__(self, foo, **kwargs):
+ super().__init__(foo, **kwargs)
+ self.od = OtaKeyset(algo_crypt='aes_cbc', kic_idx=2,
+ algo_auth='aes_cmac', kid_idx=2,
+ kic=h2b('200102030405060708090a0b0c0d0e0f'),
+ kid=h2b('201102030405060708090a0b0c0d0e0f'))
+ self.dialect = OtaDialectSms()
+ self.spi_base = SPI_CC_POR_CIPHERED_CC
+
+ def _check_response(self, r, d):
+ self.assertEqual(d['number_of_commands'], 1)
+ self.assertEqual(d['last_status_word'], '6132')
+ self.assertEqual(d['last_response_data'], u'')
+ self.assertEqual(r['response_status'], 'por_ok')
+
+ def test_resp_aes128_ciphered(self):
+ spi = self.spi_base
+ r, d = self.dialect.decode_resp(self.od, spi, '027100002412b00011ebc6b497e2cad7aedf36ace0e3a29b38853f0fe9ccde81913be5702b73abce1f')
+ self._check_response(r, d)
+
+ def test_cmd_aes128_ciphered(self):
+ spi = self.spi_base
+ r = self.dialect.encode_cmd(self.od, self.tar, spi, h2b('00a40004023f00'))
+ self.assertEqual(b2h(r), '00281506192222b00011e87cceebb2d93083011ce294f93fc4d8de80da1abae8c37ca3e72ec4432e5058')
+
+
+
+
class Test_SMS_3DES(unittest.TestCase):
tar = h2b('b00000')
"""Test the OtaDialectSms for 3DES algorithms."""