encryption password from config
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 5fb45b5..98349f5 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -6,6 +6,8 @@
uuid = {{uuid}}
database_dir = {{data_dir}}
view_index_dir = {{view_index_dir}}
+encryption_password = super_secret_password
+encryption_salt = no_saltier_than_this
; util_driver_dir =
; plugin_dir =
;os_process_timeout = 5000 ; 5 seconds. for view servers.
diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index e4673c3..f52a12f 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -64,8 +64,6 @@
%% or {error, Reason} if the file could not be opened.
%%----------------------------------------------------------------------
--define(AES_MASTER_KEY, <<0:256>>).
-
open(Filepath) ->
open(Filepath, []).
@@ -932,7 +930,7 @@
%% we've wiped all the data, including the wrapped key, so we need a new one.
init_key(#file{eof = 0} = File) ->
Key = crypto:strong_rand_bytes(32),
- WrappedKey = couch_keywrap:key_wrap(?AES_MASTER_KEY, Key),
+ WrappedKey = couch_keywrap:key_wrap(master_key(), Key),
Header = <<?ENCRYPTED_HEADER, WrappedKey/binary>>,
ok = file:write(File#file.fd, Header),
ok = file:sync(File#file.fd),
@@ -942,7 +940,7 @@
init_key(#file{key = undefined} = File) ->
case file:pread(File#file.fd, 0, 48) of
{ok, <<?ENCRYPTED_HEADER, WrappedKey/binary>>} ->
- case couch_keywrap:key_unwrap(?AES_MASTER_KEY, WrappedKey) of
+ case couch_keywrap:key_unwrap(master_key(), WrappedKey) of
fail ->
{error, unwrap_failed};
Key when is_binary(Key) ->
@@ -1023,6 +1021,27 @@
Result.
+master_key() ->
+ couch_pbkdf2:pbkdf2(sha256, master_password(), master_salt(), 100000).
+
+
+master_password() ->
+ case config:get("couchdb", "encryption_password") of
+ undefined ->
+ undefined;
+ Password ->
+ ?l2b(Password)
+ end.
+
+master_salt() ->
+ case config:get("couchdb", "encryption_salt") of
+ undefined ->
+ undefined;
+ Salt ->
+ ?l2b(Salt)
+ end.
+
+
-ifdef(TEST).
-include_lib("couch/include/couch_eunit.hrl").