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

Side by Side Diff: net/cert/x509_util_nss.h

Issue 2940763002: Move some functions from net/cert/x509_util_nss.cc into x509_certificate_nss.cc (Closed)
Patch Set: . Created 3 years, 6 months 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
« no previous file with comments | « net/cert/x509_certificate_nss.cc ('k') | net/cert/x509_util_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #ifndef NET_CERT_X509_UTIL_NSS_H_ 5 #ifndef NET_CERT_X509_UTIL_NSS_H_
6 #define NET_CERT_X509_UTIL_NSS_H_ 6 #define NET_CERT_X509_UTIL_NSS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/time/time.h"
14 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
15 #include "net/cert/x509_certificate.h"
16
17 namespace base {
18 class PickleIterator;
19 }
20 14
21 typedef struct CERTCertificateStr CERTCertificate; 15 typedef struct CERTCertificateStr CERTCertificate;
22 typedef struct CERTNameStr CERTName;
23 typedef struct PK11SlotInfoStr PK11SlotInfo; 16 typedef struct PK11SlotInfoStr PK11SlotInfo;
24 typedef struct PLArenaPool PLArenaPool;
25 typedef struct SECItemStr SECItem; 17 typedef struct SECItemStr SECItem;
26 18
27 namespace net { 19 namespace net {
28 20
29 namespace x509_util { 21 namespace x509_util {
30 22
31 // Parses the Principal attribute from |name| and outputs the result in
32 // |principal|. Returns true on success.
33 bool ParsePrincipal(CERTName* name, CertPrincipal* principal);
34
35 // Parses the date from |der_date| and outputs the result in |result|.
36 // Returns true on success.
37 bool ParseDate(const SECItem* der_date, base::Time* result);
38
39 // Parses the serial number from |certificate|.
40 std::string ParseSerialNumber(const CERTCertificate* certificate);
41
42 // Gets the dNSName and iPAddress name fields from the subjectAltName
43 // extension of |cert_handle|.
44 // If |dns_names| is non-null, each dNSName will be stored in |*dns_names|.
45 // If |ip_addrs| is non-null, each iPAddress will be stored in |*ip_addrs|.
46 // Returns true if any dNSName or iPAddress was present.
47 bool GetSubjectAltName(CERTCertificate* cert_handle,
48 std::vector<std::string>* dns_names,
49 std::vector<std::string>* ip_addrs);
50
51 // Stores the values of all rfc822Name subjectAltNames from |cert_handle| 23 // Stores the values of all rfc822Name subjectAltNames from |cert_handle|
52 // into |names|. If no names are present, clears |names|. 24 // into |names|. If no names are present, clears |names|.
53 // WARNING: This method does not validate that the rfc822Name is 25 // WARNING: This method does not validate that the rfc822Name is
54 // properly encoded; it MAY contain embedded NULs or other illegal 26 // properly encoded; it MAY contain embedded NULs or other illegal
55 // characters; care should be taken to validate the well-formedness 27 // characters; care should be taken to validate the well-formedness
56 // before using. 28 // before using.
57 NET_EXPORT void GetRFC822SubjectAltNames(CERTCertificate* cert_handle, 29 NET_EXPORT void GetRFC822SubjectAltNames(CERTCertificate* cert_handle,
58 std::vector<std::string>* names); 30 std::vector<std::string>* names);
59 31
60 // Stores the values of all Microsoft UPN subjectAltNames from |cert_handle| 32 // Stores the values of all Microsoft UPN subjectAltNames from |cert_handle|
61 // into |names|. If no names are present, clears |names|. 33 // into |names|. If no names are present, clears |names|.
62 // 34 //
63 // A "Microsoft UPN subjectAltName" is an OtherName value whose type-id 35 // A "Microsoft UPN subjectAltName" is an OtherName value whose type-id
64 // is equal to 1.3.6.1.4.1.311.20.2.3 (known as either id-ms-san-sc-logon-upn, 36 // is equal to 1.3.6.1.4.1.311.20.2.3 (known as either id-ms-san-sc-logon-upn,
65 // as described in RFC 4556, or as szOID_NT_PRINCIPAL_NAME, as 37 // as described in RFC 4556, or as szOID_NT_PRINCIPAL_NAME, as
66 // documented in Microsoft KB287547). 38 // documented in Microsoft KB287547).
67 // The value field is a UTF8String literal. 39 // The value field is a UTF8String literal.
68 // For more information: 40 // For more information:
69 // https://www.ietf.org/mail-archive/web/pkix/current/msg03145.html 41 // https://www.ietf.org/mail-archive/web/pkix/current/msg03145.html
70 // https://www.ietf.org/proceedings/65/slides/pkix-4/sld1.htm 42 // https://www.ietf.org/proceedings/65/slides/pkix-4/sld1.htm
71 // https://tools.ietf.org/html/rfc4556 43 // https://tools.ietf.org/html/rfc4556
72 // 44 //
73 // WARNING: This method does not validate that the name is 45 // WARNING: This method does not validate that the name is
74 // properly encoded; it MAY contain embedded NULs or other illegal 46 // properly encoded; it MAY contain embedded NULs or other illegal
75 // characters; care should be taken to validate the well-formedness 47 // characters; care should be taken to validate the well-formedness
76 // before using. 48 // before using.
77 NET_EXPORT void GetUPNSubjectAltNames(CERTCertificate* cert_handle, 49 NET_EXPORT void GetUPNSubjectAltNames(CERTCertificate* cert_handle,
78 std::vector<std::string>* names); 50 std::vector<std::string>* names);
79 51
80 // Creates all possible OS certificate handles from |data| encoded in a specific
81 // |format|. Returns an empty collection on failure.
82 X509Certificate::OSCertHandles CreateOSCertHandlesFromBytes(
83 const char* data,
84 size_t length,
85 X509Certificate::Format format);
86
87 // Reads a single certificate from |pickle_iter| and returns a platform-specific
88 // certificate handle. Returns an invalid handle, NULL, on failure.
89 X509Certificate::OSCertHandle ReadOSCertHandleFromPickle(
90 base::PickleIterator* pickle_iter);
91
92 // Sets |*size_bits| to be the length of the public key in bits, and sets
93 // |*type| to one of the |PublicKeyType| values. In case of
94 // |kPublicKeyTypeUnknown|, |*size_bits| will be set to 0.
95 void GetPublicKeyInfo(CERTCertificate* handle,
96 size_t* size_bits,
97 X509Certificate::PublicKeyType* type);
98
99 // Create a list of CERTName objects from a list of DER-encoded X.509
100 // DistinguishedName items. All objects are created in a given arena.
101 // |encoded_issuers| is the list of encoded DNs.
102 // |arena| is the arena used for all allocations.
103 // |out| will receive the result list on success.
104 // Return true on success. On failure, the caller must free the
105 // intermediate CERTName objects pushed to |out|.
106 bool GetIssuersFromEncodedList(
107 const std::vector<std::string>& issuers,
108 PLArenaPool* arena,
109 std::vector<CERTName*>* out);
110
111 // Returns true iff a certificate is issued by any of the issuers listed
112 // by name in |valid_issuers|.
113 // |cert_chain| is the certificate's chain.
114 // |valid_issuers| is a list of strings, where each string contains
115 // a DER-encoded X.509 Distinguished Name.
116 bool IsCertificateIssuedBy(const std::vector<CERTCertificate*>& cert_chain,
117 const std::vector<CERTName*>& valid_issuers);
118
119 // Generates a unique nickname for |slot|, returning |nickname| if it is 52 // Generates a unique nickname for |slot|, returning |nickname| if it is
120 // already unique. 53 // already unique.
121 // 54 //
122 // Note: The nickname returned will NOT include the token name, thus the 55 // Note: The nickname returned will NOT include the token name, thus the
123 // token name must be prepended if calling an NSS function that expects 56 // token name must be prepended if calling an NSS function that expects
124 // <token>:<nickname>. 57 // <token>:<nickname>.
125 // TODO(gspencer): Internationalize this: it's wrong to hard-code English. 58 // TODO(gspencer): Internationalize this: it's wrong to hard-code English.
126 std::string GetUniqueNicknameForSlot(const std::string& nickname, 59 std::string GetUniqueNicknameForSlot(const std::string& nickname,
127 const SECItem* subject, 60 const SECItem* subject,
128 PK11SlotInfo* slot); 61 PK11SlotInfo* slot);
129 62
130 } // namespace x509_util 63 } // namespace x509_util
131 64
132 } // namespace net 65 } // namespace net
133 66
134 #endif // NET_CERT_X509_UTIL_NSS_H_ 67 #endif // NET_CERT_X509_UTIL_NSS_H_
OLDNEW
« no previous file with comments | « net/cert/x509_certificate_nss.cc ('k') | net/cert/x509_util_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698