security/manager/ssl/src/nsNSSCertValidity.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsNSSCertValidity.h"
michael@0 6 #include "nsCOMPtr.h"
michael@0 7 #include "nsIDateTimeFormat.h"
michael@0 8 #include "nsDateTimeFormatCID.h"
michael@0 9 #include "nsComponentManagerUtils.h"
michael@0 10 #include "nsReadableUtils.h"
michael@0 11 #include "nsNSSShutDown.h"
michael@0 12 #include "cert.h"
michael@0 13
michael@0 14 /* Implementation file */
michael@0 15 NS_IMPL_ISUPPORTS(nsX509CertValidity, nsIX509CertValidity)
michael@0 16
michael@0 17 nsX509CertValidity::nsX509CertValidity() : mTimesInitialized(false)
michael@0 18 {
michael@0 19 /* member initializers and constructor code */
michael@0 20 }
michael@0 21
michael@0 22 nsX509CertValidity::nsX509CertValidity(CERTCertificate *cert) :
michael@0 23 mTimesInitialized(false)
michael@0 24 {
michael@0 25 nsNSSShutDownPreventionLock locker;
michael@0 26 if (cert) {
michael@0 27 SECStatus rv = CERT_GetCertTimes(cert, &mNotBefore, &mNotAfter);
michael@0 28 if (rv == SECSuccess)
michael@0 29 mTimesInitialized = true;
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 nsX509CertValidity::~nsX509CertValidity()
michael@0 34 {
michael@0 35 /* destructor code */
michael@0 36 }
michael@0 37
michael@0 38 /* readonly attribute PRTime notBefore; */
michael@0 39 NS_IMETHODIMP nsX509CertValidity::GetNotBefore(PRTime *aNotBefore)
michael@0 40 {
michael@0 41 NS_ENSURE_ARG(aNotBefore);
michael@0 42
michael@0 43 nsresult rv = NS_ERROR_FAILURE;
michael@0 44 if (mTimesInitialized) {
michael@0 45 *aNotBefore = mNotBefore;
michael@0 46 rv = NS_OK;
michael@0 47 }
michael@0 48 return rv;
michael@0 49 }
michael@0 50
michael@0 51 NS_IMETHODIMP nsX509CertValidity::GetNotBeforeLocalTime(nsAString &aNotBeforeLocalTime)
michael@0 52 {
michael@0 53 if (!mTimesInitialized)
michael@0 54 return NS_ERROR_FAILURE;
michael@0 55
michael@0 56 nsresult rv;
michael@0 57 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
michael@0 58 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
michael@0 59 if (NS_FAILED(rv)) return rv;
michael@0 60
michael@0 61 nsAutoString date;
michael@0 62 PRExplodedTime explodedTime;
michael@0 63 PR_ExplodeTime(mNotBefore, PR_LocalTimeParameters, &explodedTime);
michael@0 64 dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatSecondsForce24Hour,
michael@0 65 &explodedTime, date);
michael@0 66 aNotBeforeLocalTime = date;
michael@0 67 return NS_OK;
michael@0 68 }
michael@0 69
michael@0 70 NS_IMETHODIMP nsX509CertValidity::GetNotBeforeLocalDay(nsAString &aNotBeforeLocalDay)
michael@0 71 {
michael@0 72 if (!mTimesInitialized)
michael@0 73 return NS_ERROR_FAILURE;
michael@0 74
michael@0 75 nsresult rv;
michael@0 76 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
michael@0 77 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
michael@0 78 if (NS_FAILED(rv)) return rv;
michael@0 79
michael@0 80 nsAutoString date;
michael@0 81 PRExplodedTime explodedTime;
michael@0 82 PR_ExplodeTime(mNotBefore, PR_LocalTimeParameters, &explodedTime);
michael@0 83 dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatNone,
michael@0 84 &explodedTime, date);
michael@0 85 aNotBeforeLocalDay = date;
michael@0 86 return NS_OK;
michael@0 87 }
michael@0 88
michael@0 89
michael@0 90 NS_IMETHODIMP nsX509CertValidity::GetNotBeforeGMT(nsAString &aNotBeforeGMT)
michael@0 91 {
michael@0 92 if (!mTimesInitialized)
michael@0 93 return NS_ERROR_FAILURE;
michael@0 94
michael@0 95 nsresult rv;
michael@0 96 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
michael@0 97 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
michael@0 98 if (NS_FAILED(rv)) return rv;
michael@0 99
michael@0 100 nsAutoString date;
michael@0 101 PRExplodedTime explodedTime;
michael@0 102 PR_ExplodeTime(mNotBefore, PR_GMTParameters, &explodedTime);
michael@0 103 dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatSecondsForce24Hour,
michael@0 104 &explodedTime, date);
michael@0 105 aNotBeforeGMT = date;
michael@0 106 return NS_OK;
michael@0 107 }
michael@0 108
michael@0 109 /* readonly attribute PRTime notAfter; */
michael@0 110 NS_IMETHODIMP nsX509CertValidity::GetNotAfter(PRTime *aNotAfter)
michael@0 111 {
michael@0 112 NS_ENSURE_ARG(aNotAfter);
michael@0 113
michael@0 114 nsresult rv = NS_ERROR_FAILURE;
michael@0 115 if (mTimesInitialized) {
michael@0 116 *aNotAfter = mNotAfter;
michael@0 117 rv = NS_OK;
michael@0 118 }
michael@0 119 return rv;
michael@0 120 }
michael@0 121
michael@0 122 NS_IMETHODIMP nsX509CertValidity::GetNotAfterLocalTime(nsAString &aNotAfterLocaltime)
michael@0 123 {
michael@0 124 if (!mTimesInitialized)
michael@0 125 return NS_ERROR_FAILURE;
michael@0 126
michael@0 127 nsresult rv;
michael@0 128 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
michael@0 129 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
michael@0 130 if (NS_FAILED(rv)) return rv;
michael@0 131
michael@0 132 nsAutoString date;
michael@0 133 PRExplodedTime explodedTime;
michael@0 134 PR_ExplodeTime(mNotAfter, PR_LocalTimeParameters, &explodedTime);
michael@0 135 dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatSecondsForce24Hour,
michael@0 136 &explodedTime, date);
michael@0 137 aNotAfterLocaltime = date;
michael@0 138 return NS_OK;
michael@0 139 }
michael@0 140
michael@0 141 NS_IMETHODIMP nsX509CertValidity::GetNotAfterLocalDay(nsAString &aNotAfterLocalDay)
michael@0 142 {
michael@0 143 if (!mTimesInitialized)
michael@0 144 return NS_ERROR_FAILURE;
michael@0 145
michael@0 146 nsresult rv;
michael@0 147 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
michael@0 148 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
michael@0 149 if (NS_FAILED(rv)) return rv;
michael@0 150
michael@0 151 nsAutoString date;
michael@0 152 PRExplodedTime explodedTime;
michael@0 153 PR_ExplodeTime(mNotAfter, PR_LocalTimeParameters, &explodedTime);
michael@0 154 dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatNone,
michael@0 155 &explodedTime, date);
michael@0 156 aNotAfterLocalDay = date;
michael@0 157 return NS_OK;
michael@0 158 }
michael@0 159
michael@0 160 NS_IMETHODIMP nsX509CertValidity::GetNotAfterGMT(nsAString &aNotAfterGMT)
michael@0 161 {
michael@0 162 if (!mTimesInitialized)
michael@0 163 return NS_ERROR_FAILURE;
michael@0 164
michael@0 165 nsresult rv;
michael@0 166 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
michael@0 167 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
michael@0 168 if (NS_FAILED(rv)) return rv;
michael@0 169
michael@0 170 nsAutoString date;
michael@0 171 PRExplodedTime explodedTime;
michael@0 172 PR_ExplodeTime(mNotAfter, PR_GMTParameters, &explodedTime);
michael@0 173 dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatSecondsForce24Hour,
michael@0 174 &explodedTime, date);
michael@0 175 aNotAfterGMT = date;
michael@0 176 return NS_OK;
michael@0 177 }

mercurial