Closed yschimke closed 2 years ago
Basic Constraints from the Certificate shortly after X509 -> Certifikit.
Suggestion from here that it should be [30, 0]
Investigating here https://github.com/cashapp/certifikit/pull/98
Diffs
:13:13:13:13:3:
:0c:0c:0c:0c:1:
The Basic Constraint difference is 3->1
300c0603551d130101ff04023000
300c0603551d130101ff04021000
Diffs of 13s
Diffs from parsed content
https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/
The first thing to know about SEQUENCE is that it always uses Constructed encoding because it contains other objects. In other words, the value bytes of a SEQUENCE contain the concatenation of the encoded fields of that SEQUENCE (in the order those fields were defined). This also means that bit 6 of a SEQUENCE’s tag (the Constructed vs Primitive bit) is always set to 1. So even though the tag number for SEQUENCE is technically 0x10, its tag byte, once encoded, is always 0x30.
~I don't understand the tag classes~
From JDK BasicConstraintsExtension & DerValue
/**
* Tag value indicating an ASN.1
* "SEQUENCE" (zero to N elements, order is significant).
*/
public static final byte tag_Sequence = 0x30;
/**
* Tag value indicating an ASN.1
* "SEQUENCE OF" (one to N elements, order is significant).
*/
public static final byte tag_SequenceOf = 0x30;
From Adapters.sequence
return BasicDerAdapter(
name = name,
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 16L,
codec = codec
)
I suspect Der.writer should have constructed = true when writing BasicConstraints
Temporary fix for the crash with
try {
block(content)
if (name == "BasicConstraints") {
constructed = true
}
constructedBit = if (constructed) 0b0010_0000 else 0
constructed = true // The enclosing object is constructed.
} finally {
Seemingly because both values are optional
if (isOptional && value == defaultValue) {
// Nothing to write!
return
}
The other relates to the charset mapping. It's choosing UTF-8 over PrintableString.
https://www.alvestrand.no/objectid/2.5.4.6.html
oid: 2.5.4.6 - id-at-countryName 060355040613025553 vs 06035504060c025553
Can flip these to get it working for this certificate.
private val attributeTypeAndValue: BasicDerAdapter<AttributeTypeAndValue> = Adapters.sequence(
"AttributeTypeAndValue",
Adapters.OBJECT_IDENTIFIER,
Adapters.any(
String::class to Adapters.UTF8_STRING,
Nothing::class to Adapters.PRINTABLE_STRING,
But UTF-8 was intentional as a safe default. However 2.5.4.6 - id-at-countryName is Printable String so effectively we don't have a distinct encoding.
Addressed on other PR and I'll open another PR for our variable encoding.
From https://github.com/cashapp/certifikit/pull/94
Fails on