Closed codeslikejaggars closed 6 years ago
For gentime and utctime values near the beginning or end of the year, the wrong value will be encoded. For example:
const scheme = asn1.define('Test', function() { this.gentime() }); const startOfUnixEpoch = scheme.decode(scheme.encode(0, 'der'));
In my timezone (PDT -7) startOfUnixEpoch is -31536000000, which is 1969-01-01T00:00:00.000Z instead of 1970-01-01T00:00:00.000Z
startOfUnixEpoch
This happens because DERNode._encodeTime function uses Date.getFullYear instead of Date.getUTCFullYear:
DERNode._encodeTime
Date.getFullYear
Date.getUTCFullYear
https://github.com/indutny/asn1.js/blob/ddbca8b44fdc450d5a5898d507c64100dc5b7894/lib/asn1/encoders/der.js#L158
https://github.com/indutny/asn1.js/blob/ddbca8b44fdc450d5a5898d507c64100dc5b7894/lib/asn1/encoders/der.js#L168
For gentime and utctime values near the beginning or end of the year, the wrong value will be encoded. For example:
In my timezone (PDT -7)
startOfUnixEpoch
is -31536000000, which is 1969-01-01T00:00:00.000Z instead of 1970-01-01T00:00:00.000ZThis happens because
DERNode._encodeTime
function usesDate.getFullYear
instead ofDate.getUTCFullYear
:https://github.com/indutny/asn1.js/blob/ddbca8b44fdc450d5a5898d507c64100dc5b7894/lib/asn1/encoders/der.js#L158
https://github.com/indutny/asn1.js/blob/ddbca8b44fdc450d5a5898d507c64100dc5b7894/lib/asn1/encoders/der.js#L168