1 // Copyright (c) 2010 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/cert_test_util.h" 6 7 #include "base/file_path.h" 8 #include "base/file_util.h" 9 #include "base/path_service.h" 10 #include "net/base/x509_certificate.h" 11 12 namespace net { 13 GetTestCertsDirectory()14FilePath GetTestCertsDirectory() { 15 FilePath certs_dir; 16 PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir); 17 certs_dir = certs_dir.AppendASCII("net"); 18 certs_dir = certs_dir.AppendASCII("data"); 19 certs_dir = certs_dir.AppendASCII("ssl"); 20 certs_dir = certs_dir.AppendASCII("certificates"); 21 return certs_dir; 22 } 23 ImportCertFromFile(const FilePath & certs_dir,const std::string & cert_file)24scoped_refptr<X509Certificate> ImportCertFromFile( 25 const FilePath& certs_dir, 26 const std::string& cert_file) { 27 FilePath cert_path = certs_dir.AppendASCII(cert_file); 28 std::string cert_data; 29 if (!file_util::ReadFileToString(cert_path, &cert_data)) 30 return NULL; 31 32 CertificateList certs_in_file = 33 X509Certificate::CreateCertificateListFromBytes( 34 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO); 35 if (certs_in_file.empty()) 36 return NULL; 37 return certs_in_file[0]; 38 } 39 40 } // namespace net 41