{"record":{"id":"16ac29880b52eb5a","repo":"peass-ng/PEASS-ng","slug":"unknown-tag-tagno-encountered","errorCode":null,"errorMessage":"unknown tag {tagNo} encountered","messagePattern":"unknown tag (.+?) encountered","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs","lineNumber":128,"sourceCode":"                                if (!(asn1Obj is Asn1OctetString))\n                                {\n                                    throw new Asn1Exception(\"unknown object encountered in constructed OCTET STRING: \"\n                                        + Platform.GetTypeName(asn1Obj));\n                                }\n\n                                strings[i] = (Asn1OctetString)asn1Obj;\n                            }\n\n                            return new BerOctetString(strings);\n                        }\n                    case Asn1Tags.Sequence:\n                        return CreateDerSequence(defIn);\n                    case Asn1Tags.Set:\n                        return CreateDerSet(defIn);\n                    case Asn1Tags.External:\n                        return new DerExternal(ReadVector(defIn));\n                    default:\n                        throw new IOException(\"unknown tag \" + tagNo + \" encountered\");\n                }\n            }\n\n            return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);\n        }\n\n        internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn)\n        {\n            if (dIn.Remaining < 1)\n                return new Asn1EncodableVector(0);\n\n            Asn1InputStream subStream = new Asn1InputStream(dIn);\n            Asn1EncodableVector v = new Asn1EncodableVector();\n            Asn1Object o;\n            while ((o = subStream.ReadObject()) != null)\n            {\n                v.Add(o);\n            }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs#L110-L146","documentation":"Asn1InputStream.BuildObject throws this IOException when it encounters an ASN.1 tag number it does not know how to map to a DER object class. The default branch of the tag switch covers tags that are neither recognized universal types nor handled application/private/constructed tags.","triggerScenarios":"ReadObject/ReadVector encounters a tagNo not in BouncyCastle's supported set — e.g. reserved or exotic universal tags, unsupported APPLICATION/PRIVATE class tags, or bytes that were never valid ASN.1 shifted so a tag byte decodes to an unknown number.","commonSituations":"Parsing a certificate/PKCS structure using tag types outside BouncyCastle's supported universal set; feeding non-ASN.1 bytes (text, ZIP, truncated file) to the parser; offset misalignment from skipping bytes before parsing.","solutions":["Verify the byte stream is valid ASN.1 starting at the parse offset (use openssl asn1parse to inspect).","Check you are not feeding compressed/encrypted wrappers — decrypt/decompress before ASN.1 parsing.","Extend handling by parsing the unknown tag yourself via a custom Asn1Object or use the newer Org.BouncyCastle.Asn1 parser version with broader tag support.","Catch IOException from ReadObject and treat the input as unsupported/malformed."],"exampleFix":"// before\nAsn1Object obj = asn1Stream.ReadObject();\n// after\ntry { Asn1Object obj = asn1Stream.ReadObject(); }\ncatch (IOException ex) { throw new InvalidDataException(\"Unsupported or unknown ASN.1 tag\", ex); }","handlingStrategy":"try-catch","validationCode":"static bool HasKnownLeadingTag(byte[] data)\n{\n    if (data == null || data.Length == 0) return false;\n    int tagNo = data[0] & 0x1f; // low 5 bits of tag byte (short form)\n    // known universal tags: 1..21 incl. common DER types\n    return (data[0] & 0xc0) == 0 && tagNo <= 21;\n}","typeGuard":null,"tryCatchPattern":"Asn1Object obj;\ntry {\n    obj = stream.ReadObject();\n} catch (IOException ex) when (ex.Message.StartsWith(\"unknown tag\")) {\n    throw new NotSupportedException(\"ASN.1 stream contains a tag this parser does not support\", ex);\n}","preventionTips":["Prefer up-to-date BouncyCastle versions which cover more ASN.1 tag types","Confirm the input is ASN.1 and the parse offset is correct before ReadObject","Decrypt/decompress wrapped payloads (PKCS#7, CMS) before feeding raw bytes to the parser","Handle unsupported tags explicitly by reading the TLV manually with Asn1StreamParser if extension tags are expected"],"tags":["asn1","bouncycastle","parsing","der","unsupported-tag"],"backgroundTag":"malformed-asn1-data","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}