interface: better exception handling for _try_saving_ssl_cert_for_first_time
This commit is contained in:
@@ -237,10 +237,7 @@ class Interface(PrintError):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def _try_saving_ssl_cert_for_first_time(self, ca_ssl_context):
|
async def _try_saving_ssl_cert_for_first_time(self, ca_ssl_context):
|
||||||
try:
|
ca_signed = await self.is_server_ca_signed(ca_ssl_context)
|
||||||
ca_signed = await self.is_server_ca_signed(ca_ssl_context)
|
|
||||||
except (OSError, aiorpcx.socks.SOCKSError) as e:
|
|
||||||
raise ErrorGettingSSLCertFromServer(e) from e
|
|
||||||
if ca_signed:
|
if ca_signed:
|
||||||
with open(self.cert_path, 'w') as f:
|
with open(self.cert_path, 'w') as f:
|
||||||
# empty file means this is CA signed, not self-signed
|
# empty file means this is CA signed, not self-signed
|
||||||
@@ -282,7 +279,10 @@ class Interface(PrintError):
|
|||||||
# see if we already have cert for this server; or get it for the first time
|
# see if we already have cert for this server; or get it for the first time
|
||||||
ca_sslc = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=ca_path)
|
ca_sslc = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=ca_path)
|
||||||
if not self._is_saved_ssl_cert_available():
|
if not self._is_saved_ssl_cert_available():
|
||||||
await self._try_saving_ssl_cert_for_first_time(ca_sslc)
|
try:
|
||||||
|
await self._try_saving_ssl_cert_for_first_time(ca_sslc)
|
||||||
|
except (OSError, aiorpcx.socks.SOCKSError) as e:
|
||||||
|
raise ErrorGettingSSLCertFromServer(e) from e
|
||||||
# now we have a file saved in our certificate store
|
# now we have a file saved in our certificate store
|
||||||
siz = os.stat(self.cert_path).st_size
|
siz = os.stat(self.cert_path).st_size
|
||||||
if siz == 0:
|
if siz == 0:
|
||||||
@@ -360,7 +360,7 @@ class Interface(PrintError):
|
|||||||
break
|
break
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
else:
|
else:
|
||||||
raise Exception("could not get certificate")
|
raise GracefulDisconnect("could not get certificate after 10 tries")
|
||||||
|
|
||||||
async def get_certificate(self):
|
async def get_certificate(self):
|
||||||
sslc = ssl.SSLContext()
|
sslc = ssl.SSLContext()
|
||||||
|
|||||||
Reference in New Issue
Block a user