aszlig / hetzner

A high-level Python API for accessing the Hetzner robot.
https://pypi.python.org/pypi/hetzner
Other
128 stars 36 forks source link

Default certificate doesn't work on windows #37

Open adrianog opened 4 years ago

adrianog commented 4 years ago

A problem with the temporary file created from this was causing a failure. http://tinyurl.com/ycfs48vu "Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later)."

Solution: line 61 in hetzner\util\http.py:

        if bundle is None:
            ca_certs = NamedTemporaryFile(delete=False)
            ca_certs.write('\n'.join(
                map(str.strip, self.CA_ROOT_CERT_FALLBACK.splitlines())
            ).encode('ascii'))
            ca_certs.flush()
            cafile = ca_certs.name
            ca_certs.close()
        try:
          self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file,
                                      cert_reqs=ssl.CERT_REQUIRED,
                                      ca_certs=cafile)
        finally:
          if bundle is None:
            try:
              os.remove(bundle)
            except:
              pass
adrianog commented 4 years ago

@aszlig that said, I could not fully use this on windows because of a bunch of other problems with OS calls. Some functionality was ok.

Perhaps worth specifying this is Linux only for now.

aszlig commented 4 years ago

@adrianog: In theory only the command line helper should cause trouble on Windows, so I'd be curious which OS calls you stumbled on that were not supported.