peass-ng/PEASS-ng · error · ArgumentException

illegal object in GetInstance:

Error message

illegal object in GetInstance: 

What it means

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.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralizedTime.cs:30

    public class DerGeneralizedTime
        : Asn1Object
    {
        private readonly string time;

        /**
         * return a generalized time from the passed in object
         *
         * @exception ArgumentException if the object cannot be converted.
         */
        public static DerGeneralizedTime GetInstance(
            object obj)
        {
            if (obj == null || obj is DerGeneralizedTime)
            {
                return (DerGeneralizedTime)obj;
            }

            throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj");
        }

        /**
         * return a Generalized Time object from a tagged object.
         *
         * @param obj the tagged object holding the object we want
         * @param explicitly true if the object is meant to be explicitly
         *              tagged false otherwise.
         * @exception ArgumentException if the tagged object cannot
         *               be converted.
         */
        public static DerGeneralizedTime GetInstance(
            Asn1TaggedObject obj,
            bool isExplicit)
        {
            Asn1Object o = obj.GetObject();

            if (isExplicit || o is DerGeneralizedTime)

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Branch on the actual type: handle Asn1UtcTime via DerUtcTime.GetInstance and convert its DateTime to DerGeneralizedTime if needed
  2. Use Time.GetInstance(obj) (org.bouncycastle.asn1.x509.Time), which accepts both UTCTime and GeneralizedTime
  3. Verify the ASN.1 schema to confirm the field is defined as GeneralizedTime

Example fix

// before
var gt = DerGeneralizedTime.GetInstance(obj);
// after
var time = Time.GetInstance(obj); // handles UTCTime and GeneralizedTime
var gt = time.ToDateTime();
Defensive patterns

Strategy: type-guard

Validate before calling

if (obj is DerGeneralizedTime gt) { /* use gt */ }
else if (obj is DerUtcTime ut) { var converted = new DerGeneralizedTime(ut.ToDateTime()); }

Type guard

static bool IsGeneralizedTime(Asn1Object o) => o is DerGeneralizedTime;

Try / catch

try { var gt = DerGeneralizedTime.GetInstance(obj); }
catch (ArgumentException ex) when (ex.Message.StartsWith("illegal object in GetInstance")) {
    // fall back to Time.GetInstance(obj) which accepts UTCTime too
}

Prevention

When it happens

Trigger: Calling DerGeneralizedTime.GetInstance(obj) where obj is not a DerGeneralizedTime — commonly a DerUtcTime from a UTCTime field or another string type.

Common situations: 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.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/e912cacce495273b. Report an issue: GitHub.