证书渠道服务

pull/1/head
吴顺明 2 years ago
parent 45206f1fe6
commit 6778b406d6

@ -472,7 +472,7 @@ namespace UMC.Host
switch (str[0])
{
case "clear":
UMC.Data.ProviderConfiguration.Cache.Clear();
// UMC.Data.ProviderConfiguration.Cache.Clear();
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes("配置缓存已经清空。\r\n"));
break;
case "vpn":
@ -547,7 +547,7 @@ namespace UMC.Host
var secret = WebResource.Instance().Provider["appSecret"];
if (String.IsNullOrEmpty(secret))
{
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes("\a主体未登记请在云桌面->应用设置->安全注册中完成登记\r\n"));
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes("\a主体未登记请在云桌面中完成登记\r\n"));
break;
}
var webr2 = new Uri(APIProxy.Uri, "Certificater").WebRequest();
@ -582,12 +582,14 @@ namespace UMC.Host
{
webr2.Post(new WebMeta().Put("type", "cert", "domain", host), UMC.Proxy.Utility.Certificate);
}
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes(hs["msg"] as string ?? "正在签发证书\r\n"));
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes(String.Format("{0}\r\n\r\n强烈建议请在\b云桌面->应用设置->网关服务\f中管理证书\r\n", hs["msg"])));
}
else
{
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes(hs["msg"] as string ?? "正在签发证书\r\n"));
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes(String.Format("{0}\r\n\r\n强烈建议请在\b云桌面->应用设置->网关服务\f中管理证书\r\n", hs["msg"])));
}
}
@ -623,7 +625,7 @@ namespace UMC.Host
else
{
sb.AppendLine();
sb.AppendLine("\t更多详情,请在\b云桌面->应用设置->网关服务\f中查看");
sb.AppendLine("强烈建议:请在\b云桌面->应用设置->网关服务\f中管理证书");
}
pipeServer.Write(System.Text.Encoding.UTF8.GetBytes(sb.ToString()));
}

