Skip to content

Commit

Permalink
fix: fix cert format
Browse files Browse the repository at this point in the history
  • Loading branch information
nidbCN committed Dec 10, 2024
1 parent 3ee8cb9 commit ccc9f58
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Services/CertScanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ private async Task ScanCertAsync()
continue;
}

await using var fs = certFile.OpenRead();
using var reader = new StreamReader(fs);
var line = await reader.ReadLineAsync();
await using var certStream = certFile.OpenRead();
using var certReader = new StreamReader(certStream);
var line = await certReader.ReadLineAsync();

const string certBeginFlag = "-----BEGIN CERTIFICATE-----";
const string certEndFlag = "-----END CERTIFICATE-----";
Expand All @@ -84,7 +84,7 @@ private async Task ScanCertAsync()
// 是证书
var stringBuilder = new StringBuilder((int)certFile.Length);

while (!string.IsNullOrWhiteSpace(line = await reader.ReadLineAsync()))
while (!string.IsNullOrWhiteSpace(line = await certReader.ReadLineAsync()))
{
if (line.Contains(certEndFlag))
break;
Expand Down Expand Up @@ -120,11 +120,8 @@ private async Task ScanCertAsync()

using var keyReader = new StreamReader(privateKeyFile.OpenRead());
var keyPem = await keyReader.ReadToEndAsync();

var certPem = stringBuilder
.AppendLine()
.Append(await reader.ReadToEndAsync())
.ToString();
certStream.Seek(0, SeekOrigin.Begin);
var certPem = await certReader.ReadToEndAsync();

_logger.LogInformation("Success load cert, cert content: `{c}`, private `{p}`", certPem, keyPem);

Expand Down

0 comments on commit ccc9f58

Please sign in to comment.