public override int Run(string[] remainingArguments) { try { if (!string.IsNullOrEmpty(_privKeyPass)) { Console.Out.Write(" *** Enter password for the private key *** : "); _privKeyPass = StandardInput.GetHiddenInput(); } else { _privKeyPass = AlphaNumeric.CreateString(32); Console.Out.WriteLine($" *** The password for the private key *** : {_privKeyPass}"); } var privKey = KeyHelper.CreatePrivKey(_conf, _uow, _keyAlgo, _privKeySize, _privKeyPass, SignatureHashAlgorithm.SHA256); var pubKey = _uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.PrivateKeyId == privKey.Id).ToLambda()) .Single(); Console.Out.WriteLine($"{privKey.KeyValue}"); Console.Out.WriteLine($"{pubKey.KeyValue}"); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public void Create() { if (_uow.InstanceType == InstanceContext.DeployedOrLocal) { throw new InvalidOperationException(); } /* * create key pairs for daemons */ KeyHelper.CheckPrivKey(_conf, _uow, SshHostKeyAlgorithm.DSS, 1024, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256); KeyHelper.CheckPrivKey(_conf, _uow, SshHostKeyAlgorithm.RSA, 4096, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256); KeyHelper.CheckPrivKey(_conf, _uow, SshHostKeyAlgorithm.ECDsaNistP256, 256, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256); KeyHelper.CheckPrivKey(_conf, _uow, SshHostKeyAlgorithm.ECDsaNistP384, 384, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256); KeyHelper.CheckPrivKey(_conf, _uow, SshHostKeyAlgorithm.ECDsaNistP521, 521, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256); KeyHelper.CheckPrivKey(_conf, _uow, SshHostKeyAlgorithm.ED25519, 256, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256); /* * create composite test users */ var foundCompositeUser = _uow.Users.Get(QueryExpressionFactory.GetQueryExpression <tbl_User>() .Where(x => x.IdentityAlias == Constants.TestCompositeUser).ToLambda()) .SingleOrDefault(); if (foundCompositeUser == null) { foundCompositeUser = _uow.Users.Create( new tbl_User() { IdentityId = Guid.NewGuid(), IdentityAlias = Constants.TestCompositeUser, RequirePassword = true, RequirePublicKey = false, FileSystemType = FileSystemTypes.Composite.ToString(), Created = DateTime.Now, Enabled = true, Deletable = true, }); _uow.Commit(); KeyHelper.CreatePrivKey(_conf, _uow, foundCompositeUser, SshHostKeyAlgorithm.RSA, 2048, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256, Dns.GetHostName()); } /* * create memory test users */ var foundMemoryUser = _uow.Users.Get(QueryExpressionFactory.GetQueryExpression <tbl_User>() .Where(x => x.IdentityAlias == Constants.TestMemoryUser).ToLambda()) .SingleOrDefault(); if (foundMemoryUser == null) { foundMemoryUser = _uow.Users.Create( new tbl_User() { IdentityId = Guid.NewGuid(), IdentityAlias = Constants.TestMemoryUser, RequirePassword = true, RequirePublicKey = false, FileSystemType = FileSystemTypes.Memory.ToString(), Created = DateTime.Now, Enabled = true, Deletable = true, }); _uow.Commit(); KeyHelper.CreatePrivKey(_conf, _uow, foundMemoryUser, SshHostKeyAlgorithm.RSA, 2048, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256, Dns.GetHostName()); } /* * create smb test users */ var foundSmbUser = _uow.Users.Get(QueryExpressionFactory.GetQueryExpression <tbl_User>() .Where(x => x.IdentityAlias == Constants.TestSmbUser).ToLambda()) .SingleOrDefault(); if (foundSmbUser == null) { foundSmbUser = _uow.Users.Create( new tbl_User() { IdentityId = Guid.NewGuid(), IdentityAlias = Constants.TestSmbUser, RequirePassword = true, RequirePublicKey = false, FileSystemType = FileSystemTypes.SMB.ToString(), Created = DateTime.Now, Enabled = true, Deletable = true, }); _uow.Commit(); KeyHelper.CreatePrivKey(_conf, _uow, foundSmbUser, SshHostKeyAlgorithm.RSA, 2048, AlphaNumeric.CreateString(32), SignatureHashAlgorithm.SHA256, Dns.GetHostName()); } }