@ -308,20 +308,6 @@ namespace UMC.Host
Process.Start(startInfo);
}
// var process = System.Diagnostics.Process.GetCurrentProcess();
// if (String.Equals(process.ProcessName.ToLower(), "dotnet"))
// {
// var file = Environment.GetCommandLineArgs()[0];
// Process.Start("dotnet", $"{file} {arg}").Close();
// }
// else
// {
// var file = process.MainModule.FileName;
// Process.Start(file, arg).Close();
// }
}
private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
{

@ -1028,6 +1028,18 @@ namespace UMC.Proxy.Activities
var hosts = DataFactory.Instance().Host(site.Root);
ui2 = ui.NewSection().AddCell("应用域名", "配置", new UIClick(new WebMeta(request.Arguments).Put(g, "Host")).Send(request.Model, request.Command));
var union = Data.WebResource.Instance().Provider["union"] ?? ".";
var home = WebResource.Instance().WebDomain();
if (home == "localhost")
{
ui2.AddCell($"{site.Root}{union}[主域名]", "主域名未配置", new UIClick().Send(request.Model, "Server"));
}
else
{
ui2.AddCell($"{site.Root}{union}{home}", new UIClick("Model", "CSR", "Domain", $"{site.Root}.{home}").Send(request.Model, "Server"));
}
foreach (var h in hosts)
{
var Scheme = String.Empty;

@ -46,7 +46,8 @@ namespace UMC.Proxy.Activities
});
var provider = Data.WebResource.Instance().Provider;
ui.AddCell("主协议", provider["scheme"] ?? "http", new UIClick("Domain").Send(request.Model, request.Command))
.AddCell("主域名", provider["domain"] ?? "未设置", new UIClick("Domain").Send(request.Model, request.Command)).AddCell("连接符", provider["union"] ?? ".", new UIClick("Domain").Send(request.Model, request.Command));
.AddCell("主域名", provider["domain"] ?? "未设置", new UIClick("Domain").Send(request.Model, request.Command));
// .AddCell("连接符", provider["union"] ?? ".", new UIClick("Domain").Send(request.Model, request.Command));
ui.NewSection().AddCell("日志组件", new UIClick().Send("Proxy", "LogConf"));
@ -168,11 +169,11 @@ namespace UMC.Proxy.Activities
var union = provider["union"] ?? ".";
var scheme = provider["scheme"] ?? "http";
fm.AddRadio("主协议", "scheme").Put("http", "http", scheme == "http").Put("https", "https", scheme == "https");
fm.AddRadio("连接符", "union").Put("-", "-", union == "-").Put(".", ".", union == ".");
// fm.AddRadio("连接符", "union").Put("-", "-", union == "-").Put(".", ".", union == ".");
fm.Submit("确认", $"{request.Model}.{request.Command}");
return fm;
});
provider.Attributes["union"] = Domains["union"];
// provider.Attributes["union"] = Domains["union"];
provider.Attributes["scheme"] = Domains["scheme"];
provider.Attributes["domain"] = Domains["domain"];
@ -311,7 +312,7 @@ namespace UMC.Proxy.Activities
{
var fm = new UIFormDialog() { Title = "申请证书" };
fm.AddText("域名", "Domain", String.Empty);
fm.AddCheckBox("", "Dcv", "default").Put("自动智能验证域名所有权", "file", true)
fm.AddRadio("", "Dcv").Put("自动智能验证域名所有权", "file", true)
.Put("CName方式验证域名所有权", "cname");
fm.Submit("确认申请", $"{request.Model}.{request.Command}");
return fm;
@ -361,6 +362,12 @@ namespace UMC.Proxy.Activities
else if (string.Equals(hs["code"], "verifing"))
{
response.Redirect(request.Model, request.Command, new WebMeta("Domain", host).Put("Model", "CSR"), true);
}
else if (string.Equals(hs["code"], "privateKey"))
{
response.Redirect(request.Model, request.Command, new WebMeta("Domain", host).Put("Model", "PrivateKey"), true);
}
else if (string.Equals(hs["code"], "url"))
{
@ -460,11 +467,15 @@ namespace UMC.Proxy.Activities
csr.AddCell("证书状态", hash["state"] as string);
break;
}
if (hash.ContainsKey("expire"))
{
csr.AddCell("证书过期", hash["expire"] as string);
}
}
else if (hash.ContainsKey("state"))
{
ui.NewSection().AddCell("证书状态", hash["state"] as string);
}
if (UMC.Net.Certificater.Certificates.TryGetValue(host, out var _v))
@ -472,7 +483,7 @@ namespace UMC.Proxy.Activities
if (_v.Certificate != null)
{
var cn = _v.Certificate.Subject.Split(',').First(r => r.Trim().StartsWith("CN=")).Substring(3);
if (hash.ContainsKey("expire"))
if (hash.ContainsKey("expire") && hash.ContainsKey("order"))
{
ui.NewSection().AddCell("证书公用名", cn);
}
@ -502,7 +513,16 @@ namespace UMC.Proxy.Activities
}
ui.NewSection().AddCell("自动续签", hash["contract"] as string, new UIClick("Model", "Recharge", "Code", hash["domain"] as string).Send(request.Model, request.Command));
if (hash.ContainsKey("isLock"))
{
ui.NewSection().AddCell("自动续签", hash["contract"] as string);
}
else
{
ui.NewSection().AddCell("自动续签", hash["contract"] as string, new UIClick("Model", "Recharge", "Code", hash["domain"] as string).Send(request.Model, request.Command));
}
@ -638,6 +658,52 @@ namespace UMC.Proxy.Activities
this.Prompt("请输入正确的端口号");
}
break;
case "PrivateKey":
{
var host = this.AsyncDialog("Domain", g => this.Prompt("请输入域名"));
var privateKey = UIDialog.AsyncDialog(this.Context, "PrivateKey", r =>
{
var fm = new UIFormDialog() { Title = "证书私钥" };
fm.AddTextValue().Put("域名", host);
fm.AddTextarea("私钥", "PrivateKey", String.Empty).PlaceHolder("证书.key文件内容").Put("tip", "证书私钥"); ;
fm.Submit("确认导入", $"{request.Model}.{request.Command}");
return fm;
});
var webr2 = new Uri(APIProxy.Uri, "Certificater").WebRequest();
var rese = UMC.Proxy.Utility.Sign(webr2, WebResource.Instance().Provider["appSecret"])
.Post(new WebMeta().Put("type", "cert", "domain", host));
if (rese.StatusCode != System.Net.HttpStatusCode.OK)
{
this.Prompt("提示", rese.ReadAsString());
}
var json = rese.ReadAsString();
var cert = JSON.Deserialize<WebMeta>(json);
var domain = cert["domain"];
var publicKey = cert["publicKey"];
try
{
var x509 = X509Certificate2.CreateFromPem(publicKey, privateKey);
var p = UMC.Data.Provider.Create(domain, "privateKey");
p.Attributes["publicKey"] = publicKey;
p.Attributes["privateKey"] = privateKey;
var certs = UMC.Data.Reflection.Configuration("certs");
certs.Add(p);
UMC.Net.Certificater.Certificates[p.Name] = new Certificater { Name = p.Name, Status = 1, Certificate = x509 };
UMC.Data.Reflection.Configuration("certs", certs);
}
catch (Exception ex)
{
this.Prompt("证书错误", ex.Message);
}
this.Context.Send($"{request.Model}.{request.Command}", true);
}
break;
default:
var pr = hosts[model];

@ -243,19 +243,22 @@ namespace UMC.Proxy
r.ReadAsString(str =>
{
var cert = JSON.Deserialize<WebMeta>(str);
var domain = cert["domain"];
var privateKey = cert["privateKey"];
var publicKey = cert["publicKey"];
if (cert.ContainsKey("privateKey"))
{
var domain = cert["domain"];
var privateKey = cert["privateKey"];
var publicKey = cert["publicKey"];
var x509 = X509Certificate2.CreateFromPem(publicKey, privateKey);
var x509 = X509Certificate2.CreateFromPem(publicKey, privateKey);
var p = UMC.Data.Provider.Create(domain, "apiumc");
p.Attributes["publicKey"] = publicKey;
p.Attributes["privateKey"] = privateKey;
var certs = UMC.Data.Reflection.Configuration("certs");
certs.Add(p);
UMC.Net.Certificater.Certificates[p.Name] = new Certificater { Name = p.Name, Status = 1, Certificate = x509 };
UMC.Data.Reflection.Configuration("certs", certs);
var p = UMC.Data.Provider.Create(domain, "apiumc");
p.Attributes["publicKey"] = publicKey;
p.Attributes["privateKey"] = privateKey;
var certs = UMC.Data.Reflection.Configuration("certs");
certs.Add(p);
UMC.Net.Certificater.Certificates[p.Name] = new Certificater { Name = p.Name, Status = 1, Certificate = x509 };
UMC.Data.Reflection.Configuration("certs", certs);
}
});
}
}

@ -43,8 +43,8 @@
<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="UMC" Version="1.0.35" />
<PackageReference Include="UMC.Data" Version="1.0.43" />
<PackageReference Include="UMC" Version="1.0.36" />
<PackageReference Include="UMC.Data" Version="1.0.44" />
</ItemGroup>
<ItemGroup>
<!-- <ProjectReference Include="..\UMC\UMC.csproj" />

Loading…
Cancel
Save