Skip to content
Snippets Groups Projects
Commit ebcf8e1d authored by Felix Sidokhine's avatar Felix Sidokhine
Browse files

updater now checks data from remote server, great

parent 58933a61
No related branches found
No related tags found
No related merge requests found
Showing
with 72 additions and 486 deletions
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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;
}
......@@ -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()));
}
}
/*
* 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;
}
{
"CORE_PACKAGE_MAIN_CLASS_NAME": "net.jami.jams.server.Server",
"UPDATE_URL": "https://updates.jami.net",
"UPDATE_INTERVAL": 20000
}
/*
* 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;
}
/*
* 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
module updater {
requires jams.common;
requires lombok;
requires org.slf4j;
requires jams.launcher;
}
\ No newline at end of file
......@@ -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
......
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);
}
}
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());
......
......@@ -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
......
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");
}
}
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment