Skip to content

Commit

Permalink
Add Account-Id HTTP header (user Id's SHA256) required by LLU 4.11
Browse files Browse the repository at this point in the history
If you set “4.11.0” as the LibreLinkUp version in the Developer Settings, you receive the reply `{“message":"RequiredHeaderMissing”}` (status 400) since the recent update of the last week requires a new `Account-Id` HTTP header and you have to pass the SHA256 digest of `libreLinkUpId` as a 64-char hexadecimal string.
  • Loading branch information
gui-dos committed Jul 12, 2024
1 parent 132b14a commit 13e4a1e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xdrip/Constants/ConstantsLibreLinkUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
enum ConstantsLibreLinkUp {

/// string to hold the default LibreLinkUp version number
static let libreLinkUpVersionDefault: String = "4.7.0"
static let libreLinkUpVersionDefault: String = "4.11.0"

/// double to hold maximum sensor days for Libre sensors that upload to LibreLinkUp
/// currently easy as they are all the same at 14 days exactly (LibreLink doesn't upload the extra 12 hours)
Expand Down
5 changes: 5 additions & 0 deletions xdrip/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ extension String {
// sha1() here is a function in CryptoSwift Library
return Data(self.utf8).sha1().hexEncodedString()
}

func sha256() -> String {
// sha256() here is a function in CryptoSwift Library
return Data(self.utf8).sha256().hexEncodedString()
}

/// creates uicolor interpreting hex as hex color code, example #CED430
func hexStringToUIColor () -> UIColor {
Expand Down
2 changes: 2 additions & 0 deletions xdrip/Managers/LibreLinkUp/LibreLinkUpFollowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ class LibreLinkUpFollowManager: NSObject {
// this is pretty much the same request as done in requestLogin()
var request = URLRequest(url: url)
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
request.setValue((libreLinkUpId ?? "").sha256(), forHTTPHeaderField: "Account-Id")

for (header, value) in libreLinkUpRequestHeaders {
request.setValue(value, forHTTPHeaderField: header)
Expand Down Expand Up @@ -627,6 +628,7 @@ class LibreLinkUpFollowManager: NSObject {
// this is pretty much the same request as done in loginRequest()
var request = URLRequest(url: url)
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
request.setValue((libreLinkUpId ?? "").sha256(), forHTTPHeaderField: "Account-Id")

for (header, value) in libreLinkUpRequestHeaders {
request.setValue(value, forHTTPHeaderField: header)
Expand Down

2 comments on commit 13e4a1e

@HoLi1969
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be implemented in the next nightly of xDrip? Sadly I have no idea how to change it in my phone.

@gui-dos
Copy link
Contributor Author

@gui-dos gui-dos commented on 13e4a1e Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HoLi1969:

Note that the latest version of LibreLinkUp 4.12.0 must be specified now.

This is the beauty of open-source you can enjoy on iOS: the Swift implementation of the native algorithms to decrypt Libre 2's NFC/BLE data match Android's ones but its code is available at full while on xDrip+ you have to beg for invitations to access the private forums where the OOP2.apk and the external WebFollower implementations are discussed... :-P

Please sign in to comment.