public async Task <bool> TryLogin(string username, string password) { if (this.create_auth_cli == null) { return(false); } try { var req = new CredReq { Ip = Dns.GetHostName(), Username = username, Password = password, }; CheckCredResp result = await this.create_auth_cli.CheckCredAsync(req); ConfigForm.Username = username; ConfigForm.Password = password; // return(true); } catch (RpcException e) { Debug.LogError(e); return(false); throw; } }
public async Task <bool> GetPemFile() { if (this.create_auth_cli == null) { return(false); } try { var req = new CredReq { Ip = Dns.GetHostName(), Username = ConfigForm.Username, Password = ConfigForm.Password, }; var close_tkn = new CancellationTokenSource(); string[] tpath = { ConfigPath.StreamingAsset, "key.pem" }; if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(tpath)))) { Directory.CreateDirectory( Path.GetDirectoryName( Path.Combine(tpath))); } StreamWriter sw = (File.Exists(Path.Combine(tpath))) ? File.AppendText(Path.Combine(tpath)) : File.CreateText(Path.Combine(tpath)); using (var result = this.create_auth_cli.GetCred(req)) { while (await result.ResponseStream.MoveNext(close_tkn.Token)) { var resp_tmp = result.ResponseStream.Current; sw.WriteLine(resp_tmp.File.ToStringUtf8()); file = file + resp_tmp.File.ToStringUtf8() + "\n"; } } sw.Close(); Debug.Log(file); // try resolve var crt = new SslCredentials(Path.Combine(tpath)); // no error // file = File.ReadAllText(Path.Combine(tpath)); ConfigForm.KeyPemPath = "%StreamAsset%/" + "key.pem"; // File.Delete(Path.Combine(tpath)); return(true); } catch (RpcException e) { Debug.LogError(e); return(false); throw; } }