public async Task <IActionResult> ImportNewKey([FromBody] SshKeyCreateRequest request) { if ((await sshKeyBusiness.InsertKeyAsync(request))) { return(Created(string.Empty, null)); } return(BadRequest()); }
public Task <bool> InsertKeyAsync(SshKeyCreateRequest request) { if (request.AutoGenerate) { return(GenerateNewRsaKey(request)); } else { return(ImportRsaPublicKey(request)); } }
private async Task <bool> ImportRsaPublicKey(SshKeyCreateRequest request) { var importedKey = sshKey.FromOpenSshPublicKey(request.Public); var keyToInsert = new SshKey() { Fingerprint = sshKey.GenFingerprint(), Name = request.Name, Public = request.Public }; if ((await sshKeyRepository.InsertAsync(keyToInsert)) > 0) { logger.LogInformation("Key insert."); return(true); } return(false); }
private async Task <bool> GenerateNewRsaKey(SshKeyCreateRequest request) { var numBits = 2048; var exponent = 65537; var success = sshKey.GenerateRsaKey(numBits, exponent); string exportedPrivateKey, exportedPublicKey, exportedPpkKey; bool exportEncrypted; if (success != true) { logger.LogDebug("Bad params passed to RSA key generation method."); return(false); } // Export the RSA private key to OpenSSH, PuTTY, and XML and save. exportEncrypted = false; var fingerprint = sshKey.GenFingerprint(); exportedPrivateKey = sshKey.ToOpenSshPrivateKey(exportEncrypted); exportedPpkKey = sshKey.ToPuttyPrivateKey(exportEncrypted); exportedPublicKey = sshKey.ToOpenSshPublicKey(); var keyToInsert = new SshKey() { Fingerprint = fingerprint, Name = request.Name, Pem = exportedPrivateKey, Private = exportedPpkKey, Public = exportedPublicKey }; if ((await sshKeyRepository.InsertAsync(keyToInsert)) > 0) { logger.LogInformation("Key insert."); return(true); } return(false); }
public CreateSshKeyAction(SshKeyCreateRequest request) { Request = request; }
public async Task <bool> ImportSshKeysAsync(SshKeyCreateRequest request) { var httpResponse = await httpClient.PostAsync("api/sshkey", GetContent(request)); return(httpResponse.IsSuccessStatusCode); }