Ejemplo n.º 1
0
    def __str__(self):
        s = "Certificate name:\n"
        s += "  " + self.getName().toUri() + "\n"
        s += "Validity:\n"

        dateFormat = "%Y%m%dT%H%M%S"
        notBeforeStr = Common.datetimeFromTimestamp(
            self.getNotBefore()).strftime(dateFormat)
        notAfterStr = Common.datetimeFromTimestamp(
            self.getNotAfter()).strftime(dateFormat)

        s += "  NotBefore: " + notBeforeStr + "\n"
        s += "  NotAfter: " + notAfterStr + "\n"
        for sd in self._subjectDescriptionList:
            s += "Subject Description:\n"
            s += "  " + str(
                sd.getOid()) + ": " + sd.getValue().toRawStr() + "\n"

        s += "Public key bits:\n"
        s += Common.base64Encode(self.getPublicKeyDer().toBytes(), True)

        if len(self._extensionList) > 0:
            s += "Extensions:\n"
            for ext in self._extensionList:
                s += "  OID: " + ext.getOid() + "\n"
                s += "  Is critical: " + ('Y'
                                          if ext.isCritical() else 'N') + "\n"

                s += "  Value: " + str(ext.getValue()).encode('hex') + "\n"

        return s
Ejemplo n.º 2
0
    def __str__(self):
        s = "Certificate name:\n"
        s += "  "+self.getName().toUri()+"\n"
        s += "Validity:\n"

        dateFormat = "%Y%m%dT%H%M%S"
        notBeforeStr = Common.datetimeFromTimestamp(self.getNotBefore()).strftime(dateFormat)
        notAfterStr = Common.datetimeFromTimestamp(self.getNotAfter()).strftime(dateFormat)

        s += "  NotBefore: " + notBeforeStr+"\n"
        s += "  NotAfter: " + notAfterStr + "\n"
        for sd in self._subjectDescriptionList:
            s += "Subject Description:\n"
            s += "  " + str(sd.getOid()) + ": " + sd.getValue().toRawStr() + "\n"

        s += "Public key bits:\n"
        s += Common.base64Encode(self.getPublicKeyDer().toBytes(), True)

        if len(self._extensionList) > 0:
            s += "Extensions:\n"
            for ext in self._extensionList:
                s += "  OID: "+ext.getOid()+"\n"
                s += "  Is critical: " + ('Y' if ext.isCritical() else 'N') + "\n"

                s += "  Value: " + str(ext.getValue()).encode('hex') + "\n"

        return s
Ejemplo n.º 3
0
    def _hasIntervalOnDate(self, timePoint):
        """
        Check if the date of the time point is in any interval.

        :param float timePoint: The time point as milliseconds since Jan 1,
          1970 UTC.
        :return: True if the date of the time point is in any interval.
        :rtype: bool
        """
        timePointDateMilliseconds = RepetitiveInterval._toDateOnlyMilliseconds(
            timePoint)

        if (timePointDateMilliseconds < self._startDate
                or timePointDateMilliseconds > self._endDate):
            return False

        if self._repeatUnit == RepetitiveInterval.RepeatUnit.NONE:
            return True
        elif self._repeatUnit == RepetitiveInterval.RepeatUnit.DAY:
            durationDays = ((timePointDateMilliseconds - self._startDate) /
                            RepetitiveInterval.MILLISECONDS_IN_DAY)
            if durationDays % self._nRepeats == 0:
                return True
        else:
            timePointDate = Common.datetimeFromTimestamp(
                round(timePointDateMilliseconds / 1000.0) * 1000)
            startDate = Common.datetimeFromTimestamp(self._startDate)

            if (self._repeatUnit == RepetitiveInterval.RepeatUnit.MONTH
                    and timePointDate.day == startDate.day):
                yearDifference = timePointDate.year - startDate.year
                monthDifference = (12 * yearDifference + timePointDate.month -
                                   startDate.month)
                if monthDifference % self._nRepeats == 0:
                    return True
            elif (self._repeatUnit == RepetitiveInterval.RepeatUnit.YEAR
                  and timePointDate.day == startDate.day
                  and timePointDate.month == startDate.month):
                difference = timePointDate.year - startDate.year
                if difference % self._nRepeats == 0:
                    return True

        return False
