{"record":{"id":"e912cacce495273b","repo":"peass-ng/PEASS-ng","slug":"illegal-object-in-getinstance-e912ca","errorCode":null,"errorMessage":"illegal object in GetInstance: ","messagePattern":"illegal object in GetInstance: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralizedTime.cs","lineNumber":30,"sourceCode":"    public class DerGeneralizedTime\n        : Asn1Object\n    {\n        private readonly string time;\n\n        /**\n         * return a generalized time from the passed in object\n         *\n         * @exception ArgumentException if the object cannot be converted.\n         */\n        public static DerGeneralizedTime GetInstance(\n            object obj)\n        {\n            if (obj == null || obj is DerGeneralizedTime)\n            {\n                return (DerGeneralizedTime)obj;\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj), \"obj\");\n        }\n\n        /**\n         * return a Generalized Time object from a tagged object.\n         *\n         * @param obj the tagged object holding the object we want\n         * @param explicitly true if the object is meant to be explicitly\n         *              tagged false otherwise.\n         * @exception ArgumentException if the tagged object cannot\n         *               be converted.\n         */\n        public static DerGeneralizedTime GetInstance(\n            Asn1TaggedObject obj,\n            bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerGeneralizedTime)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralizedTime.cs#L12-L48","documentation":"This DerGeneralizedTime.GetInstance overload returns the object only when it is null or already a DerGeneralizedTime; it performs no conversion from other ASN.1 types. Passing any other Asn1Object (e.g. DerUtcTime or DerPrintableString) throws ArgumentException that includes the runtime type name.","triggerScenarios":"Calling DerGeneralizedTime.GetInstance(obj) where obj is not a DerGeneralizedTime — commonly a DerUtcTime from a UTCTime field or another string type.","commonSituations":"Certificate/TBS parsing where time fields may be UTCTime (pre-2050 convention) or GeneralizedTime; code that assumes all timestamps are GeneralizedTime; producers that switched time encodings.","solutions":["Branch on the actual type: handle Asn1UtcTime via DerUtcTime.GetInstance and convert its DateTime to DerGeneralizedTime if needed","Use Time.GetInstance(obj) (org.bouncycastle.asn1.x509.Time), which accepts both UTCTime and GeneralizedTime","Verify the ASN.1 schema to confirm the field is defined as GeneralizedTime"],"exampleFix":"// before\nvar gt = DerGeneralizedTime.GetInstance(obj);\n// after\nvar time = Time.GetInstance(obj); // handles UTCTime and GeneralizedTime\nvar gt = time.ToDateTime();","handlingStrategy":"type-guard","validationCode":"if (obj is DerGeneralizedTime gt) { /* use gt */ }\nelse if (obj is DerUtcTime ut) { var converted = new DerGeneralizedTime(ut.ToDateTime()); }","typeGuard":"static bool IsGeneralizedTime(Asn1Object o) => o is DerGeneralizedTime;","tryCatchPattern":"try { var gt = DerGeneralizedTime.GetInstance(obj); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"illegal object in GetInstance\")) {\n    // fall back to Time.GetInstance(obj) which accepts UTCTime too\n}","preventionTips":["Use Time.GetInstance (x509.Time) to accept both UTCTime and GeneralizedTime","Remember pre-2050 timestamps are typically UTCTime in certificates","Never assume a time field's ASN.1 encoding; branch on the concrete type"],"tags":["asn1","bouncycastle","type-cast","argument-validation"],"backgroundTag":"illegal-object-in-getinstance","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}