x509_certificate_model.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 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. 4 5#ifndef NET_BASE_X509_CERTIFICATE_MODEL_H_ 6#define NET_BASE_X509_CERTIFICATE_MODEL_H_ 7#pragma once 8 9#include "net/base/cert_database.h" 10#include "net/base/cert_type.h" 11#include "net/base/x509_certificate.h" 12 13// This namespace defines a set of functions to be used in UI-related bits of 14// X509 certificates. It decouples the UI from the underlying crypto library 15// (currently NSS or OpenSSL - in development). 16// This is currently only used by linux, as mac / windows use their own native 17// certificate viewers and crypto libraries. 18namespace x509_certificate_model { 19 20std::string GetCertNameOrNickname( 21 net::X509Certificate::OSCertHandle cert_handle); 22 23std::string GetTokenName(net::X509Certificate::OSCertHandle cert_handle); 24 25std::string GetVersion(net::X509Certificate::OSCertHandle cert_handle); 26 27net::CertType GetType(net::X509Certificate::OSCertHandle cert_handle); 28 29std::string GetEmailAddress(net::X509Certificate::OSCertHandle cert_handle); 30 31void GetUsageStrings( 32 net::X509Certificate::OSCertHandle cert_handle, 33 std::vector<std::string>* usages); 34 35std::string GetKeyUsageString(net::X509Certificate::OSCertHandle cert_handle); 36 37std::string GetSerialNumberHexified( 38 net::X509Certificate::OSCertHandle cert_handle, 39 const std::string& alternative_text); 40 41std::string GetIssuerCommonName( 42 net::X509Certificate::OSCertHandle cert_handle, 43 const std::string& alternative_text); 44 45std::string GetIssuerOrgName( 46 net::X509Certificate::OSCertHandle cert_handle, 47 const std::string& alternative_text); 48 49std::string GetIssuerOrgUnitName( 50 net::X509Certificate::OSCertHandle cert_handle, 51 const std::string& alternative_text); 52 53std::string GetSubjectOrgName( 54 net::X509Certificate::OSCertHandle cert_handle, 55 const std::string& alternative_text); 56 57std::string GetSubjectOrgUnitName( 58 net::X509Certificate::OSCertHandle cert_handle, 59 const std::string& alternative_text); 60 61std::string GetSubjectCommonName( 62 net::X509Certificate::OSCertHandle cert_handle, 63 const std::string& alternative_text); 64 65bool GetTimes(net::X509Certificate::OSCertHandle cert_handle, 66 base::Time* issued, base::Time* expires); 67 68std::string GetTitle(net::X509Certificate::OSCertHandle cert_handle); 69std::string GetIssuerName(net::X509Certificate::OSCertHandle cert_handle); 70std::string GetSubjectName(net::X509Certificate::OSCertHandle cert_handle); 71 72void GetEmailAddresses(net::X509Certificate::OSCertHandle cert_handle, 73 std::vector<std::string>* email_addresses); 74 75void 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); 79 80struct Extension { 81 std::string name; 82 std::string value; 83}; 84 85typedef std::vector<Extension> Extensions; 86 87void GetExtensions( 88 const std::string& critical_label, 89 const std::string& non_critical_label, 90 net::X509Certificate::OSCertHandle cert_handle, 91 Extensions* extensions); 92 93// Hash a certificate using the given algorithm, return the result as a 94// colon-seperated hex string. 95std::string HashCertSHA256(net::X509Certificate::OSCertHandle cert_handle); 96std::string HashCertSHA1(net::X509Certificate::OSCertHandle cert_handle); 97 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. 101std::string ProcessIDN(const std::string& input); 102 103void GetCertChainFromCert(net::X509Certificate::OSCertHandle cert_handle, 104 net::X509Certificate::OSCertHandles* cert_handles); 105void DestroyCertChain(net::X509Certificate::OSCertHandles* cert_handles); 106 107std::string GetDerString(net::X509Certificate::OSCertHandle cert_handle); 108std::string GetCMSString(const net::X509Certificate::OSCertHandles& cert_chain, 109 size_t start, size_t end); 110 111std::string ProcessSecAlgorithmSignature( 112 net::X509Certificate::OSCertHandle cert_handle); 113std::string ProcessSecAlgorithmSubjectPublicKey( 114 net::X509Certificate::OSCertHandle cert_handle); 115std::string ProcessSecAlgorithmSignatureWrap( 116 net::X509Certificate::OSCertHandle cert_handle); 117 118std::string ProcessSubjectPublicKeyInfo( 119 net::X509Certificate::OSCertHandle cert_handle); 120 121std::string ProcessRawBitsSignatureWrap( 122 net::X509Certificate::OSCertHandle cert_handle); 123 124void RegisterDynamicOids(); 125 126} // namespace x509_certificate_model 127 128#endif // NET_BASE_X509_CERTIFICATE_MODEL_H_ 129