def sshKeygen(request): keyFilePath = getNewTempFilePath() subprocess.check_output( [ 'ssh-keygen' , '-q' , '-t', 'rsa' , '-f', keyFilePath , '-N', '' , '-C', 'polychart' ]) with open(keyFilePath) as f: privateKey = f.read() with open(keyFilePath + '.pub') as f: publicKey = f.read() deleteOnExit(keyFilePath + '.pub') return jsonResponse({'privateKey': privateKey, 'publicKey': publicKey})
def sshFileExists(request): clientDsObj = json.loads(request.body) username = clientDsObj['username'] host = clientDsObj['host'] port = int(clientDsObj['port']) privateKey = clientDsObj['privateKey'] filePath = clientDsObj['filePath'] socket = bool(clientDsObj.get('isSocket', False)) if not validate.linuxUsername(username): return jsonResponse({'status': 'connFailed', 'invalidField': 'username'}) if not validate.hostname(host): return jsonResponse({'status': 'connFailed', 'invalidField': 'host'}) if not validate.filepath(filePath): return jsonResponse({'status': 'connFailed', 'invalidField': 'filePath'}) # 0600 permissions required by ssh keyPath = getNewTempFilePath() with os.fdopen(os.open(keyPath, os.O_WRONLY | os.O_CREAT, 0600), 'w') as f: f.write(privateKey)