Search in sources :

Example 1 with SU3File

use of net.i2p.crypto.SU3File in project i2p.i2p by i2p.

the class ConsoleUpdateManager method handleRouterFile.

/**
 *  Process sud, su2, or su3
 *  @return success
 *  @since 0.9.9
 */
private boolean handleRouterFile(URI uri, String actualVersion, File f, boolean isSU3) {
    String url = uri.toString();
    updateStatus("<b>" + _t("Update downloaded") + "</b>");
    File to = new File(_context.getRouterDir(), Router.UPDATE_FILE);
    String err;
    // Process the file
    if (isSU3) {
        SU3File up = new SU3File(_context, f);
        File temp = new File(_context.getTempDir(), "su3out-" + _context.random().nextLong() + ".zip");
        try {
            if (up.verifyAndMigrate(temp)) {
                String ver = up.getVersionString();
                int type = up.getContentType();
                if (ver == null || VersionComparator.comp(RouterVersion.VERSION, ver) >= 0)
                    err = "Old version " + ver;
                else if (type != SU3File.CONTENT_ROUTER)
                    err = "Bad su3 content type " + type;
                else if (!FileUtil.copy(temp, to, true, false))
                    err = "Failed copy to " + to;
                else
                    // success
                    err = null;
            } else {
                err = "Signature failed, signer " + DataHelper.stripHTML(up.getSignerString()) + ' ' + up.getSigType();
            }
        } catch (IOException ioe) {
            _log.error("SU3 extract error", ioe);
            err = DataHelper.stripHTML(ioe.toString());
        } finally {
            temp.delete();
        }
    } else {
        TrustedUpdate up = new TrustedUpdate(_context);
        err = up.migrateVerified(RouterVersion.VERSION, f, to);
    }
    // f.delete();
    if (err == null) {
        String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);
        // So unsigned update handler doesn't overwrite unless newer.
        long modtime = _context.clock().now();
        _context.router().saveConfig(NewsHelper.PROP_LAST_UPDATE_TIME, Long.toString(modtime));
        if ("install".equals(policy)) {
            _log.log(Log.CRIT, "Update was downloaded and verified, restarting to install it");
            updateStatus("<b>" + _t("Update verified") + "</b><br>" + _t("Restarting"));
            restart();
        } else {
            _log.logAlways(Log.WARN, "Update was downloaded and verified, will be installed at next restart");
            // SummaryHelper will display restart info separately
            updateStatus("");
        }
    } else {
        _log.log(Log.CRIT, err + " from " + url);
        updateStatus("<b>" + err + ' ' + _t("from {0}", linkify(url)) + " </b>");
    }
    return err == null;
}
Also used : TrustedUpdate(net.i2p.crypto.TrustedUpdate) IOException(java.io.IOException) SU3File(net.i2p.crypto.SU3File) SU3File(net.i2p.crypto.SU3File) File(java.io.File)

Example 2 with SU3File

use of net.i2p.crypto.SU3File in project i2p.i2p by i2p.

the class NewsFetcher method processSU3.

/**
 *  Process the fetched su3 news file _tempFile.
 *  Handles 3 types of contained files: xml.gz (preferred), xml, and html (old format fake xml)
 *
 *  @return the temp file contining the HTML-format news.xml
 *  @since 0.9.17
 */
