我使用SNMP4J (Version2.5.3)在SNMP V3中配置的目标上启动SNMP查询。它可以很好地工作在所有组合的auth / priv协议,除了隐私AES 256协议!我只能得到一个无效的回复。
以下是代码:
public static void main(String[] args) throws Exception
{
String targetAddress = "udp:10.2.1.41/161";
String userName = "mip_aes256";
OID authProtocol = AuthSHA.ID;
String authPassphrase = "mip_user_AuthPassword";
OID privProtocol = PrivAES256.ID;
String privPassphrase = "mip_user_PrivPassword";
// build a PDU with all the OIDs
ScopedPDU requestPDU = new ScopedPDU();
requestPDU.add(new VariableBinding(new OID("1.3.6.1.2.1.1.1.0")));
requestPDU.setType(PDU.GET);
UserTarget target = new UserTarget();
target.setTimeout(5000);
target.setVersion(SnmpConstants.version3);
target.setAddress(GenericAddress.parse(targetAddress));
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(new OctetString(userName));
TransportMapping<UdpAddress> transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
// add user to the USM
snmp.getUSM().addUser(new OctetString(userName),
new UsmUser(new OctetString(userName),
authProtocol,
new OctetString(authPassphrase),
privProtocol,
new OctetString(privPassphrase)));
transport.listen();
ResponseEvent re = snmp.send(requestPDU, target);
PDU responsePDU = re.getResponse();
if (responsePDU == null)
{
System.out.println("responsePDU == null :");
System.out.println("> Error : " + re.getError());
System.out.println("> Address : " + re.getPeerAddress());
System.out.println("> Source : " + re.getSource());
System.out.println("> User object : " + re.getUserObject());
}
else if (responsePDU.getVariableBindings() != null)
{
for (VariableBinding vb : responsePDU.getVariableBindings())
{
System.out.println(vb.getOid() + " --> " + vb.getVariable());
}
}
}
我很确定路由器配置是好的(思科路由器上的网络提供商配置)。我的Java 8安装(在Ubuntu 64上)包括用于无限强度的Java密码扩展。你对这件事有什么想法吗?
谢谢你的帮助,
向西尔万问好
发布于 2017-01-24 16:20:22
SNMPv3 AES 256是非标准的.谷歌的snmpv3 aes 256将详细说明这一点。根据我们的经验,并不是所有的实现都将互操作。这就是标准化的目的。
发布于 2017-01-26 15:47:59
我已经找到了一个改变,使其工作的思科2900。
OID privProtocol = PrivAES256With3DESKeyExtension.ID;
SecurityProtocols.getInstance().addPrivacyProtocol(new PrivAES256With3DESKeyExtension());
我希望这能帮到别人!
https://stackoverflow.com/questions/41825332
复制相似问题