diff --git a/pyVmomi/SoapAdapter.py b/pyVmomi/SoapAdapter.py index e1b6b39..1522bc7 100644 --- a/pyVmomi/SoapAdapter.py +++ b/pyVmomi/SoapAdapter.py @@ -104,6 +104,17 @@ def encode(string, encoding): return string.encode(encoding) return u(string) +## Thumbprint mismatch exception +# +class ThumbprintMismatchException(Exception): + def __init__(self, expected, actual): + Exception.__init__(self, "Server has wrong SHA1 thumbprint: %s " + "(required) != %s (server)" % ( + expected, actual)) + + self.expected = expected + self.actual = actual + ## Escape <, >, & def XmlEscape(xmlStr): escaped = xmlStr.replace("&", "&").replace(">", ">").replace("<", "<") @@ -930,9 +941,7 @@ try: sha1.update(derCert) sha1Digest = sha1.hexdigest().lower() if sha1Digest != thumbprint: - raise Exception("Server has wrong SHA1 thumbprint: {0} " - "(required) != {1} (server)".format( - thumbprint, sha1Digest)) + raise ThumbprintMismatchException(thumbprint, sha1Digest) # Function used to wrap sockets with SSL _SocketWrapper = ssl.wrap_socket diff --git a/pyVmomi/__init__.py b/pyVmomi/__init__.py index 999204e..47dc56f 100644 --- a/pyVmomi/__init__.py +++ b/pyVmomi/__init__.py @@ -198,7 +198,7 @@ except ImportError: pyVmomi.VmomiSupport.GetVmodlType("vmodl.DynamicData") from pyVmomi.SoapAdapter import SoapStubAdapter, StubAdapterBase, SoapCmdStubAdapter, \ - SessionOrientedStub + SessionOrientedStub, ThumbprintMismatchException types = pyVmomi.VmomiSupport.types