如何制作BMC初始密码
更新时间:2025/10/15
在Gitcode上查看源码如何制作BMC初始密码
预置的密码类型
BMC存在以下预置密码:
| 名称 | 类型 | 解释 |
|---|---|---|
| 2号用户Linux密码 | 单向hash | 大部分认证接口使用(Web/Redfish/SSH/串口) |
| 2号用户IPMI接口密码 | 对称加密 | IPMI基于RMCP协议使用 |
| 2号用户SNMP接口鉴权Key | 单向hash | SNMP V3协议使用 |
| 2号用户SNMP接口加密Key | 单向hash | SNMP V3协议使用 |
| 只读团体名 | 对称加密 | SNMP V1/V2c协议使用 |
| 读写团体名 | 对称加密 | SNMP V1/V2c协议使用 |
Linux密码
基于盐值加密码明文,使用Linux接口生成即可:
lua
local crypt = require 'utils.crypt'
local crypt_password = crypt.crypt("xxxxxxx", "$6$xxxxxxx$")
print(crypt_password)SNMP鉴权、加密Key
使用SNMP官方提供的generate_ku接口生成:
lua
local utils = require 'infrastructure.utils'
local ok, snmp_ku = utils.generate_ku(4, "xxxx")
print(snmp_ku)预置的两个KU相同,真实业务场景可以不同。
对称加密密码
此部分默认使用KMC加密,需要创建一个空的KMC密钥文件,并制作好相关的域和Key:
c
void test_default_ksf_encrypt_pwd(const char *pwd, int domain_id, int key_id){
int ret = 0;
KmcMkInfo mkInfo = {
.domainId = 1
};
unsigned char ct[300] = {0};
WsecUint32 ct_len = sizeof(ct);
ret = KmcGetMk(0, &mkInfo);
ret = KmcActivateMk(domain_id, key_id);
ret = KmcGetActiveMk(domain_id, &mkInfo, ct, &ct_len);
ct_len = sizeof(ct);
ret = SdpEncryptEx(domain_id, WSEC_ALGID_AES256_GCM, reinterpret_cast<const unsigned char *>(pwd), strlen(pwd), ct, reinterpret_cast<WsecUint32 *>(&ct_len));
int ciphertext_len = ct_len;
char temp[3] = {0};
char str[300] = {0};
int str_len= sizeof(str);
/*
将N位字节转变成16进制数字字符串
*/
for (size_t i = 0; i < ciphertext_len; i++) {
(void)snprintf_s(temp, sizeof(temp), sizeof(temp) - 1, "%02x", ct[i]);
ret = strncat_s(str, str_len, temp, strlen(temp));
}
printf("\n#### KMC encrypted key:%s\n", str);
}void test_init_openubmc_default_key() { const char* filePatha = "/home/xxx/datatocheck_openubmc.dat"; const char* filePathb = "/home/xxx/datatocheck_openubmc.bak"; int ret = 0;
ret = InitKMC(filePatha, filePathb, 0, 0, 0);
unsigned char plaintextKey[] = {1,2,3,4,5,6,7,8,9};
ret = KmcRegisterMkEx(1, 0, plaintextKey, sizeof(plaintextKey));
ret = KmcSetMkStatus(0, 1, KMC_KEY_STATUS_INACTIVE);
ret = KmcSetMkStatus(1, 0, KMC_KEY_STATUS_ACTIVE);
// create domain
KmcCfgDomainInfo domainInfo = {0};
int dc = KmcGetDomainCount();
for (int i = 0; i < dc; ++i) {
ret = KmcGetDomain(i, &domainInfo);
printf("#### KmcGetDomain: %d, desc: %s\n", domainInfo.domainId, domainInfo.desc);
}
int mkCount = KmcGetMkCount();
KmcMkInfo mkInfo = {0};
for (int i = 0; i < mkCount; ++i) {
ret = KmcGetMk(i, &mkInfo);
printf("#### KmcGetMk domainId: %d, keyId: %d, keyType: %d\n", mkInfo.domainId, mkInfo.keyId, mkInfo.keyType);
}
test_default_ksf_encrypt_pwd("xxxxx",1,0);
}
最后打印出来的KMC encrypted key后面就是加密密码,`/home/xxx/datatocheck_openubmc.dat`文件就是生成的加密文件。