diff --git a/ad-connector/src/main/java/module-info.java b/ad-connector/src/main/java/module-info.java deleted file mode 100644 index 55dd8f33f589ca4b12fd623b0a761d91b76ecff8..0000000000000000000000000000000000000000 --- a/ad-connector/src/main/java/module-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module ad.connector { - requires lombok; - requires jams.common; - requires org.slf4j; - requires ddc.core; - requires ddc.service; - requires jsoniter; - requires javassist; -} \ No newline at end of file diff --git a/authentication-module/src/main/java/module-info.java b/authentication-module/src/main/java/module-info.java deleted file mode 100644 index 2c6673f43f47ec3635aa8a59db1a53aa15aaa8da..0000000000000000000000000000000000000000 --- a/authentication-module/src/main/java/module-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module authentication.module { - requires jams.common; - requires nimbus.jose.jwt; - requires datastore; - requires lombok; - requires jami.dht; -} \ No newline at end of file diff --git a/datastore/src/main/java/module-info.java b/datastore/src/main/java/module-info.java deleted file mode 100644 index 11ad398ce2eb64a686bfb1cbd3dbabf80de3b53f..0000000000000000000000000000000000000000 --- a/datastore/src/main/java/module-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module datastore { - exports net.jami.datastore.main; - requires jams.common; - requires lombok; - requires org.slf4j; - requires java.sql; - requires derby; - requires java.base; - exports net.jami.datastore.dao; -} \ No newline at end of file diff --git a/jami-dht/src/main/java/module-info.java b/jami-dht/src/main/java/module-info.java deleted file mode 100644 index 27f07db38cf98caa22c596cc30f89c6d40edd98a..0000000000000000000000000000000000000000 --- a/jami-dht/src/main/java/module-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module jami.dht { - exports net.jami.jams.dht; - requires lombok; - requires msgpack.core; - requires org.apache.commons.codec; - requires org.slf4j; - requires jams.common; -} \ No newline at end of file diff --git a/jami-nameserver/src/main/java/module-info.java b/jami-nameserver/src/main/java/module-info.java deleted file mode 100644 index c78e95b947ee93aaa456ee24da45a9ce9fa37c32..0000000000000000000000000000000000000000 --- a/jami-nameserver/src/main/java/module-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module jami.nameserver { - requires jams.common; - requires datastore; - requires lombok; - exports net.jami.jams.nameserver; - requires org.slf4j; - requires jsoniter; -} \ No newline at end of file diff --git a/jams-ca/src/main/java/module-info.java b/jams-ca/src/main/java/module-info.java deleted file mode 100644 index c8d654a4f948e75f3801d1de762ad8f230fd3e5a..0000000000000000000000000000000000000000 --- a/jams-ca/src/main/java/module-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module jams.ca { - exports net.jami.jams.ca; - exports net.jami.jams.ca.workers.csr.builders; - requires jams.common; - requires org.bouncycastle.pkix; - requires lombok; - requires org.slf4j; - requires org.bouncycastle.provider; - requires jsoniter; -} \ No newline at end of file diff --git a/jams-common/src/main/java/module-info.java b/jams-common/src/main/java/module-info.java deleted file mode 100644 index b45f2121dba54f22dec6baa7ca8494c10814bdcc..0000000000000000000000000000000000000000 --- a/jams-common/src/main/java/module-info.java +++ /dev/null @@ -1,85 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -/** - * - * These may be required for tests to complete. - * - * //--add-opens - * // java.base/sun.security.rsa=jsoniter - * // --add-opens - * // java.base/sun.security.pkcs=jsoniter - * // --add-opens - * // java.base/sun.security.x509=jsoniter - * // --add-opens - * // java.base/sun.security.util=jsoniter - * // --add-opens - * // java.base/java.security.cert=jsoniter - * // --add-opens - * // java.base/java.lang=jsoniter - * // --add-opens - * // java.base/java.lang=javassist - */ - -module jams.common { - opens net.jami.jams.common.cryptoengineapi; - opens net.jami.jams.common.utils; - opens net.jami.jams.common.serialization; - opens net.jami.jams.common.jami; - requires lombok; - requires org.slf4j; - requires org.bouncycastle.pkix; - requires org.bouncycastle.provider; - requires jsoniter; - requires javassist; - opens net.jami.jams.common.objects.roots; - opens net.jami.jams.common.objects.requests; - exports net.jami.jams.common.objects.user; - exports net.jami.jams.common.objects.devices; - exports net.jami.jams.common.cryptoengineapi; - exports net.jami.jams.common.utils; - exports net.jami.jams.common.serialization; - exports net.jami.jams.common.objects.system; - exports net.jami.jams.common.objects.roots; - exports net.jami.jams.common.objects.contacts; - exports net.jami.jams.common.objects.requests; - exports net.jami.jams.common.authentication; - exports net.jami.jams.common.dao; - exports net.jami.jams.common.dao.connectivity; - exports net.jami.jams.common.authentication.activedirectory; - opens net.jami.jams.common.authentication.activedirectory to ad.connector ; - exports net.jami.jams.common.authentication.ldap; - exports net.jami.jams.common.jami; - exports net.jami.jams.common.authmodule; - exports net.jami.jams.common.server; - exports net.jami.jams.common.authentication.local; - exports net.jami.jams.common.objects.responses; - exports net.jami.jams.common.cryptoengineapi.ocsp; - exports net.jami.jams.common.updater; - exports net.jami.jams.common.updater.subscription; - requires jdk.crypto.cryptoki; - requires java.base; - requires java.sql; - requires org.apache.xbean.classloader; - requires java.naming; -} - diff --git a/jams-common/src/main/java/net/jami/jams/common/updater/FileDescription.java b/jams-common/src/main/java/net/jami/jams/common/updater/FileDescription.java index 6a8133bd6fe89d6771f7d3ebca2de4a1d98dde68..1f681b213d4d5bc2875817031cc600065d8fd916 100644 --- a/jams-common/src/main/java/net/jami/jams/common/updater/FileDescription.java +++ b/jams-common/src/main/java/net/jami/jams/common/updater/FileDescription.java @@ -2,12 +2,14 @@ package net.jami.jams.common.updater; import lombok.*; +import java.math.BigDecimal; + @Getter @Setter @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode -public class FileDescription { +public class FileDescription implements Comparable { private String fileName; private String version; @@ -15,4 +17,10 @@ public class FileDescription { private String mainClass; + @Override + public int compareTo(Object o) { + if(o == null) throw new NullPointerException(); + if(!(o instanceof FileDescription)) throw new ClassCastException(); + return new BigDecimal(this.version).compareTo(new BigDecimal(((FileDescription) o).getVersion())); + } } diff --git a/jams-launcher/src/main/java/module-info.java b/jams-launcher/src/main/java/module-info.java deleted file mode 100644 index 5a0f4a5c8624ec5d0a61e1c1e8d96fa45cb88dec..0000000000000000000000000000000000000000 --- a/jams-launcher/src/main/java/module-info.java +++ /dev/null @@ -1,33 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ - -module jams.launcher { - exports launcher; - requires lombok; - requires org.slf4j; - requires java.base; - requires jams.common; - requires jams.server; - requires org.apache.xbean.classloader; -} - diff --git a/jams-launcher/src/main/resources/oem/config.json b/jams-launcher/src/main/resources/oem/config.json index 80336b76a6fa4e6bcd65b870533b00429a1bc05d..38f19fa03ae297b2da6c142c89afbe85a41f5aae 100644 --- a/jams-launcher/src/main/resources/oem/config.json +++ b/jams-launcher/src/main/resources/oem/config.json @@ -1,5 +1,4 @@ { - "CORE_PACKAGE_MAIN_CLASS_NAME": "net.jami.jams.server.Server", "UPDATE_URL": "https://updates.jami.net", "UPDATE_INTERVAL": 20000 } diff --git a/jams-server/src/main/java/module-info.java b/jams-server/src/main/java/module-info.java deleted file mode 100644 index 8e637e19b224a37c587ad4278f49c18c2d4810ff..0000000000000000000000000000000000000000 --- a/jams-server/src/main/java/module-info.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module jams.server { - requires jams.ca; - requires jams.common; - requires java.management; - requires lombok; - requires org.slf4j; - requires org.apache.tomcat.embed.core; - requires tomcat.annotations.api; - requires jsoniter; - requires javassist; - requires datastore; - requires org.apache.xbean.classloader; - requires org.bouncycastle.pkix; - requires org.bouncycastle.provider; - requires jami.nameserver; - requires jami.dht; - requires nimbus.jose.jwt; - requires java.desktop; - - exports net.jami.jams.server.servlets.general to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.filters to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.api.auth.login to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.api.auth.device to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.api.auth.directory to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.api.auth.user to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.api.install to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.api.jaminameserver to org.apache.tomcat.embed.core; - exports net.jami.jams.server.servlets.x509 to org.apache.tomcat.embed.core; - exports net.jami.jams.server; - exports net.jami.jams.server.core; - - -} diff --git a/ldap-connector/src/main/java/module-info.java b/ldap-connector/src/main/java/module-info.java deleted file mode 100644 index d07ae47cee2df31286ab9b4499492065626ea33d..0000000000000000000000000000000000000000 --- a/ldap-connector/src/main/java/module-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/* -* Copyright (C) 2020 by Savoir-faire Linux -* Authors: William Enright <william.enright@savoirfairelinux.com> -* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> -* Johnny Flores <johnny.flores@savoirfairelinux.com> -* Mohammed Raza <mohammed.raza@savoirfairelinux.com> -* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -module ldap.connector { - requires jams.common; - requires jsoniter; - requires lombok; - requires org.slf4j; - requires ldaptive; -} \ No newline at end of file diff --git a/updater/src/main/java/module-info.java b/updater/src/main/java/module-info.java deleted file mode 100644 index da50f318236d8d2995cb839bd71c32c5acd4d155..0000000000000000000000000000000000000000 --- a/updater/src/main/java/module-info.java +++ /dev/null @@ -1,6 +0,0 @@ -module updater { - requires jams.common; - requires lombok; - requires org.slf4j; - requires jams.launcher; -} \ No newline at end of file diff --git a/updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java b/updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java index d1fd434df18a50922e8b40d2e469d0350c87d93d..cc897187322d7eb9e6f8458740feab8e3cb471a3 100644 --- a/updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java +++ b/updater/src/main/java/net/jami/jams/updater/JAMSUpdater.java @@ -18,6 +18,8 @@ import java.util.concurrent.atomic.AtomicBoolean; @Setter public class JAMSUpdater implements AppUpdater { + public static final String UPDATE_SERVER_URL = "https://updates.jami.net"; + public static final AtomicBoolean updateAvailable = new AtomicBoolean(false); private final AtomicBoolean doUpdate; private final UpdateCheckTask updateCheckTask = new UpdateCheckTask(); @@ -27,9 +29,10 @@ public class JAMSUpdater implements AppUpdater { public volatile static X509Certificate certificate; public volatile static PrivateKey privateKey; + public JAMSUpdater(AtomicBoolean doUpdate) { this.doUpdate = doUpdate; - timer.schedule(new UpdateCheckTask(),0,150_000); + timer.schedule(updateCheckTask,0,10_000); } @Override @@ -39,7 +42,7 @@ public class JAMSUpdater implements AppUpdater { @Override public HashMap<String,FileDescription> getRemoteVersions() { - return null; + return updateCheckTask.getRemoteData(); } @Override diff --git a/updater/src/main/java/net/jami/jams/updater/LocalVersionRepository.java b/updater/src/main/java/net/jami/jams/updater/LocalVersionRepository.java deleted file mode 100644 index f5557bb4efe9275222da857a96c2e8c0c11e2ba6..0000000000000000000000000000000000000000 --- a/updater/src/main/java/net/jami/jams/updater/LocalVersionRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.jami.jams.updater; - -import net.jami.jams.common.updater.FileDescription; -import net.jami.jams.common.updater.FileRepository; -import net.jami.jams.common.utils.VersioningUtils; - -import java.util.HashMap; - -public class LocalVersionRepository implements FileRepository { - - @Override - public HashMap<String, FileDescription> getFileVersions() { - return VersioningUtils.checkVersion(null); - } -} diff --git a/updater/src/main/java/net/jami/jams/updater/UpdateCheckTask.java b/updater/src/main/java/net/jami/jams/updater/UpdateCheckTask.java index a462c04be108c67e049381fe2e1f0653a56dc585..49d20953b7eba551f379a6104e92da03e12b3b43 100644 --- a/updater/src/main/java/net/jami/jams/updater/UpdateCheckTask.java +++ b/updater/src/main/java/net/jami/jams/updater/UpdateCheckTask.java @@ -1,32 +1,78 @@ package net.jami.jams.updater; +import com.jsoniter.JsonIterator; +import com.jsoniter.any.Any; import lombok.Getter; import lombok.Setter; 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 java.io.InputStream; +import java.security.KeyStore; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.TimerTask; +import static net.jami.jams.updater.JAMSUpdater.UPDATE_SERVER_URL; + @Slf4j @Getter @Setter public class UpdateCheckTask extends TimerTask { - private HashMap<String, FileDescription> remoteData; + private HashMap<String, FileDescription> remoteData = new HashMap<>(); + private HashMap<String, FileDescription> localData; + private SSLContext sslContext; + private volatile KeyStore trustStore; + private static final String KEYSTORE_TYPE = "JKS"; protected UpdateCheckTask() { + 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); + //Inject the SSL Connection here for a first time. + sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, null).build(); + } + catch (Exception e){ + log.error("Could not initialize the trust store with error {}",e.getMessage()); + } } @Override public void run() { try { - remoteData = new HashMap<>(); + //Get the local data + localData = VersioningUtils.checkVersion(null); //Download the info from the remote server. - - //Compare with local -> if(remote > local) - JAMSUpdater.updateAvailable.set(true); - + HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build(); + HttpResponse response = httpClient.execute(new HttpGet(UPDATE_SERVER_URL + "/versions.json")); + //Step 2: Load the file into the hashmaps + Any any = JsonIterator.deserialize(response.getEntity().getContent().readAllBytes()); + any.asMap().forEach((k, v) -> + remoteData.put(v.get("filename").toString(),new FileDescription( + v.get("filename").toString(), + v.get("version").toString(), + v.get("md5").toString(), + k)) + ); + //Compare and set to to true up-stream + localData.forEach((k,v) -> { + if(remoteData.get(k).compareTo(v) > 0){ + JAMSUpdater.updateAvailable.set(true); + } + }); } catch (Exception e){ log.error("Could not check for updates with error: {}",e.getMessage()); diff --git a/updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java b/updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java index cdd7ec5b52f3ea8ce946358573bd8a25edd0220c..2db357708b76f88eb1bd334314f44aaa466337a4 100644 --- a/updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java +++ b/updater/src/main/java/net/jami/jams/updater/UpdateDownloader.java @@ -15,6 +15,12 @@ public class UpdateDownloader { //TODO: Download the files and dump them into a tmp folder. public boolean downloadFiles(){ try { + //We can perpetually reload this,it doesn't really harm anything. + //KeyStore ks = KeyStore.getInstance(KEYSTORE_TYPE); + //ks.load(null); + //ks.setKeyEntry("licenses", JAMSUpdater.privateKey,"".toCharArray(),new Certificate[]{JAMSUpdater.certificate}); + //sslContext = SSLContexts.custom().loadKeyMaterial(ks, "".toCharArray()).loadTrustMaterial(trustStore, null) + // .build(); //Build the SSL context here, (this is fairly simple) //Try to download the files and store the to /tmp diff --git a/updater/src/main/java/net/jami/jams/updater/UpdateVersionRepository.java b/updater/src/main/java/net/jami/jams/updater/UpdateVersionRepository.java deleted file mode 100644 index 7c5570c8d37e20bc1198c9a1cea342058cd87769..0000000000000000000000000000000000000000 --- a/updater/src/main/java/net/jami/jams/updater/UpdateVersionRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.jami.jams.updater; - -import net.jami.jams.common.updater.FileDescription; -import net.jami.jams.common.updater.FileRepository; -import net.jami.jams.common.utils.VersioningUtils; - -import java.io.File; -import java.util.HashMap; - -public class UpdateVersionRepository implements FileRepository { - - @Override - public HashMap<String, FileDescription> getFileVersions() { - return VersioningUtils.checkVersion(System.getProperty("user.dir") + File.separator + "tmp"); - } -} diff --git a/updater/src/main/java/net/jami/jams/updater/internal/SFLTrustStore.java b/updater/src/main/java/net/jami/jams/updater/internal/SFLTrustStore.java deleted file mode 100644 index 17564f6c44ac0a3839e2d483cdf17f8227f456a8..0000000000000000000000000000000000000000 --- a/updater/src/main/java/net/jami/jams/updater/internal/SFLTrustStore.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.jami.jams.updater.internal; - -import lombok.extern.slf4j.Slf4j; -import net.jami.jams.common.utils.X509Utils; - -import javax.net.ssl.X509TrustManager; -import java.io.InputStream; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -@Slf4j -public class SFLTrustStore implements X509TrustManager { - - X509Certificate[] sflCertificate = new X509Certificate[1]; - - //TODO: This just returns the SavoirFaireLinux CA everywhere - get this from the OEM resources folder. - //Also keep in mind that since we fork off the launcher, it will not scan this one, but rather - //The launcher. - public SFLTrustStore() { - try { - InputStream is = SFLTrustStore.class.getClassLoader().getResourceAsStream("ca.crt"); - X509Certificate certificate = X509Utils.getCertificateFromPEMString(new String(is.readAllBytes())); - sflCertificate[0] = certificate; - } - catch (Exception e){ - log.error("Could not load the SavoirFaireLinux certificate with error: {}",e.getMessage()); - } - } - - @Override - public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { - - } - - @Override - public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { - boolean failedCheck = false; - for(int i=0; i < x509Certificates.length; i++){ - try { - x509Certificates[i].verify(sflCertificate[0].getPublicKey()); - } - catch (Exception e){ - throw new CertificateException("Failed to verify the server's identity..."); - } - } - } - - //Implement this. - @Override - public X509Certificate[] getAcceptedIssuers() { - return sflCertificate; - } -}