Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: net/base/x509_util_ios.cc

Issue 10928107: Support x509 certificate on iOS. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added unittests and fixed compilation issues. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/x509_util_ios.h"
6
7 #include <cert.h>
8 #include <nss.h>
9 #include <prtypes.h>
10
11 #include "base/mac/scoped_cftyperef.h"
12 #include "crypto/nss_util.h"
13 #include "net/base/x509_certificate.h"
14
15 using base::mac::ScopedCFTypeRef;
16
17 namespace net {
18
19 namespace x509_util {
20
21 namespace {
22
23 // Creates an NSS certificate handle from |data|, which is |length| bytes in
24 // size.
25 CERTCertificate* CreateNSSCertHandleFromBytes(const char* data,
26 int length) {
27 if (length < 0)
28 return NULL;
29
30 crypto::EnsureNSSInit();
31
32 if (!NSS_IsInitialized())
33 return NULL;
34
35 SECItem der_cert;
36 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data));
37 der_cert.len = length;
38 der_cert.type = siDERCertBuffer;
39
40 // Parse into a certificate structure.
41 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL,
42 PR_FALSE, PR_TRUE);
43 }
44
45 } // namespace
46
47 CERTCertificate* CreateNSSCertHandleFromOSHandle(
48 SecCertificateRef cert_handle) {
49 ScopedCFTypeRef<CFDataRef> cert_data(SecCertificateCopyData(cert_handle));
50 return CreateNSSCertHandleFromBytes(
51 reinterpret_cast<const char*>(CFDataGetBytePtr(cert_data)),
52 CFDataGetLength(cert_data));
53 }
54
55 SecCertificateRef CreateOSCertHandleFromNSSHandle(
56 CERTCertificate* nss_cert_handle) {
57 return X509Certificate::CreateOSCertHandleFromBytes(
58 reinterpret_cast<const char*>(nss_cert_handle->derCert.data),
59 nss_cert_handle->derCert.len);
60 }
61
62 NSSCertificate::NSSCertificate(SecCertificateRef cert_handle) {
63 nss_cert_handle_ = x509_util::CreateNSSCertHandleFromOSHandle(cert_handle);
64 }
65
66 NSSCertificate::~NSSCertificate() {
67 CERT_DestroyCertificate(nss_cert_handle_);
68 }
69
70 CERTCertificate* NSSCertificate::cert_handle() {
71 return nss_cert_handle_;
72 }
73
74 } // namespace x509_util
75
76 } // namespace net
77
OLDNEW
« no previous file with comments | « net/base/x509_util_ios.h ('k') | net/net.gyp » ('j') | net/net.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698