ber: display x509af.utcTime year in 4 digits

Because:
- the 2-digit year can only be in the range 1950..2049 according to
https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
- to avoid confusion, interpreting the year/month/day in a different order may
still represent a valid date.
- now both utcTime and GeneralizedTime are displayed in exactly the same way.
- some tools, like Perl, apply a different date range when converting 2-digit years.

In packet-ber.c two parameters are added to the function dissect_ber_UTCTime:
datestrptr: if not NULL return datetime string instead of adding to tree
or NULL when packet is malformed
tvblen: if not NULL return consumed packet bytes
Also the memory allocation for outstr is now done using the recommended method
as described in the README.developer document.

The calling function in x509af/x509sat uses this to prepend the century.
Added generated files.

Change-Id: I714c2e8e7f899211caaa1f4136ca0d27cb1aba4a
Reviewed-on: https://code.wireshark.org/review/35414
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
This commit is contained in:
Andre Luyer 2019-12-27 17:45:06 +01:00 committed by Pascal Quantin
parent 3f17a8948f
commit dbfb204f48
19 changed files with 88 additions and 33 deletions

View File

@ -145,6 +145,17 @@ CertificateList/signedCertificateList/revokedCertificates/_item/userCertificate
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
offset=call_ber_oid_callback(actx->external.direct_reference, tvb, offset, actx->pinfo, tree, NULL);
#.FN_BODY Time/utcTime
char *outstr, *newstr;
guint32 tvblen;
/* the 2-digit year can only be in the range 1950..2049 https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1 */
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, &outstr, &tvblen);
if (hf_index >= 0 && outstr) {
newstr = wmem_strconcat(wmem_packet_scope(), outstr[0] < '5' ? "20": "19", outstr, NULL);
proto_tree_add_string(tree, hf_index, tvb, offset - tvblen, tvblen, newstr);
}
#.FN_BODY SubjectName
const char* str;

View File

@ -374,6 +374,17 @@ XDayOf/fifth fifth_dayof
#.END
#.FN_BODY Time/utcTime
char *outstr, *newstr;
guint32 tvblen;
/* the 2-digit year can only be in the range 1950..2049 https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1 */
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, &outstr, &tvblen);
if (hf_index >= 0 && outstr) {
newstr = wmem_strconcat(wmem_packet_scope(), outstr[0] < '5' ? "20": "19", outstr, NULL);
proto_tree_add_string(tree, hf_index, tvb, offset - tvblen, tvblen, newstr);
}
#.FN_BODY GUID
gint8 ber_class;
gboolean pc;

View File

@ -768,7 +768,7 @@ dissect_HI2Operations_LocalTimeStamp(gboolean implicit_tag _U_, tvbuff_t *tvb _U
static int
dissect_HI2Operations_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -422,7 +422,7 @@ dissect_acp133_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
static int
dissect_acp133_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -3780,12 +3780,13 @@ invalid:
return end_offset;
}
/* datestrptr: if not NULL return datetime string instead of adding to tree or NULL when packet is malformed
* tvblen: if not NULL return consumed packet bytes
*/
int
dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id)
dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char **datestrptr, guint32 *tvblen)
{
char outstr[33];
char *outstrptr = outstr;
char *outstr, *outstrptr;
const guint8 *instr;
gint8 ber_class;
gboolean pc;
@ -3798,6 +3799,11 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
proto_tree *error_tree;
const gchar *error_str = NULL;
outstrptr = outstr = (char *)wmem_alloc(wmem_packet_scope(), 29);
if (datestrptr) *datestrptr = NULL; /* mark invalid */
if (tvblen) *tvblen = 0;
if (!implicit_tag) {
hoffset = offset;
identifier_offset = offset;
@ -3908,9 +3914,14 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
goto malformed;
}
if (hf_id >= 0) {
proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr);
if (datestrptr) {
*datestrptr = outstr; /* mark as valid */
} else {
if (hf_id >= 0) {
proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr);
}
}
if (tvblen) *tvblen = len;
return offset+len;
malformed:
@ -3927,10 +3938,11 @@ malformed:
"%s",
error_str);
if (tvblen) *tvblen = len;
return offset+len;
}
/* 8.6 Encoding of a bitstring value */
int

View File

@ -167,8 +167,7 @@ WS_DLL_PUBLIC int dissect_ber_set_of(gboolean implicit_tag, asn1_ctx_t *actx, pr
WS_DLL_PUBLIC int dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
WS_DLL_PUBLIC int dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
WS_DLL_PUBLIC int dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char **datestrptr, guint32 *tvblen);
extern int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const int **named_bits, int num_named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb);
WS_DLL_PUBLIC int dissect_ber_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const int **named_bits, gint num_named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb);

View File

