<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15028] CalendarServer/trunk/calendarserver/tools/diagnose.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15028">15028</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-08-04 10:39:33 -0700 (Tue, 04 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Remove TLS cert checks since front-end proxy handles that now</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsdiagnosepy">CalendarServer/trunk/calendarserver/tools/diagnose.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsdiagnosepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/diagnose.py (15027 => 15028)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/diagnose.py        2015-08-03 21:59:39 UTC (rev 15027)
+++ CalendarServer/trunk/calendarserver/tools/diagnose.py        2015-08-04 17:39:33 UTC (rev 15028)
</span><span class="lines">@@ -26,15 +26,8 @@
</span><span class="cx"> import subprocess
</span><span class="cx"> import urllib2
</span><span class="cx"> 
</span><del>-from twext.internet.ssl import ChainingOpenSSLContextFactory
-import OpenSSL
</del><span class="cx"> 
</span><del>-
</del><span class="cx"> PREFS_PLIST = &quot;/Library/Server/Preferences/Calendar.plist&quot;
</span><del>-SSLPrivateKey = &quot;&quot;
-SSLCertAdmin = &quot;&quot;
-SSLPassPhraseDialog = &quot;&quot;
-SSLPort = &quot;&quot;
</del><span class="cx"> ServerHostName = &quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -154,16 +147,6 @@
</span><span class="cx"> 
</span><span class="cx">     connectToAgent(password)
</span><span class="cx"> 
</span><del>-    if keys.get(&quot;EnableSSL&quot;, &quot;False&quot;) == &quot;True&quot;:
-        success, message = verifyTLSCertificate(keys)
-        if success:
-            print(&quot;TLS Certificate OK&quot;)
-        else:
-            print(&quot;Problem with TLS certificate: {}&quot;.format(message))
-            print(&quot;Try resetting the certificate for Calendar and Contacts in Server.app&quot;)
-    else:
-        print(&quot;TLS is disabled&quot;)
-
</del><span class="cx">     connectToCaldavd(keys)
</span><span class="cx"> 
</span><span class="cx">     showWebApps()
</span><span class="lines">@@ -415,30 +398,13 @@
</span><span class="cx">         &quot;Authentication.Basic.Enabled&quot;,
</span><span class="cx">         &quot;Authentication.Digest.Enabled&quot;,
</span><span class="cx">         &quot;Authentication.Kerberos.Enabled&quot;,
</span><del>-        &quot;EnableSSL&quot;,
</del><ins>+        &quot;ServerHostName&quot;,
</ins><span class="cx">         &quot;HTTPPort&quot;,
</span><span class="cx">         &quot;SSLPort&quot;,
</span><del>-        &quot;RedirectHTTPToHTTPS&quot;,
-        &quot;SSLCertificate&quot;,
-        &quot;SSLPrivateKey&quot;,
-        &quot;SSLAuthorityChain&quot;,
-        &quot;SSLCertAdmin&quot;,
-        &quot;SSLPassPhraseDialog&quot;,
-        &quot;ServerHostName&quot;,
</del><span class="cx">     )
</span><span class="cx">     hidden = [
</span><del>-        &quot;SSLCertificate&quot;,
-        &quot;SSLPrivateKey&quot;,
-        &quot;SSLAuthorityChain&quot;,
-        &quot;SSLCertAdmin&quot;,
-        &quot;SSLPassPhraseDialog&quot;,
</del><span class="cx">         &quot;ServerHostName&quot;,
</span><span class="cx">     ]
</span><del>-    ifHasValue = [
-        &quot;SSLCertificate&quot;,
-        &quot;SSLPrivateKey&quot;,
-        &quot;SSLAuthorityChain&quot;,
-    ]
</del><span class="cx">     keys = {}
</span><span class="cx">     for line in stdout.split(&quot;\n&quot;):
</span><span class="cx">         if &quot;=&quot; in line:
</span><span class="lines">@@ -446,8 +412,6 @@
</span><span class="cx">             keys[key] = value
</span><span class="cx">             if key not in hidden:
</span><span class="cx">                 print(&quot;{key} : {value}&quot;.format(key=key, value=value))
</span><del>-            if key in ifHasValue and value:
-                print(&quot;{key} is set&quot;.format(key=key))
</del><span class="cx">     return keys
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -637,211 +601,32 @@
</span><span class="cx">     print()
</span><span class="cx">     print(&quot;Server connection:&quot;)
</span><span class="cx"> 
</span><del>-    httpPort = keys.get(&quot;HTTPPort&quot;, &quot;8008&quot;)
-    sslPort = keys.get(&quot;SSLPort&quot;, &quot;8443&quot;)
-    # redirect = keys.get(&quot;RedirectHTTPToHTTPS&quot;, &quot;False&quot;) == &quot;True&quot;
-    sslEnabled = keys.get(&quot;EnableSSL&quot;, &quot;False&quot;) == &quot;True&quot;
</del><ins>+    url = &quot;https://{host}/principals/&quot;.format(host=keys[&quot;ServerHostName&quot;])
+    try:
+        print(&quot;Attempting to send a request to port 443...&quot;)
+        response = urllib2.urlopen(url, timeout=30)
+        html = response.read()
+        code = response.getcode()
+        print(code, html)
+        if code == 200:
+            print(&quot;Received 200 response&quot;)
</ins><span class="cx"> 
</span><del>-    if httpPort:
-        url = &quot;http://localhost:{}/&quot;.format(httpPort)
-        try:
-            print(&quot;Attempting to send a request to port {}...&quot;.format(httpPort))
-            response = urllib2.urlopen(url, timeout=30)
-            html = response.read()
-            code = response.getcode()
-            print(code, html)
-            if code == 200:
-                print(&quot;Received 200 response&quot;)
</del><ins>+    except urllib2.HTTPError as e:
+        code = e.code
+        reason = e.reason
</ins><span class="cx"> 
</span><del>-        except urllib2.HTTPError as e:
-            code = e.code
-            reason = e.reason
-
-            if code == 401:
-                print(&quot;Got the expected response&quot;)
-            else:
-                print(
-                    &quot;Got an unexpected response: {code} {reason}&quot;.format(
-                        code=code, reason=reason
-                    )
-                )
-
-        except Exception as e:
</del><ins>+        if code == 401:
+            print(&quot;Got the expected response&quot;)
+        else:
</ins><span class="cx">             print(
</span><del>-                &quot;Can't connect to port {port}: {error}&quot;.format(
-                    port=httpPort, error=e
</del><ins>+                &quot;Got an unexpected response: {code} {reason}&quot;.format(
+                    code=code, reason=reason
</ins><span class="cx">                 )
</span><span class="cx">             )
</span><span class="cx"> 
</span><del>-
-    if sslPort and sslEnabled:
-        url = &quot;https://localhost:{}/&quot;.format(sslPort)
-        try:
-            print(&quot;Attempting to send a request to port {}...&quot;.format(sslPort))
-            response = urllib2.urlopen(url, timeout=30)
-            html = response.read()
-            code = response.getcode()
-            print(code, html)
-            if code == 200:
-                print(&quot;Received 200 response&quot;)
-
-        except urllib2.HTTPError as e:
-            code = e.code
-            reason = e.reason
-
-            if code == 401:
-                print(&quot;Got the expected response&quot;)
-            else:
-                print(
-                    &quot;Got an unexpected response: {code} {reason}&quot;.format(
-                        code=code, reason=reason
-                    )
-                )
-
-        except Exception as e:
-            print(
-                &quot;Can't connect to port {port}: {error}&quot;.format(
-                    port=sslPort, error=e
-                )
-            )
-    else:
-        print(&quot;Skipping TLS port since it's disabled&quot;)
-
-
-
-def getSSLPassphrase(*ignored):
-
-    if not SSLPrivateKey:
-        return None
-
-    if SSLCertAdmin and os.path.isfile(SSLCertAdmin):
-        child = subprocess.Popen(
-            args=[
-                &quot;sudo&quot;, SSLCertAdmin,
-                &quot;--get-private-key-passphrase&quot;, SSLPrivateKey,
-            ],
-            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-        )
-        output, error = child.communicate()
-
-        if child.returncode:
-            print(
-                &quot;Could not get passphrase for key: {error}&quot;.format(
-                    error=error
-                )
-            )
-        else:
-            print(&quot;Obtained passphrase for key&quot;)
-            return output.strip()
-
-    if (
-        SSLPassPhraseDialog and
-        os.path.isfile(SSLPassPhraseDialog)
-    ):
-        sslPrivKey = open(SSLPrivateKey)
-        try:
-            keyType = None
-            for line in sslPrivKey.readlines():
-                if &quot;-----BEGIN RSA PRIVATE KEY-----&quot; in line:
-                    keyType = &quot;RSA&quot;
-                    break
-                elif &quot;-----BEGIN DSA PRIVATE KEY-----&quot; in line:
-                    keyType = &quot;DSA&quot;
-                    break
-        finally:
-            sslPrivKey.close()
-
-        if keyType is None:
-            print(&quot;Could not get private key type for key&quot;)
-        else:
-            child = subprocess.Popen(
-                args=[
-                    SSLPassPhraseDialog,
-                    &quot;{}:{}&quot;.format(ServerHostName, SSLPort),
-                    keyType,
-                ],
-                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-            )
-            output, error = child.communicate()
-
-            if child.returncode:
-                print(
-                    &quot;Could not get passphrase for key: {error}&quot;.format(
-                        error=error
-                    )
-                )
-            else:
-                return output.strip()
-
-    return None
-
-
-
-def verifyTLSCertificate(keys):
-    &quot;&quot;&quot;
-    If a TLS certificate is configured, make sure it exists, is non empty,
-    and that it's valid.
-    &quot;&quot;&quot;
-    global SSLPrivateKey
-    global SSLCertAdmin
-    global SSLPassPhraseDialog
-    global SSLPort
-    global ServerHostName
-
-    certPath = keys.get(&quot;SSLCertificate&quot;, &quot;&quot;)
-    keyPath = keys.get(&quot;SSLPrivateKey&quot;, &quot;&quot;)
-    chainPath = keys.get(&quot;SSLAuthorityChain&quot;, &quot;&quot;)
-
-    SSLPrivateKey = keyPath
-    SSLCertAdmin = keys.get(&quot;SSLCertAdmin&quot;, &quot;&quot;)
-    SSLPassPhraseDialog = keys.get(&quot;SSLPassPhraseDialog&quot;, &quot;&quot;)
-    SSLPort = keys.get(&quot;SSLPort&quot;, &quot;&quot;)
-    ServerHostName = keys.get(&quot;ServerHostName&quot;, &quot;&quot;)
-
-    print()
-    print(&quot;Checking TLS Certificate:&quot;)
-
-    if certPath:
-        if not os.path.exists(certPath):
-            message = (
-                &quot;The configured TLS certificate ({cert}) is missing&quot;.format(
-                    cert=certPath
-                )
-            )
-            return False, message
-    else:
-        return False, &quot;EnableSSL is set to true, but certificate path not set&quot;
-
-    length = os.stat(certPath).st_size
-    if length == 0:
-            message = (
-                &quot;The configured TLS certificate ({cert}) is empty&quot;.format(
-                    cert=certPath
-                )
-            )
-            return False, message
-
-    try:
-        ChainingOpenSSLContextFactory(
-            keyPath,
-            certPath,
-            certificateChainFile=chainPath,
-            passwdCallback=getSSLPassphrase,
-            sslmethod=getattr(OpenSSL.SSL, &quot;SSLv23_METHOD&quot;),
-            ciphers=&quot;RC4-SHA:HIGH:!ADH&quot;
-        )
</del><span class="cx">     except Exception as e:
</span><del>-        message = (
-            &quot;The configured TLS certificate ({cert}) cannot be used: {reason}&quot;.format(
-                cert=certPath,
-                reason=str(e)
-            )
-        )
-        return False, message
</del><ins>+        print(&quot;Can't connect to port 443: {error}&quot;.format(error=e))
</ins><span class="cx"> 
</span><del>-    return True, &quot;TLS enabled&quot;
</del><span class="cx"> 
</span><del>-
-
</del><span class="cx"> if __name__ == &quot;__main__&quot;:
</span><span class="cx">     main()
</span></span></pre>
</div>
</div>

</body>
</html>