1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_NET_X509_CERTIFICATE_MODEL_H_
6 #define CHROME_COMMON_NET_X509_CERTIFICATE_MODEL_H_
8 #include "net/cert/cert_type.h"
9 #include "net/cert/x509_certificate.h"
11 // This namespace defines a set of functions to be used in UI-related bits of
12 // X509 certificates. It decouples the UI from the underlying crypto library
13 // (currently NSS or OpenSSL - in development).
14 // This is currently only used by linux, as mac / windows use their own native
15 // certificate viewers and crypto libraries.
16 namespace x509_certificate_model {
18 std::string GetCertNameOrNickname(
19 net::X509Certificate::OSCertHandle cert_handle);
21 std::string GetNickname(net::X509Certificate::OSCertHandle cert_handle);
23 std::string GetTokenName(net::X509Certificate::OSCertHandle cert_handle);
25 std::string GetVersion(net::X509Certificate::OSCertHandle cert_handle);
27 net::CertType GetType(net::X509Certificate::OSCertHandle cert_handle);
29 std::string GetEmailAddress(net::X509Certificate::OSCertHandle cert_handle);
32 net::X509Certificate::OSCertHandle cert_handle,
33 std::vector<std::string>* usages);
35 std::string GetKeyUsageString(net::X509Certificate::OSCertHandle cert_handle);
37 std::string GetSerialNumberHexified(
38 net::X509Certificate::OSCertHandle cert_handle,
39 const std::string& alternative_text);
41 std::string GetIssuerCommonName(
42 net::X509Certificate::OSCertHandle cert_handle,
43 const std::string& alternative_text);
45 std::string GetIssuerOrgName(
46 net::X509Certificate::OSCertHandle cert_handle,
47 const std::string& alternative_text);
49 std::string GetIssuerOrgUnitName(
50 net::X509Certificate::OSCertHandle cert_handle,
51 const std::string& alternative_text);
53 std::string GetSubjectOrgName(
54 net::X509Certificate::OSCertHandle cert_handle,
55 const std::string& alternative_text);
57 std::string GetSubjectOrgUnitName(
58 net::X509Certificate::OSCertHandle cert_handle,
59 const std::string& alternative_text);
61 std::string GetSubjectCommonName(
62 net::X509Certificate::OSCertHandle cert_handle,
63 const std::string& alternative_text);
65 bool GetTimes(net::X509Certificate::OSCertHandle cert_handle,
66 base::Time* issued, base::Time* expires);
68 std::string GetTitle(net::X509Certificate::OSCertHandle cert_handle);
69 std::string GetIssuerName(net::X509Certificate::OSCertHandle cert_handle);
70 std::string GetSubjectName(net::X509Certificate::OSCertHandle cert_handle);
72 void GetEmailAddresses(net::X509Certificate::OSCertHandle cert_handle,
73 std::vector<std::string>* email_addresses);
75 void GetNicknameStringsFromCertList(const net::CertificateList& certs,
76 const std::string& cert_expired,
77 const std::string& cert_not_yet_valid,
78 std::vector<std::string>* nick_names);
85 typedef std::vector<Extension> Extensions;
88 const std::string& critical_label,
89 const std::string& non_critical_label,
90 net::X509Certificate::OSCertHandle cert_handle,
91 Extensions* extensions);
93 // Hash a certificate using the given algorithm, return the result as a
94 // colon-seperated hex string.
95 std::string HashCertSHA256(net::X509Certificate::OSCertHandle cert_handle);
96 std::string HashCertSHA1(net::X509Certificate::OSCertHandle cert_handle);
98 // For host values, if they contain IDN Punycode-encoded A-labels, this will
99 // return a string suitable for display that contains both the original and the
100 // decoded U-label form. Otherwise, the string will be returned as is.
101 std::string ProcessIDN(const std::string& input);
103 void GetCertChainFromCert(net::X509Certificate::OSCertHandle cert_handle,
104 net::X509Certificate::OSCertHandles* cert_handles);
105 void DestroyCertChain(net::X509Certificate::OSCertHandles* cert_handles);
107 std::string GetDerString(net::X509Certificate::OSCertHandle cert_handle);
108 std::string GetCMSString(const net::X509Certificate::OSCertHandles& cert_chain,
109 size_t start, size_t end);
111 std::string ProcessSecAlgorithmSignature(
112 net::X509Certificate::OSCertHandle cert_handle);
113 std::string ProcessSecAlgorithmSubjectPublicKey(
114 net::X509Certificate::OSCertHandle cert_handle);
115 std::string ProcessSecAlgorithmSignatureWrap(
116 net::X509Certificate::OSCertHandle cert_handle);
118 std::string ProcessSubjectPublicKeyInfo(
119 net::X509Certificate::OSCertHandle cert_handle);
121 std::string ProcessRawBitsSignatureWrap(
122 net::X509Certificate::OSCertHandle cert_handle);
124 void RegisterDynamicOids();
126 // Format a buffer as |hex_separator| separated string, with 16 bytes on each
127 // line separated using |line_separator|.
128 std::string ProcessRawBytesWithSeparators(const unsigned char* data,
131 char line_separator);
133 // Format a buffer as a space separated string, with 16 bytes on each line.
134 std::string ProcessRawBytes(const unsigned char* data,
138 // Format a buffer as a space separated string, with 16 bytes on each line.
139 // |data_length| is the length in bits.
140 std::string ProcessRawBits(const unsigned char* data,
144 } // namespace x509_certificate_model
146 #endif // CHROME_COMMON_NET_X509_CERTIFICATE_MODEL_H_