private File processSU3() throws IOException {
    SU3File su3 = new SU3File(_context, _tempFile);
    // real xml, maybe gz, maybe not
    File to1 = new File(_context.getTempDir(), "tmp-" + _context.random().nextInt() + ".xml");
    // real xml
    File to2 = new File(_context.getTempDir(), "tmp2-" + _context.random().nextInt() + ".xml");
    try {
        su3.verifyAndMigrate(to1);
        int type = su3.getFileType();
        if (su3.getContentType() != SU3File.CONTENT_NEWS)
            throw new IOException("bad content type: " + su3.getContentType());
        if (type == SU3File.TYPE_HTML)
            return to1;
        if (type != SU3File.TYPE_XML && type != SU3File.TYPE_XML_GZ)
            throw new IOException("bad file type: " + type);
        File xml;
        if (type == SU3File.TYPE_XML_GZ) {
            gunzip(to1, to2);
            xml = to2;
            to1.delete();
        } else {
            xml = to1;
        }
        NewsXMLParser parser = new NewsXMLParser(_context);
        Node root = parser.parse(xml);
        xml.delete();
        NewsMetadata data = parser.getMetadata();
        List<NewsEntry> entries = parser.getEntries();
        // add entries to the news manager
        ClientAppManager cmgr = _context.clientAppManager();
        if (cmgr != null) {
            NewsManager nmgr = (NewsManager) cmgr.getRegisteredApp(NewsManager.APP_NAME);
            if (nmgr != null) {
                nmgr.addEntries(entries);
                List<Node> nodes = NewsXMLParser.getNodes(root, "entry");
                nmgr.storeEntries(nodes);
            }
        }
        // Persist any new CRL entries
        List<CRLEntry> crlEntries = parser.getCRLEntries();
        if (crlEntries != null)
            persistCRLEntries(crlEntries);
        else
            _log.info("No CRL entries found in news feed");
        // Block any new blocklist entries
        BlocklistEntries ble = parser.getBlocklistEntries();
        if (ble != null && ble.isVerified())
            processBlocklistEntries(ble);
        else
            _log.info("No blocklist entries found in news feed");
        // store entries and metadata in old news.xml format
        String sudVersion = su3.getVersionString();
        String signingKeyName = su3.getSignerString();
        File to3 = new File(_context.getTempDir(), "tmp3-" + _context.random().nextInt() + ".xml");
        outputOldNewsXML(data, entries, sudVersion, signingKeyName, to3);
        return to3;
    } finally {
        to2.delete();
    }
}
Also used : NewsMetadata(net.i2p.router.news.NewsMetadata) Node(org.cybergarage.xml.Node) IOException(java.io.IOException) CRLEntry(net.i2p.router.news.CRLEntry) SU3File(net.i2p.crypto.SU3File) NewsEntry(net.i2p.router.news.NewsEntry) ClientAppManager(net.i2p.app.ClientAppManager) NewsXMLParser(net.i2p.router.news.NewsXMLParser) NewsManager(net.i2p.router.news.NewsManager) BlocklistEntries(net.i2p.router.news.BlocklistEntries) SU3File(net.i2p.crypto.SU3File) SecureFile(net.i2p.util.SecureFile) File(java.io.File)

Example 3 with SU3File

use of net.i2p.crypto.SU3File in project i2p.i2p by i2p.

the class PluginUpdateRunner method processSU3.

/**
 *  @since 0.9.15
 */
private void processSU3(File f, File appDir, String url) {
    SU3File su3 = new SU3File(_context, f);
    File to = new File(_context.getTempDir(), "tmp" + _context.random().nextInt() + ZIP);
    String sudVersion;
    String signingKeyName;
    try {
        su3.verifyAndMigrate(to);
        if (su3.getFileType() != SU3File.TYPE_ZIP)
            throw new IOException("bad file type");
        if (su3.getContentType() != SU3File.CONTENT_PLUGIN)
            throw new IOException("bad content type");
        sudVersion = su3.getVersionString();
        signingKeyName = su3.getSignerString();
    } catch (IOException ioe) {
        statusDone("<b>" + ioe + ' ' + _t("from {0}", url) + " </b>");
        f.delete();
        to.delete();
        return;
    }
    Properties props = getPluginConfig(f, to, url);
    if (props == null)
        return;
    String signer = props.getProperty("signer");
    if (signer == null || signer.length() <= 0) {
        f.delete();
        to.delete();
        statusDone("<b>" + _t("Plugin from {0} contains an invalid key", url) + "</b>");
        return;
    }
    if (!signer.equals(signingKeyName)) {
        f.delete();
        to.delete();
        if (signingKeyName == null)
            _log.error("Failed to verify plugin signature, corrupt plugin or bad signature, signed by: " + signer);
        else
            // shouldn't happen
            _log.error("Plugin signer \"" + signer + "\" does not match new signer in plugin.config file \"" + signingKeyName + "\"");
        statusDone("<b>" + _t("Plugin signature verification of {0} failed", url) + "</b>");
        return;
    }
    processFinal(to, appDir, url, props, sudVersion, null, signer);
}
Also used : IOException(java.io.IOException) SU3File(net.i2p.crypto.SU3File) OrderedProperties(net.i2p.util.OrderedProperties) Properties(java.util.Properties) SecureFile(net.i2p.util.SecureFile) SU3File(net.i2p.crypto.SU3File) File(java.io.File)

Aggregations

File (java.io.File)3 IOException (java.io.IOException)3 SU3File (net.i2p.crypto.SU3File)3 SecureFile (net.i2p.util.SecureFile)2 Properties (java.util.Properties)1 ClientAppManager (net.i2p.app.ClientAppManager)1 TrustedUpdate (net.i2p.crypto.TrustedUpdate)1 BlocklistEntries (net.i2p.router.news.BlocklistEntries)1 CRLEntry (net.i2p.router.news.CRLEntry)1 NewsEntry (net.i2p.router.news.NewsEntry)1 NewsManager (net.i2p.router.news.NewsManager)1 NewsMetadata (net.i2p.router.news.NewsMetadata)1 NewsXMLParser (net.i2p.router.news.NewsXMLParser)1 OrderedProperties (net.i2p.util.OrderedProperties)1 Node (org.cybergarage.xml.Node)1