Differences From:
File
src/xfer.c
part of check-in
[48c4e69d2b]
- Cluster-based synchronization appears to be working.
by
drh on
2007-09-09 17:51:16.
Also file
src/xfer.c
part of check-in
[bbcb6326c9]
- Pulled in the navbar and timeline changes.
by
aku on
2007-09-17 00:58:51.
[view]
To:
File
src/xfer.c
part of check-in
[776753118f]
- The nonce of a login card in the sync protocol is now the SHA1 hash
of the remainder of the sync message. The signature is the SHA1 hash
of the concatenation of the nonce and the users password.
by
drh on
2007-09-12 02:25:37.
Also file
src/xfer.c
part of check-in
[f76192b245]
- Pulled the latest CLI, website, and sqlite changes into the importer branch.
by
aku on
2007-09-17 01:00:32.
[view]
@@ -248,18 +248,35 @@
}
db_finalize(&q);
}
+/*
+** Compute an SHA1 hash on the tail of pMsg. Verify that it matches the
+** the hash given in pHash. Return 1 on a successful match. Return 0
+** if there is a mismatch.
+*/
+static int check_tail_hash(Blob *pHash, Blob *pMsg){
+ Blob tail;
+ Blob h2;
+ int rc;
+ blob_tail(pMsg, &tail);
+ sha1sum_blob(&tail, &h2);
+ rc = blob_compare(pHash, &h2);
+ blob_reset(&h2);
+ blob_reset(&tail);
+ return rc==0;
+}
+
/*
** Check the signature on an application/x-fossil payload received by
** the HTTP server. The signature is a line of the following form:
**
** login LOGIN NONCE SIGNATURE
**
-** The NONCE is a random string. The server will never accept a
-** repeat NONCE. SIGNATURE is the SHA1 checksum of the NONCE
-** concatenated with the users password.
+** The NONCE is the SHA1 hash of the remainder of the input.
+** SIGNATURE is the SHA1 checksum of the NONCE concatenated
+** with the users password.
**
** The parameters to this routine are ephermeral blobs holding the
** LOGIN, NONCE and SIGNATURE.
**
@@ -275,11 +292,8 @@
void check_login(Blob *pLogin, Blob *pNonce, Blob *pSig){
Stmt q;
int rc;
- if( db_exists("SELECT 1 FROM rcvfrom WHERE nonce=%B", pNonce) ){
- return; /* Never accept a repeated nonce */
- }
db_prepare(&q, "SELECT pw, cap, uid FROM user WHERE login=%B", pLogin);
if( db_step(&q)==SQLITE_ROW ){
Blob pw, combined, hash;
blob_zero(&pw);
@@ -537,9 +551,9 @@
&& xfer.nToken==4
){
if( disableLogin ){
g.okRead = g.okWrite = 1;
- }else{
+ }else if( check_tail_hash(&xfer.aToken[2], xfer.pIn) ){
check_login(&xfer.aToken[1], &xfer.aToken[2], &xfer.aToken[3]);
}
}else