Back to index

lightning-sunbird  0.9+nobinonly
nsOCSPResponder.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  *   Ian McGreer <mcgreer@netscape.com>
00023  *   Javier Delgadillo <javi@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsOCSPResponder.h"
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsIDateTimeFormat.h"
00043 #include "nsDateTimeFormatCID.h"
00044 #include "nsComponentManagerUtils.h"
00045 #include "nsReadableUtils.h"
00046 
00047 #include "certdb.h"
00048 
00049 /* Implementation file */
00050 NS_IMPL_ISUPPORTS1(nsOCSPResponder, nsIOCSPResponder)
00051 
00052 nsOCSPResponder::nsOCSPResponder()
00053 {
00054   /* member initializers and constructor code */
00055 }
00056 
00057 nsOCSPResponder::nsOCSPResponder(const PRUnichar * aCA, const PRUnichar * aURL)
00058 {
00059   mCA.Assign(aCA);
00060   mURL.Assign(aURL);
00061 }
00062 
00063 nsOCSPResponder::~nsOCSPResponder()
00064 {
00065   /* destructor code */
00066 }
00067 
00068 /* readonly attribute */
00069 NS_IMETHODIMP nsOCSPResponder::GetResponseSigner(PRUnichar** aCA)
00070 {
00071   NS_ENSURE_ARG(aCA);
00072   *aCA = ToNewUnicode(mCA);
00073   return NS_OK;
00074 }
00075 
00076 /* readonly attribute */
00077 NS_IMETHODIMP nsOCSPResponder::GetServiceURL(PRUnichar** aURL)
00078 {
00079   NS_ENSURE_ARG(aURL);
00080   *aURL = ToNewUnicode(mURL);
00081   return NS_OK;
00082 }
00083 
00084 PRBool nsOCSPResponder::IncludeCert(CERTCertificate *aCert)
00085 {
00086   CERTCertTrust *trust;
00087   char *nickname;
00088 
00089   trust = aCert->trust;
00090   nickname = aCert->nickname;
00091 
00092   PR_ASSERT(trust != nsnull);
00093 
00094   // Check that trust is non-null //
00095   if (trust == nsnull) {
00096     return PR_FALSE;
00097   }
00098 
00099   if ( ( ( trust->sslFlags & CERTDB_INVISIBLE_CA ) ||
00100          (trust->emailFlags & CERTDB_INVISIBLE_CA ) ||
00101          (trust->objectSigningFlags & CERTDB_INVISIBLE_CA ) ) ||
00102        nickname == NULL) {
00103       return PR_FALSE;
00104   }
00105   if ((trust->sslFlags & CERTDB_VALID_CA) ||
00106       (trust->emailFlags & CERTDB_VALID_CA) ||
00107       (trust->objectSigningFlags & CERTDB_VALID_CA)) {
00108       return PR_TRUE;
00109   }
00110   return PR_FALSE;
00111 }
00112 
00113 // CmpByCAName
00114 //
00115 // Compare two responders their token name.  Returns -1, 0, 1 as
00116 // in strcmp.  No token name (null) is treated as >.
00117 PRInt32 nsOCSPResponder::CmpCAName(nsIOCSPResponder *a, nsIOCSPResponder *b)
00118 {
00119   PRInt32 cmp1;
00120   nsXPIDLString aTok, bTok;
00121   a->GetResponseSigner(getter_Copies(aTok));
00122   b->GetResponseSigner(getter_Copies(bTok));
00123   if (aTok != nsnull && bTok != nsnull) {
00124     cmp1 = Compare(aTok, bTok);
00125   } else {
00126     cmp1 = (aTok == nsnull) ? 1 : -1;
00127   }
00128   return cmp1;
00129 }
00130 
00131 // ocsp_compare_entries
00132 //
00133 // Compare two responders.  Returns -1, 0, 1 as
00134 // in strcmp.  Entries with urls come before those without urls.
00135 PRInt32 nsOCSPResponder::CompareEntries(nsIOCSPResponder *a, nsIOCSPResponder *b)
00136 {
00137   nsXPIDLString aURL, bURL;
00138   nsAutoString aURLAuto, bURLAuto;
00139 
00140   a->GetServiceURL(getter_Copies(aURL));
00141   aURLAuto.Assign(aURL);
00142   b->GetServiceURL(getter_Copies(bURL));
00143   bURLAuto.Assign(bURL);
00144 
00145   if (!aURLAuto.IsEmpty()) {
00146     if (!bURLAuto.IsEmpty()) {
00147       return nsOCSPResponder::CmpCAName(a, b);
00148     } else {
00149       return -1;
00150     }
00151   } else {
00152     if (!bURLAuto.IsEmpty()) {
00153       return 1;
00154     } else {
00155       return nsOCSPResponder::CmpCAName(a, b);
00156     }
00157   }
00158 }
00159