aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2008-08-01 16:44:06 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2008-08-01 16:44:06 +0000
commitd255e44bfab095f26a068bbb47efe8aa01f3caa5 (patch)
tree8ff803f0647837328e613a685ea6a7b7b04b8b8f
parent1fa1d7736e36b499973805a496539292c3731008 (diff)
From Martin Peylo (bug 2507):
The attached patch enables asn2wrs.py and packet-ber.c to decode UTCTime according to the definitions in X.680. svn path=/trunk/; revision=25897
-rw-r--r--epan/dissectors/packet-ber.c134
-rw-r--r--epan/dissectors/packet-ber.h2
-rwxr-xr-xtools/asn2wrs.py8
3 files changed, 144 insertions, 0 deletions
diff --git a/epan/dissectors/packet-ber.c b/epan/dissectors/packet-ber.c
index d4c47cec6d..2167155b00 100644
--- a/epan/dissectors/packet-ber.c
+++ b/epan/dissectors/packet-ber.c
@@ -3717,6 +3717,140 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
return offset;
}
+
+int
+dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id)
+{
+ char outstr[33];
+ char *outstrptr = outstr;
+ const guint8 *instr;
+ gint8 class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len, i, n;
+ int hoffset;
+ proto_item *cause;
+
+ if(!implicit_tag){
+ hoffset = offset;
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
+
+ /* sanity check: we only handle UTCTime */
+ if( (class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_UTCTime) ) {
+ tvb_ensure_bytes_exist(tvb, hoffset, 2);
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: UTCTime expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str(class,ber_class_codes,"Unknown"), class,
+ pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
+ proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
+ expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: UTCTime expected");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ }
+ return offset+len;
+ }
+ } else {
+ len = tvb_length_remaining(tvb,offset);
+ }
+
+ instr = tvb_get_ptr(tvb, offset, len);
+
+ /* YYMMDDhhmm */
+ for(i=0;i<10;i++) {
+ if(instr[i] < '0' || instr[i] > '9') {
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "first 10 octets have to contain YYMMDDhhmm in digits");
+ goto malformed;
+ }
+ }
+ g_snprintf(outstrptr, 15, "%.2s-%.2s-%.2s %.2s:%.2s", instr, instr+2, instr+4, instr+6, instr+8);
+ outstrptr+= 14;
+
+ /* (ss)? */
+ if(len >= 12) {
+ if(instr[i] >= '0' && instr[i] <= '9') {
+ i++;
+ if(instr[i] >= '0' && instr[i] <= '9') {
+ i++;
+ g_snprintf(outstrptr, 4, ":%.2s", instr+10);
+ outstrptr+=3;
+ } else {
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "if 11th octet is a digit for seconds, "
+ "the 12th octet has to be a digit, too");
+ goto malformed;
+ }
+ }
+ }
+
+ /* Z|([+-]hhmm) */
+ switch (instr[i]) {
+ case 'Z':
+ if(len!=i+1) {
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "there must be no further octets after \'Z\'");
+ goto malformed;
+ }
+ g_snprintf(outstrptr, 7, " (UTC)");
+ i++;
+ break;
+ case '-':
+ case '+':
+ if(len!=i+5) {
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "4 digits must follow on \'+\' resp. \'-\'");
+ goto malformed;
+ }
+ for(n=i+1;n<i+5;n++) {
+ if(instr[n] < '0' || instr[n] > '9') {
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "4 digits must follow on \'+\' resp. \'-\'");
+ goto malformed;
+ }
+ }
+ g_snprintf(outstrptr, 12, " (UTC%c%.4s)", instr[i], instr+i+1);
+ i+=5;
+ break;
+ default:
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "unexpected character in %dth octet, "
+ "must be \'Z\', \'+\' or \'-\'", i+1);
+ goto malformed;
+ break;
+ }
+
+ if(len!=i) {
+ cause = proto_tree_add_text(tree, tvb, offset, len,
+ "BER Error: malformed UTCTime encoding, "
+ "%d unexpected character%s after %dth octet",
+ len-i, (len==i-1?"s":""), i);
+ goto malformed;
+ }
+
+ if(hf_id >= 0){
+ proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr);
+ }
+
+ return offset+len;
+malformed:
+ proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
+ expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: malformed UTCTime encoding");
+ g_snprintf(outstr, (len>29)?31:len+1, "%s", instr);
+ if(hf_id >= 0){
+ proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr);
+ }
+ return offset+len;
+}
+
+
/* 8.6 Encoding of a bitstring value */
int dissect_ber_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
{
diff --git a/epan/dissectors/packet-ber.h b/epan/dissectors/packet-ber.h
index 6145e763ac..fde968e073 100644
--- a/epan/dissectors/packet-ber.h
+++ b/epan/dissectors/packet-ber.h
@@ -200,6 +200,8 @@ extern int dissect_ber_old_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto
extern int dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
+extern int dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
+
typedef struct _asn_namedbit {
guint32 bit;
int *p_id;
diff --git a/tools/asn2wrs.py b/tools/asn2wrs.py
index cf2020aba5..ddcbbfa116 100755
--- a/tools/asn2wrs.py
+++ b/tools/asn2wrs.py
@@ -4846,6 +4846,14 @@ class UTCTime (RestrictedCharacterStringType):
def eth_tsname(self):
return 'UTCTime'
+ def eth_type_default_body(self, ectx, tname):
+ if (ectx.Ber()):
+ body = ectx.eth_fn_call('dissect_%(ER)s_%(STRING_TYPE)s', ret='offset',
+ par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'),))
+ return body
+ else:
+ return RestrictedCharacterStringType.eth_type_default_body(self, ectx, tname)
+
class ObjectDescriptor (RestrictedCharacterStringType):
def eth_tsname(self):
return 'ObjectDescriptor'