Skip to content

Instantly share code, notes, and snippets.

@muromec
Last active August 29, 2015 14:02
Show Gist options
  • Save muromec/fa3d896be964bb1a9f4c to your computer and use it in GitHub Desktop.
Save muromec/fa3d896be964bb1a9f4c to your computer and use it in GitHub Desktop.
ASN1.js bug
var asn1 = require('asn1.js');
var broken = function() {
var B = asn1.define('B', function() {
this.seq().obj( // NO implicit tag here
this.key('b').octstr()
);
});
var A = asn1.define('Bug', function() {
this.seq().obj(
this.implicit(0).use(B)
)
});
return A.decode(coded, 'der');
}
var works = function(coded) {
var B = asn1.define('B', function() {
this.seq().implicit(0).obj( // IMPLICIT tag copied from parent
this.key('b').octstr()
);
});
var A = asn1.define('Bug', function() {
this.seq().obj(
this.implicit(0).use(B)
)
});
return A.decode(coded, 'der');
}
var coded = new Buffer('300720050403313233', 'hex');
works(coded);
console.log("ok");
broken(coded);
console.log("ok?");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment