unset https only mode during validation step for Firefox

Former-commit-id: d0d0b5aca8
Former-commit-id: 359cb4b63120ad93626b0e16435c7085da8cc4be
This commit is contained in:
idk
2022-09-02 18:25:27 -04:00
parent cfed313fc9
commit 516f56a0e4
4 changed files with 58 additions and 4 deletions

View File

@ -1 +1 @@
655b9ac751e4e25ef3d1b66016967c02d815de96
4b8e0c481fded43b2f222f26e4b3ea8430fe4b47

View File

@ -1 +1 @@
cfcee8a5955e68b1d49017a1f82b416c44c92412
a1748cb5be11c848b82c16f781234c86fd197a01

View File

@ -1 +1 @@
e79d34f3afacc5d7ea12f54a52c9393b2f81f814
92b56055f29b1a0a48dc7574afa67df38092e442

View File

@ -1,6 +1,10 @@
package net.i2p.i2pfirefox;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* I2PFirefoxProfileChecker.java
@ -74,7 +78,57 @@ public class I2PFirefoxProfileChecker {
System.out.println("extensions directory is invalid");
return false;
}
return true;
return deRestrictHTTPS(profileDir.toString());
}
private static boolean deRestrictHTTPS(String profile) {
// String profile = profileDirectory();
File profileDir = new File(profile);
if (profileDir.exists()) {
File prefOverrides = new File(profile, "prefs.js");
if (prefOverrides.exists()) {
undoHttpsOnlyMode(prefOverrides);
}
File userSettings = new File(profile, "user.js");
if (userSettings.exists()) {
undoHttpsOnlyMode(userSettings);
}
File userOverrides = new File(profile, "user-overrides.js");
if (userOverrides.exists()) {
undoHttpsOnlyMode(userOverrides);
}
}
return false;
}
private static boolean undoHttpsOnlyMode(File fileToBeModified) {
String oldString = "\"dom.security.https_only_mode\", true";
String newString = "\"dom.security.https_only_mode\", false";
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try {
reader = new BufferedReader(new FileReader(fileToBeModified));
String line = reader.readLine();
while (line != null) {
oldContent = oldContent + line + System.lineSeparator();
line = reader.readLine();
}
String newContent = oldContent.replaceAll(oldString, newString);
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
writer.close();
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Return true if the file is valid.