mrmay-dev / owntags

Ⓣ OwnTags is an OwnTracks client for tracking your own 'AirTags' 🏷 made with OpenHaystack.
11 stars 5 forks source link

Error with `OUTPUT_FOLDER = Configuration[“owntag_options“][“output_folder "]` #3

Closed mrmay-dev closed 1 year ago

mrmay-dev commented 1 year ago

error first reported here

As a quick look, line 18:

OUTPUT_FOLDER = Konfiguration["owntag_options"]["output_folder"]`

This tells the script where to find the .keyfiles. I'm poking at this now and looking at what I'm using now to update/fix this.

mrmay-dev commented 1 year ago

Here's a quick-fix for the issue. I'll update the repo after checking for other bugs.

Make sure the .keys files are in a directory called keys under the application folder. Like this:

owntags/
└── application/
    └── keys/
        ├── prefix-1.keyfile
        └── prefix-2.keyfile

Now, edit line 18.

REMOVE this line:

REPLACE IT with this one:

Let me know if the change works for you.

23tom2323 commented 1 year ago

Thanks for progressing the project. I made the changes...

python3 request_reports.py
Traceback (most recent call last):
  File "/Users/Downloads/OwnTracks/owntags-main/application/request_reports.py", line 13, in <module>
    from apple_cryptography import *
  File "/Users/Downloads/OwnTracks/owntags-main/application/apple_cryptography.py", line 19, in <module>
    from OwnTags_plugin import get_configuration
  File "/Users/Downloads/OwnTracks/owntags-main/application/OwnTags_plugin.py", line 7, in <module>
    import paho.mqtt.publish as publish
ModuleNotFoundError: No module named 'paho'
python3 owntags.sh 
  File "/Users/Downloads/OwnTracks/owntags-main/owntags.sh", line 5
    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
                       ^
SyntaxError: invalid syntax

Hope this helps. You need a coffee cash register :-)

Systm21 commented 1 year ago

fixed in https://github.com/mrmay-dev/owntags/pull/4

Systm21 commented 1 year ago

Thanks for progressing the project. I made the changes...

python3 request_reports.py
Traceback (most recent call last):
  File "/Users/Downloads/OwnTracks/owntags-main/application/request_reports.py", line 13, in <module>
    from apple_cryptography import *
  File "/Users/Downloads/OwnTracks/owntags-main/application/apple_cryptography.py", line 19, in <module>
    from OwnTags_plugin import get_configuration
  File "/Users/Downloads/OwnTracks/owntags-main/application/OwnTags_plugin.py", line 7, in <module>
    import paho.mqtt.publish as publish
ModuleNotFoundError: No module named 'paho'

You have to install Paho-mqtt. pip3 install paho-mqtt

python3 owntags.sh 
  File "/Users/Downloads/OwnTracks/owntags-main/owntags.sh", line 5
    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
                       ^
SyntaxError: invalid syntax

owntags.sh is a Shell file, not python, syntax is : ./owntags.sh

mrmay-dev commented 1 year ago

@Systm21 got it. I didn't pull it directly from your request... but (noob problem) didn't know how to just pull an item or two from the changes you proposed. I'm learning. :)

23tom2323 commented 1 year ago

I made the changes...

python3 request_reports.py
2023 Sep 12 (Tue) 08:04:37
Using python3
Days: 0, Hrs: 0, Min: 60
Traceback (most recent call last):
  File "/Users/Downloads/OwnTracks/owntags-main/application/request_reports.py", line 62, in <module>
    iCloud_decryptionkey = args.key if args.key else retrieveICloudKey()
                                                     ^^^^^^^^^^^^^^^^^^^
  File "/Users/Downloads/OwnTracks/owntags-main/application/apple_cryptography.py", line 58, in retrieveICloudKey
    db_key = unpad(decrypt(db_key_enc, algorithms.TripleDES(master_key), modes.CBC(db_key_IV)), algorithms.TripleDES.block_size)[:24]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Downloads/OwnTracks/owntags-main/application/apple_cryptography.py", line 41, in unpad
    return unpadder.update(paddedBinary) + unpadder.finalize()
                                           ^^^^^^^^^^^^^^^^^^^
  File "/Users/Library/Python/3.11/lib/python/site-packages/cryptography/hazmat/primitives/padding.py", line 160, in finalize
    result = _byte_unpadding_check(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Library/Python/3.11/lib/python/site-packages/cryptography/hazmat/primitives/padding.py", line 102, in _byte_unpadding_check
    raise ValueError("Invalid padding bytes.")
ValueError: Invalid padding bytes.
mrmay-dev commented 1 year ago

This error looks like what you get when the password is missing or wrong in the settings.toml. Try the version just uploaded and create a new settings.toml by copying the settings-template.toml and filling in the details.

Check out the README.md on the repo's front page for more instructions.

Also, update the Python libraries. The cryptography is super important.

pip install --upgrade pip
pip install pyobjc cryptography six paho-mqtt 
Systm21 commented 1 year ago

...also please use updated files in repo, can have something todo with the old toml problem.

23tom2323 commented 1 year ago

Found a mistake in mine: Oh man. The settings-template.toml also clearly states Password macOS/computer…. I had the iCloud password in there. 😕 Now comes:

./owntags.sh 24:00
2023 Sep 12 (Tue) 16:14:35
Using python3
Days: 0, Hrs: 24, Min: 0
500 Internal Server Error

        HELP: This error is generally happens when something is wrong with the request.
        Usually no keys were requested, meaning the keys folder is probably empty. 

Traceback (most recent call last):
  File "/Users/maquis/Downloads/owntags-main_12-09-2023_V2/application/request_reports.py", line 124, in <module>
    raise Exception(response_status)
Exception: (500, 'Internal Server Error')
-- END SCRIPT --

I think the problem could be the keys.

I added the car1.keyfile and the private key B64 to the /owntags/application/keys/ folder. (OpenHaystack with right click on the tracker -> Copy private key B64)

The content of my car1.keyfile is one line: VcD4QkiUJeYVBZHmCNSROkXk9CjApDmU0WEq2w== (This is not the original private key B64 just an example)

Is the car1.keyfile correct?

My settings.toml :

-- INSTRUCTIONS --

Make a copy of this file and rename it settings.toml.

add information about your system, MQTT broker, OwnTracks setup.

Create a new settings block for each tag.

[owntag_options] password = "XXXXXX" # macOS/computer password print_history = 1

positive numbers (4), the number of messages you want to see

# negative numbers (-1) will print all fetched locations,
# 0 will turn printing fetched locations off

status_msg = false # publish status and metadata

Status messages can be sent to an MQTT Topic

status_base = "status/owntags" # topic for status messages

[mqtt_secrets]

mqtt_broker = "192.168.1.86" # broker address mqtt_port = 1884 # 1883 if no TLS; 8883 if TLS mqtt_user = "USER" # Broker user mqtt_pass = "PWD" # Broker password

MQTT options for using TLS. No changes needed if your server is not using TLS.

mqtt_tls = "None" # To use TLS comment out this line by putting a '#' in front of it.

Uncomment these lines and adjust to your needs

[mqtt_secrets.mqtt_tls]

ca_certs = "keys/isrgrootx1.cer" # cert location, the 'keys' folder is a good place

# download HiveMQ certificate: https://community.hivemq.com/t/frequently-asked-questions/514
# create users at https://console.hivemq.com

[owntracks_options] owntracks_device = "owntracks/phone" # user Topic Base of your phone or device with owntracks, used for waypoints owntags_base = nan # topic base for tags. If nan owntracks_device will be used.

Each tag can be configured to appear as 'waypoints' on your device only, or as 'locations' that are shared

with other users. 'locations' are easier to start with.

OwnTags can share the tag as both, odd things will happen and be prepared for some challenges.

[tag_options.prefix]

tag_name = "prefix" # the prefix of your key

location = true # (not required) locations are seen by everyone with access to the topic (they act like users)

waypoint = false # (not required) waypoints are only seen on your phone (or device)

timestamp = 1000000001 # (required for wayponts) Must be unique, can be any past Unix/Posix timestamp.

radius = false # (not required) use number for radius in meters, if false turn off, if true use confidence

[tag_options.car1] tag_name = "car1"
location = true waypoint = false
timestamp = 1000000001
radius = false

[tag_options.car2] tag_name = "car2"
location = true waypoint = false
timestamp = 1000000002
radius = false

[tag_options.unicorn] tag_name = "unicorn"
location = true waypoint = false
timestamp = 1000000003
radius = false

[tag_options.dragon] tag_name = "dragon"
location = true waypoint = false
timestamp = 1000000004
radius = false

Advance Features

tag_image = nan # base 64 encoded, 200x200, PNG or JPEG image mqtt_topic = nan # (not required) topic for this tag, if nan owntags_base will be used status_topic = false # (not required) if True messages will be published to status_base/prefix

Systm21 commented 1 year ago

The keys must be converted to the format, which is used in the headless-haystack project.

23tom2323 commented 1 year ago

I can create new keys using headless-haystack (generate_keys.py)

The result would be: SROSOM_keyfile SROSOM_devices.json SROSOM.keys

Is the SROSOM.keys file the correct format? Then I would feed them my data.

Systm21 commented 1 year ago

.keys, yes