indutny / asn1.js

ASN.1 Decoder/Encoder/DSL
MIT License
181 stars 64 forks source link

gentime and utctime values encoded with wrong year #105

Closed codeslikejaggars closed 6 years ago

codeslikejaggars commented 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

This happens because DERNode._encodeTime function uses Date.getFullYear instead of 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