mirror of
				https://github.com/3proxy/3proxy.git
				synced 2025-11-04 07:42:39 +08:00 
			
		
		
		
	Fixed SSLPlugin handling
This commit is contained in:
		
							parent
							
								
									c02210d8c6
								
							
						
					
					
						commit
						313f5adcee
					
				@ -52,14 +52,14 @@ static size_t bin2hex (const char* bin, size_t bin_length, char* str, size_t str
 | 
				
			|||||||
	char *p;
 | 
						char *p;
 | 
				
			||||||
	size_t i;
 | 
						size_t i;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if ( str_length < ( bin_length+1) ) 
 | 
						if ( str_length < ( (bin_length*2)+1) ) 
 | 
				
			||||||
		return 0; 
 | 
							return 0; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p = str; 
 | 
						p = str; 
 | 
				
			||||||
	for ( i=0; i < bin_length; ++i )  
 | 
						for ( i=0; i < bin_length; ++i )  
 | 
				
			||||||
	{ 
 | 
						{ 
 | 
				
			||||||
		*p++ = hexMap[*bin >> 4];  
 | 
							*p++ = hexMap[(*(unsigned char *)bin) >> 4];  
 | 
				
			||||||
		*p++ = hexMap[*bin & 0xf]; 
 | 
							*p++ = hexMap[(*(unsigned char *)bin) & 0xf]; 
 | 
				
			||||||
		++bin;
 | 
							++bin;
 | 
				
			||||||
	} 
 | 
						} 
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -115,10 +115,18 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert)
 | 
				
			|||||||
	char p2[] = "3proxy";
 | 
						char p2[] = "3proxy";
 | 
				
			||||||
	char p3[] = "3proxy CA";
 | 
						char p3[] = "3proxy CA";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	char hash_name_sha1[sizeof(src_cert->sha1_hash)*2 + 1];
 | 
						int hash_size = 20;
 | 
				
			||||||
	char cache_name[200];
 | 
						char hash_sha1[20];
 | 
				
			||||||
 | 
						char hash_name_sha1[(20*2) + 1];
 | 
				
			||||||
 | 
						char cache_name[256];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bin2hex(src_cert->sha1_hash, sizeof(src_cert->sha1_hash), hash_name_sha1, sizeof(hash_name_sha1));
 | 
						err = X509_digest(src_cert, EVP_sha1(), hash_sha1, NULL);
 | 
				
			||||||
 | 
						if(!err){
 | 
				
			||||||
 | 
							X509_free(dst_cert);
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bin2hex(hash_sha1, 20, hash_name_sha1, sizeof(hash_name_sha1));
 | 
				
			||||||
	sprintf(cache_name, "%s%s.pem", cert_path, hash_name_sha1);
 | 
						sprintf(cache_name, "%s%s.pem", cert_path, hash_name_sha1);
 | 
				
			||||||
	/* check if certificate is already cached */
 | 
						/* check if certificate is already cached */
 | 
				
			||||||
	fcache = fopen(cache_name, "rb");
 | 
						fcache = fopen(cache_name, "rb");
 | 
				
			||||||
@ -153,19 +161,11 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Its self signed so set the issuer name to be the same as the
 | 
					 | 
				
			||||||
 	 * subject.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	err = X509_set_issuer_name(dst_cert, name);
 | 
						err = X509_set_issuer_name(dst_cert, name);
 | 
				
			||||||
	if(!err){
 | 
						if(!err){
 | 
				
			||||||
		X509_free(dst_cert);
 | 
							X509_free(dst_cert);
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = X509_digest(dst_cert, EVP_sha1(), dst_cert->sha1_hash, NULL);
 | 
					 | 
				
			||||||
	if(!err){
 | 
					 | 
				
			||||||
		X509_free(dst_cert);
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	err = X509_sign(dst_cert, CA_key, EVP_sha256());
 | 
						err = X509_sign(dst_cert, CA_key, EVP_sha256());
 | 
				
			||||||
	if(!err){
 | 
						if(!err){
 | 
				
			||||||
		X509_free(dst_cert);
 | 
							X509_free(dst_cert);
 | 
				
			||||||
 | 
				
			|||||||
@ -57,6 +57,7 @@ struct SSLqueue {
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
static struct SSLqueue *searchSSL(SOCKET s){
 | 
					static struct SSLqueue *searchSSL(SOCKET s){
 | 
				
			||||||
	struct SSLqueue *sslq = NULL;
 | 
						struct SSLqueue *sslq = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pthread_mutex_lock(&ssl_mutex);
 | 
						pthread_mutex_lock(&ssl_mutex);
 | 
				
			||||||
	for(sslq = SSLq; sslq; sslq = sslq->next)
 | 
						for(sslq = SSLq; sslq; sslq = sslq->next)
 | 
				
			||||||
		if(sslq->s == s) break;
 | 
							if(sslq->s == s) break;
 | 
				
			||||||
@ -66,19 +67,21 @@ static struct SSLqueue *searchSSL(SOCKET s){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void addSSL(SOCKET s, SSL_CERT cert, SSL_CONN conn, struct clientparam* param){
 | 
					static void addSSL(SOCKET s, SSL_CERT cert, SSL_CONN conn, struct clientparam* param){
 | 
				
			||||||
	struct SSLqueue *sslq;
 | 
						struct SSLqueue *sslq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sslq = (struct SSLqueue *) malloc(sizeof(struct SSLqueue));
 | 
						sslq = (struct SSLqueue *) malloc(sizeof(struct SSLqueue));
 | 
				
			||||||
	sslq->s = s;
 | 
						sslq->s = s;
 | 
				
			||||||
	sslq->cert = cert;
 | 
						sslq->cert = cert;
 | 
				
			||||||
	sslq->conn = conn;
 | 
						sslq->conn = conn;
 | 
				
			||||||
 | 
						sslq->param = param;
 | 
				
			||||||
	pthread_mutex_lock(&ssl_mutex);
 | 
						pthread_mutex_lock(&ssl_mutex);
 | 
				
			||||||
	sslq->next = SSLq;
 | 
						sslq->next = SSLq;
 | 
				
			||||||
	sslq->param = param;
 | 
					 | 
				
			||||||
	SSLq = sslq;
 | 
						SSLq = sslq;
 | 
				
			||||||
	pthread_mutex_unlock(&ssl_mutex);
 | 
						pthread_mutex_unlock(&ssl_mutex);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int delSSL(SOCKET s){
 | 
					int delSSL(SOCKET s){
 | 
				
			||||||
	struct SSLqueue *sqi, *sqt = NULL;
 | 
						struct SSLqueue *sqi, *sqt = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!SSLq) return 0;
 | 
						if(!SSLq) return 0;
 | 
				
			||||||
	pthread_mutex_lock(&ssl_mutex);
 | 
						pthread_mutex_lock(&ssl_mutex);
 | 
				
			||||||
	if(SSLq){
 | 
						if(SSLq){
 | 
				
			||||||
@ -114,13 +117,15 @@ static int ssl_send(SOCKET s, const void *msg, size_t len, int flags){
 | 
				
			|||||||
	struct SSLqueue *sslq;
 | 
						struct SSLqueue *sslq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((sslq = searchSSL(s))){
 | 
						if ((sslq = searchSSL(s))){
 | 
				
			||||||
		int i=0, res, err;
 | 
							int res, err;
 | 
				
			||||||
		do {
 | 
							if((res = ssl_write(sslq->conn, (void *)msg, len)) <= 0){
 | 
				
			||||||
			if((res = ssl_write(sslq->conn, (void *)msg, len)) < 0) {
 | 
					 | 
				
			||||||
			err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
								err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
				
			||||||
					usleep(10*SLEEPTIME);
 | 
								if (err == SSL_ERROR_WANT_WRITE){
 | 
				
			||||||
 | 
									_set_errno(EAGAIN);
 | 
				
			||||||
 | 
									return -1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else _set_errno(err);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		} while (res < 0 && (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) && ++i < 100); 
 | 
					 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -136,13 +141,15 @@ static int ssl_sendto(SOCKET s, const void *msg, size_t len, int flags, const st
 | 
				
			|||||||
	struct SSLqueue *sslq;
 | 
						struct SSLqueue *sslq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((sslq = searchSSL(s))){
 | 
						if ((sslq = searchSSL(s))){
 | 
				
			||||||
		int i=0, res, err;
 | 
							int res, err;
 | 
				
			||||||
		do {
 | 
							if((res = ssl_write(sslq->conn, (void *)msg, len)) <= 0) {
 | 
				
			||||||
			if((res = ssl_write(sslq->conn, (void *)msg, len)) < 0) {
 | 
					 | 
				
			||||||
			err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
								err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
				
			||||||
					usleep(10*SLEEPTIME);
 | 
								if (err == SSL_ERROR_WANT_WRITE){
 | 
				
			||||||
 | 
									_set_errno(EAGAIN);
 | 
				
			||||||
 | 
									return -1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else _set_errno(err);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		} while (res < 0 && (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) && ++i < 100); 
 | 
					 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -157,16 +164,17 @@ static int ssl_recvfrom(SOCKET s, void *msg, size_t len, int flags, struct socka
 | 
				
			|||||||
	struct SSLqueue *sslq;
 | 
						struct SSLqueue *sslq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((sslq = searchSSL(s))){
 | 
						if ((sslq = searchSSL(s))){
 | 
				
			||||||
		int i=0, res, err;
 | 
							int res, err;
 | 
				
			||||||
		do {
 | 
							if((res = ssl_read(sslq->conn, (void *)msg, len)) <= 0) {
 | 
				
			||||||
			if((res = ssl_read(sslq->conn, (void *)msg, len)) < 0) {
 | 
					 | 
				
			||||||
			err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
								err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
				
			||||||
					usleep(10*SLEEPTIME);
 | 
								if (err == SSL_ERROR_WANT_READ) {
 | 
				
			||||||
 | 
									_set_errno(EAGAIN);
 | 
				
			||||||
 | 
									return -1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else _set_errno(err);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		} while (res < 0 && (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) && ++i < 100); 
 | 
					 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return sso._recvfrom(s, msg, len, flags, from, fromlen);
 | 
						return sso._recvfrom(s, msg, len, flags, from, fromlen);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -178,13 +186,15 @@ static int WINAPI ssl_recv(SOCKET s, void *msg, size_t len, int flags){
 | 
				
			|||||||
	struct SSLqueue *sslq;
 | 
						struct SSLqueue *sslq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((sslq = searchSSL(s))){
 | 
						if ((sslq = searchSSL(s))){
 | 
				
			||||||
		int i=0, res, err;
 | 
							int res, err;
 | 
				
			||||||
		do {
 | 
							if((res = ssl_read(sslq->conn, (void *)msg, len)) <= 0) {
 | 
				
			||||||
			if((res = ssl_read(sslq->conn, (void *)msg, len)) < 0) {
 | 
					 | 
				
			||||||
			err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
								err = SSL_get_error((SSL *)((ssl_conn*)sslq->conn)->ssl, res);
 | 
				
			||||||
					usleep(10*SLEEPTIME);
 | 
								if (err == SSL_ERROR_WANT_READ) {
 | 
				
			||||||
 | 
									_set_errno(EAGAIN);
 | 
				
			||||||
 | 
									return -1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else _set_errno(err);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		} while (res < 0 && (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) && ++i < 100); 
 | 
					 | 
				
			||||||
		return res;
 | 
							return res;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -764,10 +764,14 @@ for(;;){
 | 
				
			|||||||
	if(param->redirectfunc) {
 | 
						if(param->redirectfunc) {
 | 
				
			||||||
		if(req)myfree(req);
 | 
							if(req)myfree(req);
 | 
				
			||||||
		if(buf)myfree(buf);
 | 
							if(buf)myfree(buf);
 | 
				
			||||||
 | 
					 | 
				
			||||||
		return (*param->redirectfunc)(param);
 | 
							return (*param->redirectfunc)(param);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	param->res =  mapsocket(param, conf.timeouts[CONNECTION_L]);
 | 
						param->res =  mapsocket(param, conf.timeouts[CONNECTION_L]);
 | 
				
			||||||
 | 
						if(param->redirectfunc) {
 | 
				
			||||||
 | 
							if(req)myfree(req);
 | 
				
			||||||
 | 
							if(buf)myfree(buf);
 | 
				
			||||||
 | 
							return (*param->redirectfunc)(param);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	RETURN(param->res);
 | 
						RETURN(param->res);
 | 
				
			||||||
 }
 | 
					 }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user