Ejemplo n.º 4
0
    def _hasIntervalOnDate(self, timePoint):
        """
        Check if the date of the time point is in any interval.

        :param float timePoint: The time point as milliseconds since Jan 1,
          1970 UTC.
        :return: True if the date of the time point is in any interval.
        :rtype: bool
        """
        timePointDateMilliseconds = RepetitiveInterval._toDateOnlyMilliseconds(timePoint)

        if (timePointDateMilliseconds < self._startDate or
            timePointDateMilliseconds > self._endDate):
            return False

        if self._repeatUnit == RepetitiveInterval.RepeatUnit.NONE:
            return True
        elif self._repeatUnit == RepetitiveInterval.RepeatUnit.DAY:
            durationDays = ((timePointDateMilliseconds - self._startDate) /
                            RepetitiveInterval.MILLISECONDS_IN_DAY)
            if durationDays % self._nRepeats == 0:
                return True
        else:
            timePointDate = Common.datetimeFromTimestamp(
              round(timePointDateMilliseconds / 1000.0) * 1000)
            startDate = Common.datetimeFromTimestamp(self._startDate)

            if (self._repeatUnit == RepetitiveInterval.RepeatUnit.MONTH and
                  timePointDate.day == startDate.day):
                yearDifference = timePointDate.year - startDate.year
                monthDifference = (12 * yearDifference +
                  timePointDate.month - startDate.month)
                if monthDifference % self._nRepeats == 0:
                  return True
            elif (self._repeatUnit == RepetitiveInterval.RepeatUnit.YEAR and
                  timePointDate.day == startDate.day and
                  timePointDate.month == startDate.month):
                difference = timePointDate.year - startDate.year
                if difference % self._nRepeats == 0:
                  return True

        return False
Ejemplo n.º 5
0
    def toDerTimeString(msSince1970):
        """
        Convert a UNIX timestamp to the internal string representation
        :param msSince1970: Timestamp as milliseconds since Jan 1, 1970
        :type msSince1970: float
        :return: The time string
        :rtype: str
        """
        utcTime = Common.datetimeFromTimestamp(msSince1970)

        derTime = utcTime.strftime("%Y%m%d%H%M%SZ")
        return derTime
Ejemplo n.º 6
0
    def toIsoString(msSince1970):
        """
        Convert a UNIX timestamp to ISO time representation with the "T" in the
        middle.

        :param float msSince1970: Timestamp as milliseconds since Jan 1, 1970 UTC.
        :return: The string representation.
        :rtype: str
        """
        dateFormat = "%Y%m%dT%H%M%S"
        return Common.datetimeFromTimestamp(
          round(msSince1970 / 1000.0) * 1000).strftime(dateFormat)
Ejemplo n.º 7
0
    def toDerTimeString(msSince1970):
        """
        Convert a UNIX timestamp to the internal string representation
        :param msSince1970: Timestamp as milliseconds since Jan 1, 1970
        :type msSince1970: float
        :return: The time string
        :rtype: str
        """
        utcTime = Common.datetimeFromTimestamp(msSince1970)

        derTime = utcTime.strftime("%Y%m%d%H%M%SZ")
        return derTime
Ejemplo n.º 8
0
    def toIsoString(msSince1970):
        """
        Convert a UNIX timestamp to ISO time representation with the "T" in the
        middle.

        :param float msSince1970: Timestamp as milliseconds since Jan 1, 1970 UTC.
        :return: The string representation.
        :rtype: str
        """
        dateFormat = "%Y%m%dT%H%M%S"
        return Common.datetimeFromTimestamp(
          round(msSince1970 / 1000.0) * 1000).strftime(dateFormat)