Commit 9de8bf6f authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Don't use net::HashValue in parse_ocsp.h.

This avoids a blocker on removing HASH_VALUE_SHA1 and was unnecessary.
The |key_hash| field can just as easily be a der::Input and BoringSSL
already has abstractions for computing a digest. It also allows us to
fill in missing hash functions.

Bug: 564281
Change-Id: Ib044df61bb7bdfc4c5b021861c8f0561635dc6a8
Reviewed-on: https://chromium-review.googlesource.com/545017Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481929}
parent 5d42403d
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include <algorithm> #include <algorithm>
#include "base/sha1.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "crypto/sha2.h"
#include "net/cert/internal/cert_errors.h" #include "net/cert/internal/cert_errors.h"
#include "net/cert/internal/parse_ocsp.h" #include "net/cert/internal/parse_ocsp.h"
#include "net/der/encode_values.h" #include "net/der/encode_values.h"
#include "third_party/boringssl/src/include/openssl/digest.h"
#include "third_party/boringssl/src/include/openssl/sha.h"
namespace net { namespace net {
...@@ -215,18 +215,16 @@ bool ParseResponderID(const der::Input& raw_tlv, ...@@ -215,18 +215,16 @@ bool ParseResponderID(const der::Input& raw_tlv,
out->name = id_input; out->name = id_input;
} else if (id_tag == der::ContextSpecificConstructed(2)) { } else if (id_tag == der::ContextSpecificConstructed(2)) {
der::Parser key_parser(id_input); der::Parser key_parser(id_input);
der::Input responder_key; der::Input key_hash;
if (!key_parser.ReadTag(der::kOctetString, &responder_key)) if (!key_parser.ReadTag(der::kOctetString, &key_hash))
return false; return false;
if (key_parser.HasMore()) if (key_parser.HasMore())
return false; return false;
if (key_hash.Length() != SHA_DIGEST_LENGTH)
SHA1HashValue key_hash;
if (responder_key.Length() != sizeof(key_hash.data))
return false; return false;
memcpy(key_hash.data, responder_key.UnsafeData(), sizeof(key_hash.data));
out->type = OCSPResponseData::ResponderType::KEY_HASH; out->type = OCSPResponseData::ResponderType::KEY_HASH;
out->key_hash = HashValue(key_hash); out->key_hash = key_hash;
} else { } else {
return false; return false;
} }
...@@ -425,25 +423,17 @@ bool ParseOCSPResponse(const der::Input& raw_tlv, OCSPResponse* out) { ...@@ -425,25 +423,17 @@ bool ParseOCSPResponse(const der::Input& raw_tlv, OCSPResponse* out) {
namespace { namespace {
// Checks that the |type| hash of |value| is equal to |hash| // Checks that the |type| hash of |value| is equal to |hash|
bool VerifyHash(HashValueTag type, bool VerifyHash(const EVP_MD* type,
const der::Input& hash, const der::Input& hash,
const der::Input& value) { const der::Input& value) {
HashValue target(type); unsigned value_hash_len;
if (target.size() != hash.Length()) uint8_t value_hash[EVP_MAX_MD_SIZE];
return false; if (!EVP_Digest(value.UnsafeData(), value.Length(), value_hash,
memcpy(target.data(), hash.UnsafeData(), target.size()); &value_hash_len, type, nullptr)) {
HashValue value_hash(type);
if (type == HASH_VALUE_SHA1) {
base::SHA1HashBytes(value.UnsafeData(), value.Length(), value_hash.data());
} else if (type == HASH_VALUE_SHA256) {
std::string hash_string = crypto::SHA256HashString(value.AsString());
memcpy(value_hash.data(), hash_string.data(), value_hash.size());
} else {
return false; return false;
} }
return target == value_hash; return hash == der::Input(value_hash, value_hash_len);
} }
// Checks that the input |id_tlv| parses to a valid CertID and matches the // Checks that the input |id_tlv| parses to a valid CertID and matches the
...@@ -456,7 +446,7 @@ bool CheckCertID(const der::Input& id_tlv, ...@@ -456,7 +446,7 @@ bool CheckCertID(const der::Input& id_tlv,
if (!ParseOCSPCertID(id_tlv, &id)) if (!ParseOCSPCertID(id_tlv, &id))
return false; return false;
HashValueTag type = HASH_VALUE_SHA1; const EVP_MD* type = nullptr;
switch (id.hash_algorithm) { switch (id.hash_algorithm) {
case DigestAlgorithm::Md2: case DigestAlgorithm::Md2:
case DigestAlgorithm::Md4: case DigestAlgorithm::Md4:
...@@ -464,15 +454,17 @@ bool CheckCertID(const der::Input& id_tlv, ...@@ -464,15 +454,17 @@ bool CheckCertID(const der::Input& id_tlv,
// Unsupported. // Unsupported.
return false; return false;
case DigestAlgorithm::Sha1: case DigestAlgorithm::Sha1:
type = HASH_VALUE_SHA1; type = EVP_sha1();
break; break;
case DigestAlgorithm::Sha256: case DigestAlgorithm::Sha256:
type = HASH_VALUE_SHA256; type = EVP_sha256();
break; break;
case DigestAlgorithm::Sha384: case DigestAlgorithm::Sha384:
type = EVP_sha384();
break;
case DigestAlgorithm::Sha512: case DigestAlgorithm::Sha512:
NOTIMPLEMENTED(); type = EVP_sha512();
return false; break;
} }
if (!VerifyHash(type, id.issuer_name_hash, certificate.issuer_tlv)) if (!VerifyHash(type, id.issuer_name_hash, certificate.issuer_tlv))
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "net/base/hash_value.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/cert/internal/parse_certificate.h" #include "net/cert/internal/parse_certificate.h"
#include "net/cert/internal/signature_algorithm.h" #include "net/cert/internal/signature_algorithm.h"
...@@ -147,7 +146,7 @@ struct NET_EXPORT OCSPResponseData { ...@@ -147,7 +146,7 @@ struct NET_EXPORT OCSPResponseData {
struct ResponderID { struct ResponderID {
ResponderType type; ResponderType type;
der::Input name; der::Input name;
HashValue key_hash; der::Input key_hash;
}; };
OCSPResponseData(); OCSPResponseData();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment