Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-jams
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-jams
Commits
5ad6d939
Commit
5ad6d939
authored
4 years ago
by
Felix Sidokhine
Browse files
Options
Downloads
Patches
Plain Diff
added comparing of checksums
parent
104dec09
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java
+1
-1
1 addition, 1 deletion
updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java
updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java
+46
-4
46 additions, 4 deletions
...src/main/java/net/jami/jams/updater/UpdateDownloader.java
with
47 additions
and
5 deletions
updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java
+
1
−
1
View file @
5ad6d939
...
...
@@ -59,7 +59,7 @@ public class JAMSUpdater implements AppUpdater {
@Override
public
void
doUpdate
()
{
//Some logic here about replacing the existing files.
boolean
res
=
updateDownloader
.
downloadFiles
();
boolean
res
=
updateDownloader
.
downloadFiles
(
getRemoteVersions
()
);
//Notify back up-stream to the launcher that we want the update to happen.
if
(
res
)
{
doUpdate
.
set
(
true
);
...
...
This diff is collapsed.
Click to expand it.
updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java
+
46
−
4
View file @
5ad6d939
package
net.jami.jams.updater
;
import
lombok.extern.slf4j.Slf4j
;
import
net.jami.jams.common.updater.FileDescription
;
import
net.jami.jams.common.utils.VersioningUtils
;
import
net.jami.jams.common.utils.X509Utils
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.ssl.SSLContexts
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSocketFactory
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.security.KeyStore
;
import
java.security.cert.Certificate
;
import
java.security.cert.X509Certificate
;
import
java.util.HashMap
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
static
net
.
jami
.
jams
.
updater
.
JAMSUpdater
.
UPDATE_SERVER_URL
;
@Slf4j
public
class
UpdateDownloader
{
private
SSLSocketFactory
sslSocketFactory
;
private
SSLContext
sslContext
;
private
static
final
String
KEYSTORE_TYPE
=
"JKS"
;
private
KeyStore
trustStore
;
public
UpdateDownloader
()
{
try
{
InputStream
is
=
UpdateCheckTask
.
class
.
getClassLoader
().
getResourceAsStream
(
"oem/ca.crt"
);
...
...
@@ -33,8 +45,18 @@ public class UpdateDownloader {
}
}
private
void
downloadFile
(
File
tmpFolder
,
FileDescription
fileDescription
)
throws
Exception
{
HttpClient
httpClient
=
HttpClients
.
custom
().
setSSLContext
(
sslContext
).
build
();
HttpResponse
httpResponse
=
httpClient
.
execute
(
new
HttpGet
(
UPDATE_SERVER_URL
+
"/updates/"
+
fileDescription
.
getFileName
()));
if
(
httpResponse
.
getStatusLine
().
getStatusCode
()
!=
200
)
return
;
FileOutputStream
fos
=
new
FileOutputStream
(
tmpFolder
.
getPath
()
+
"/"
+
fileDescription
.
getFileName
());
httpResponse
.
getEntity
().
writeTo
(
fos
);
fos
.
close
();
}
//TODO: Download the files and dump them into a tmp folder.
public
boolean
downloadFiles
(){
public
boolean
downloadFiles
(
HashMap
<
String
,
FileDescription
>
files
){
try
{
//We can perpetually reload this,it doesn't really harm anything.
//Build the SSL context here, (this is fairly simple)
...
...
@@ -43,9 +65,29 @@ public class UpdateDownloader {
ks
.
setKeyEntry
(
"licenses"
,
JAMSUpdater
.
privateKey
,
""
.
toCharArray
(),
new
Certificate
[]{
JAMSUpdater
.
certificate
});
sslContext
=
SSLContexts
.
custom
().
loadKeyMaterial
(
ks
,
""
.
toCharArray
()).
loadTrustMaterial
(
trustStore
,
null
).
build
();
//Try to download the files and store the to /tmp
File
tmpFolder
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
"/tmp/"
);
if
(!
tmpFolder
.
mkdirs
()){
log
.
error
(
"Could not create temporary folder to store the update files!"
);
return
false
;
}
files
.
forEach
((
k
,
v
)
->
{
try
{
downloadFile
(
tmpFolder
,
v
);
}
catch
(
Exception
e
){
log
.
error
(
"Could not download a file with error {}"
,
e
.
getMessage
());
}
});
//Check file checksums and trigger the update cycle itself - but this is already done in the outer function.
return
true
;
HashMap
<
String
,
FileDescription
>
downloadedFileInfo
=
VersioningUtils
.
checkVersion
(
System
.
getProperty
(
"user.dir"
)
+
"/tmp"
);
AtomicBoolean
checksumOk
=
new
AtomicBoolean
(
true
);
files
.
forEach
((
k
,
v
)
->{
if
(
downloadedFileInfo
.
containsKey
(
k
)
&&
!
downloadedFileInfo
.
get
(
k
).
getMd5hash
().
equals
(
v
.
getMd5hash
())){
checksumOk
.
set
(
false
);
}
});
return
checksumOk
.
get
();
}
catch
(
Exception
e
){
log
.
error
(
"Could not check for updates with error: {}"
,
e
.
getMessage
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment