Loksi 2026.10.0 : source correspondante des quatre applis

Export du dépôt interne d'Aleop, révision 0936ea1 (fichiers publiés identiques à e46bc12).
Paquets construits depuis cette source :
- Android : AAB 2026.10.0, code 4
- iPhone : archive 2026.10.0 (18)
- Bureau : macOS universel build 13, Windows build 14, MSIX build 15
- Extensions Chrome, Edge et Firefox : 2026.10.0.3
Cette révision appartient à :
Aleop a révisé 2026-10-12 17:04:06 +02:00
1 Parent c3608b3938
révision 1c39f76f96
34 fichiers modifiés
+5093 -15

Aucun fichier ne correspond à votre recherche

+95
Voir le fichier
@@ -0,0 +1,95 @@
// GPL-3.0-only. Loksi: vault name or address entered at login (decision of 04/10/2026).
// Copied by mobile/ios/loksi.py into BitwardenShared. Same rule as the Loksi browser
// extension (extensions/loksi-coffre.ts) and the Android app (LoksiVault.kt).
import Foundation
/// Loksi: turns what the user typed into a vault address, and checks that a vault answers.
///
enum LoksiVault {
/// Domain of the Loksi vaults. The vault name "abc" gives https://abc.loksi.fr.
static let domain = "loksi.fr"
/// The name chosen in the order funnel: 2 to 20 lowercase letters or digits, a hyphen
/// allowed but neither first nor last. Never interpolated as typed: it matches this
/// pattern or it is refused.
private static let namePattern = "^[a-z0-9](?:[a-z0-9-]{0,18}[a-z0-9])$"
/// Time allowed for the /api/config check.
private static let timeout: TimeInterval = 10
/// Base address of the vault for what was typed, or `nil` if it is refused.
///
/// A vault name gives https://<name>.loksi.fr. Otherwise a full https address without
/// credentials, query or fragment, for a customer with their own domain.
///
static func address(for input: String) -> URL? {
let value = input.trimmingCharacters(in: .whitespacesAndNewlines)
if value.range(of: namePattern, options: .regularExpression) != nil {
return URL(string: "https://\(value).\(domain)")
}
guard value.hasPrefix("https://"),
let components = URLComponents(string: value),
components.scheme == "https",
let host = components.host, !host.isEmpty,
components.user == nil, components.password == nil,
components.query == nil, components.fragment == nil
else {
return nil
}
var path = components.percentEncodedPath
while path.hasSuffix("/") {
path.removeLast()
}
let port = components.port.map { ":\($0)" } ?? ""
return URL(string: "https://\(host)\(port)\(path)")
}
/// Whether a Vaultwarden server answers on /api/config at `base`.
///
/// - Parameters:
/// - base: The vault address returned by `address(for:)`.
/// - fetch: Returns the body of a successful GET, or `nil`.
///
static func isVault(
_ base: URL,
fetch: (URL) async -> Data? = LoksiVault.get,
) async -> Bool {
guard let body = await fetch(base.appendingPathComponent("api/config")),
let json = try? JSONSerialization.jsonObject(with: body) as? [String: Any],
let server = json["server"] as? [String: Any]
else {
return false
}
return server["name"] as? String == "Vaultwarden"
}
/// A GET without cookies or redirects, the body if the answer is 200.
///
static func get(_ url: URL) async -> Data? {
let configuration = URLSessionConfiguration.ephemeral
configuration.timeoutIntervalForRequest = timeout
let session = URLSession(configuration: configuration, delegate: NoRedirect(), delegateQueue: nil)
defer { session.finishTasksAndInvalidate() }
var request = URLRequest(url: url)
request.setValue("application/json", forHTTPHeaderField: "Accept")
guard let (data, response) = try? await session.data(for: request),
(response as? HTTPURLResponse)?.statusCode == 200
else {
return nil
}
return data
}
/// Refuses redirects: the vault must answer at the address itself.
///
private final class NoRedirect: NSObject, URLSessionTaskDelegate {
func urlSession(
_ session: URLSession,
task: URLSessionTask,
willPerformHTTPRedirection response: HTTPURLResponse,
newRequest request: URLRequest,
) async -> URLRequest? {
nil
}
}
}
+78
Voir le fichier
@@ -0,0 +1,78 @@
// GPL-3.0-only. Loksi: tests of the vault name rule, copied by mobile/ios/loksi.py.
import BitwardenKit
import Networking
import UIKit
import XCTest
@testable import BitwardenShared
class LoksiVaultTests: BitwardenTestCase {
/// A vault name gives https://<name>.loksi.fr.
func test_address_name() {
XCTAssertEqual(LoksiVault.address(for: "aleop")?.absoluteString, "https://aleop.loksi.fr")
XCTAssertEqual(LoksiVault.address(for: " mon-entreprise ")?.absoluteString, "https://mon-entreprise.loksi.fr")
XCTAssertEqual(LoksiVault.address(for: "ab")?.absoluteString, "https://ab.loksi.fr")
}
/// A full https address stays accepted, without its trailing slash.
func test_address_fullHttps() {
XCTAssertEqual(LoksiVault.address(for: "https://coffre.client.fr/")?.absoluteString, "https://coffre.client.fr")
XCTAssertEqual(
LoksiVault.address(for: "https://coffre.client.fr:8443/vault")?.absoluteString,
"https://coffre.client.fr:8443/vault",
)
}
/// Canaries: these must be refused.
func test_address_refused() {
for input in [
"ABC", "abc.evil.test", "ABC/../x", "http://", "http://abc.loksi.fr", "a", "-abc", "abc-",
"abcdefghijklmnopqrstu", "https://user:pass@abc.loksi.fr", "https://abc.loksi.fr?x=1",
"https://abc.loksi.fr#x", "", "https://",
] {
XCTAssertNil(LoksiVault.address(for: input), input)
}
}
/// Only a Vaultwarden answer on /api/config is a vault.
func test_isVault() async {
let base = URL(string: "https://aleop.loksi.fr")!
var asked: URL?
let vaultwarden = await LoksiVault.isVault(base) { url in
asked = url
return Data(#"{"server":{"name":"Vaultwarden"}}"#.utf8)
}
XCTAssertTrue(vaultwarden)
XCTAssertEqual(asked?.absoluteString, "https://aleop.loksi.fr/api/config")
}
/// The server sees the upstream Bitwarden version in Bitwarden-Client-Version, never the
/// displayed Loksi one. Canary: the test host shows Loksi's own version, the header must differ.
func test_serverVersion_isUpstream() async throws {
let handler = DefaultHeadersRequestHandler(
appVersion: LoksiUpstream.bitwardenVersion,
userAgentBuilder: UserAgentBuilder(
appName: "Loksi",
appVersion: LoksiUpstream.bitwardenVersion,
systemDevice: UIDevice.current,
),
)
var request = HTTPRequest(url: URL(string: "https://aleop.loksi.fr/api/config")!)
let handled = try await handler.handle(&request)
let header = handled.headers["Bitwarden-Client-Version"]
XCTAssertEqual(header, LoksiUpstream.bitwardenVersion)
XCTAssertNotEqual(header, Bundle.main.appVersion)
XCTAssertNotEqual(header, "2026.10.0")
}
/// Canaries: another server, a non JSON answer or no answer is not a vault.
func test_isVault_refused() async {
let base = URL(string: "https://abc.loksi.fr")!
for body in [#"{"server":{"name":"Bitwarden"}}"#, "<html>404</html>", #"{"server":null}"#] {
let result = await LoksiVault.isVault(base) { _ in Data(body.utf8) }
XCTAssertFalse(result, body)
}
let none = await LoksiVault.isVault(base) { _ in nil }
XCTAssertFalse(none)
}
}