mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 23:18:27 +02:00
feat: remove hash server validation (MESSENGER-6759)
This commit is contained in:
@@ -79,7 +79,6 @@ extension UserDefaults
|
||||
private func checkUrlSavety(_ serverUrl: String) async -> Bool {
|
||||
if BWIBuildSettings.shared.bwiEnableLoginProtection {
|
||||
let protectionService = LoginProtectionService()
|
||||
protectionService.hashes = BWIBuildSettings.shared.bwiHashes
|
||||
|
||||
return await protectionService.isValid(serverUrl)
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,6 @@ import Foundation
|
||||
import CryptoKit
|
||||
|
||||
@objcMembers class LoginProtectionService : NSObject {
|
||||
var hashes: [String]?
|
||||
|
||||
@objc func isValid(_ homeserverAddress: String, ignoreNetworkConnectionLost: Bool = false) async -> Bool {
|
||||
// bwi #6162 a homeserveraddress is valid when there is either
|
||||
@@ -45,15 +44,6 @@ import CryptoKit
|
||||
}
|
||||
}
|
||||
|
||||
if BWIBuildSettings.shared.bwiEnableLoginProtection && !validHomeserver {
|
||||
if let hashes = hashes {
|
||||
let string = self.normalizeLoginUrl(homeserverAddress)
|
||||
let hashedString = self.hashedString(string)
|
||||
|
||||
validHomeserver = hashes.contains(hashedString)
|
||||
}
|
||||
}
|
||||
|
||||
return validHomeserver
|
||||
}
|
||||
|
||||
@@ -63,10 +53,4 @@ import CryptoKit
|
||||
|
||||
return tmpString
|
||||
}
|
||||
|
||||
private func hashedString(_ string: String) -> String {
|
||||
let data = Data(string.utf8)
|
||||
let hash = SHA256.hash(data: data)
|
||||
return hash.compactMap { String(format: "%02x", $0) }.joined()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2022 BWI GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
@testable import Element
|
||||
|
||||
class LoginProtectionTests: XCTestCase {
|
||||
|
||||
let hashes = ["34f2dfdb69edeef64ae9f53cea21c7e27db19566d440174c5bc3949d87ae90f6",
|
||||
"04feebbb6cc530f26db673ee7d781c57870cfc7c6d1814d63dc703a3da522619"
|
||||
]
|
||||
|
||||
func testValidURL() throws {
|
||||
let service = LoginProtectionService()
|
||||
service.hashes = hashes
|
||||
|
||||
XCTAssertTrue(service.isValid("https://www.wellbehaved.de"))
|
||||
}
|
||||
|
||||
func testInvalidURL() throws {
|
||||
let service = LoginProtectionService()
|
||||
service.hashes = hashes
|
||||
|
||||
XCTAssertFalse(service.isValid("https://www.unknown.org"))
|
||||
}
|
||||
|
||||
func testSimpleURL() throws {
|
||||
let service = LoginProtectionService()
|
||||
service.hashes = hashes
|
||||
|
||||
XCTAssertTrue(service.isValid("www.simple.com"))
|
||||
}
|
||||
|
||||
func testMalformatedURL() throws {
|
||||
let service = LoginProtectionService()
|
||||
service.hashes = hashes
|
||||
|
||||
XCTAssertFalse(service.isValid("ur%%l@blalalal"))
|
||||
}
|
||||
|
||||
func testNoHashlist() throws {
|
||||
let service = LoginProtectionService()
|
||||
|
||||
XCTAssertFalse(service.isValid("https://www.wellbehaved.de"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user