Skip to content

Commit

Permalink
Merge pull request #201 from TurBoss/ServerPEM
Browse files Browse the repository at this point in the history
Fix generate server.pem
  • Loading branch information
abma authored Apr 8, 2017
2 parents ac1999b + 98130aa commit 51f79be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions DataHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ def loadCertificates(self):
import certificate
certificate.create_self_signed_cert(certfile)
os.chmod(certfile, 0o600)
f = open(certfile, "r")
self.cert = ssl.PrivateCertificate.loadPEM(f.read()).options()
f.close()
with open(certfile, 'r') as data:
self.cert = ssl.PrivateCertificate.loadPEM(data.read()).options()

def parseFiles(self):
if os.path.isfile('motd.txt'):
Expand Down
10 changes: 5 additions & 5 deletions certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time

def timestr():
return time.strftime("%Y%m%d%H%M%SZ", time.gmtime())
return time.strftime("%Y%m%d%H%M%SZ", time.gmtime()).encode("UTF-8")

def create_self_signed_cert(filename):
# creates a serlf-signed certificate
Expand Down Expand Up @@ -34,9 +34,9 @@ def create_self_signed_cert(filename):
cert.set_pubkey(k)
cert.sign(k, 'sha1')

f = open(filename, "wt")
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))
f.close()
with open(filename, 'wt') as certfile:
certfile.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("UTF-8"))
certfile.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("UTF-8"))


#create_self_signed_cert("server.key")

0 comments on commit 51f79be

Please sign in to comment.