我正在尝试用express js 提供服务。它将通过API收集信息。该 API 需要 key 和 cert 。我还设置了各种东西。但它在我的本地计算机上给了我0A00018E:SSL例程::ca md太弱错误。这是我的代码
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const https = require('https');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
// Define certificate and key file paths
const certFile = path.join(__dirname, '../certs/create.crt');
const keyFile = path.join(__dirname, '../certs/create.key');
// Define agent options
const agentOptions = {
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
rejectUnauthorized: false,
minVersion: 'TLSv1'
};
// Create https.Agent with the options
const agent = new https.Agent(agentOptions);
// Function to get secure token
const getSecureToken = async () => {
try {
const postData = {
password: '123456Aa',
userName: 'test'
};
const response = await axios.post(
'https://url.com:7700/transaction/token',
postData,
{
headers: { 'Content-Type': 'application/json' },
httpsAgent: agent // Use the custom https agent
}
);
return response.data.transactionId;
} catch (error) {
console.error(`Error fetching secure token: ${error.stack || error.message}`);
throw new Error(`Error fetching secure token: ${error.message}`);
}
};
我该如何解决这个问题?预先感谢
答案就在错误消息中(错误:0A00018E:SSL例程::ca md太弱)。 OpenSSL 拒绝使用 CA 证书,因为某些参数现在被认为是不安全的。这可能是由于证书使用 MD5 或 SHA1 进行签名导致的。
您应该使用签名的安全哈希算法重新生成 CA 和证书,因为您当前使用的哈希算法不再被认为是安全的。
可以通过将以下内容添加到 openssl.cnf 来解决此问题:
tls-cipher "DEFAULT:@SECLEVEL=0"