我正在尝试将 pfx 证书存储在 GCP 机密管理器上。我的节点应用程序在通过 fs.readFileSync 从本地文件系统读取证书文件时工作正常,但是当我通过 gcp 秘密管理器客户端库获取证书时,我在节点 http 请求期间收到一个mac 验证错误(密码也是正确的并存储在gcp 秘密管理器,用 openssl 检查过)。
我的请求是带有以下选项的 node/https,
const options = {
host: url.host,
path: url.path,
method: "POST",
headers: { "Content-Type": "application/json" },
pfx: IdCert,
ca: CaCert,
passphrase: CertPass,
rejectUnauthorized: true,
};
我访问证书的方式是通过下面的getSecretData:
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
const asyncConfig = require('config/async').asyncConfig;
const client = new SecretManagerServiceClient();
const getSecretData = ( projectId, name )=>{
const close = async ()=>{
const [version] = await client.accessSecretVersion({
name: `projects/${projectId}/secrets/${name}/versions/latest`,
});
return version.payload.data;
}
return close;
}
PS:使用 node-config 将证书存储在实例中并通过以下方式访问它们
const config = require("config"); // node-config package
const IdCert = config.get('IdCert')