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

Unified Diff: net/base/x509_certificate_openssl.cc

Issue 8432026: Fix X509CertificateTest.SerialNumbers on OpenSSL builds after http://crrev.com/107956 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For real this time, fix compile Created 9 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/x509_certificate_openssl.cc
diff --git a/net/base/x509_certificate_openssl.cc b/net/base/x509_certificate_openssl.cc
index 58809112d63733dd61dbb99a941fd2b103030e2e..8583e4d0dccda38def3669309e0fea1c65669105 100644
--- a/net/base/x509_certificate_openssl.cc
+++ b/net/base/x509_certificate_openssl.cc
@@ -17,6 +17,7 @@
#include "base/pickle.h"
#include "base/sha1.h"
#include "base/string_number_conversions.h"
+#include "base/string_util.h"
#include "crypto/openssl_util.h"
#include "net/base/asn1_util.h"
#include "net/base/cert_status_flags.h"
@@ -327,11 +328,19 @@ void X509Certificate::Initialize() {
fingerprint_ = CalculateFingerprint(cert_handle_);
chain_fingerprint_ = CalculateChainFingerprint();
- ASN1_INTEGER* num = X509_get_serialNumber(cert_handle_);
- if (num) {
- serial_number_ = std::string(
- reinterpret_cast<char*>(num->data),
- num->length);
+ ASN1_INTEGER* serial_num = X509_get_serialNumber(cert_handle_);
+ if (serial_num) {
+ // ASN1_INTEGERS represent the decoded number, in a format internal to
+ // OpenSSL. Most notably, this may have leading zeroes stripped off for
+ // numbers whose first byte is >= 0x80. Thus, it is necessary to
+ // re-encoded the integer back into DER, which is what the interface
+ // of X509Certificate exposes, to ensure callers get the proper (DER)
+ // value.
joth 2011/11/01 09:16:33 I think the comment already answers this, but is t
+ int bytes_required = i2c_ASN1_INTEGER(serial_num, NULL);
+ unsigned char* buffer = reinterpret_cast<unsigned char*>(
+ WriteInto(&serial_number_, bytes_required + 1));
+ int bytes_written = i2c_ASN1_INTEGER(serial_num, &buffer);
+ DCHECK_EQ(static_cast<size_t>(bytes_written), serial_number_.size());
}
ParsePrincipal(cert_handle_, X509_get_subject_name(cert_handle_), &subject_);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698