Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a5987a51 authored by Brian Carlstrom's avatar Brian Carlstrom
Browse files

SslCertificate should clone Dates

To avoid external tampering with Dates withing SslCertificate by code
holding on to pointers to Dates used in the constructor or code
mutating values returned by the accessors, we now clone Dates taking
in as arguments and returned to callers.
parent 626e805d
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -128,8 +128,8 @@ public class SslCertificate {
            String issuedTo, String issuedBy, Date validNotBefore, Date validNotAfter) {
        mIssuedTo = new DName(issuedTo);
        mIssuedBy = new DName(issuedBy);
        mValidNotBefore = validNotBefore;
        mValidNotAfter = validNotAfter;
        mValidNotBefore = cloneDate(validNotBefore);
        mValidNotAfter  = cloneDate(validNotAfter);
    }

    /**
@@ -148,7 +148,7 @@ public class SslCertificate {
     * "" if none has been set
     */
    public Date getValidNotBeforeDate() {
        return mValidNotBefore;
        return cloneDate(mValidNotBefore);
    }

    /**
@@ -166,7 +166,7 @@ public class SslCertificate {
     * "" if none has been set
     */
    public Date getValidNotAfterDate() {
        return mValidNotAfter;
        return cloneDate(mValidNotAfter);
    }

    /**
@@ -223,6 +223,16 @@ public class SslCertificate {
        return new SimpleDateFormat(ISO_8601_DATE_FORMAT).format(date);
    }

    /**
     * Clone a possibly null Date
     */
    private static Date cloneDate(Date date) {
        if (date == null) {
            return null;
        }
        return (Date) date.clone();
    }

    /**
     * A distinguished name helper class: a 3-tuple of:
     * - common name (CN),