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

Side by Side Diff: net/base/x509_certificate_openssl.cc

Issue 11458012: SSLCertRequestInfo: Add |valid_cas| and |valid_key_types| (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/x509_certificate.h" 5 #include "net/base/x509_certificate.h"
6 6
7 #include <openssl/asn1.h> 7 #include <openssl/asn1.h>
8 #include <openssl/crypto.h> 8 #include <openssl/crypto.h>
9 #include <openssl/obj_mac.h> 9 #include <openssl/obj_mac.h>
10 #include <openssl/pem.h> 10 #include <openssl/pem.h>
11 #include <openssl/pkcs7.h> 11 #include <openssl/pkcs7.h>
12 #include <openssl/sha.h> 12 #include <openssl/sha.h>
13 #include <openssl/ssl.h> 13 #include <openssl/ssl.h>
14 #include <openssl/x509v3.h> 14 #include <openssl/x509v3.h>
15 15
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/pickle.h" 17 #include "base/pickle.h"
18 #include "base/sha1.h" 18 #include "base/sha1.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "crypto/openssl_util.h" 21 #include "crypto/openssl_util.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
24 #include "net/base/ssl_cert_request_info.h"
25 #include "net/base/x509_cert_types.h"
24 #include "net/base/x509_util_openssl.h" 26 #include "net/base/x509_util_openssl.h"
25 27
26 #if defined(OS_ANDROID) 28 #if defined(OS_ANDROID)
27 #include "base/logging.h" 29 #include "base/logging.h"
28 #include "net/android/network_library.h" 30 #include "net/android/network_library.h"
29 #endif 31 #endif
30 32
31 namespace net { 33 namespace net {
32 34
33 namespace { 35 namespace {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 *type = kPublicKeyTypeECDSA; 466 *type = kPublicKeyTypeECDSA;
465 *size_bits = EVP_PKEY_size(key); 467 *size_bits = EVP_PKEY_size(key);
466 break; 468 break;
467 case EVP_PKEY_DH: 469 case EVP_PKEY_DH:
468 *type = kPublicKeyTypeDH; 470 *type = kPublicKeyTypeDH;
469 *size_bits = EVP_PKEY_size(key) * 8; 471 *size_bits = EVP_PKEY_size(key) * 8;
470 break; 472 break;
471 } 473 }
472 } 474 }
473 475
476 bool X509Certificate::IsValidClientCertificate(
477 const SSLCertRequestInfo& cert_info) {
478
479 bool cert_still_valid = true;
480 DCHECK(cert_info.no_client_certs == true);
481
482 // TODO(digit): Check certificate authorities.
483 // It's unclear what the best way to do this is, i.e. the specication
484 // states that about the "certificate_authorities" field of a
485 // CertificateRequest message:
486 //
487 // A list of the distinguished names of acceptable certificate
488 // authorities. These distinguished names may specify a desired
489 // distinguished name for a root CA or for a subordinate CA;
490 // thus, this message can be used both to describe known roots
491 // and a desired authorization space.
492 //
493 // The "authorization space" seems to indicate that each listed
494 // distinguished name may only include a small set of strings that
495 // need to be matched against those in the certificate chain.
496 //
497 // For now, ignore this step, and assume that the server will
498 // perform the verification itself.
499 //
500
501 // Check the key type
502 crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> scoped_key(
503 X509_get_pubkey(cert_handle_));
504 if (!scoped_key.get())
505 return false;
506
507 SSLClientCertType key_type;
508 switch (scoped_key.get()->type) {
509 case EVP_PKEY_RSA:
510 key_type = CLIENT_CERT_RSA_SIGN;
511 break;
512 #if 0
513 // TODO(digit): Add CLIENT_CERT_DSA_SIGN to SSLClientCertType.
514 case EVP_PKEY_DSA:
515 key_type = CLIENT_CERT_DSA_SIGN;
516 break;
517 #endif
Ryan Sleevi 2012/12/11 21:30:24 While NACKed, I don't think we should add unreacha
digit1 2012/12/11 23:05:31 Thanks, I'll remove the #if .. #endif block. A bug
518 case EVP_PKEY_EC:
519 key_type = CLIENT_CERT_ECDSA_SIGN;
520 break;
521 default:
522 // Unknown key type
523 return false;
524 }
525
526 cert_still_valid = false;
527 for (size_t n = 0; n < cert_info.valid_key_types.size(); ++n) {
528 if (cert_info.valid_key_types[n] == key_type) {
529 cert_still_valid = true;
530 break;
531 }
532 }
533
534 return cert_still_valid;
535 }
536
474 } // namespace net 537 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698