Files
fiscoBcosJDK/diagnose-certs.ps1

114 lines
3.9 KiB
PowerShell
Raw Permalink Normal View History

2026-02-09 17:45:06 +08:00
Write-Host "=== FISCO BCOS 国密证书诊断 ===" -ForegroundColor Cyan
Write-Host ""
$projectRoot = Get-Location
Write-Host "项目目录: $projectRoot" -ForegroundColor Gray
Write-Host ""
# 检查证书目录
Write-Host "1. 检查证书目录结构..." -ForegroundColor Yellow
$certPath = "conf\gm"
if (Test-Path "conf") {
Write-Host " ✓ conf 目录存在" -ForegroundColor Green
if (Test-Path $certPath) {
Write-Host " ✓ conf\gm 目录存在" -ForegroundColor Green
} else {
Write-Host " ✗ conf\gm 目录不存在" -ForegroundColor Red
Write-Host ""
Write-Host "请创建目录: mkdir conf\gm -Force" -ForegroundColor Yellow
}
} else {
Write-Host " ✗ conf 目录不存在" -ForegroundColor Red
Write-Host ""
Write-Host "请创建目录: mkdir conf\gm -Force" -ForegroundColor Yellow
}
Write-Host ""
# 检查证书文件
Write-Host "2. 检查国密证书文件..." -ForegroundColor Yellow
$requiredFiles = @(
"gmca.crt",
"gmsdk.crt",
"gmsdk.key",
"gmensdk.crt",
"gmensdk.key"
)
$allPresent = $true
foreach ($file in $requiredFiles) {
$filePath = "conf\gm\$file"
if (Test-Path $filePath) {
$fileSize = (Get-Item $filePath).Length
$firstLine = (Get-Content $filePath -First 1 -ErrorAction SilentlyContinue)
if ($firstLine -match "BEGIN") {
Write-Host "$file ($fileSize 字节) - 格式正确" -ForegroundColor Green
} else {
Write-Host "$file ($fileSize 字节) - 格式可能有问题" -ForegroundColor Yellow
}
} else {
Write-Host "$file - 文件不存在" -ForegroundColor Red
$allPresent = $false
}
}
Write-Host ""
# 检查配置文件
Write-Host "3. 检查配置文件..." -ForegroundColor Yellow
if (Test-Path "config.toml") {
Write-Host " ✓ config.toml 存在" -ForegroundColor Green
$content = Get-Content "config.toml" -Raw
if ($content -match 'useSMCrypto\s*=\s*"true"') {
Write-Host " ✓ 国密模式已启用" -ForegroundColor Green
} else {
Write-Host " ⚠ 国密模式未启用" -ForegroundColor Yellow
}
if ($content -match 'certPath\s*=\s*"([^"]+)"') {
$certPathConfig = $matches[1]
Write-Host " 证书路径配置: $certPathConfig" -ForegroundColor Gray
}
} else {
Write-Host " ✗ config.toml 不存在" -ForegroundColor Red
}
Write-Host ""
# 检查 resources 目录
Write-Host "4. 检查 resources 配置..." -ForegroundColor Yellow
if (Test-Path "src\main\resources\config.toml") {
Write-Host " ✓ src\main\resources\config.toml 存在" -ForegroundColor Green
} else {
Write-Host " ✗ src\main\resources\config.toml 不存在" -ForegroundColor Red
Write-Host " 需要复制: copy config.toml src\main\resources\" -ForegroundColor Yellow
}
Write-Host ""
# 总结
Write-Host "=== 诊断总结 ===" -ForegroundColor Cyan
if ($allPresent) {
Write-Host "✓ 所有证书文件都已就位" -ForegroundColor Green
Write-Host ""
Write-Host "如果仍然连接失败,请检查:" -ForegroundColor Yellow
Write-Host " 1. 证书是否来自正确的节点服务器" -ForegroundColor Gray
Write-Host " 2. 证书文件内容是否完整" -ForegroundColor Gray
Write-Host " 3. 节点是否确实使用国密模式" -ForegroundColor Gray
} else {
Write-Host "✗ 缺少必要的证书文件" -ForegroundColor Red
Write-Host ""
Write-Host "请按以下步骤获取证书:" -ForegroundColor Yellow
Write-Host " 1. 在节点服务器上: cd /path/to/fisco/nodes/127.0.0.1/sdk" -ForegroundColor Gray
Write-Host " 2. 打包证书: tar -czf ~/fisco-gm-certs.tar.gz gm/" -ForegroundColor Gray
Write-Host " 3. 下载到 Windows 并解压到项目的 conf 目录" -ForegroundColor Gray
}
Write-Host ""
Write-Host "需要更详细的帮助,请查看节点日志或联系管理员" -ForegroundColor Gray