File: testssl.h

package info (click to toggle)
apt-cacher-ng 0.7.27-1~bpo70+1
  • links: PTS
  • area: main
  • in suites: wheezy-backports
  • size: 1,740 kB
  • sloc: cpp: 13,987; sh: 519; perl: 442; ansic: 414; makefile: 77
file content (49 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

// crudely stripped down acng code just for testing purposes
int main()
{

SSL * ssl(NULL);
SSL_CTX *m_ctx(0);
BIO *m_bio(0);
	int hret(0);
	if(!m_ctx)
	{
		m_ctx = SSL_CTX_new(SSLv23_client_method());
		if(!m_ctx)
			goto ssl_init_fail;

	}

	ssl = SSL_new(m_ctx);
	if(!ssl)
		goto ssl_init_fail;

 	SSL_set_connect_state(ssl);
 	SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY
 			| SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
 			| SSL_MODE_ENABLE_PARTIAL_WRITE);

 	if((hret=SSL_set_fd(ssl, hret)) != 1)
 		goto ssl_init_fail_retcode;
	if((hret=SSL_connect(ssl)) != 1)
		goto ssl_init_fail_retcode;

 	m_bio = BIO_new(BIO_f_ssl());
 	BIO_set_ssl(m_bio, ssl, BIO_NOCLOSE);

 	BIO_set_nbio(m_bio, 1);

	hret=SSL_get_verify_result(ssl);
	if( hret != X509_V_OK)
		goto ssl_init_fail;

	return true;

	ssl_init_fail_retcode:
	ssl_init_fail:
	return false;
}