예제 #1
0
    def tesla_key_verification(self,
                               key,
                               gst_wn,
                               gst_tow,
                               position,
                               svid=None):
        """Authenticates a TESLA key with the gst_wn and gst_tow from when it has been received.
        It also needs the position of the key in the mack block. The rest of the necessary data must
        be uploaded to the object before

        :param key: TESLA key to be authenticated
        :type key: BitArray

        :param gst_wn: Galileo Satellite Time Week Number of the TESLA key
        :type gst_wn: BitArray

        :param gst_wn: Galileo Satellite Time Time of Week of the TESLA key
        :type gst_wn: BitArray

        :param position: Position of the TESLA key inside the MACK keys
        :type position: int

        :param svid: Override the current svid
        :param svid: int

        :returns: Tuple with a bool that indicates if the key has been verified and its key index
        :rtype: tuple

        """

        if not svid:
            svid = self.svid

        alpha = self.OSNMA_data['alpha'].get_data()
        key_size = self.OSNMA_data['KS'].get_meaning()
        gst = gst_wn + gst_tow
        key_index = self.__get_key_index(gst, position, svid)
        new_keys_dict = {}

        new_keys_dict[key_index] = osnma_structures.KeyEntry(
            key_index, gst_wn, gst_tow, key)

        for index in reversed(range(key_index)):
            gst = self.__gst_subfragment(index)
            hash_object = hashlib.new(self.__HF)
            hash_object.update((key + gst + alpha).tobytes())
            prev_key = bs.BitArray(hash_object.digest())
            key = prev_key[:key_size]

            if index not in self.__key_table.keys():
                new_keys_dict[index] = osnma_structures.KeyEntry(
                    index, gst[:12], gst[12:], key)
            else:
                verified = (key == self.__key_table[index].key)
                break

        if verified:
            self.__key_table.update(new_keys_dict)

        return verified, key_index
예제 #2
0
    def load_floating_key(self, index, gst_WN, gst_TOW, key):
        """Loads a floating key of the chain to speed up chain authentication

        :param index: TESLA key index in the current chain.
        :type index: int

        :param gst_WN: GST Week Number where the key was transmited.
        :type gst_WN: BitArray

        :param gst_TOW: GST Time of the Week where the key was transmited.
        :type gst_TOW: BitArray

        :param key: TESLA key
        :type key: BitArray
        """
        self.__key_table[index] = osnma_structures.KeyEntry(
            index, gst_WN, gst_TOW, key)
예제 #3
0
    def load(self, field_name, data):
        """Load data to the OSNMa Field indicated. Also triggers secondary actions related to
        certain fields that modify the size of other fields or the use of certain funcions.

        :param field_name: Name of the OSNMA Field
        :type field_name: String

        :param data: Data of the field
        :type data: BitArray; formated String for bin, oct or hex
        """

        # Try to create a BitArray object with the data
        data = self.__convert_to_BitArray(data)

        current_field = self.OSNMA_data[field_name]
        current_field.set_data(data)

        # Secondary actions related to certain fields
        if current_field.name == 'KS':
            self.OSNMA_data['KROOT'].size = current_field.get_meaning()
        elif current_field.name == 'HF':
            self.__HF = current_field.get_meaning()
        elif current_field.name == 'MF':
            self.__MF = current_field.get_meaning()
        elif current_field.name == 'KROOT':
            entry_wn = self.OSNMA_data['KROOT_WN'].get_data()
            entry_tow = self.OSNMA_data['KROOT_TOWH'].get_data_uint(
            ) * 3600 - 30
            entry_tow = bs.BitArray(uint=entry_tow, length=20)
            self.__key_table[0] = osnma_structures.KeyEntry(
                0, entry_wn, entry_tow, data)
        elif current_field.name == 'NPKT':
            ds_alg = current_field.get_meaning()
            ds_alg_info = osnma_structures.pubk_lengths[ds_alg]
            self.OSNMA_data['DS'].size = ds_alg_info['signature']
            self.OSNMA_data['NPK'].size = ds_alg_info['npk']
예제 #4
0
 def load_floating_key(self, index, gst_WN, gst_TOW, key):
     """Loads a floating key of the chain to speed up chain authentication
     """
     self.__key_table[index] = osnma_structures.KeyEntry(
         index, gst_WN, gst_TOW, key)