diff options
| author | Lars Ingebrigtsen | 2019-09-20 23:57:34 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-20 23:57:34 +0200 |
| commit | 280cf93f313925375cf57d1d64bfbe940f950452 (patch) | |
| tree | a70d009252a4487495b60b6a4e7b0420138d2937 | |
| parent | c3958e48f6a257fa7e681b2b39ea83d677bcb2f3 (diff) | |
| download | emacs-280cf93f313925375cf57d1d64bfbe940f950452.tar.gz emacs-280cf93f313925375cf57d1d64bfbe940f950452.zip | |
Further touch-ups to the auth-source obfuscation
* lisp/auth-source.el (auth-source--obfuscate): Avoid leaking the
length of the password by using PKCS#7 padding.
| -rw-r--r-- | lisp/auth-source.el | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 365ed2fa284..464facdeafa 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el | |||
| @@ -1172,42 +1172,45 @@ FILE is the file from which we obtained this token." | |||
| 1172 | ;; have to call `auth-source-forget-all-cached'. | 1172 | ;; have to call `auth-source-forget-all-cached'. |
| 1173 | (unless auth-source--session-nonce | 1173 | (unless auth-source--session-nonce |
| 1174 | (setq auth-source--session-nonce | 1174 | (setq auth-source--session-nonce |
| 1175 | (apply #'string (cl-loop repeat 32 | 1175 | (apply #'string (cl-loop repeat 16 |
| 1176 | collect (random 128))))) | 1176 | collect (random 128))))) |
| 1177 | (if (and (fboundp 'gnutls-symmetric-encrypt) | 1177 | (if (and (fboundp 'gnutls-symmetric-encrypt) |
| 1178 | (gnutls-available-p)) | 1178 | (gnutls-available-p)) |
| 1179 | (let ((cdata (car (last (gnutls-ciphers))))) | 1179 | (let ((cdata (car (last (gnutls-ciphers))))) |
| 1180 | (mapconcat | 1180 | (mapconcat |
| 1181 | #'base64-encode-string | 1181 | #'base64-encode-string |
| 1182 | (append | 1182 | (gnutls-symmetric-encrypt |
| 1183 | (list (format "%d" (length string))) | 1183 | (pop cdata) |
| 1184 | (gnutls-symmetric-encrypt | 1184 | (auth-source--pad auth-source--session-nonce |
| 1185 | (pop cdata) | 1185 | (plist-get cdata :cipher-keysize)) |
| 1186 | (auth-source--pad auth-source--session-nonce | 1186 | (list 'iv-auto (plist-get cdata :cipher-ivsize)) |
| 1187 | (plist-get cdata :cipher-keysize)) | 1187 | (auth-source--pad string (plist-get cdata :cipher-blocksize))) |
| 1188 | (list 'iv-auto (plist-get cdata :cipher-ivsize)) | ||
| 1189 | (auth-source--pad string (plist-get cdata :cipher-blocksize)))) | ||
| 1190 | "-")) | 1188 | "-")) |
| 1191 | (mapcar #'1- string))) | 1189 | (mapcar #'1- string))) |
| 1192 | 1190 | ||
| 1193 | (defun auth-source--pad (s length) | 1191 | (defun auth-source--pad (string length) |
| 1194 | "Pad string S to a modulo of LENGTH." | 1192 | "Pad string S to a modulo of LENGTH." |
| 1195 | (concat s (make-string (- length (mod (length s) length)) ?\0))) | 1193 | (let ((pad (- length (mod (length string) length)))) |
| 1194 | (concat string (make-string pad pad)))) | ||
| 1195 | |||
| 1196 | (defun auth-source--unpad (string) | ||
| 1197 | "Remove PKCS#7 padding from STRING." | ||
| 1198 | (substring string 0 (- (length string) | ||
| 1199 | (aref string (1- (length string)))))) | ||
| 1196 | 1200 | ||
| 1197 | (defun auth-source--deobfuscate (data) | 1201 | (defun auth-source--deobfuscate (data) |
| 1198 | (if (and (fboundp 'gnutls-symmetric-encrypt) | 1202 | (if (and (fboundp 'gnutls-symmetric-encrypt) |
| 1199 | (gnutls-available-p)) | 1203 | (gnutls-available-p)) |
| 1200 | (let ((cdata (car (last (gnutls-ciphers)))) | 1204 | (let ((cdata (car (last (gnutls-ciphers)))) |
| 1201 | (bits (split-string data "-"))) | 1205 | (bits (split-string data "-"))) |
| 1202 | (substring | 1206 | (auth-source--unpad |
| 1203 | (car | 1207 | (car |
| 1204 | (gnutls-symmetric-decrypt | 1208 | (gnutls-symmetric-decrypt |
| 1205 | (pop cdata) | 1209 | (pop cdata) |
| 1206 | (auth-source--pad auth-source--session-nonce | 1210 | (auth-source--pad auth-source--session-nonce |
| 1207 | (plist-get cdata :cipher-keysize)) | 1211 | (plist-get cdata :cipher-keysize)) |
| 1208 | (base64-decode-string (caddr bits)) | 1212 | (base64-decode-string (cadr bits)) |
| 1209 | (base64-decode-string (cadr bits)))) | 1213 | (base64-decode-string (car bits)))))) |
| 1210 | 0 (string-to-number (base64-decode-string (car bits))))) | ||
| 1211 | (apply #'string (mapcar #'1+ data)))) | 1214 | (apply #'string (mapcar #'1+ data)))) |
| 1212 | 1215 | ||
| 1213 | (cl-defun auth-source-netrc-search (&rest spec | 1216 | (cl-defun auth-source-netrc-search (&rest spec |