@@ -126,7 +126,7 @@ public void download(URL url, File tmpFile, Progress progress, String statusText
126
126
}
127
127
128
128
public void download (URL url , File tmpFile , Progress progress , String statusText , ProgressListener progressListener , boolean noResume , boolean allowCache ) throws Exception {
129
- FileDownloader downloader = new FileDownloader (url , tmpFile , allowCache );
129
+ final FileDownloader downloader = new FileDownloader (url , tmpFile , allowCache );
130
130
downloader .addObserver ((o , arg ) -> {
131
131
FileDownloader me = (FileDownloader ) o ;
132
132
String msg = "" ;
@@ -148,22 +148,24 @@ public void download(URL url, File tmpFile, Progress progress, String statusText
148
148
public void downloadIndexAndSignature (MultiStepProgress progress , URL packageIndexUrl , ProgressListener progressListener , SignatureVerifier signatureVerifier ) throws Exception {
149
149
150
150
// Extract the file name from the url
151
- String indexFileName = FilenameUtils .getName (packageIndexUrl .getPath ());
152
- File packageIndex = BaseNoGui .indexer .getIndexFile (indexFileName );
151
+ final String indexFileName = FilenameUtils .getName (packageIndexUrl .getPath ());
152
+ final File packageIndex = BaseNoGui .indexer .getIndexFile (indexFileName );
153
153
154
154
final String statusText = tr ("Downloading platforms index..." );
155
155
156
156
// Create temp files
157
- File packageIndexTemp = File .createTempFile (indexFileName , ".tmp" );
157
+ final File packageIndexTemp = File .createTempFile (indexFileName , ".tmp" );
158
158
try {
159
159
// Download package index
160
160
download (packageIndexUrl , packageIndexTemp , progress , statusText , progressListener , true , true );
161
+ final URL signatureUrl = new URL (packageIndexUrl .toString () + ".sig" );
161
162
162
163
if (verifyDomain (packageIndexUrl )) {
163
- URL signatureUrl = new URL (packageIndexUrl .toString () + ".sig" );
164
-
165
164
if (checkSignature (progress , signatureUrl , progressListener , signatureVerifier , statusText , packageIndexTemp )) {
166
165
Files .move (packageIndexTemp .toPath (), packageIndex .toPath (), StandardCopyOption .REPLACE_EXISTING );
166
+ } else {
167
+ log .info ("The cached files have been removed. {} {}" , packageIndexUrl , signatureUrl );
168
+ FileDownloader .invalidateFiles (packageIndexUrl , signatureUrl );
167
169
}
168
170
} else {
169
171
// Move the package index to the destination when the signature is not necessary
@@ -196,18 +198,25 @@ public boolean verifyDomain(URL url) {
196
198
197
199
public boolean checkSignature (MultiStepProgress progress , URL signatureUrl , ProgressListener progressListener , SignatureVerifier signatureVerifier , String statusText , File fileToVerify ) throws Exception {
198
200
201
+ final boolean allowInsecurePackages =
202
+ PreferencesData .getBoolean ("allow_insecure_packages" , false );
203
+ if (allowInsecurePackages ) {
204
+ log .info ("Allow insecure packages is true the signature will be skip and return always verified" );
205
+ return true ;
206
+ }
207
+
199
208
// Signature file name
200
- String signatureFileName = FilenameUtils .getName (signatureUrl .getPath ());
201
- File packageIndexSignature = BaseNoGui .indexer .getIndexFile (signatureFileName );
202
- File packageIndexSignatureTemp = File .createTempFile (signatureFileName , ".tmp" );
209
+ final String signatureFileName = FilenameUtils .getName (signatureUrl .getPath ());
210
+ final File packageIndexSignature = BaseNoGui .indexer .getIndexFile (signatureFileName );
211
+ final File packageIndexSignatureTemp = File .createTempFile (signatureFileName , ".tmp" );
203
212
204
213
205
214
try {
206
215
// Download signature
207
216
download (signatureUrl , packageIndexSignatureTemp , progress , statusText , progressListener , true );
208
217
209
218
// Verify the signature before move the files
210
- boolean signatureVerified = signatureVerifier .isSigned (fileToVerify , packageIndexSignatureTemp );
219
+ final boolean signatureVerified = signatureVerifier .isSigned (fileToVerify , packageIndexSignatureTemp );
211
220
if (signatureVerified ) {
212
221
log .info ("Signature verified. url={}, signature url={}, file to verify={}, signature file={}" , signatureUrl , signatureUrl , fileToVerify , packageIndexSignatureTemp );
213
222
// Move if the signature is ok
0 commit comments