Back to index

lightning-sunbird  0.9+nobinonly
nsCipherInfo.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 Mozilla Communicator.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2002
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Kai Engert <kaie@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsCipherInfo.h"
00039 #include "nsReadableUtils.h"
00040 #include "nsEnumeratorUtils.h"
00041 #include "nsCRT.h"
00042 #include "nsNSSComponent.h"
00043 #include "ssl.h"
00044 #include "sslproto.h"
00045 
00046 NS_IMPL_ISUPPORTS1(nsCipherInfoService, nsICipherInfoService)
00047 
00048 nsCipherInfoService::nsCipherInfoService()
00049 {
00050 }
00051 
00052 nsCipherInfoService::~nsCipherInfoService()
00053 {
00054 }
00055 
00056 NS_IMETHODIMP nsCipherInfoService::GetCipherInfoByPrefString(const nsACString &aPrefString, nsICipherInfo * *aCipherInfo)
00057 {
00058   NS_ENSURE_ARG_POINTER(aCipherInfo);
00059 
00060   PRUint16 cipher_id = 0;
00061   nsresult rv = nsNSSComponent::GetNSSCipherIDFromPrefString(aPrefString, cipher_id);
00062   if (NS_FAILED(rv))
00063     return rv;
00064 
00065   *aCipherInfo = new nsCipherInfo(cipher_id);
00066   NS_IF_ADDREF(*aCipherInfo);
00067   rv = *aCipherInfo != nsnull ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00068   return rv;
00069 }
00070 
00071 NS_IMPL_ISUPPORTS1(nsCipherInfo, nsICipherInfo)
00072 
00073 nsCipherInfo::nsCipherInfo(PRUint16 aCipherId)
00074 :mHaveInfo(PR_FALSE)
00075 {
00076   for (PRUint16 i = 0; i < SSL_NumImplementedCiphers; ++i)
00077   {
00078     const PRUint16 i_id = SSL_ImplementedCiphers[i];
00079     if (i_id != aCipherId)
00080       continue;
00081   
00082     PRBool isGood = (
00083       (SECSuccess == SSL_GetCipherSuiteInfo(i_id, &mInfo, sizeof(mInfo)))
00084       &&
00085       (sizeof(mInfo) == mInfo.length));
00086 
00087     if (!isGood)
00088     {
00089       NS_ASSERTION(0, "unable to get info for implemented cipher");
00090       continue;
00091     }
00092     
00093     mHaveInfo = PR_TRUE;
00094   }
00095 }
00096 
00097 nsCipherInfo::~nsCipherInfo()
00098 {
00099 }
00100 
00101 NS_IMETHODIMP nsCipherInfo::GetLongName(nsACString &aLongName)
00102 {
00103   if (!mHaveInfo)
00104     return NS_ERROR_NOT_AVAILABLE;
00105 
00106   aLongName = ToNewCString(nsDependentCString(mInfo.cipherSuiteName));
00107   return NS_OK;
00108 }
00109 
00110 NS_IMETHODIMP nsCipherInfo::GetIsSSL2(PRBool *aIsSSL2)
00111 {
00112   NS_ENSURE_ARG_POINTER(aIsSSL2);
00113 
00114   if (!mHaveInfo)
00115     return NS_ERROR_NOT_AVAILABLE;
00116 
00117   *aIsSSL2 = SSL_IS_SSL2_CIPHER(mInfo.cipherSuite);
00118   return NS_OK;
00119 }
00120 
00121 NS_IMETHODIMP nsCipherInfo::GetIsFIPS(PRBool *aIsFIPS)
00122 {
00123   NS_ENSURE_ARG_POINTER(aIsFIPS);
00124 
00125   if (!mHaveInfo)
00126     return NS_ERROR_NOT_AVAILABLE;
00127 
00128   *aIsFIPS = mInfo.isFIPS;
00129   return NS_OK;
00130 }
00131 
00132 NS_IMETHODIMP nsCipherInfo::GetIsExportable(PRBool *aIsExportable)
00133 {
00134   NS_ENSURE_ARG_POINTER(aIsExportable);
00135 
00136   if (!mHaveInfo)
00137     return NS_ERROR_NOT_AVAILABLE;
00138 
00139   *aIsExportable = mInfo.isExportable;
00140   return NS_OK;
00141 }
00142 
00143 NS_IMETHODIMP nsCipherInfo::GetNonStandard(PRBool *aNonStandard)
00144 {
00145   NS_ENSURE_ARG_POINTER(aNonStandard);
00146 
00147   if (!mHaveInfo)
00148     return NS_ERROR_NOT_AVAILABLE;
00149 
00150   *aNonStandard = mInfo.nonStandard;
00151   return NS_OK;
00152 }
00153 
00154 NS_IMETHODIMP nsCipherInfo::GetSymCipherName(nsACString &aSymCipherName)
00155 {
00156   if (!mHaveInfo)
00157     return NS_ERROR_NOT_AVAILABLE;
00158 
00159   aSymCipherName = mInfo.symCipherName;
00160   return NS_OK;
00161 }
00162 
00163 NS_IMETHODIMP nsCipherInfo::GetAuthAlgorithmName(nsACString &aAuthAlgorithmName)
00164 {
00165   if (!mHaveInfo)
00166     return NS_ERROR_NOT_AVAILABLE;
00167 
00168   aAuthAlgorithmName = mInfo.authAlgorithmName;
00169   return NS_OK;
00170 }
00171 
00172 NS_IMETHODIMP nsCipherInfo::GetKeaTypeName(nsACString &aKeaTypeName)
00173 {
00174   if (!mHaveInfo)
00175     return NS_ERROR_NOT_AVAILABLE;
00176 
00177   aKeaTypeName = mInfo.keaTypeName;
00178   return NS_OK;
00179 }
00180 
00181 NS_IMETHODIMP nsCipherInfo::GetMacAlgorithmName(nsACString &aMacAlgorithmName)
00182 {
00183   if (!mHaveInfo)
00184     return NS_ERROR_NOT_AVAILABLE;
00185 
00186   aMacAlgorithmName = mInfo.macAlgorithmName;
00187   return NS_OK;
00188 }
00189 
00190 NS_IMETHODIMP nsCipherInfo::GetEffectiveKeyBits(PRInt32 *aEffectiveKeyBits)
00191 {
00192   NS_ENSURE_ARG_POINTER(aEffectiveKeyBits);
00193 
00194   if (!mHaveInfo)
00195     return NS_ERROR_NOT_AVAILABLE;
00196 
00197   *aEffectiveKeyBits = mInfo.effectiveKeyBits;
00198   return NS_OK;
00199 }