1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2000
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
41 #include "nsCRLInfo.h"
42 #include "nsIDateTimeFormat.h"
43 #include "nsDateTimeFormatCID.h"
45 #include "nsComponentManagerUtils.h"
46 #include "nsReadableUtils.h"
47 #include "nsNSSShutDown.h"
60 NS_IMPL_ISUPPORTS1(nsCRLInfo
, nsICRLInfo
)
62 nsCRLInfo::nsCRLInfo()
64 /* member initializers and constructor code */
67 nsCRLInfo::nsCRLInfo(CERTSignedCrl
*signedCrl
)
69 nsNSSShutDownPreventionLock locker
;
70 CERTCrl
*crl
= &(signedCrl
->crl
);
73 nsAutoString nameInDb
;
74 nsAutoString nextUpdateLocale
;
75 nsAutoString lastUpdateLocale
;
76 nsCAutoString lastFetchURL
;
77 PRTime lastUpdate
= 0;
78 PRTime nextUpdate
= 0;
81 // Get the information we need here //
82 char * o
= CERT_GetOrgName(&(crl
->name
));
84 org
= NS_ConvertASCIItoUTF16(o
);
88 char * ou
= CERT_GetOrgUnitName(&(crl
->name
));
90 orgUnit
= NS_ConvertASCIItoUTF16(ou
);
91 //At present, the ou is being used as the unique key - but this
92 //would change, one support for delta crls come in.
97 nsCOMPtr
<nsIDateTimeFormat
> dateFormatter
= do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID
);
100 if (crl
->lastUpdate
.len
) {
101 sec_rv
= DER_UTCTimeToTime(&lastUpdate
, &(crl
->lastUpdate
));
102 if (sec_rv
== SECSuccess
&& dateFormatter
) {
103 dateFormatter
->FormatPRTime(nsnull
, kDateFormatShort
, kTimeFormatNone
,
104 lastUpdate
, lastUpdateLocale
);
108 if (crl
->nextUpdate
.len
) {
110 sec_rv
= DER_UTCTimeToTime(&nextUpdate
, &(crl
->nextUpdate
));
111 if (sec_rv
== SECSuccess
&& dateFormatter
) {
112 dateFormatter
->FormatPRTime(nsnull
, kDateFormatShort
, kTimeFormatNone
,
113 nextUpdate
, nextUpdateLocale
);
117 char * url
= signedCrl
->url
;
122 mOrg
.Assign(org
.get());
123 mOrgUnit
.Assign(orgUnit
.get());
124 mLastUpdateLocale
.Assign(lastUpdateLocale
.get());
125 mNextUpdateLocale
.Assign(nextUpdateLocale
.get());
126 mLastUpdate
= lastUpdate
;
127 mNextUpdate
= nextUpdate
;
128 mNameInDb
.Assign(nameInDb
.get());
129 mLastFetchURL
= lastFetchURL
;
132 nsCRLInfo::~nsCRLInfo()
134 /* destructor code */
137 /* readonly attribute */
138 NS_IMETHODIMP
nsCRLInfo::GetOrganization(nsAString
& aOrg
)
144 /* readonly attribute */
145 NS_IMETHODIMP
nsCRLInfo::GetOrganizationalUnit(nsAString
& aOrgUnit
)
151 NS_IMETHODIMP
nsCRLInfo::GetLastUpdateLocale(nsAString
& aLastUpdateLocale
)
153 aLastUpdateLocale
= mLastUpdateLocale
;
157 NS_IMETHODIMP
nsCRLInfo::GetNextUpdateLocale(nsAString
& aNextUpdateLocale
)
159 aNextUpdateLocale
= mNextUpdateLocale
;
163 NS_IMETHODIMP
nsCRLInfo::GetLastUpdate(PRTime
* aLastUpdate
)
165 NS_ENSURE_ARG(aLastUpdate
);
166 *aLastUpdate
= mLastUpdate
;
170 NS_IMETHODIMP
nsCRLInfo::GetNextUpdate(PRTime
* aNextUpdate
)
172 NS_ENSURE_ARG(aNextUpdate
);
173 *aNextUpdate
= mNextUpdate
;
177 NS_IMETHODIMP
nsCRLInfo::GetNameInDb(nsAString
& aNameInDb
)
179 aNameInDb
= mNameInDb
;
183 NS_IMETHODIMP
nsCRLInfo::GetLastFetchURL(nsACString
& aLastFetchURL
)
185 aLastFetchURL
= mLastFetchURL
;