• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/cert/cert_status_flags.h"
6 
7 #include "base/check_op.h"
8 #include "base/notreached.h"
9 #include "net/base/net_errors.h"
10 
11 namespace net {
12 
MapCertStatusToNetError(CertStatus cert_status)13 int MapCertStatusToNetError(CertStatus cert_status) {
14   // A certificate may have multiple errors.  We report the most
15   // serious error.
16 
17   // Unrecoverable errors
18   if (cert_status & CERT_STATUS_INVALID)
19     return ERR_CERT_INVALID;
20   if (cert_status & CERT_STATUS_PINNED_KEY_MISSING)
21     return ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN;
22 
23   // Potentially recoverable errors
24   if (cert_status & CERT_STATUS_KNOWN_INTERCEPTION_BLOCKED)
25     return ERR_CERT_KNOWN_INTERCEPTION_BLOCKED;
26   if (cert_status & CERT_STATUS_REVOKED)
27     return ERR_CERT_REVOKED;
28   if (cert_status & CERT_STATUS_AUTHORITY_INVALID)
29     return ERR_CERT_AUTHORITY_INVALID;
30   if (cert_status & CERT_STATUS_COMMON_NAME_INVALID)
31     return ERR_CERT_COMMON_NAME_INVALID;
32   if (cert_status & CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED)
33     return ERR_CERTIFICATE_TRANSPARENCY_REQUIRED;
34   if (cert_status & CERT_STATUS_SYMANTEC_LEGACY)
35     return ERR_CERT_SYMANTEC_LEGACY;
36   if (cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION)
37     return ERR_CERT_NAME_CONSTRAINT_VIOLATION;
38   if (cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM)
39     return ERR_CERT_WEAK_SIGNATURE_ALGORITHM;
40   if (cert_status & CERT_STATUS_WEAK_KEY)
41     return ERR_CERT_WEAK_KEY;
42   if (cert_status & CERT_STATUS_DATE_INVALID)
43     return ERR_CERT_DATE_INVALID;
44   if (cert_status & CERT_STATUS_VALIDITY_TOO_LONG)
45     return ERR_CERT_VALIDITY_TOO_LONG;
46   if (cert_status & CERT_STATUS_NON_UNIQUE_NAME) {
47     return ERR_CERT_NON_UNIQUE_NAME;
48   }
49   if (cert_status & CERT_STATUS_UNABLE_TO_CHECK_REVOCATION)
50     return ERR_CERT_UNABLE_TO_CHECK_REVOCATION;
51   if (cert_status & CERT_STATUS_NO_REVOCATION_MECHANISM)
52     return ERR_CERT_NO_REVOCATION_MECHANISM;
53 
54   // Unknown status. The assumption is 0 (an OK status) won't be used here.
55   NOTREACHED();
56 }
57 
58 }  // namespace net
59