@@ -134,76 +134,6 @@ SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) {
134134 return SSLSessionPointer (d2i_SSL_SESSION (nullptr , &buf, length));
135135}
136136
137- std::unordered_multimap<std::string, std::string>
138- GetCertificateAltNames (X509* cert) {
139- std::unordered_multimap<std::string, std::string> map;
140- BIOPointer bio (BIO_new (BIO_s_mem ()));
141- BUF_MEM* mem;
142- int idx = X509_get_ext_by_NID (cert, NID_subject_alt_name, -1 );
143- if (idx < 0 ) // There is no subject alt name
144- return map;
145-
146- X509_EXTENSION* ext = X509_get_ext (cert, idx);
147- CHECK_NOT_NULL (ext);
148- const X509V3_EXT_METHOD* method = X509V3_EXT_get (ext);
149- CHECK_EQ (method, X509V3_EXT_get_nid (NID_subject_alt_name));
150-
151- GENERAL_NAMES* names = static_cast <GENERAL_NAMES*>(X509V3_EXT_d2i (ext));
152- if (names == nullptr ) // There are no names
153- return map;
154-
155- for (int i = 0 ; i < sk_GENERAL_NAME_num (names); i++) {
156- USE (BIO_reset (bio.get ()));
157- GENERAL_NAME* gen = sk_GENERAL_NAME_value (names, i);
158- if (gen->type == GEN_DNS) {
159- ASN1_IA5STRING* name = gen->d .dNSName ;
160- BIO_write (bio.get (), name->data , name->length );
161- BIO_get_mem_ptr (bio.get (), &mem);
162- map.emplace (" dns" , std::string (mem->data , mem->length ));
163- } else {
164- STACK_OF (CONF_VALUE)* nval = i2v_GENERAL_NAME (
165- const_cast <X509V3_EXT_METHOD*>(method), gen, nullptr );
166- if (nval == nullptr )
167- continue ;
168- X509V3_EXT_val_prn (bio.get (), nval, 0 , 0 );
169- sk_CONF_VALUE_pop_free (nval, X509V3_conf_free);
170- BIO_get_mem_ptr (bio.get (), &mem);
171- std::string value (mem->data , mem->length );
172- if (value.compare (0 , 11 , " IP Address:" ) == 0 ) {
173- map.emplace (" ip" , value.substr (11 ));
174- } else if (value.compare (0 , 4 , " URI:" ) == 0 ) {
175- url::URL url (value.substr (4 ));
176- if (url.flags () & url::URL_FLAGS_CANNOT_BE_BASE ||
177- url.flags () & url::URL_FLAGS_FAILED) {
178- continue ; // Skip this one
179- }
180- map.emplace (" uri" , url.host ());
181- }
182- }
183- }
184- sk_GENERAL_NAME_pop_free (names, GENERAL_NAME_free);
185- return map;
186- }
187-
188- std::string GetCertificateCN (X509* cert) {
189- X509_NAME* subject = X509_get_subject_name (cert);
190- if (subject != nullptr ) {
191- int nid = OBJ_txt2nid (" CN" );
192- int idx = X509_NAME_get_index_by_NID (subject, nid, -1 );
193- if (idx != -1 ) {
194- X509_NAME_ENTRY* cn = X509_NAME_get_entry (subject, idx);
195- if (cn != nullptr ) {
196- ASN1_STRING* cn_str = X509_NAME_ENTRY_get_data (cn);
197- if (cn_str != nullptr ) {
198- return std::string (reinterpret_cast <const char *>(
199- ASN1_STRING_get0_data (cn_str)));
200- }
201- }
202- }
203- }
204- return std::string ();
205- }
206-
207137long VerifyPeerCertificate ( // NOLINT(runtime/int)
208138 const SSLPointer& ssl,
209139 long def) { // NOLINT(runtime/int)
0 commit comments