| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h" | 5 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 std::string file_data; | 53 std::string file_data; |
| 54 if (!base::ReadFileToString(file_path, &file_data)) { | 54 if (!base::ReadFileToString(file_path, &file_data)) { |
| 55 std::cerr << "ERROR: ReadFileToString " << file_path.value() << ": " | 55 std::cerr << "ERROR: ReadFileToString " << file_path.value() << ": " |
| 56 << strerror(errno) << "\n"; | 56 << strerror(errno) << "\n"; |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 ExtractCertificatesFromData(file_data, file_path, certs); | 59 ExtractCertificatesFromData(file_data, file_path, certs); |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ReadChainFromFile(const base::FilePath& file_path, | 63 bool ReadChainFromFile(const base::FilePath& file_path, |
| 64 CertInput* target, | 64 CertInput* target, |
| 65 std::vector<CertInput>* intermediates) { | 65 std::vector<CertInput>* intermediates) { |
| 66 std::vector<CertInput> tmp_certs; | 66 std::vector<CertInput> tmp_certs; |
| 67 if (!ReadCertificatesFromFile(file_path, &tmp_certs)) | 67 if (!ReadCertificatesFromFile(file_path, &tmp_certs)) |
| 68 return; | 68 return false; |
| 69 |
| 70 if (tmp_certs.empty()) |
| 71 return true; |
| 69 | 72 |
| 70 *target = tmp_certs.front(); | 73 *target = tmp_certs.front(); |
| 71 | 74 |
| 72 intermediates->insert(intermediates->end(), ++tmp_certs.begin(), | 75 intermediates->insert(intermediates->end(), ++tmp_certs.begin(), |
| 73 tmp_certs.end()); | 76 tmp_certs.end()); |
| 77 return true; |
| 74 } | 78 } |
| 75 | 79 |
| 76 bool WriteToFile(const base::FilePath& file_path, const std::string& data) { | 80 bool WriteToFile(const base::FilePath& file_path, const std::string& data) { |
| 77 if (base::WriteFile(file_path, data.data(), data.size()) < 0) { | 81 if (base::WriteFile(file_path, data.data(), data.size()) < 0) { |
| 78 std::cerr << "ERROR: WriteFile " << file_path.value() << ": " | 82 std::cerr << "ERROR: WriteFile " << file_path.value() << ": " |
| 79 << strerror(errno) << "\n"; | 83 << strerror(errno) << "\n"; |
| 80 return false; | 84 return false; |
| 81 } | 85 } |
| 82 return true; | 86 return true; |
| 83 } | 87 } |
| 84 | 88 |
| 85 void PrintCertError(const std::string& error, const CertInput& cert) { | 89 void PrintCertError(const std::string& error, const CertInput& cert) { |
| 86 std::cerr << error << " " << cert.source_file_path.value(); | 90 std::cerr << error << " " << cert.source_file_path.value(); |
| 87 if (!cert.source_details.empty()) | 91 if (!cert.source_details.empty()) |
| 88 std::cerr << " (" << cert.source_details << ")"; | 92 std::cerr << " (" << cert.source_details << ")"; |
| 89 std::cerr << "\n"; | 93 std::cerr << "\n"; |
| 90 } | 94 } |
| OLD | NEW |