Ejemplo n.º 1
0
 def concatenate(self, other_dataset):
     fft_c = concatenate(self.fft, other_dataset.fft)
     gyro_c = concatenate(self.gyro, other_dataset.gyro)
     lin_accel_c = concatenate(self.lin_accel, other_dataset.lin_accel)
     labels_gesture_detection_c = concatenate(
         self.labels_gesture_detection,
         other_dataset.labels_gesture_detection)
     labels_gesture_type_c = concatenate(self.labels_gesture_type,
                                         other_dataset.labels_gesture_type)
     return Dataset(fft_c, gyro_c, lin_accel_c, labels_gesture_detection_c,
                    labels_gesture_type_c)
Ejemplo n.º 2
0
 def data(self, excluded_session_ids=None):
     if excluded_session_ids is None:
         excluded_session_ids = []
     fft, gyro, lin_accel, labels_gesture_detection, labels_gesture_type = None, None, None, None, None
     for i in [
             i for i in range(len(self.sessions))
             if i not in excluded_session_ids
     ]:
         s_fft, s_gyro, s_lin_accel, s_labels_gesture_detection, s_labels_gesture_type = self.sessions[
             i].data()
         fft = concatenate(fft, s_fft)
         gyro = concatenate(gyro, s_gyro)
         lin_accel = concatenate(lin_accel, s_lin_accel)
         labels_gesture_detection = concatenate(labels_gesture_detection,
                                                s_labels_gesture_detection)
         labels_gesture_type = concatenate(labels_gesture_type,
                                           s_labels_gesture_type)
     return fft, gyro, lin_accel, labels_gesture_detection, labels_gesture_type
Ejemplo n.º 3
0
 def data(self, excluded_participants=None):
     if excluded_participants is None:
         excluded_participants = []
     fft, gyro, lin_accel, labels_gesture_detection, labels_gesture_type = None, None, None, None, None
     for participant in [
             participant for participant in self.participants
             if participant not in excluded_participants
     ]:
         p_fft, p_gyro, p_lin_accel, p_labels_gesture_detection, p_labels_gesture_type = participant.data(
         )
         fft = concatenate(fft, p_fft)
         gyro = concatenate(gyro, p_gyro)
         lin_accel = concatenate(lin_accel, p_lin_accel)
         labels_gesture_detection = concatenate(labels_gesture_detection,
                                                p_labels_gesture_detection)
         labels_gesture_type = concatenate(labels_gesture_type,
                                           p_labels_gesture_type)
     return fft, gyro, lin_accel, labels_gesture_detection, labels_gesture_type
Ejemplo n.º 4
0
 def manage_request(self, data):
     # quello che mi arriva  è del tipo [OPCODE|S|C|sito|...|nonce|hash]kcs | IV   
     unpacked_data = utility.unpack_message(data, 4)
     if(unpacked_data is None or len(unpacked_data) != 2):
         utility.print_user_log(self.client_address,"Bad packet format")
         return (False, 109)
     encrypted_data , IV = unpacked_data
     decrypted_data = utility.decrypt_AES(encrypted_data, self.session_key, IV)
     if decrypted_data is None:
         return (False, 102)
     #print decrypted_data
     decrypted_fields = utility.unpack_message(decrypted_data, 4)
     if decrypted_data is None:
         utility.print_user_log(self.client_address,"Bad packet format")
         return (False, 109)
     data_to_hash = ''.join(decrypted_fields[:-1])
     hashed_data_c = decrypted_fields[-1]
     hashed_data = utility.get_hash(data_to_hash)
     ret = utility.secure_cmp(hashed_data_c, hashed_data)
     utility.print_user_log(self.client_address,"Request: %s" % decrypted_fields[0])
     if ret is False:
         print hexlify(hashed_data_c)
         print hexlify(hashed_data)
         utility.print_user_log(self.client_address,"Different hashes")
         return (False, 103)
     #print fields
     nonce = decrypted_fields[-2]
     if nonce in self.nonces:
         utility.print_user_log(self.client_address, "No fresh nonce!!")
         return (False, 104)
     self.nonces.append(nonce)
     #print fields
     
     #execute query
     response_fields = self.execute_query(decrypted_fields[:-2])   # è una lista [:-2] tutto tranne nonce hash
     
     response_fields.append(nonce) # aggiungo nonce alla lista
     response = utility.concatenate(*response_fields)
     hashed_response = utility.get_hash(response)               
     #print "hash,", hashed_response
     #data_to_pack = utility.concatenate((response, hashed_response)) # concateno hash alla risposta
     response_fields.append(hashed_response)
     #print "RF: ",response_fields
     packed_message = utility.pack_message(*response_fields)
     #print packed_message
     IV = os.urandom(16)
     data_to_send = utility.encrypt_AES(packed_message, self.session_key, IV)
     if data_to_send is None:
         return (False, 106)
     data_to_send = utility.pack_message(data_to_send, IV)
     #print "DATA TO SEND \n", data_to_send
     #un = utility.unpack_message(data_to_send, 4)
     #print "ENC",un[0]
     #print "IV", un[1]
     utility.print_user_log(self.client_address, 'Response: '+ response_fields[0])
     return (True, data_to_send)
Ejemplo n.º 5
0
    def message_M4(self, nonce_prot_c):
        utility.print_user_log(self.client_address,'Sending M4...')

        hash_nonce_c = utility.get_hash(nonce_prot_c)
        data_to_pack = utility.concatenate('100', self.server_ID, self.client_ID, hash_nonce_c)
        hash_data = utility.get_hash(data_to_pack)
        data = utility.pack_message('100', self.server_ID, self.client_ID, hash_nonce_c, hash_data)
        IV = os.urandom(16)
        enc_data = utility.encrypt_AES(data, self.session_key, IV)
        if enc_data is None:
            utility.print_user_log(self.client_address, '[ERROR] Error during encryption')
            return None
        data_to_send = utility.pack_message(enc_data, IV)
        return data_to_send