Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
LukaP

Python filenames

14 minutes ago, LukaP said:

context.load_cert_chain(certfile="[].pem".format(username), keyfile="[]key.pem".format(username))

Sounds like a fun project!, You are using the wrong syntax for the string form, change [] to {} as shown below :)

 

>>> username = "hello"
>>> "[].pem".format(username)
'[].pem'
>>> "{}.pem".format(username)
'hello.pem'
>>>

 

Recommended Posts

Posted · Original PosterOP

Im making a messaging server and client in python for uni. We have to implement SSL/TLS encryption. 

 

So i use this code to create a context, but come up with a problem when i try to pass certificate and key files to it

def setup_SSL_context():

	#uporabi samo TLS, ne SSL
	context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
	# certifikat je obvezen
	context.verify_mode = ssl.CERT_REQUIRED
	#nalozi svoje certifikate
	context.load_cert_chain(certfile="luka.pem", keyfile="lukakey.pem") # the line that confuses python
	# nalozi certifikate CAjev (samopodp. cert.= svoja CA!)
	context.load_verify_locations('server.pem')
	# nastavi SSL CipherSuites (nacin kriptiranja)
	context.set_ciphers('AES128-SHA')
	return context

if i directly pass the files like that, its all working properly, but well, i want this client to support more than one user, so my solution was to pass filenames as formatted strings like this

username = input() # yes i did input luka...
#foo
context.load_cert_chain(certfile="[].pem".format(username), keyfile="[]key.pem".format(username))

which threw a FileNotFound Exception, but only on the lukakey.pem file...

 

Does anyone have any idea why it does that?


"Unofficially Official" Leading Scientific Research and Development Officer of the Official Star Citizen LTT Conglomerate | Reaper Squad, Idris Captain | 1x Aurora LN


Game developer, AI researcher, Developing the UOLTT mobile apps


G SIX [My Mac Pro G5 CaseMod Thread]

Link to post
Share on other sites
Posted · Best Answer
14 minutes ago, LukaP said:

context.load_cert_chain(certfile="[].pem".format(username), keyfile="[]key.pem".format(username))

Sounds like a fun project!, You are using the wrong syntax for the string form, change [] to {} as shown below :)

 

>>> username = "hello"
>>> "[].pem".format(username)
'[].pem'
>>> "{}.pem".format(username)
'hello.pem'
>>>

 

Link to post
Share on other sites
Posted · Original PosterOP
2 minutes ago, Adraen said:

You are using [] instead of {}

 


>>> username = "hello"
>>> "[].pem".format(username)
'[].pem'
>>> "{}.pem".format(username)
'hello.pem'
>>>

 

I am a moron, thank you xD


"Unofficially Official" Leading Scientific Research and Development Officer of the Official Star Citizen LTT Conglomerate | Reaper Squad, Idris Captain | 1x Aurora LN


Game developer, AI researcher, Developing the UOLTT mobile apps


G SIX [My Mac Pro G5 CaseMod Thread]

Link to post
Share on other sites
On 6/9/2016 at 7:07 PM, LukaP said:

I am a moron, thank you xD

I agree from the bottom of my heart <3


  ﷲ   Muslim Member  ﷲ

KennyS and ScreaM are my role models in CSGO.

CPU: i3-4130 Motherboard: Gigabyte H81M-S2PH RAM: 8GB Kingston hyperx fury HDD: WD caviar black 1TB GPU: MSI 750TI twin frozr II Case: Aerocool Xpredator X3 PSU: Corsair RM650

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×