SvenTiigi / VanMoofKit

A Swift Package to communicate with a VanMoof S3 & X3 Bike 🚲
https://sventiigi.github.io/VanMoofKit/
MIT License
68 stars 8 forks source link

directly use encryption key #3

Closed kimbauters closed 1 year ago

kimbauters commented 1 year ago

Is your feature request related to a problem?

no

What solution would you like?

Identify if the app could work without touching VanMoof servers.

What alternatives have you considered?

none

Any additional context?

With VanMoof now filing for bankruptcy there is concern whether their servers will stay in the air. Tools such as https://github.com/grossartig/vanmoof-encryption-key-exporter allow you to safeguard your key.

Looking through the code VanMoof.Bike.Details has exactly these details. Would it be feasible to import an encryption key export JSON? From a quick glance it even looks like it could be directly decoded to the Details. Before I start rummaging around myself I just wanted to check if this is indeed a feasible approach or if there is something else that would require VanMoof server access.

SvenTiigi commented 1 year ago

Hi @kimbauters,

Thanks for the heads up! I wasn't aware of the current situation with VanMoof's possible bankruptcy.

To backup the access to your bike alongside with its encryption key you can easily encode the instance of a VanMoof.Bike and also decode it back.

// Retrieve all bikes on an authenticated instance of VanMoof
let bikes = try await vanMoof.bikes()

for bike in bikes {
    // Encode Bike to JSON Data
    let bikeJSONData = try JSONEncoder().encode(bike)
    // Optionally write data to file
    try bikeJSONData.write(to: URL(string: "..."))
    // Or decode it back from the data
    let decodedBike = try JSONDecoder().decode(Bike.self, from: bikeJSONData)
}

All other parts of the VanMoofKit doesn't require any kind of VanMoof server communication as the connection to the bike itself is established via Bluetooth Low Energy.

Also I might be adding an executable target to the VanMoofKit which can be executed on macOS to export the JSON and the Encryption Key similar to the vanmoof-encryption-key-exporter 🤔

kimbauters commented 1 year ago

Brilliant, I will have a go with the library over the weekend. Everything is very neatly structured so this should be easy :).

A macOS app would likely be helpful for some and would be easy to implement. It may not be a bad idea to stick to the same format as the other repository? It's just a JSON dump so should hopefully not be more than some rewording for some fields.

SvenTiigi commented 1 year ago

I've just added a small prototype (https://github.com/SvenTiigi/VanMoofKit/commit/8cd8e628bff1af9a59d07066b65a12ece13c1748) on the develop branch:

$ git clone -b develop https://github.com/SvenTiigi/VanMoofKit
$ cd VanMoofKit
$ swift run vanmoof export --username "knight.rider@vanmoof.com" --password "********"

After running the last command the export will be automatically saved at ~/Desktop For more information please see the updated README.md on the develop branch.

SvenTiigi commented 1 year ago

The VanMoofCLI is now available with the latest release 0.0.3 allowing to export the VanMoof account data.