From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/86673 Path: news.gmane.org!not-for-mail From: Jeff Bellegarde Newsgroups: gmane.emacs.gnus.general Subject: Re: Severe limitations in auth-source-macos-keychain-search Date: Mon, 25 Jan 2016 08:17:26 -0800 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1453741606 24924 80.91.229.3 (25 Jan 2016 17:06:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 Jan 2016 17:06:46 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M34899@lists.math.uh.edu Mon Jan 25 18:06:34 2016 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from lists1.math.uh.edu ([129.7.128.208]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aNkb4-0005gQ-EV for ding-account@gmane.org; Mon, 25 Jan 2016 18:06:34 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.85) (envelope-from ) id 1aNkaF-0005QA-Ib; Mon, 25 Jan 2016 11:05:43 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by lists1.math.uh.edu with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1aNkBe-0005Ew-Hr for ding@lists.math.uh.edu; Mon, 25 Jan 2016 10:40:18 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.85) (envelope-from ) id 1aNkBa-0004nK-A0 for ding@lists.math.uh.edu; Mon, 25 Jan 2016 10:40:18 -0600 Original-Received: from plane.gmane.org ([80.91.229.3]) by quimby.gnus.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1aNkBY-0000CN-UB for ding@gnus.org; Mon, 25 Jan 2016 17:40:12 +0100 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aNkBR-000751-Fk for ding@gnus.org; Mon, 25 Jan 2016 17:40:05 +0100 Original-Received: from static-50-53-124-53.bvtn.or.frontiernet.net ([50.53.124.53]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Jan 2016 17:40:05 +0100 Original-Received: from bellegar by static-50-53-124-53.bvtn.or.frontiernet.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Jan 2016 17:40:05 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 79 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: static-50-53-124-53.bvtn.or.frontiernet.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:82PhUiX0hTJp0tpzDl8F00dn5rI= X-Spam-Score: -1.8 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:86673 Archived-At: Nikolai Weibull writes: > Hi! > > Is anyone actually using auth-source-macos-keychain-search (with Gnus)? > I just finished hacking something into shape. I added the following to my .gnus. I doubt it's the best solution but it appears to work on my machine. ;; 1. spec contains lists for `host' and `port'. I use `first' to arbitrarily search for only the first key. ;; 2. Use -P to search for port instead of -r. -r requires a 4 character term and disallows a term like 'https'. ;; -P seems to work for strings and port numbers. (eval-when-compile (require 'cl)) (defun* auth-source-macos-keychain-search-items (coll type max &rest spec &key label type host user port &allow-other-keys) (let* ((keychain-generic (eq type 'macos-keychain-generic)) (args `(,(if keychain-generic "find-generic-password" "find-internet-password") "-g")) (ret (list :type type))) (when label (setq args (append args (list "-l" label)))) (when host (setq args (append args (list (if keychain-generic "-c" "-s") (first host))))) (when user (setq args (append args (list "-a" user)))) (when port (let ((port (first port))) (if keychain-generic (setq args (append args (list "-s" port))) (setq args (append args (list ;; (if (string-match "[0-9]+" port) "-P" "-r") "-P" port)))))) (unless (equal coll "default") (setq args (append args (list coll)))) (with-temp-buffer (message "Calling security with '%s'" args) (apply 'call-process "/usr/bin/security" nil t nil args) (goto-char (point-min)) (while (not (eobp)) (cond ((looking-at "^password: \"\\(.+\\)\"$") (setq ret (auth-source-macos-keychain-result-append ret keychain-generic "secret" (lexical-let ((v (match-string 1))) (lambda () v))))) ;; TODO: check if this is really the label ;; match 0x00000007 ="AppleID" ((looking-at "^[ ]+0x00000007 =\"\\(.+\\)\"") (setq ret (auth-source-macos-keychain-result-append ret keychain-generic "label" (match-string 1)))) ;; match "crtr"="aapl" ;; match "svce"="AppleID" ((looking-at "^[ ]+\"\\([a-z]+\\)\"[^=]+=\"\\(.+\\)\"") (setq ret (auth-source-macos-keychain-result-append ret keychain-generic (match-string 1) (match-string 2))))) (forward-line))) ;; return `ret' iff it has the :secret key (and (plist-get ret :secret) (list ret))))