mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Prevent ssh-keygen prompting for passphrase when blank
This commit is contained in:
		| @@ -22,49 +22,32 @@ var log; | ||||
|  | ||||
| function runSshKeygenCommand(args,cwd,env) { | ||||
|     return new Promise(function(resolve, reject) { | ||||
|         console.log("Spawning command",args); | ||||
|         try { | ||||
|             var child = child_process.spawn(sshkeygenCommand, args, {cwd: cwd, detached: true, env: env}); | ||||
|             var stdout = ""; | ||||
|             var stderr = ""; | ||||
|         var child = child_process.spawn(sshkeygenCommand, args, {cwd: cwd, detached: true, env: env}); | ||||
|         var stdout = ""; | ||||
|         var stderr = ""; | ||||
|  | ||||
|             var watchdog = setTimeout(function() { | ||||
|                 console.log("TIMEOUT"); | ||||
|                 console.log("stdout",stdout); | ||||
|                 console.log("stderr",stderr); | ||||
|                 child.kill(); | ||||
|             },6000); | ||||
|  | ||||
|             child.stdout.on('data', function(data) { | ||||
|                 stdout += data; | ||||
|             }); | ||||
|             child.stderr.on('data', function(data) { | ||||
|                 stderr += data; | ||||
|             }); | ||||
|             child.on('close', function(code, signal) { | ||||
|                 clearTimeout(watchdog); | ||||
|                 console.log("sshKeyGen closed",code); | ||||
|                 console.log("sshKeyGen",stdout); | ||||
|                 console.log("sshKeyGen",stderr); | ||||
|                 if (code !== 0) { | ||||
|                     var err = new Error(stderr); | ||||
|                     err.stdout = stdout; | ||||
|                     err.stderr = stderr; | ||||
|                     if (/passphrase is too short/.test(stderr)) { | ||||
|                         err.code = "key_passphrase_too_short"; | ||||
|                     } else if(/Key must at least be 1024 bits/.test(stderr)) { | ||||
|                         err.code = "key_length_too_short"; | ||||
|                     } | ||||
|                     reject(err); | ||||
|         child.stdout.on('data', function(data) { | ||||
|             stdout += data; | ||||
|         }); | ||||
|         child.stderr.on('data', function(data) { | ||||
|             stderr += data; | ||||
|         }); | ||||
|         child.on('close', function(code, signal) { | ||||
|             if (code !== 0) { | ||||
|                 var err = new Error(stderr); | ||||
|                 err.stdout = stdout; | ||||
|                 err.stderr = stderr; | ||||
|                 if (/passphrase is too short/.test(stderr)) { | ||||
|                     err.code = "key_passphrase_too_short"; | ||||
|                 } else if(/Key must at least be 1024 bits/.test(stderr)) { | ||||
|                     err.code = "key_length_too_short"; | ||||
|                 } | ||||
|                 else { | ||||
|                     resolve(stdout); | ||||
|                 } | ||||
|             }); | ||||
|         } catch(err) { | ||||
|             console.log("Threw error",err); | ||||
|             reject(err); | ||||
|         } | ||||
|                 reject(err); | ||||
|             } | ||||
|             else { | ||||
|                 resolve(stdout); | ||||
|             } | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| @@ -83,9 +66,8 @@ function generateKey(options) { | ||||
|     if (options.comment) { | ||||
|         args.push('-C', options.comment); | ||||
|     } | ||||
|     if (options.password) { | ||||
|         args.push('-N', options.password); | ||||
|     } | ||||
|     args.push('-N', options.password||''); | ||||
|  | ||||
|     return runSshKeygenCommand(args,__dirname); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user