Fossil SCM

Further enhancements to SEE integration.

mistachkin 2017-05-30 01:26 UTC see
Commit 53048387fbca12313348a6ecd984a79cfdab28a0545978fdc9caef7491961fae
--- src/config.h
+++ src/config.h
@@ -185,10 +185,13 @@
185185
typedef unsigned __int64 uint64_t;
186186
#else
187187
# include <stdint.h>
188188
#endif
189189
190
+#if USE_SEE && !defined(SQLITE_HAS_CODEC)
191
+# define SQLITE_HAS_CODEC
192
+#endif
190193
#include "sqlite3.h"
191194
192195
/*
193196
** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257.
194197
*/
195198
--- src/config.h
+++ src/config.h
@@ -185,10 +185,13 @@
185 typedef unsigned __int64 uint64_t;
186 #else
187 # include <stdint.h>
188 #endif
189
 
 
 
190 #include "sqlite3.h"
191
192 /*
193 ** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257.
194 */
195
--- src/config.h
+++ src/config.h
@@ -185,10 +185,13 @@
185 typedef unsigned __int64 uint64_t;
186 #else
187 # include <stdint.h>
188 #endif
189
190 #if USE_SEE && !defined(SQLITE_HAS_CODEC)
191 # define SQLITE_HAS_CODEC
192 #endif
193 #include "sqlite3.h"
194
195 /*
196 ** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257.
197 */
198
+30 -10
--- src/db.c
+++ src/db.c
@@ -34,10 +34,13 @@
3434
# include <windows.h>
3535
# endif
3636
#else
3737
# include <pwd.h>
3838
#endif
39
+#if USE_SEE && !defined(SQLITE_HAS_CODEC)
40
+# define SQLITE_HAS_CODEC
41
+#endif
3942
#include <sqlite3.h>
4043
#include <sys/types.h>
4144
#include <sys/stat.h>
4245
#include <unistd.h>
4346
#include <time.h>
@@ -1048,14 +1051,20 @@
10481051
void db_maybe_set_encryption_key(sqlite3 *db, const char *zDbName){
10491052
Blob key;
10501053
blob_init(&key, 0, 0);
10511054
db_maybe_obtain_encryption_key(zDbName, &key);
10521055
if( blob_size(&key)>0 ){
1053
- char *zCmd = sqlite3_mprintf("PRAGMA key(%Q)", blob_str(&key));
1054
- sqlite3_exec(db, zCmd, 0, 0, 0);
1055
- fossil_secure_zero(zCmd, strlen(zCmd));
1056
- sqlite3_free(zCmd);
1056
+ if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
1057
+ char *zCmd = sqlite3_mprintf("PRAGMA key(%Q)", blob_str(&key));
1058
+ sqlite3_exec(db, zCmd, 0, 0, 0);
1059
+ fossil_secure_zero(zCmd, strlen(zCmd));
1060
+ sqlite3_free(zCmd);
1061
+#if USE_SEE
1062
+ }else{
1063
+ sqlite3_key(db, blob_str(&key), -1);
1064
+#endif
1065
+ }
10571066
}
10581067
blob_reset(&key);
10591068
}
10601069
10611070
/*
@@ -1107,19 +1116,30 @@
11071116
/*
11081117
** zDbName is the name of a database file. Attach zDbName using
11091118
** the name zLabel.
11101119
*/
11111120
void db_attach(const char *zDbName, const char *zLabel){
1112
- char *zCmd;
11131121
Blob key;
11141122
blob_init(&key, 0, 0);
11151123
db_maybe_obtain_encryption_key(zDbName, &key);
1116
- zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
1117
- zDbName, zLabel, blob_str(&key));
1118
- db_multi_exec(zCmd /*works-like:""*/);
1119
- fossil_secure_zero(zCmd, strlen(zCmd));
1120
- sqlite3_free(zCmd);
1124
+ if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
1125
+ char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
1126
+ zDbName, zLabel, blob_str(&key));
1127
+ db_multi_exec(zCmd /*works-like:""*/);
1128
+ fossil_secure_zero(zCmd, strlen(zCmd));
1129
+ sqlite3_free(zCmd);
1130
+ }else{
1131
+ char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY ''",
1132
+ zDbName, zLabel);
1133
+ db_multi_exec(zCmd /*works-like:""*/);
1134
+ sqlite3_free(zCmd);
1135
+#if USE_SEE
1136
+ if( blob_size(&key)>0 ){
1137
+ sqlite3_key_v2(g.db, zLabel, blob_str(&key), -1);
1138
+ }
1139
+#endif
1140
+ }
11211141
blob_reset(&key);
11221142
}
11231143
11241144
/*
11251145
** Change the schema name of the "main" database to zLabel.
11261146
--- src/db.c
+++ src/db.c
@@ -34,10 +34,13 @@
34 # include <windows.h>
35 # endif
36 #else
37 # include <pwd.h>
38 #endif
 
 
 
39 #include <sqlite3.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <unistd.h>
43 #include <time.h>
@@ -1048,14 +1051,20 @@
1048 void db_maybe_set_encryption_key(sqlite3 *db, const char *zDbName){
1049 Blob key;
1050 blob_init(&key, 0, 0);
1051 db_maybe_obtain_encryption_key(zDbName, &key);
1052 if( blob_size(&key)>0 ){
1053 char *zCmd = sqlite3_mprintf("PRAGMA key(%Q)", blob_str(&key));
1054 sqlite3_exec(db, zCmd, 0, 0, 0);
1055 fossil_secure_zero(zCmd, strlen(zCmd));
1056 sqlite3_free(zCmd);
 
 
 
 
 
 
1057 }
1058 blob_reset(&key);
1059 }
1060
1061 /*
@@ -1107,19 +1116,30 @@
1107 /*
1108 ** zDbName is the name of a database file. Attach zDbName using
1109 ** the name zLabel.
1110 */
1111 void db_attach(const char *zDbName, const char *zLabel){
1112 char *zCmd;
1113 Blob key;
1114 blob_init(&key, 0, 0);
1115 db_maybe_obtain_encryption_key(zDbName, &key);
1116 zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
1117 zDbName, zLabel, blob_str(&key));
1118 db_multi_exec(zCmd /*works-like:""*/);
1119 fossil_secure_zero(zCmd, strlen(zCmd));
1120 sqlite3_free(zCmd);
 
 
 
 
 
 
 
 
 
 
 
 
1121 blob_reset(&key);
1122 }
1123
1124 /*
1125 ** Change the schema name of the "main" database to zLabel.
1126
--- src/db.c
+++ src/db.c
@@ -34,10 +34,13 @@
34 # include <windows.h>
35 # endif
36 #else
37 # include <pwd.h>
38 #endif
39 #if USE_SEE && !defined(SQLITE_HAS_CODEC)
40 # define SQLITE_HAS_CODEC
41 #endif
42 #include <sqlite3.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <unistd.h>
46 #include <time.h>
@@ -1048,14 +1051,20 @@
1051 void db_maybe_set_encryption_key(sqlite3 *db, const char *zDbName){
1052 Blob key;
1053 blob_init(&key, 0, 0);
1054 db_maybe_obtain_encryption_key(zDbName, &key);
1055 if( blob_size(&key)>0 ){
1056 if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
1057 char *zCmd = sqlite3_mprintf("PRAGMA key(%Q)", blob_str(&key));
1058 sqlite3_exec(db, zCmd, 0, 0, 0);
1059 fossil_secure_zero(zCmd, strlen(zCmd));
1060 sqlite3_free(zCmd);
1061 #if USE_SEE
1062 }else{
1063 sqlite3_key(db, blob_str(&key), -1);
1064 #endif
1065 }
1066 }
1067 blob_reset(&key);
1068 }
1069
1070 /*
@@ -1107,19 +1116,30 @@
1116 /*
1117 ** zDbName is the name of a database file. Attach zDbName using
1118 ** the name zLabel.
1119 */
1120 void db_attach(const char *zDbName, const char *zLabel){
 
1121 Blob key;
1122 blob_init(&key, 0, 0);
1123 db_maybe_obtain_encryption_key(zDbName, &key);
1124 if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
1125 char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY %Q",
1126 zDbName, zLabel, blob_str(&key));
1127 db_multi_exec(zCmd /*works-like:""*/);
1128 fossil_secure_zero(zCmd, strlen(zCmd));
1129 sqlite3_free(zCmd);
1130 }else{
1131 char *zCmd = sqlite3_mprintf("ATTACH DATABASE %Q AS %Q KEY ''",
1132 zDbName, zLabel);
1133 db_multi_exec(zCmd /*works-like:""*/);
1134 sqlite3_free(zCmd);
1135 #if USE_SEE
1136 if( blob_size(&key)>0 ){
1137 sqlite3_key_v2(g.db, zLabel, blob_str(&key), -1);
1138 }
1139 #endif
1140 }
1141 blob_reset(&key);
1142 }
1143
1144 /*
1145 ** Change the schema name of the "main" database to zLabel.
1146
+5 -1
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -201,11 +201,15 @@
201201
nByte = savedKeySize * sizeof(char);
202202
zKey = sqlite3_malloc( (int)nByte );
203203
if( zKey ){
204204
memcpy(zKey, zSavedKey, nByte);
205205
*pzKey = zKey;
206
- *pnKey = (int)strlen(zKey);
206
+ if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
207
+ *pnKey = (int)strlen(zKey);
208
+ }else{
209
+ *pnKey = -1;
210
+ }
207211
}else{
208212
fossil_fatal("failed to allocate %u bytes for key", nByte);
209213
}
210214
}
211215
#endif
212216
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -201,11 +201,15 @@
201 nByte = savedKeySize * sizeof(char);
202 zKey = sqlite3_malloc( (int)nByte );
203 if( zKey ){
204 memcpy(zKey, zSavedKey, nByte);
205 *pzKey = zKey;
206 *pnKey = (int)strlen(zKey);
 
 
 
 
207 }else{
208 fossil_fatal("failed to allocate %u bytes for key", nByte);
209 }
210 }
211 #endif
212
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -201,11 +201,15 @@
201 nByte = savedKeySize * sizeof(char);
202 zKey = sqlite3_malloc( (int)nByte );
203 if( zKey ){
204 memcpy(zKey, zSavedKey, nByte);
205 *pzKey = zKey;
206 if( fossil_getenv("FOSSIL_USE_SEE_TEXTKEY")==0 ){
207 *pnKey = (int)strlen(zKey);
208 }else{
209 *pnKey = -1;
210 }
211 }else{
212 fossil_fatal("failed to allocate %u bytes for key", nByte);
213 }
214 }
215 #endif
216
--- www/env-opts.md
+++ www/env-opts.md
@@ -141,10 +141,16 @@
141141
`FOSSIL_HOME`: Location of the `~/.fossil` file. The first environment
142142
variable found in the environment from the list `FOSSIL_HOME`,
143143
`LOCALAPPDATA` (Windows), `APPDATA` (Windows), `HOMEDRIVE` and
144144
`HOMEPATH` (Windows, used together), and `HOME` is used as the
145145
location of the `~/.fossil` file.
146
+
147
+
148
+`FOSSIL_USE_SEE_TEXTKEY`: If set, treat the encryption key string for
149
+SEE as text to be hashed into the actaul encryption key. This has no
150
+effect if Fossil was not compiled with SEE support enabled.
151
+
146152
147153
`FOSSIL_USER`: Name of the default user account if the checkout, local
148154
or global `default-user` setting is not present. The first environment
149155
variable found in the environment from the list `FOSSIL_USER`, `USER`,
150156
`LOGNAME`, and `USERNAME` is the user name. If none of those are set,
151157
--- www/env-opts.md
+++ www/env-opts.md
@@ -141,10 +141,16 @@
141 `FOSSIL_HOME`: Location of the `~/.fossil` file. The first environment
142 variable found in the environment from the list `FOSSIL_HOME`,
143 `LOCALAPPDATA` (Windows), `APPDATA` (Windows), `HOMEDRIVE` and
144 `HOMEPATH` (Windows, used together), and `HOME` is used as the
145 location of the `~/.fossil` file.
 
 
 
 
 
 
146
147 `FOSSIL_USER`: Name of the default user account if the checkout, local
148 or global `default-user` setting is not present. The first environment
149 variable found in the environment from the list `FOSSIL_USER`, `USER`,
150 `LOGNAME`, and `USERNAME` is the user name. If none of those are set,
151
--- www/env-opts.md
+++ www/env-opts.md
@@ -141,10 +141,16 @@
141 `FOSSIL_HOME`: Location of the `~/.fossil` file. The first environment
142 variable found in the environment from the list `FOSSIL_HOME`,
143 `LOCALAPPDATA` (Windows), `APPDATA` (Windows), `HOMEDRIVE` and
144 `HOMEPATH` (Windows, used together), and `HOME` is used as the
145 location of the `~/.fossil` file.
146
147
148 `FOSSIL_USE_SEE_TEXTKEY`: If set, treat the encryption key string for
149 SEE as text to be hashed into the actaul encryption key. This has no
150 effect if Fossil was not compiled with SEE support enabled.
151
152
153 `FOSSIL_USER`: Name of the default user account if the checkout, local
154 or global `default-user` setting is not present. The first environment
155 variable found in the environment from the list `FOSSIL_USER`, `USER`,
156 `LOGNAME`, and `USERNAME` is the user name. If none of those are set,
157

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button