1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Personal Security Manager Module
16 : *
17 : * The Initial Developer of the Original Code is
18 : * the Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2010
20 : * the Initial Developer. All Rights Reserved.
21 : * Contributor(s):
22 : * Honza Bambas <honzab@firemni.cz>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsNSSCertificateFakeTransport.h"
39 : #include "nsCOMPtr.h"
40 : #include "nsNSSCertificate.h"
41 : #include "nsIX509Cert.h"
42 : #include "nsString.h"
43 : #include "nsXPIDLString.h"
44 : #include "nsISupportsPrimitives.h"
45 : #include "nsIProgrammingLanguage.h"
46 : #include "nsIObjectOutputStream.h"
47 : #include "nsIObjectInputStream.h"
48 :
49 : #ifdef PR_LOGGING
50 : extern PRLogModuleInfo* gPIPNSSLog;
51 : #endif
52 :
53 : /* nsNSSCertificateFakeTransport */
54 :
55 0 : NS_IMPL_THREADSAFE_ISUPPORTS3(nsNSSCertificateFakeTransport, nsIX509Cert,
56 : nsISerializable,
57 : nsIClassInfo)
58 :
59 0 : nsNSSCertificateFakeTransport::nsNSSCertificateFakeTransport() :
60 0 : mCertSerialization(nsnull)
61 : {
62 0 : }
63 :
64 0 : nsNSSCertificateFakeTransport::~nsNSSCertificateFakeTransport()
65 : {
66 0 : if (mCertSerialization)
67 0 : SECITEM_FreeItem(mCertSerialization, true);
68 0 : }
69 :
70 : /* readonly attribute string dbKey; */
71 : NS_IMETHODIMP
72 0 : nsNSSCertificateFakeTransport::GetDbKey(char * *aDbKey)
73 : {
74 0 : NS_NOTREACHED("Unimplemented on content process");
75 0 : return NS_ERROR_NOT_IMPLEMENTED;
76 : }
77 :
78 : /* readonly attribute string windowTitle; */
79 : NS_IMETHODIMP
80 0 : nsNSSCertificateFakeTransport::GetWindowTitle(char * *aWindowTitle)
81 : {
82 0 : NS_NOTREACHED("Unimplemented on content process");
83 0 : return NS_ERROR_NOT_IMPLEMENTED;
84 : }
85 :
86 : NS_IMETHODIMP
87 0 : nsNSSCertificateFakeTransport::GetNickname(nsAString &aNickname)
88 : {
89 0 : NS_NOTREACHED("Unimplemented on content process");
90 0 : return NS_ERROR_NOT_IMPLEMENTED;
91 : }
92 :
93 : NS_IMETHODIMP
94 0 : nsNSSCertificateFakeTransport::GetEmailAddress(nsAString &aEmailAddress)
95 : {
96 0 : NS_NOTREACHED("Unimplemented on content process");
97 0 : return NS_ERROR_NOT_IMPLEMENTED;
98 : }
99 :
100 : NS_IMETHODIMP
101 0 : nsNSSCertificateFakeTransport::GetEmailAddresses(PRUint32 *aLength, PRUnichar*** aAddresses)
102 : {
103 0 : NS_NOTREACHED("Unimplemented on content process");
104 0 : return NS_ERROR_NOT_IMPLEMENTED;
105 : }
106 :
107 : NS_IMETHODIMP
108 0 : nsNSSCertificateFakeTransport::ContainsEmailAddress(const nsAString &aEmailAddress, bool *result)
109 : {
110 0 : NS_NOTREACHED("Unimplemented on content process");
111 0 : return NS_ERROR_NOT_IMPLEMENTED;
112 : }
113 :
114 : NS_IMETHODIMP
115 0 : nsNSSCertificateFakeTransport::GetCommonName(nsAString &aCommonName)
116 : {
117 0 : NS_NOTREACHED("Unimplemented on content process");
118 0 : return NS_ERROR_NOT_IMPLEMENTED;
119 : }
120 :
121 : NS_IMETHODIMP
122 0 : nsNSSCertificateFakeTransport::GetOrganization(nsAString &aOrganization)
123 : {
124 0 : NS_NOTREACHED("Unimplemented on content process");
125 0 : return NS_ERROR_NOT_IMPLEMENTED;
126 : }
127 :
128 : NS_IMETHODIMP
129 0 : nsNSSCertificateFakeTransport::GetIssuerCommonName(nsAString &aCommonName)
130 : {
131 0 : NS_NOTREACHED("Unimplemented on content process");
132 0 : return NS_ERROR_NOT_IMPLEMENTED;
133 : }
134 :
135 : NS_IMETHODIMP
136 0 : nsNSSCertificateFakeTransport::GetIssuerOrganization(nsAString &aOrganization)
137 : {
138 0 : NS_NOTREACHED("Unimplemented on content process");
139 0 : return NS_ERROR_NOT_IMPLEMENTED;
140 : }
141 :
142 : NS_IMETHODIMP
143 0 : nsNSSCertificateFakeTransport::GetIssuerOrganizationUnit(nsAString &aOrganizationUnit)
144 : {
145 0 : NS_NOTREACHED("Unimplemented on content process");
146 0 : return NS_ERROR_NOT_IMPLEMENTED;
147 : }
148 :
149 : /* readonly attribute nsIX509Cert issuer; */
150 : NS_IMETHODIMP
151 0 : nsNSSCertificateFakeTransport::GetIssuer(nsIX509Cert * *aIssuer)
152 : {
153 0 : NS_NOTREACHED("Unimplemented on content process");
154 0 : return NS_ERROR_NOT_IMPLEMENTED;
155 : }
156 :
157 : NS_IMETHODIMP
158 0 : nsNSSCertificateFakeTransport::GetOrganizationalUnit(nsAString &aOrganizationalUnit)
159 : {
160 0 : NS_NOTREACHED("Unimplemented on content process");
161 0 : return NS_ERROR_NOT_IMPLEMENTED;
162 : }
163 :
164 : /*
165 : * nsIEnumerator getChain();
166 : */
167 : NS_IMETHODIMP
168 0 : nsNSSCertificateFakeTransport::GetChain(nsIArray **_rvChain)
169 : {
170 0 : NS_NOTREACHED("Unimplemented on content process");
171 0 : return NS_ERROR_NOT_IMPLEMENTED;
172 : }
173 :
174 : NS_IMETHODIMP
175 0 : nsNSSCertificateFakeTransport::GetSubjectName(nsAString &_subjectName)
176 : {
177 0 : NS_NOTREACHED("Unimplemented on content process");
178 0 : return NS_ERROR_NOT_IMPLEMENTED;
179 : }
180 :
181 : NS_IMETHODIMP
182 0 : nsNSSCertificateFakeTransport::GetIssuerName(nsAString &_issuerName)
183 : {
184 0 : NS_NOTREACHED("Unimplemented on content process");
185 0 : return NS_ERROR_NOT_IMPLEMENTED;
186 : }
187 :
188 : NS_IMETHODIMP
189 0 : nsNSSCertificateFakeTransport::GetSerialNumber(nsAString &_serialNumber)
190 : {
191 0 : NS_NOTREACHED("Unimplemented on content process");
192 0 : return NS_ERROR_NOT_IMPLEMENTED;
193 : }
194 :
195 : NS_IMETHODIMP
196 0 : nsNSSCertificateFakeTransport::GetSha1Fingerprint(nsAString &_sha1Fingerprint)
197 : {
198 0 : NS_NOTREACHED("Unimplemented on content process");
199 0 : return NS_ERROR_NOT_IMPLEMENTED;
200 : }
201 :
202 : NS_IMETHODIMP
203 0 : nsNSSCertificateFakeTransport::GetMd5Fingerprint(nsAString &_md5Fingerprint)
204 : {
205 0 : NS_NOTREACHED("Unimplemented on content process");
206 0 : return NS_ERROR_NOT_IMPLEMENTED;
207 : }
208 :
209 : NS_IMETHODIMP
210 0 : nsNSSCertificateFakeTransport::GetTokenName(nsAString &aTokenName)
211 : {
212 0 : NS_NOTREACHED("Unimplemented on content process");
213 0 : return NS_ERROR_NOT_IMPLEMENTED;
214 : }
215 :
216 : NS_IMETHODIMP
217 0 : nsNSSCertificateFakeTransport::GetRawDER(PRUint32 *aLength, PRUint8 **aArray)
218 : {
219 0 : NS_NOTREACHED("Unimplemented on content process");
220 0 : return NS_ERROR_NOT_IMPLEMENTED;
221 : }
222 :
223 : NS_IMETHODIMP
224 0 : nsNSSCertificateFakeTransport::GetValidity(nsIX509CertValidity **aValidity)
225 : {
226 0 : NS_NOTREACHED("Unimplemented on content process");
227 0 : return NS_ERROR_NOT_IMPLEMENTED;
228 : }
229 :
230 : NS_IMETHODIMP
231 0 : nsNSSCertificateFakeTransport::VerifyForUsage(PRUint32 usage, PRUint32 *verificationResult)
232 : {
233 0 : NS_NOTREACHED("Unimplemented on content process");
234 0 : return NS_ERROR_NOT_IMPLEMENTED;
235 : }
236 :
237 : NS_IMETHODIMP
238 0 : nsNSSCertificateFakeTransport::GetUsagesArray(bool localOnly,
239 : PRUint32 *_verified,
240 : PRUint32 *_count,
241 : PRUnichar ***_usages)
242 : {
243 0 : NS_NOTREACHED("Unimplemented on content process");
244 0 : return NS_ERROR_NOT_IMPLEMENTED;
245 : }
246 :
247 : NS_IMETHODIMP
248 0 : nsNSSCertificateFakeTransport::GetUsagesString(bool localOnly,
249 : PRUint32 *_verified,
250 : nsAString &_usages)
251 : {
252 0 : NS_NOTREACHED("Unimplemented on content process");
253 0 : return NS_ERROR_NOT_IMPLEMENTED;
254 : }
255 :
256 : /* readonly attribute nsIASN1Object ASN1Structure; */
257 : NS_IMETHODIMP
258 0 : nsNSSCertificateFakeTransport::GetASN1Structure(nsIASN1Object * *aASN1Structure)
259 : {
260 0 : NS_NOTREACHED("Unimplemented on content process");
261 0 : return NS_ERROR_NOT_IMPLEMENTED;
262 : }
263 :
264 : NS_IMETHODIMP
265 0 : nsNSSCertificateFakeTransport::Equals(nsIX509Cert *other, bool *result)
266 : {
267 0 : NS_NOTREACHED("Unimplemented on content process");
268 0 : return NS_ERROR_NOT_IMPLEMENTED;
269 : }
270 :
271 : NS_IMETHODIMP
272 0 : nsNSSCertificateFakeTransport::Write(nsIObjectOutputStream* aStream)
273 : {
274 : // On a non-chrome process we don't have mCert because we lack
275 : // nsNSSComponent. nsNSSCertificateFakeTransport object is used only to carry the
276 : // certificate serialization.
277 :
278 0 : nsresult rv = aStream->Write32(mCertSerialization->len);
279 0 : if (NS_FAILED(rv)) {
280 0 : return rv;
281 : }
282 :
283 0 : return aStream->WriteByteArray(mCertSerialization->data, mCertSerialization->len);
284 : }
285 :
286 : NS_IMETHODIMP
287 0 : nsNSSCertificateFakeTransport::Read(nsIObjectInputStream* aStream)
288 : {
289 : PRUint32 len;
290 0 : nsresult rv = aStream->Read32(&len);
291 0 : if (NS_FAILED(rv)) {
292 0 : return rv;
293 : }
294 :
295 0 : nsXPIDLCString str;
296 0 : rv = aStream->ReadBytes(len, getter_Copies(str));
297 0 : if (NS_FAILED(rv)) {
298 0 : return rv;
299 : }
300 :
301 : // On a non-chrome process we cannot instatiate mCert because we lack
302 : // nsNSSComponent. nsNSSCertificateFakeTransport object is used only to carry the
303 : // certificate serialization.
304 :
305 0 : mCertSerialization = SECITEM_AllocItem(nsnull, nsnull, len);
306 0 : if (!mCertSerialization)
307 0 : return NS_ERROR_OUT_OF_MEMORY;
308 0 : PORT_Memcpy(mCertSerialization->data, str.Data(), len);
309 :
310 0 : return NS_OK;
311 : }
312 :
313 : NS_IMETHODIMP
314 0 : nsNSSCertificateFakeTransport::GetInterfaces(PRUint32 *count, nsIID * **array)
315 : {
316 0 : *count = 0;
317 0 : *array = nsnull;
318 0 : return NS_OK;
319 : }
320 :
321 : NS_IMETHODIMP
322 0 : nsNSSCertificateFakeTransport::GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
323 : {
324 0 : *_retval = nsnull;
325 0 : return NS_OK;
326 : }
327 :
328 : NS_IMETHODIMP
329 0 : nsNSSCertificateFakeTransport::GetContractID(char * *aContractID)
330 : {
331 0 : *aContractID = nsnull;
332 0 : return NS_OK;
333 : }
334 :
335 : NS_IMETHODIMP
336 0 : nsNSSCertificateFakeTransport::GetClassDescription(char * *aClassDescription)
337 : {
338 0 : *aClassDescription = nsnull;
339 0 : return NS_OK;
340 : }
341 :
342 : NS_IMETHODIMP
343 0 : nsNSSCertificateFakeTransport::GetClassID(nsCID * *aClassID)
344 : {
345 0 : *aClassID = (nsCID*) nsMemory::Alloc(sizeof(nsCID));
346 0 : if (!*aClassID)
347 0 : return NS_ERROR_OUT_OF_MEMORY;
348 0 : return GetClassIDNoAlloc(*aClassID);
349 : }
350 :
351 : NS_IMETHODIMP
352 0 : nsNSSCertificateFakeTransport::GetImplementationLanguage(PRUint32 *aImplementationLanguage)
353 : {
354 0 : *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
355 0 : return NS_OK;
356 : }
357 :
358 : NS_IMETHODIMP
359 0 : nsNSSCertificateFakeTransport::GetFlags(PRUint32 *aFlags)
360 : {
361 0 : *aFlags = nsIClassInfo::THREADSAFE;
362 0 : return NS_OK;
363 : }
364 :
365 : static NS_DEFINE_CID(kNSSCertificateCID, NS_X509CERT_CID);
366 :
367 : NS_IMETHODIMP
368 0 : nsNSSCertificateFakeTransport::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
369 : {
370 0 : *aClassIDNoAlloc = kNSSCertificateCID;
371 0 : return NS_OK;
372 : }
|