OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef NET_BASE_X509_UTIL_NSS_H_ | |
6 #define NET_BASE_X509_UTIL_NSS_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/time.h" | |
12 #include "net/base/x509_certificate.h" | |
13 | |
14 class PickleIterator; | |
15 | |
16 typedef struct CERTCertificateStr CERTCertificate; | |
17 typedef struct CERTNameStr CERTName; | |
18 typedef struct PLArenaPool PLArenaPool; | |
19 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey; | |
20 typedef struct SECItemStr SECItem; | |
21 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; | |
22 | |
23 namespace net { | |
24 | |
25 namespace x509_util { | |
26 | |
27 // Creates a self-signed certificate containing |public_key|. Subject, serial | |
28 // number and validity period are given as parameters. The certificate is | |
29 // signed by |private_key|. The hashing algorithm for the signature is SHA-1. | |
30 // |subject| is a distinguished name defined in RFC4514. | |
31 CERTCertificate* CreateSelfSignedCert( | |
32 SECKEYPublicKey* public_key, | |
33 SECKEYPrivateKey* private_key, | |
34 const std::string& subject, | |
35 uint32 serial_number, | |
36 base::Time not_valid_before, | |
37 base::Time not_valid_after); | |
38 | |
39 #if defined(USE_NSS) || defined(OS_IOS) | |
40 // Parses the Principal attribute from |name| and outputs the result in | |
41 // |principal|. | |
42 void ParsePrincipal(CERTName* name, | |
43 CertPrincipal* principal); | |
44 | |
45 // Parses the date from |der_date| and outputs the result in |result|. | |
46 void ParseDate(const SECItem* der_date, base::Time* result); | |
47 | |
48 // Parses the serial number from |certificate|. | |
49 std::string ParseSerialNumber(const CERTCertificate* certificate); | |
50 | |
51 // Gets the subjectAltName extension field from the certificate, if any. | |
52 void GetSubjectAltName(CERTCertificate* cert_handle, | |
53 std::vector<std::string>* dns_names, | |
54 std::vector<std::string>* ip_addrs); | |
55 | |
56 // Creates all possible OS certificate handles from |data| encoded in a specific | |
57 // |format|. Returns an empty collection on failure. | |
58 X509Certificate::OSCertHandles CreateOSCertHandlesFromBytes( | |
59 const char* data, | |
60 int length, | |
61 X509Certificate::Format format); | |
62 | |
63 // Reads a single certificate from |pickle_iter| and returns a platform-specific | |
64 // certificate handle. Returns an invalid handle, NULL, on failure. | |
65 X509Certificate::OSCertHandle ReadOSCertHandleFromPickle( | |
66 PickleIterator* pickle_iter); | |
67 | |
68 // Sets |*size_bits| to be the length of the public key in bits, and sets | |
69 // |*type| to one of the |PublicKeyType| values. In case of | |
70 // |kPublicKeyTypeUnknown|, |*size_bits| will be set to 0. | |
71 void GetPublicKeyInfo(CERTCertificate* handle, | |
72 size_t* size_bits, | |
73 X509Certificate::PublicKeyType* type); | |
74 | |
75 // Create a list of CERTName objects from a list of DER-encoded X.509 | |
76 // DistinguishedName items. All objects are created in a given arena. | |
77 // |encoded_issuers| is the list of encoded DNs. | |
78 // |arena| is the arena used for all allocations. | |
79 // |out| will receive the result list on success. | |
80 // Return true on success. On failure, the caller must free the | |
81 // intermediate CERTName objects pushed to |out|. | |
82 bool GetIssuersFromEncodedList( | |
83 const std::vector<std::string>& issuers, | |
84 PLArenaPool* arena, | |
85 std::vector<CERTName*>* out); | |
86 | |
87 // Returns true iff a certificate is issued by any of the issuers listed | |
88 // by name in |valid_issuers|. | |
89 // |cert_chain| is the certificate's chain. | |
90 // |valid_issuers| is a list of strings, where each string contains | |
91 // a DER-encoded X.509 Distinguished Name. | |
92 bool IsCertificateIssuedBy(const std::vector<CERTCertificate*>& cert_chain, | |
93 const std::vector<CERTName*>& valid_issuers); | |
94 | |
95 #endif // defined(USE_NSS) || defined(OS_IOS) | |
96 | |
97 } // namespace x509_util | |
98 | |
99 } // namespace net | |
100 | |
101 #endif // NET_BASE_X509_UTIL_NSS_H_ | |
OLD | NEW |