import os

# Default values for production, may be overridden later based on environment
class FlaskConfig(object):
    DEBUG = False
    TESTING = False
    WTF_CSRF_ENABLED = True

# Use different secret keys for the two different applications so their
# sessions can't be confused.
# TODO consider using salts instead: http://pythonhosted.org//itsdangerous/#the-salt
class SourceInterfaceFlaskConfig(FlaskConfig):
    SECRET_KEY = 'RVVzhdwJCh0aRpKu5XiKpjWHcOWvIm7ntxSzXoU5uWA='

class JournalistInterfaceFlaskConfig(FlaskConfig):
    SECRET_KEY = 'IplVQ9FeWKc28rYccoRhSchthOLM8oCdaeqSgrsIEkQ='

# These files are in the same directory as config.py. Use absolute paths to
# avoid potential problems with the test runner - otherwise, you have to be in
# this directory when you run the code.
SECUREDROP_ROOT = os.path.dirname(os.path.realpath(__file__))

SOURCE_TEMPLATES_DIR = os.path.join(SECUREDROP_ROOT, 'source_templates')
JOURNALIST_TEMPLATES_DIR = os.path.join(SECUREDROP_ROOT, 'journalist_templates')
WORD_LIST = os.path.join(SECUREDROP_ROOT, 'wordlist')
NOUNS = os.path.join(SECUREDROP_ROOT, 'dictionaries/nouns.txt')
ADJECTIVES = os.path.join(SECUREDROP_ROOT, './dictionaries/adjectives.txt')

JOURNALIST_PIDFILE = "/tmp/journalist.pid"
SOURCE_PIDFILE = "/tmp/source.pid"

# "head -c 32 /dev/urandom | base64" for constructing public ID from source codename
SCRYPT_ID_PEPPER = '4TpWpD3qvJvaYq5LgjuoAGfWio6o69pfOWKiue1ZVu8='
# "head -c 32 /dev/urandom | base64" for stretching source codename into GPG passphrase
SCRYPT_GPG_PEPPER = 'bBizEs8qjZrLIsgOv/Ql9TjLmQnZykMU4kQfsNjSFN4='
SCRYPT_PARAMS = dict(N=2**14, r=8, p=1)

# Fingerprint of the public key to use for encrypting submissions
# Defaults to test_journalist_key.pub, which is used for development and testing
JOURNALIST_KEY = '65A1B5FF195B56353CC63DFFCC40EF1228271441'

# Directory where SecureDrop stores the database file, GPG keyring, and
# encrypted submissions.
SECUREDROP_DATA_ROOT = '/var/lib/securedrop'

# Modify configuration for alternative environments
env = os.environ.get('SECUREDROP_ENV') or 'prod'

if env == 'prod':
    pass
elif env == 'dev':
    # Enable Flask's debugger for development
    FlaskConfig.DEBUG = True
    # Hack to get around cookies not considering the port as part of the origin
    SourceInterfaceFlaskConfig.SESSION_COOKIE_NAME = 'source_session'
    JournalistInterfaceFlaskConfig.SESSION_COOKIE_NAME = 'journalist_session'
elif env == 'test':
    FlaskConfig.TESTING = True
    # Disable CSRF checks for tests to make writing tests easier
    FlaskConfig.WTF_CSRF_ENABLED = False
    # TODO use a unique temporary directory for each test so we can parallelize them
    SECUREDROP_DATA_ROOT = '/tmp/securedrop'

# The following configuration is dependent on SECUREDROP_DATA_ROOT

# Directory where encrypted submissions are stored
STORE_DIR=os.path.join(SECUREDROP_DATA_ROOT, 'store')

# Directory where GPG keyring is stored
GPG_KEY_DIR=os.path.join(SECUREDROP_DATA_ROOT, 'keys')

# Database configuration
# TODO we currently use sqlite in production since it is sufficient and simple,
# but in the future may want to be able to choose a different database
# depending on the environment
DATABASE_ENGINE = 'sqlite'
DATABASE_FILE = os.path.join(SECUREDROP_DATA_ROOT, 'db.sqlite')


@@ -2099,20 +2099,115 @@
 d':%0A    
-pass
+# This is recommended for performance, and also resolves #369%0A    FlaskConfig.USE_X_SENDFILE = True
 %0Aelif en
@@ -2602,18 +2602,8 @@
 cks 
-for tests 
 to m

Update ansible's copy of config.py