|
19 | 19 |
|
20 | 20 | import java.io.File; |
21 | 21 | import java.io.FileInputStream; |
| 22 | +import java.io.FileNotFoundException; |
22 | 23 | import java.io.IOException; |
23 | 24 | import java.util.Properties; |
24 | 25 |
|
| 26 | +import io.github.explodingbottle.jmagicproxy.logging.LoggingLevel; |
| 27 | +import io.github.explodingbottle.jmagicproxy.logging.ProxyLogger; |
| 28 | + |
25 | 29 | /** |
26 | 30 | * This class is very useful to find issues that may be related to the |
27 | 31 | * java.security file with disabled algorithms. |
|
32 | 36 | public class DisabledAlgorithmsWarner { |
33 | 37 |
|
34 | 38 | private Properties javaSecurity; |
| 39 | + private ProxyLogger logger; |
35 | 40 |
|
36 | 41 | /** |
37 | 42 | * Gets ready the warner. |
38 | 43 | * |
39 | | - * @throws IOException if an issue happens to load the file. |
40 | 44 | */ |
41 | | - public DisabledAlgorithmsWarner() throws IOException { |
| 45 | + public DisabledAlgorithmsWarner() { |
| 46 | + logger = ProxyMain.getLoggerProvider().createLogger(); |
42 | 47 | javaSecurity = new Properties(); |
43 | | - FileInputStream is = new FileInputStream( |
44 | | - new File(new File(new File(System.getProperty("java.home"), "lib"), "security"), "java.security")); |
45 | | - javaSecurity.load(is); |
46 | | - is.close(); |
| 48 | + FileInputStream is = null; |
| 49 | + try { |
| 50 | + is = new FileInputStream( |
| 51 | + new File(new File(new File(System.getProperty("java.home"), "lib"), "security"), "java.security")); |
| 52 | + } catch (FileNotFoundException e) { |
| 53 | + logger.log(LoggingLevel.WARN, |
| 54 | + "Failed to open the input stream to check java.security. No warnings will be emitted.", e); |
| 55 | + } |
| 56 | + if (is != null) { |
| 57 | + try { |
| 58 | + javaSecurity.load(is); |
| 59 | + } catch (IOException e) { |
| 60 | + logger.log(LoggingLevel.WARN, "Failed to load the properties contained in java.security.", e); |
| 61 | + } |
| 62 | + try { |
| 63 | + is.close(); |
| 64 | + } catch (IOException e) { |
| 65 | + logger.log(LoggingLevel.WARN, "Failed to close the java.security file.", e); |
| 66 | + } |
| 67 | + } |
| 68 | + |
47 | 69 | } |
48 | 70 |
|
| 71 | + /** |
| 72 | + * This function will say if the user must be warned about the |
| 73 | + * jdk.tls.disabledAlgorithms property. |
| 74 | + * |
| 75 | + * @return if the user must be warned about jdk.tls.disabledAlgorithms. |
| 76 | + */ |
49 | 77 | public boolean mustWarn() { |
50 | 78 | String found = javaSecurity.getProperty("jdk.tls.disabledAlgorithms"); |
51 | 79 | if (found != null && !found.trim().isEmpty()) |
|
0 commit comments