001/* 002 * #%L 003 * Netarchivesuite - common 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023package dk.netarkivet.common.distribute; 024 025import java.io.File; 026 027import dk.netarkivet.common.exceptions.ArgumentNotValid; 028import dk.netarkivet.common.exceptions.IOFailure; 029import dk.netarkivet.common.utils.Settings; 030 031/** 032 * A remote file implemented with point-to-point HTTPS communication. Optimised to communicate locally, if file is on 033 * the same host. Optimised to transfer 0 byte files inline. Will use one shared certificate for secure communication. 034 */ 035@SuppressWarnings({"serial"}) 036public class HTTPSRemoteFile extends HTTPRemoteFile { 037 038 /** The default place in classpath where the settings file can be found. */ 039 private static final String DEFAULT_SETTINGS_CLASSPATH = "dk/netarkivet/common/distribute/HTTPSRemoteFileSettings.xml"; 040 041 /* 042 * The static initialiser is called when the class is loaded. It will add default values for all settings defined in 043 * this class, by loading them from a settings.xml file in classpath. 044 */ 045 static { 046 Settings.addDefaultClasspathSettings(DEFAULT_SETTINGS_CLASSPATH); 047 } 048 049 // NOTE: The constants defining setting names below are left non-final on 050 // purpose! Otherwise, the static initialiser that loads default values 051 // will not run. 052 053 /** 054 * <b>settings.common.remoteFile.certificateKeyStore</b>: <br> 055 * The setting for the keystore file used for HTTPS remotefiles. It contains the certificate for HTTPS 056 */ 057 public static String HTTPSREMOTEFILE_KEYSTORE_FILE = "settings.common.remoteFile.certificateKeyStore"; 058 059 /** 060 * <b>settings.common.remoteFile.certificateKeyStorePassword</b>: <br> 061 * The setting for the password that the keystore used for HTTPS remotefile keystore is encrypted with. Refer to the 062 * configuration manual for how to build a keystore. 063 */ 064 public static String HTTPSREMOTEFILE_KEYSTORE_PASSWORD = "settings.common.remoteFile.certificateKeyStorePassword"; 065 066 /** 067 * <b>settings.common.remoteFile.certificatePassword</b>: <br> 068 * The setting for the password that the certificate used for HTTPS remotefile (private key) is encrypted with. 069 */ 070 public static String HTTPSREMOTEFILE_KEY_PASSWORD = "settings.common.remoteFile.certificatePassword"; 071 072 /** 073 * Initialises a remote file implemented by point-to-point HTTPS communication. 074 * 075 * @param file The file to make a remote file for 076 * @param useChecksums Whether communications are checksummed. If true, getChecksum will also return the checksum. 077 * @param fileDeletable if true, the file given to this method is deletable, once it is transferred. 078 * @param multipleDownloads if true, the file may be transferred more than once. Otherwise, all file handles are 079 * attempted to be made invalid after the first transfer, although no guarantees are made. 080 * @throws ArgumentNotValid if file is null, or not a readable file. 081 * @throws IOFailure if checksums are requested, but i/o errors occur while checksumming. 082 */ 083 protected HTTPSRemoteFile(File file, boolean useChecksums, boolean fileDeletable, boolean multipleDownloads) { 084 super(file, useChecksums, fileDeletable, multipleDownloads); 085 } 086 087 /** 088 * Initialises a remote file implemented by point-to-point HTTPS communication. 089 * 090 * @param f The file to make a remote file for 091 * @param useChecksums Whether communications are checksummed. If true, getChecksum will also return the checksum. 092 * @param fileDeletable if true, the file given to this method is deletable, once it is transferred. 093 * @param multipleDownloads if true, the file may be transferred more than once. Otherwise, all file handles are 094 * attempted to be made invalid after the first transfer, although no guarantees are made. 095 * @throws ArgumentNotValid if file is null, or not a readable file. 096 * @throws IOFailure if checksums are requested, but i/o errors occur while checksumming. 097 */ 098 public static RemoteFile getInstance(File f, Boolean useChecksums, Boolean fileDeletable, Boolean multipleDownloads) { 099 return new HTTPSRemoteFile(f, useChecksums, fileDeletable, multipleDownloads); 100 } 101 102 /** 103 * Get the HTTPS serving registry for remote files. Overrides the HTTP registry use by HTTPRemoteFile. 104 * 105 * @return registry for remote files. 106 */ 107 protected HTTPRemoteFileRegistry getRegistry() { 108 return HTTPSRemoteFileRegistry.getInstance(); 109 } 110 111}