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