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
c92ad62d
Commit
c92ad62d
authored
4 years ago
by
William Enright
Browse files
Options
Downloads
Patches
Plain Diff
fixed update downloader incorrectly loading sslcontext and license
parent
a7ee34bc
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/UpdateDownloader.java
+37
-9
37 additions, 9 deletions
...src/main/java/net/jami/jams/updater/UpdateDownloader.java
updater/src/main/resources/oem/ca.crt
+0
-0
0 additions, 0 deletions
updater/src/main/resources/oem/ca.crt
with
37 additions
and
9 deletions
updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java
+
37
−
9
View file @
c92ad62d
...
...
@@ -30,6 +30,7 @@ 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
net.jami.jams.server.licensing.LicenseService
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpGet
;
...
...
@@ -43,6 +44,7 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.security.KeyStore
;
import
java.security.KeyStoreException
;
import
java.security.cert.Certificate
;
import
java.security.cert.X509Certificate
;
import
java.util.HashMap
;
...
...
@@ -62,6 +64,19 @@ public class UpdateDownloader {
private
HashMap
<
String
,
FileDescription
>
remoteChecksums
=
new
HashMap
<>();
public
UpdateDownloader
()
{
try
{
InputStream
is
=
UpdateCheckTask
.
class
.
getClassLoader
().
getResourceAsStream
(
"oem/ca.crt"
);
X509Certificate
certificate
=
X509Utils
.
getCertificateFromPEMString
(
new
String
(
is
.
readAllBytes
()));
trustStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
trustStore
.
load
(
null
,
null
);
trustStore
.
setCertificateEntry
(
"ca"
,
certificate
);
}
catch
(
Exception
e
){
log
.
info
(
"Could not load SFL's CA - this should not happen! detailed error: {}"
,
e
.
getMessage
());
}
try
{
InputStream
input
=
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
"oem/config.json"
);
Any
any
=
JsonIterator
.
deserialize
(
input
.
readAllBytes
());
...
...
@@ -76,23 +91,36 @@ public class UpdateDownloader {
public
boolean
downloadFiles
(
HashMap
<
String
,
FileDescription
>
files
)
{
//I know this contradicts my dogma, but this really would have been an overkill for this project,
//I just claim that everything which is not core gets dumped to the lib directory.
//We can perpetually reload this,it doesn't really harm anything.
//Build the SSL context here, (this is fairly simple)
KeyStore
ks
=
null
;
try
{
ks
=
KeyStore
.
getInstance
(
KEYSTORE_TYPE
);
ks
.
load
(
null
);
LicenseService
licenseService
=
new
LicenseService
();
licenseService
.
loadLicense
();
ks
.
setKeyEntry
(
"licenses"
,
JAMSUpdater
.
privateKey
,
""
.
toCharArray
(),
new
Certificate
[]{
JAMSUpdater
.
certificate
});
sslContext
=
SSLContexts
.
custom
().
loadKeyMaterial
(
ks
,
""
.
toCharArray
()).
loadTrustMaterial
(
trustStore
,
null
).
build
();
}
catch
(
Exception
e
)
{
log
.
warn
(
"Could not download an update with error "
+
e
.
toString
());
}
// temp folder for safe download and integrity check
File
tmpFolder
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
"/tmp/"
);
tmpFolder
.
mkdirs
();
if
(!
tmpFolder
.
mkdirs
()){
log
.
error
(
"Could not create temporary folder to store the update files!"
);
return
false
;
}
files
.
forEach
((
k
,
v
)
->
{
try
{
HttpClient
httpClient
=
HttpClients
.
custom
().
setSSLContext
(
sslContext
).
build
();
HttpResponse
httpResponse
=
httpClient
.
execute
(
new
HttpGet
(
UPDATE_SERVER_URL
+
"/updates/"
+
v
.
getFileName
()));
if
(
httpResponse
.
getStatusLine
().
getStatusCode
()
==
200
)
{
log
.
info
(
tmpFolder
.
getPath
()
+
"/"
+
v
.
getFileName
());
FileOutputStream
fos
=
new
FileOutputStream
(
tmpFolder
.
getPath
()
+
"/"
+
v
.
getFileName
());
httpResponse
.
getEntity
().
writeTo
(
fos
);
fos
.
close
();
}
else
{
log
.
warn
(
"The server declared an update but does not have the required files?!"
);
}
if
(
httpResponse
.
getStatusLine
().
getStatusCode
()
!=
200
)
return
;
FileOutputStream
fos
=
new
FileOutputStream
(
tmpFolder
.
getPath
()
+
"/"
+
v
.
getFileName
());
httpResponse
.
getEntity
().
writeTo
(
fos
);
fos
.
close
();
}
catch
(
Exception
e1
)
{
log
.
warn
(
"Could not download an update with error "
+
e1
.
toString
());
}
...
...
This diff is collapsed.
Click to expand it.
updater/src/main/resources/ca.crt
→
updater/src/main/resources/
oem/
ca.crt
+
0
−
0
View file @
c92ad62d
File moved
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