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

Unified Diff: net/cert/x509_certificate.cc

Issue 16946002: Resolve certificate references in ONC by PEM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed automation part. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« net/cert/x509_certificate.h ('K') | « net/cert/x509_certificate.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/x509_certificate.cc
diff --git a/net/cert/x509_certificate.cc b/net/cert/x509_certificate.cc
index 942078b5d5a390c492ce83a9a790a062bd7cc75a..63e7e5cbdb51e5e1b2dddacff5a04042fdf654f1 100644
--- a/net/cert/x509_certificate.cc
+++ b/net/cert/x509_certificate.cc
@@ -216,6 +216,33 @@ void SplitOnChar(const base::StringPiece& src,
}
}
+// Returns the PEM encoded data from an OSCertHandle. If the return value is
+// true, then the PEM encoded certificate is written to |pem_encoded|.
+bool GetPEMEncoded(X509Certificate::OSCertHandle cert_handle,
+ std::string* pem_encoded) {
+ std::string der_encoded;
+ if (!X509Certificate::GetDEREncoded(cert_handle, &der_encoded) ||
+ der_encoded.empty()) {
+ return false;
+ }
+ std::string b64_encoded;
+ if (!base::Base64Encode(der_encoded, &b64_encoded) || b64_encoded.empty())
+ return false;
+ *pem_encoded = "-----BEGIN CERTIFICATE-----\n";
+
+ // Divide the Base-64 encoded data into 64-character chunks, as per
+ // 4.3.2.4 of RFC 1421.
+ static const size_t kChunkSize = 64;
+ size_t chunks = (b64_encoded.size() + (kChunkSize - 1)) / kChunkSize;
+ for (size_t i = 0, chunk_offset = 0; i < chunks;
+ ++i, chunk_offset += kChunkSize) {
+ pem_encoded->append(b64_encoded, chunk_offset, kChunkSize);
+ pem_encoded->append("\n");
+ }
+ pem_encoded->append("-----END CERTIFICATE-----\n");
+ return true;
+}
+
} // namespace
bool X509Certificate::LessThan::operator()(X509Certificate* lhs,
@@ -654,39 +681,19 @@ bool X509Certificate::VerifyNameMatch(const std::string& hostname) const {
return VerifyHostname(hostname, subject_.common_name, dns_names, ip_addrs);
}
-// static
-bool X509Certificate::GetPEMEncoded(OSCertHandle cert_handle,
- std::string* pem_encoded) {
- std::string der_encoded;
- if (!GetDEREncoded(cert_handle, &der_encoded) || der_encoded.empty())
- return false;
- std::string b64_encoded;
- if (!base::Base64Encode(der_encoded, &b64_encoded) || b64_encoded.empty())
- return false;
- *pem_encoded = "-----BEGIN CERTIFICATE-----\n";
-
- // Divide the Base-64 encoded data into 64-character chunks, as per
- // 4.3.2.4 of RFC 1421.
- static const size_t kChunkSize = 64;
- size_t chunks = (b64_encoded.size() + (kChunkSize - 1)) / kChunkSize;
- for (size_t i = 0, chunk_offset = 0; i < chunks;
- ++i, chunk_offset += kChunkSize) {
- pem_encoded->append(b64_encoded, chunk_offset, kChunkSize);
- pem_encoded->append("\n");
- }
- pem_encoded->append("-----END CERTIFICATE-----\n");
- return true;
+bool X509Certificate::GetPEMEncoded(std::string* pem_encoded) const {
+ return net::GetPEMEncoded(os_cert_handle(), pem_encoded);
Mattias Nissler (ping if slow) 2013/06/14 12:56:44 net qualifier not needed?
pneubeck (no reviews) 2013/06/21 12:53:56 Otherwise, GCC doesn't resolve to the function in
}
bool X509Certificate::GetPEMEncodedChain(
std::vector<std::string>* pem_encoded) const {
std::vector<std::string> encoded_chain;
std::string pem_data;
- if (!GetPEMEncoded(os_cert_handle(), &pem_data))
+ if (!GetPEMEncoded(&pem_data))
return false;
encoded_chain.push_back(pem_data);
for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) {
- if (!GetPEMEncoded(intermediate_ca_certs_[i], &pem_data))
+ if (!net::GetPEMEncoded(intermediate_ca_certs_[i], &pem_data))
Mattias Nissler (ping if slow) 2013/06/14 12:56:44 no need for the net qualifier?
pneubeck (no reviews) 2013/06/21 12:53:56 ditto.
return false;
encoded_chain.push_back(pem_data);
}
« net/cert/x509_certificate.h ('K') | « net/cert/x509_certificate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698