Long time listener, first time caller. I've been struggling with this on and off for several days, and I know when I've been beaten.

I want to parse SNMP trap PDUs from BER/DER encoded ASN1 into a nested hash. I'd prefer to use Convert::ASN1, because I use it similarly and successfully with LDAP in the same application.

Try as I might, I cannot get Convert::ASN1 to parse the trapPDU ASN1 ABNF.

There are a number of issues, the big one being that the Convert::ASN1 docs don't describe the coverage of ASN1 ABNFs. It's difficult to determine what's supported, and what isn't. It's possible that the support simply isn't complete enough to describe SNMP traps.

I can parse the outer SNMP envelope:

my $desc = q( SNMPMessage ::= SEQUENCE { version INTEGER, community OCTET STRING, pdu ANY } ); my $asn = Convert::ASN1->new(); $asn->prepare($desc) or die $asn->error; my $snmp_message = $asn->find("SNMPMessage");

That gets me as far as:

$VAR1 = { 'community' => 'public', 'version' => 0, 'pdu' => <binary whatnot>, };

But from here things get tricky. I've tried using the ABNF directly from the RFC, but it needs a bunch of massaging before Convert::ASN1 will ->prepare() it. I massage until it compiles, but then simply end up with 'decode errors'.

I can go on with everything I've tried, but my main question is just: has anyone managed to get Convert::ASN1 to work with SNMP? Or is this hopeless? Should I just try to use a basic BER/DER decoder and try to build a parser manually? (that's what SNMP does, it seems)


In reply to Getting Convert::ASN1 to parse SNMP traps by fishbot_v2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.