@ -1580,7 +1580,7 @@ dissect_cms_MessageDigest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offs
static int
dissect_cms_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -1599,7 +1599,7 @@ dissect_dap_PagedResultsRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, in
static int
dissect_dap_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -663,7 +663,7 @@ dissect_dop_NULL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, a
static int
dissect_dop_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -422,7 +422,7 @@ dissect_dsp_DomainInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
static int
dissect_dsp_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -1168,7 +1168,7 @@ dissect_p1_Signature(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U
static int
dissect_p1_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}
@ -2771,7 +2771,7 @@ dissect_p1_Time(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, as
tvbuff_t *arrival = NULL;
p1_address_ctx_t* ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
if(arrival && ctx && ctx->do_address)

View File

@ -866,7 +866,7 @@ static int dissect_p22_ForwardedContentToken(gboolean implicit_tag _U_, tvbuff_t
static int
dissect_p22_Time(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -1343,7 +1343,7 @@ dissect_p7_NumberRange(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
static int
dissect_p7_CreationTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}
@ -3501,7 +3501,7 @@ dissect_p7_ReportSummary(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offse
static int
dissect_p7_DeferredDeliveryCancellationTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}
@ -3510,7 +3510,7 @@ dissect_p7_DeferredDeliveryCancellationTime(gboolean implicit_tag _U_, tvbuff_t
static int
dissect_p7_DeletionTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}
@ -3613,7 +3613,7 @@ dissect_p7_StoragePeriod(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offse
static int
dissect_p7_StorageTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -440,7 +440,7 @@ dissect_p772_ExemptedAddressSeq(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, in
static int
dissect_p772_ExtendedAuthorisationInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -218,7 +218,7 @@ dissect_pkix1explicit_CertificateSerialNumber(gboolean implicit_tag _U_, tvbuff_
static int
dissect_pkix1explicit_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
return offset;
}

View File

@ -352,7 +352,7 @@ static int
dissect_rtse_CommonReference(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
#line 128 "./asn1/rtse/rtse.cnf"
tvbuff_t *string = NULL;
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, NULL, NULL);
if(open_request && string)
col_append_fstr(actx->pinfo->cinfo, COL_INFO, " %s", tvb_format_text(string, 0, tvb_reported_length(string)));

View File

@ -74,7 +74,7 @@ static int hf_x509af_notBefore = -1; /* Time */
static int hf_x509af_notAfter = -1; /* Time */
static int hf_x509af_algorithm = -1; /* AlgorithmIdentifier */
static int hf_x509af_subjectPublicKey = -1; /* T_subjectPublicKey */
static int hf_x509af_utcTime = -1; /* UTCTime */
static int hf_x509af_utcTime = -1; /* T_utcTime */
static int hf_x509af_generalizedTime = -1; /* GeneralizedTime */
static int hf_x509af_Extensions_item = -1; /* Extension */
static int hf_x509af_extnId = -1; /* T_extnId */
@ -259,8 +259,19 @@ dissect_x509af_AlgorithmIdentifier(gboolean implicit_tag _U_, tvbuff_t *tvb _U_,
static int
dissect_x509af_UTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
dissect_x509af_T_utcTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
#line 149 "./asn1/x509af/x509af.cnf"
char *outstr, *newstr;
guint32 tvblen;
/* the 2-digit year can only be in the range 1950..2049 https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1 */
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, &outstr, &tvblen);
if (hf_index >= 0 && outstr) {
newstr = wmem_strconcat(wmem_packet_scope(), outstr[0] < '5' ? "20": "19", outstr, NULL);
proto_tree_add_string(tree, hf_index, tvb, offset - tvblen, tvblen, newstr);
}
return offset;
}
@ -282,7 +293,7 @@ const value_string x509af_Time_vals[] = {
};
static const ber_choice_t Time_choice[] = {
{ 0, &hf_x509af_utcTime , BER_CLASS_UNI, BER_UNI_TAG_UTCTime, BER_FLAGS_NOOWNTAG, dissect_x509af_UTCTime },
{ 0, &hf_x509af_utcTime , BER_CLASS_UNI, BER_UNI_TAG_UTCTime, BER_FLAGS_NOOWNTAG, dissect_x509af_T_utcTime },
{ 1, &hf_x509af_generalizedTime, BER_CLASS_UNI, BER_UNI_TAG_GeneralizedTime, BER_FLAGS_NOOWNTAG, dissect_x509af_GeneralizedTime },
{ 0, NULL, 0, 0, 0, NULL }
};
@ -324,7 +335,7 @@ static const ber_choice_t SubjectName_choice[] = {
static int
dissect_x509af_SubjectName(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
#line 149 "./asn1/x509af/x509af.cnf"
#line 160 "./asn1/x509af/x509af.cnf"
const char* str;
offset = dissect_ber_choice(actx, tree, tvb, offset,

View File

@ -1450,7 +1450,18 @@ dissect_x509sat_SyntaxGeneralizedTime(gboolean implicit_tag _U_, tvbuff_t *tvb _
static int
dissect_x509sat_SyntaxUTCTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index);
#line 378 "./asn1/x509sat/x509sat.cnf"
char *outstr, *newstr;
guint32 tvblen;
/* the 2-digit year can only be in the range 1950..2049 https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1 */
offset = dissect_ber_UTCTime(implicit_tag, actx, tree, tvb, offset, hf_index, &outstr, &tvblen);
if (hf_index >= 0 && outstr) {
newstr = wmem_strconcat(wmem_packet_scope(), outstr[0] < '5' ? "20": "19", outstr, NULL);
proto_tree_add_string(tree, hf_index, tvb, offset - tvblen, tvblen, newstr);
}
return offset;
}
@ -1602,7 +1613,7 @@ dissect_x509sat_SyntaxGeneralString(gboolean implicit_tag _U_, tvbuff_t *tvb _U_
static int
dissect_x509sat_GUID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
#line 378 "./asn1/x509sat/x509sat.cnf"
#line 389 "./asn1/x509sat/x509sat.cnf"
gint8 ber_class;
gboolean pc;
gint32 tag;

View File

@ -5246,7 +5246,7 @@ class UTCTime (RestrictedCharacterStringType):
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'),))
par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s', 'NULL', 'NULL'),))
return body
else:
return RestrictedCharacterStringType.eth_type_default_body(self, ectx, tname)