Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed exception when parsing certificates containing GeneralizedTime #21

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ String keyToString(Key key, [String prefix = '']) {
ASN1BitString keyToAsn1(Key key) {
var s = ASN1Sequence();
if (key is RsaPublicKey) {
s..add(ASN1Integer(key.modulus))..add(ASN1Integer(key.exponent));
s
..add(ASN1Integer(key.modulus))
..add(ASN1Integer(key.exponent));
}
return ASN1BitString(s.encodedBytes);
}
Expand Down Expand Up @@ -242,6 +244,7 @@ dynamic toDart(ASN1Object obj) {
if (obj is ASN1OctetString) return obj.stringValue;
if (obj is ASN1PrintableString) return obj.stringValue;
if (obj is ASN1UtcTime) return obj.dateTimeValue;
if (obj is ASN1GeneralizedTime) return obj.dateTimeValue;
if (obj is ASN1IA5String) return obj.stringValue;
if (obj is ASN1UTF8String) return obj.utf8StringValue;
switch (obj.tag) {
Expand Down
Binary file added test/files/generalized_time.der
Binary file not shown.
12 changes: 12 additions & 0 deletions test/x509_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,16 @@ void main() {
}
});
});

group('Certificate fields', () {
test('Parse Generalized time', () {
var f = File('test/files/generalized_time.der');
var bytes = f.readAsBytesSync();
var parser = ASN1Parser(bytes);
expect(parser.hasNext(), isTrue);

var c = X509Certificate.fromAsn1(parser.nextObject() as ASN1Sequence);
expect(c, isA<X509Certificate>());
});
});
}