[CalendarServer-changes] [15241] CalendarServer/trunk/bin

source_changes at macosforge.org source_changes at macosforge.org
Wed Oct 28 06:47:26 PDT 2015


Revision: 15241
          http://trac.calendarserver.org//changeset/15241
Author:   cdaboo at apple.com
Date:     2015-10-28 06:47:26 -0700 (Wed, 28 Oct 2015)
Log Message:
-----------
Unlock keychain to allow access to certs when testing or running.

Modified Paths:
--------------
    CalendarServer/trunk/bin/run
    CalendarServer/trunk/bin/test

Added Paths:
-----------
    CalendarServer/trunk/bin/keychain_unlock.py

Added: CalendarServer/trunk/bin/keychain_unlock.py
===================================================================
--- CalendarServer/trunk/bin/keychain_unlock.py	                        (rev 0)
+++ CalendarServer/trunk/bin/keychain_unlock.py	2015-10-28 13:47:26 UTC (rev 15241)
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+##
+# Copyright (c) 2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from subprocess import Popen, PIPE, STDOUT
+import os
+import sys
+
+password_file = os.path.expanduser("~/.keychain")
+
+def isKeychainUnlocked():
+
+    child = Popen(
+        args=[
+            "/usr/bin/security", "show-keychain-info",
+            "login.keychain",
+        ],
+        stdout=PIPE, stderr=STDOUT,
+    )
+    _ignore_output, _ignore_error = child.communicate()
+
+    if child.returncode:
+        return False
+    else:
+        return True
+
+
+
+def unlockKeychain():
+
+    if not os.path.isfile(password_file):
+        print("Could not unlock login.keychain: no password available.")
+        return False
+
+    with open(password_file) as f:
+        password = f.read().strip()
+
+    child = Popen(
+        args=[
+            "/usr/bin/security", "unlock-keychain",
+            "-p", password,
+            "login.keychain",
+        ],
+        stdout=PIPE, stderr=STDOUT,
+    )
+    output, error = child.communicate()
+
+    if child.returncode:
+        print("Could not unlock login.keychain: {}".format(error if error else output))
+        return False
+    else:
+        print("Unlocked login.keychain")
+        return True
+
+
+
+if __name__ == '__main__':
+
+    if os.path.isfile("/usr/bin/security"):
+        if isKeychainUnlocked():
+            print("Keychain already unlocked")
+        else:
+            # If the identity exists we are done
+            result = unlockKeychain()
+    else:
+        print("Keychain access utility ('security') not found")
+        result = False
+    sys.exit(0 if True else 1)


Property changes on: CalendarServer/trunk/bin/keychain_unlock.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: CalendarServer/trunk/bin/run
===================================================================
--- CalendarServer/trunk/bin/run	2015-10-27 17:40:22 UTC (rev 15240)
+++ CalendarServer/trunk/bin/run	2015-10-28 13:47:26 UTC (rev 15241)
@@ -159,6 +159,18 @@
       caldavd_wrapper_command="";
     #fi;
 
+    #
+    # Do keychain unlock on OS X
+    #
+    if [ -z "${USE_OPENSSL-}" ]; then
+      case "$(uname -s)" in
+        Darwin)
+          bin/python bin/keychain_unlock.py
+          ;;
+      esac;
+    fi;  
+
+
     echo "";
     echo "Starting server...";
     export PYTHON="${python}";

Modified: CalendarServer/trunk/bin/test
===================================================================
--- CalendarServer/trunk/bin/test	2015-10-27 17:40:22 UTC (rev 15240)
+++ CalendarServer/trunk/bin/test	2015-10-28 13:47:26 UTC (rev 15241)
@@ -106,6 +106,16 @@
 find "${wd}" -name \*.pyc -print0 | xargs -0 rm;
 
 
+#
+# Do keychain unlock on OS X
+#
+if [ -z "${USE_OPENSSL-}" ]; then
+  case "$(uname -s)" in
+    Darwin)
+      bin/python bin/keychain_unlock.py
+      ;;
+  esac;
+fi;  
 
 #
 # Unit tests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151028/032162a2/attachment.html>


More information about the calendarserver-changes mailing list