<s> """<STR_LIT>""" <EOL> import os <EOL> from twisted . conch . ssh import keys <EOL> from twisted . python import log <EOL> def getRSAKeys ( cfg ) : <EOL> """<STR_LIT:U+0020>""" <EOL> publicKeyFile = cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> privateKeyFile = cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not ( os . path . exists ( publicKeyFile ) and os . path . exists ( privateKeyFile ) ) : <EOL> log . msg ( "<STR_LIT>" ) <EOL> from Crypto . PublicKey import RSA <EOL> from twisted . python import randbytes <EOL> KEY_LENGTH = <NUM_LIT> <EOL> rsaKey = RSA . generate ( KEY_LENGTH , randbytes . secureRandom ) <EOL> publicKeyString = keys . Key ( rsaKey ) . public ( ) . toString ( '<STR_LIT>' ) <EOL> privateKeyString = keys . Key ( rsaKey ) . toString ( '<STR_LIT>' ) <EOL> with open ( publicKeyFile , '<STR_LIT>' ) as f : <EOL> f . write ( publicKeyString ) <EOL> with open ( privateKeyFile , '<STR_LIT>' ) as f : <EOL> f . write ( privateKeyString ) <EOL> else : <EOL> with open ( publicKeyFile , '<STR_LIT:r>' ) as f : <EOL> publicKeyString = f . read ( ) <EOL> with open ( privateKeyFile , '<STR_LIT:r>' ) as f : <EOL> privateKeyString = f . read ( ) <EOL> return publicKeyString , privateKeyString <EOL> def getDSAKeys ( cfg ) : <EOL> """<STR_LIT:U+0020>""" <EOL> publicKeyFile = cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> privateKeyFile = cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not ( os . path . exists ( publicKeyFile ) and os . path . exists ( privateKeyFile ) ) : <EOL> log . msg ( "<STR_LIT>" ) <EOL> from Crypto . PublicKey import DSA <EOL> from twisted . python import randbytes <EOL> KEY_LENGTH = <NUM_LIT> <EOL> dsaKey = DSA . generate ( KEY_LENGTH , randbytes . secureRandom ) <EOL> publicKeyString = keys . Key ( dsaKey ) . public ( ) . toString ( '<STR_LIT>' ) <EOL> privateKeyString = keys . Key ( dsaKey ) . toString ( '<STR_LIT>' ) <EOL> with open ( publicKeyFile , '<STR_LIT>' ) as f : <EOL> f . write ( publicKeyString ) <EOL> with open ( privateKeyFile , '<STR_LIT>' ) as f : <EOL> f . write ( privateKeyString ) <EOL> else : <EOL> with open ( publicKeyFile , '<STR_LIT:r>' ) as f : <EOL> publicKeyString = f . read ( ) <EOL> with open ( privateKeyFile , '<STR_LIT:r>' ) as f : <EOL> privateKeyString = f . read ( ) <EOL> return publicKeyString , privateKeyString </s>
