Created
February 9, 2020 23:58
-
-
Save jonnystorm/1575bacf028249ecf63d0f7e89ee8d72 to your computer and use it in GitHub Desktop.
SNMPv3 USM AuthPriv AES test for Erlang OTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(test_snmp). | |
-export([main/0]). | |
main() -> | |
snmpm:start(), | |
EngineID = [128,0,0,0,6], | |
SecName = "v3_user", | |
AuthPass = "authpass", | |
AuthKey = | |
snmp:passwd2localized_key(sha, AuthPass, EngineID), | |
PrivPass = "privpass", | |
PrivKey = | |
snmp:passwd2localized_key(md5, PrivPass, EngineID), | |
Credentials = | |
[ {auth, usmHMACSHAAuthProtocol}, | |
{auth_key, AuthKey}, | |
{priv, usmAesCfb128Protocol}, | |
{priv_key, PrivKey} | |
], | |
Config = | |
[ {engine_id, EngineID}, | |
{address, {192,0,2,1}}, | |
{version, v3}, | |
{sec_model, usm}, | |
{sec_level, authPriv}, | |
{sec_name, SecName} | |
], | |
snmpm:register_user(SecName, snmpm_user_default, nil), | |
snmpm:register_usm_user(EngineID, SecName, Credentials), | |
snmpm:register_agent(SecName, "v3_agent", Config), | |
RequestID = 0, | |
ErrorStatus = noError, | |
ErrorIndex = 0, | |
Varbinds = | |
[ {varbind, [1,3,6,1,2,1,1,5,0], 'OCTET STRING', [], 0} | |
], | |
PduType = 'get-request', | |
CtxEngineID = "", | |
Context = "", | |
ScopedPDU = | |
{ scopedPdu, | |
CtxEngineID, | |
Context, | |
{ pdu, | |
PduType, | |
RequestID, | |
ErrorStatus, | |
ErrorIndex, | |
Varbinds | |
} | |
}, | |
{ok, MsgMaxSize} = | |
snmpm_config:get_engine_max_message_size(), | |
MsgSecurityParameters = | |
{ usmSecurityParameters, | |
_MsgAuthoritativeEngineID = EngineID, | |
_MsgAuthoritativeEngineBoots = 1, | |
_MsgAuthoritativeEngineTime = 0, | |
_MsgUserName = SecName, | |
_MsgAuthenticationParameters = AuthKey, | |
_MsgPrivacyParameters = PrivKey | |
}, | |
Message = | |
{ message, | |
_Version = 'version-3', | |
{ v3_hdr, | |
_MsgID = 1, | |
MsgMaxSize, | |
_MsgFlags = snmp_misc:mk_msg_flags(PduType, 2), | |
_MsgSecurityModel = 3, % SEC_USM | |
MsgSecurityParameters, | |
0 | |
}, | |
Data = snmp_pdus:enc_scoped_pdu(ScopedPDU) | |
}, | |
{_, CredVals} = lists:unzip(Credentials), | |
SecLevel = 2, | |
SecData = | |
list_to_tuple([SecName|CredVals]), | |
Msg = | |
snmpm_usm:generate_outgoing_msg( | |
Message, | |
EngineID, | |
SecName, | |
SecData, | |
SecLevel | |
), | |
{message, _Version, Hdr, NextData} = | |
snmp_pdus:dec_message_only(Msg), | |
{ v3_hdr, | |
_MsgID, | |
_MsgMaxSize, | |
_MsgFlags, | |
_SecModel, | |
SecParams, | |
_Hdr_size | |
} = Hdr, | |
{ ok, | |
{ _MsgAuthEngineID, | |
_SecName, | |
ScopedPDUBytes, | |
_CachedSecData | |
} | |
} = | |
snmpm_usm:process_incoming_msg( | |
Msg, | |
NextData, | |
SecParams, | |
SecLevel | |
), | |
Data = ScopedPDUBytes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
It seems that github is not able figure out how to do this,
we think because you have rebased and force-pushed that PR
since it was done.
So, create a new one instead.
Regards,
/BMK