001/**
002 *
003 * Copyright 2017 Paul Schaub
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.omemo;
018
019import java.io.File;
020
021/**
022 * Contains OMEMO related configuration options.
023 *
024 * @author Paul Schaub
025 */
026public final class OmemoConfiguration {
027
028    /**
029     * Ignore own other stale devices that we did not receive a message from for a period of time.
030     * Ignoring means do not encrypt messages for them. This helps to mitigate stale devices that threaten
031     * forward secrecy by never advancing ratchets.
032     */
033    private static boolean IGNORE_STALE_DEVICES = true;
034    private static int IGNORE_STALE_DEVICE_AFTER_HOURS = 24 * 7;         //One week
035
036    /**
037     * Delete stale devices from the device list after a period of time.
038     */
039    private static boolean DELETE_STALE_DEVICES = true;
040    private static int DELETE_STALE_DEVICE_AFTER_HOURS = 24 * 7 * 4;     //4 weeks
041
042    /**
043     * Upload a new signed prekey in intervals. This improves forward secrecy. Old keys are kept for some more time and
044     * then deleted.
045     */
046    private static boolean RENEW_OLD_SIGNED_PREKEYS = false;
047    private static int RENEW_OLD_SIGNED_PREKEYS_AFTER_HOURS = 24 * 7;    //One week
048    private static int MAX_NUMBER_OF_STORED_SIGNED_PREKEYS = 4;
049
050    /**
051     * Add a plaintext body hint about omemo encryption to the message.
052     */
053    private static boolean ADD_OMEMO_HINT_BODY = true;
054
055    /**
056     * Add Explicit Message Encryption hint (XEP-0380) to the message.
057     */
058    private static boolean ADD_EME_ENCRYPTION_HINT = true;
059
060    /**
061     * Add MAM storage hint to allow the server to store messages that do not contain a body.
062     */
063    private static boolean ADD_MAM_STORAGE_HINT = true;
064
065    private static File FILE_BASED_OMEMO_STORE_DEFAULT_PATH = null;
066
067    public static void setIgnoreStaleDevices(boolean ignore) {
068        IGNORE_STALE_DEVICES = ignore;
069    }
070
071    public static boolean getIgnoreStaleDevices() {
072        return IGNORE_STALE_DEVICES;
073    }
074
075    public static void setIgnoreStaleDevicesAfterHours(int hours) {
076        if (hours <= 0) {
077            throw new IllegalArgumentException("Hours must be greater than 0.");
078        }
079        IGNORE_STALE_DEVICE_AFTER_HOURS = hours;
080    }
081
082    public static int getIgnoreStaleDevicesAfterHours() {
083        return IGNORE_STALE_DEVICE_AFTER_HOURS;
084    }
085
086    public static void setDeleteStaleDevices(boolean delete) {
087        DELETE_STALE_DEVICES = delete;
088    }
089
090    public static boolean getDeleteStaleDevices() {
091        return DELETE_STALE_DEVICES;
092    }
093
094    public static void setDeleteStaleDevicesAfterHours(int hours) {
095        if (hours <= 0) {
096            throw new IllegalArgumentException("Hours must be greater than 0.");
097        }
098        DELETE_STALE_DEVICE_AFTER_HOURS = hours;
099    }
100
101    public static int getDeleteStaleDevicesAfterHours() {
102        return DELETE_STALE_DEVICE_AFTER_HOURS;
103    }
104
105    public static void setRenewOldSignedPreKeys(boolean renew) {
106        RENEW_OLD_SIGNED_PREKEYS = renew;
107    }
108
109    public static boolean getRenewOldSignedPreKeys() {
110        return RENEW_OLD_SIGNED_PREKEYS;
111    }
112
113    public static void setRenewOldSignedPreKeysAfterHours(int hours) {
114        if (hours <= 0) {
115            throw new IllegalArgumentException("Hours must be greater than 0.");
116        }
117        RENEW_OLD_SIGNED_PREKEYS_AFTER_HOURS = hours;
118    }
119
120    public static int getRenewOldSignedPreKeysAfterHours() {
121        return RENEW_OLD_SIGNED_PREKEYS_AFTER_HOURS;
122    }
123
124    public static void setMaxNumberOfStoredSignedPreKeys(int number) {
125        if (number <= 0) {
126            throw new IllegalArgumentException("Number must be greater than 0.");
127        }
128        MAX_NUMBER_OF_STORED_SIGNED_PREKEYS = number;
129    }
130
131    public static int getMaxNumberOfStoredSignedPreKeys() {
132        return MAX_NUMBER_OF_STORED_SIGNED_PREKEYS;
133    }
134
135    public static void setAddOmemoHintBody(boolean addHint) {
136        ADD_OMEMO_HINT_BODY = addHint;
137    }
138
139    public static boolean getAddOmemoHintBody() {
140        return ADD_OMEMO_HINT_BODY;
141    }
142
143    public static void setAddEmeEncryptionHint(boolean addHint) {
144        ADD_EME_ENCRYPTION_HINT = addHint;
145    }
146
147    public static boolean getAddEmeEncryptionHint() {
148        return ADD_EME_ENCRYPTION_HINT;
149    }
150
151    public static void setAddMAMStorageProcessingHint(boolean addStorageHint) {
152        ADD_MAM_STORAGE_HINT = addStorageHint;
153    }
154
155    public static boolean getAddMAMStorageProcessingHint() {
156        return ADD_MAM_STORAGE_HINT;
157    }
158
159    public static void setFileBasedOmemoStoreDefaultPath(File path) {
160        FILE_BASED_OMEMO_STORE_DEFAULT_PATH = path;
161    }
162
163    public static File getFileBasedOmemoStoreDefaultPath() {
164        return FILE_BASED_OMEMO_STORE_DEFAULT_PATH;
165    }
166}