forked from core/mobile_nebula
Hide CA expiration errors on managed sites (#128)
This commit is contained in:
parent
69d0641874
commit
693c7b6346
|
@ -52,7 +52,7 @@ class Sites(private var engine: FlutterEngine) {
|
||||||
val context = MainActivity.getContext()!!
|
val context = MainActivity.getContext()!!
|
||||||
val site = containers[id]!!.site
|
val site = containers[id]!!.site
|
||||||
|
|
||||||
val baseDir = if(site.managed == true) context.noBackupFilesDir else context.filesDir
|
val baseDir = if(site.managed) context.noBackupFilesDir else context.filesDir
|
||||||
val siteDir = baseDir.resolve("sites").resolve(id)
|
val siteDir = baseDir.resolve("sites").resolve(id)
|
||||||
siteDir.deleteRecursively()
|
siteDir.deleteRecursively()
|
||||||
refreshSites()
|
refreshSites()
|
||||||
|
@ -275,7 +275,7 @@ class Site(context: Context, siteDir: File) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasErrors) {
|
if (hasErrors && !managed) {
|
||||||
errors.add("There are issues with 1 or more ca certificates")
|
errors.add("There are issues with 1 or more ca certificates")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,15 @@ class Site: Codable {
|
||||||
id = incoming.id
|
id = incoming.id
|
||||||
staticHostmap = incoming.staticHostmap
|
staticHostmap = incoming.staticHostmap
|
||||||
unsafeRoutes = incoming.unsafeRoutes ?? []
|
unsafeRoutes = incoming.unsafeRoutes ?? []
|
||||||
|
lhDuration = incoming.lhDuration
|
||||||
|
port = incoming.port
|
||||||
|
cipher = incoming.cipher
|
||||||
|
sortKey = incoming.sortKey ?? 0
|
||||||
|
logVerbosity = incoming.logVerbosity ?? "info"
|
||||||
|
mtu = incoming.mtu ?? 1300
|
||||||
|
managed = incoming.managed ?? false
|
||||||
|
lastManagedUpdate = incoming.lastManagedUpdate
|
||||||
|
rawConfig = incoming.rawConfig
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let rawCert = incoming.cert
|
let rawCert = incoming.cert
|
||||||
|
@ -232,7 +241,7 @@ class Site: Codable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasErrors) {
|
if (hasErrors && !managed) {
|
||||||
errors.append("There are issues with 1 or more ca certificates")
|
errors.append("There are issues with 1 or more ca certificates")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,16 +257,6 @@ class Site: Codable {
|
||||||
errors.append("Unable to create the site directory: \(error.localizedDescription)")
|
errors.append("Unable to create the site directory: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
|
|
||||||
lhDuration = incoming.lhDuration
|
|
||||||
port = incoming.port
|
|
||||||
cipher = incoming.cipher
|
|
||||||
sortKey = incoming.sortKey ?? 0
|
|
||||||
logVerbosity = incoming.logVerbosity ?? "info"
|
|
||||||
mtu = incoming.mtu ?? 1300
|
|
||||||
managed = incoming.managed ?? false
|
|
||||||
lastManagedUpdate = incoming.lastManagedUpdate
|
|
||||||
rawConfig = incoming.rawConfig
|
|
||||||
|
|
||||||
if (managed && (try? getDNCredentials())?.invalid != false) {
|
if (managed && (try? getDNCredentials())?.invalid != false) {
|
||||||
errors.append("Unable to fetch managed updates - please re-enroll the device")
|
errors.append("Unable to fetch managed updates - please re-enroll the device")
|
||||||
}
|
}
|
||||||
|
@ -307,16 +306,16 @@ class Site: Codable {
|
||||||
func invalidateDNCredentials() throws {
|
func invalidateDNCredentials() throws {
|
||||||
let creds = try getDNCredentials()
|
let creds = try getDNCredentials()
|
||||||
creds.invalid = true
|
creds.invalid = true
|
||||||
|
|
||||||
if (!(try creds.save(siteID: self.id))) {
|
if (!(try creds.save(siteID: self.id))) {
|
||||||
throw "failed to store dn credentials in keychain"
|
throw "failed to store dn credentials in keychain"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDNCredentials() throws {
|
func validateDNCredentials() throws {
|
||||||
let creds = try getDNCredentials()
|
let creds = try getDNCredentials()
|
||||||
creds.invalid = false
|
creds.invalid = false
|
||||||
|
|
||||||
if (!(try creds.save(siteID: self.id))) {
|
if (!(try creds.save(siteID: self.id))) {
|
||||||
throw "failed to store dn credentials in keychain"
|
throw "failed to store dn credentials in keychain"
|
||||||
}
|
}
|
||||||
|
@ -370,16 +369,16 @@ class DNCredentials: Codable {
|
||||||
get { return _invalid ?? false }
|
get { return _invalid ?? false }
|
||||||
set { _invalid = newValue }
|
set { _invalid = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
private var _invalid: Bool?
|
private var _invalid: Bool?
|
||||||
|
|
||||||
func save(siteID: String) throws -> Bool {
|
func save(siteID: String) throws -> Bool {
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
let rawDNCredentials = try encoder.encode(self)
|
let rawDNCredentials = try encoder.encode(self)
|
||||||
|
|
||||||
return KeyChain.save(key: "\(siteID).dnCredentials", data: rawDNCredentials, managed: true)
|
return KeyChain.save(key: "\(siteID).dnCredentials", data: rawDNCredentials, managed: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case hostID
|
case hostID
|
||||||
case privateKey
|
case privateKey
|
||||||
|
|
|
@ -154,13 +154,16 @@ class _SiteConfigScreenState extends State<SiteConfigScreen> {
|
||||||
|
|
||||||
Widget _keys() {
|
Widget _keys() {
|
||||||
final certError = site.certInfo == null || site.certInfo!.validity == null || !site.certInfo!.validity!.valid;
|
final certError = site.certInfo == null || site.certInfo!.validity == null || !site.certInfo!.validity!.valid;
|
||||||
var caError = site.ca.length == 0;
|
var caError = false;
|
||||||
if (!caError) {
|
if (!site.managed) {
|
||||||
site.ca.forEach((ca) {
|
var caError = site.ca.length == 0;
|
||||||
if (ca.validity == null || !ca.validity!.valid) {
|
if (!caError) {
|
||||||
caError = true;
|
site.ca.forEach((ca) {
|
||||||
}
|
if (ca.validity == null || !ca.validity!.valid) {
|
||||||
});
|
caError = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConfigSection(
|
return ConfigSection(
|
||||||
|
|
Loading…
Reference in New Issue