Back to index

lightning-sunbird  0.9+nobinonly
nsCRLInfo.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "prmem.h"
00038 #include "prerror.h"
00039 #include "prprf.h"
00040 
00041 #include "nsCRLInfo.h"
00042 #include "nsIDateTimeFormat.h"
00043 #include "nsDateTimeFormatCID.h"
00044 #include "nsCOMPtr.h"
00045 #include "nsComponentManagerUtils.h"
00046 #include "nsReadableUtils.h"
00047 #include "nsNSSShutDown.h"
00048 
00049 #include "nspr.h"
00050 extern "C" {
00051 #include "pk11func.h"
00052 #include "certdb.h"
00053 #include "cert.h"
00054 #include "secerr.h"
00055 #include "nssb64.h"
00056 #include "secasn1.h"
00057 #include "secder.h"
00058 }
00059 
00060 static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
00061 
00062 NS_IMPL_ISUPPORTS1(nsCRLInfo, nsICRLInfo)
00063 
00064 nsCRLInfo::nsCRLInfo()
00065 {
00066   /* member initializers and constructor code */
00067 }
00068 
00069 nsCRLInfo::nsCRLInfo(CERTSignedCrl *signedCrl)
00070 {
00071   nsNSSShutDownPreventionLock locker;
00072   CERTCrl *crl = &(signedCrl->crl);
00073   nsAutoString org;
00074   nsAutoString orgUnit;
00075   nsAutoString nameInDb;
00076   nsAutoString nextUpdateLocale;
00077   nsAutoString lastUpdateLocale;
00078   nsCAutoString lastFetchURL;
00079   PRTime lastUpdate = 0;
00080   PRTime nextUpdate = 0;
00081   SECStatus sec_rv;
00082   
00083   // Get the information we need here //
00084   char * o = CERT_GetOrgName(&(crl->name));
00085   if (o) {
00086     org = NS_ConvertASCIItoUCS2(o);
00087     PORT_Free(o);
00088   }
00089 
00090   char * ou = CERT_GetOrgUnitName(&(crl->name));
00091   if (ou) {
00092     orgUnit = NS_ConvertASCIItoUCS2(ou);
00093     //At present, the ou is being used as the unique key - but this
00094     //would change, one support for delta crls come in.
00095     nameInDb =  orgUnit;
00096     PORT_Free(ou);
00097   }
00098   
00099   nsCOMPtr<nsIDateTimeFormat> dateFormatter = do_CreateInstance(kDateTimeFormatCID);
00100   
00101   // Last Update time
00102   if (crl->lastUpdate.len) {
00103     sec_rv = DER_UTCTimeToTime(&lastUpdate, &(crl->lastUpdate));
00104     if (sec_rv == SECSuccess && dateFormatter) {
00105       dateFormatter->FormatPRTime(nsnull, kDateFormatShort, kTimeFormatNone,
00106                             lastUpdate, lastUpdateLocale);
00107     }
00108   }
00109 
00110   if (crl->nextUpdate.len) {
00111     // Next update time
00112     sec_rv = DER_UTCTimeToTime(&nextUpdate, &(crl->nextUpdate));
00113     if (sec_rv == SECSuccess && dateFormatter) {
00114       dateFormatter->FormatPRTime(nsnull, kDateFormatShort, kTimeFormatNone,
00115                             nextUpdate, nextUpdateLocale);
00116     }
00117   }
00118 
00119   char * url = signedCrl->url;
00120   if(url) {
00121     lastFetchURL =  url;
00122   }
00123 
00124   mOrg.Assign(org.get());
00125   mOrgUnit.Assign(orgUnit.get());
00126   mLastUpdateLocale.Assign(lastUpdateLocale.get());
00127   mNextUpdateLocale.Assign(nextUpdateLocale.get());
00128   mLastUpdate = lastUpdate;
00129   mNextUpdate = nextUpdate;
00130   mNameInDb.Assign(nameInDb.get());
00131   mLastFetchURL = lastFetchURL;
00132 }
00133 
00134 nsCRLInfo::~nsCRLInfo()
00135 {
00136   /* destructor code */
00137 }
00138 
00139 /* readonly attribute */
00140 NS_IMETHODIMP nsCRLInfo::GetOrganization(nsAString & aOrg)
00141 {
00142   aOrg = mOrg;
00143   return NS_OK;
00144 }
00145 
00146 /* readonly attribute */
00147 NS_IMETHODIMP nsCRLInfo::GetOrganizationalUnit(nsAString & aOrgUnit)
00148 {
00149   aOrgUnit = mOrgUnit;
00150   return NS_OK;
00151 }
00152 
00153 NS_IMETHODIMP nsCRLInfo::GetLastUpdateLocale(nsAString & aLastUpdateLocale)
00154 {
00155   aLastUpdateLocale = mLastUpdateLocale;
00156   return NS_OK;
00157 }
00158 
00159 NS_IMETHODIMP nsCRLInfo::GetNextUpdateLocale(nsAString & aNextUpdateLocale)
00160 {
00161   aNextUpdateLocale = mNextUpdateLocale;
00162   return NS_OK;
00163 }
00164 
00165 NS_IMETHODIMP nsCRLInfo::GetLastUpdate(PRTime* aLastUpdate)
00166 {
00167   NS_ENSURE_ARG(aLastUpdate);
00168   *aLastUpdate = mLastUpdate;
00169   return NS_OK;
00170 }
00171 
00172 NS_IMETHODIMP nsCRLInfo::GetNextUpdate(PRTime* aNextUpdate)
00173 {
00174   NS_ENSURE_ARG(aNextUpdate);
00175   *aNextUpdate = mNextUpdate;
00176   return NS_OK;
00177 }
00178 
00179 NS_IMETHODIMP nsCRLInfo::GetNameInDb(nsAString & aNameInDb)
00180 {
00181   aNameInDb = mNameInDb;
00182   return NS_OK;
00183 }
00184 
00185 NS_IMETHODIMP nsCRLInfo::GetLastFetchURL(nsACString & aLastFetchURL)
00186 {
00187   aLastFetchURL = mLastFetchURL;
00188   return NS_OK;
00189 }