advertise ADC protocol with ALPN
This commit is contained in:
		
							parent
							
								
									b27c44e633
								
							
						
					
					
						commit
						566cd9a9db
					
				| @ -1,4 +1,5 @@ | ||||
| language: cpp | ||||
| dist: xenial | ||||
| compiler: | ||||
|   - gcc | ||||
|   - clang | ||||
|  | ||||
| @ -153,6 +153,32 @@ static const SSL_METHOD* get_ssl_method(const char* tls_version) | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * List of supported protocols for ALPN. | ||||
|  * We only support "adc" protocol. | ||||
|  */ | ||||
| unsigned char alpn_protocols[] = { | ||||
|      3, 'a', 'd', 'c', | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
|  * Callback for the server to select a protocol from the list | ||||
|  * sent by the client via ALPN. | ||||
|  */ | ||||
| int alpn_server_select_protocol(SSL *ssl, const unsigned char **out, unsigned char *outlen, | ||||
|                                  const unsigned char *in, unsigned int inlen, void *arg) | ||||
| { | ||||
|     int res = SSL_select_next_proto((unsigned char **)out, outlen, | ||||
|                     alpn_protocols, sizeof(alpn_protocols), in, inlen); | ||||
|     if (res == OPENSSL_NPN_NO_OVERLAP) | ||||
|     { | ||||
|         // set default protocol
 | ||||
|         *out = alpn_protocols; | ||||
|         *outlen = 1+alpn_protocols[0]; | ||||
|     } | ||||
|     return SSL_TLSEXT_ERR_OK; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Create a new SSL context. | ||||
|  */ | ||||
| @ -195,6 +221,8 @@ struct ssl_context_handle* net_ssl_context_create(const char* tls_version, const | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	SSL_CTX_set_alpn_select_cb(ctx->ssl, alpn_server_select_protocol, NULL); | ||||
| 
 | ||||
| 	return (struct ssl_context_handle*) ctx; | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user