I’ve written an https server in C++ using cpp-httplib (https://github.com/yhirose/cpp-httplib). My requirement is that it needs to work with pre-shared key and cipher DHE-PSK-AES256-CBC-SHA
or DHE-PSK-AES256-CBC-SHA384
.
I understand those are TLSv1 ciphers that are considered weak, therefore they are somewhat disabled by default.
Here is the relevant part of my code:
<code>httplib::SSLServer *const ssl_server = new httplib::SSLServer([](SSL_CTX &context)
SSL_CTX_set_psk_server_callback(&context, psk_callback);
SSL_CTX *const context = ssl_server->ssl_context();
// Section added later, it doesn't work either.
SSL_CTX_set_security_level(context, 0);
SSL_CTX_set_min_proto_version(context, TLS1_VERSION);
SSL_CTX_set_max_proto_version(context, TLS1_VERSION);
SSL_CTX_set_cipher_list(context, "DHE-PSK-AES256-CBC-SHA:DHE-PSK-AES256-CBC-SHA384");
SSL_CTX_set_ciphersuites(context, "");
// End of section added later.
ssl_server->listen("0.0.0.0", 50051);
<code>httplib::SSLServer *const ssl_server = new httplib::SSLServer([](SSL_CTX &context)
{
SSL_CTX_set_psk_server_callback(&context, psk_callback);
return true;
});
SSL_CTX *const context = ssl_server->ssl_context();
// Section added later, it doesn't work either.
SSL_CTX_set_security_level(context, 0);
SSL_CTX_set_min_proto_version(context, TLS1_VERSION);
SSL_CTX_set_max_proto_version(context, TLS1_VERSION);
SSL_CTX_set_cipher_list(context, "DHE-PSK-AES256-CBC-SHA:DHE-PSK-AES256-CBC-SHA384");
SSL_CTX_set_ciphersuites(context, "");
// End of section added later.
ssl_server->listen("0.0.0.0", 50051);
</code>
httplib::SSLServer *const ssl_server = new httplib::SSLServer([](SSL_CTX &context)
{
SSL_CTX_set_psk_server_callback(&context, psk_callback);
return true;
});
SSL_CTX *const context = ssl_server->ssl_context();
// Section added later, it doesn't work either.
SSL_CTX_set_security_level(context, 0);
SSL_CTX_set_min_proto_version(context, TLS1_VERSION);
SSL_CTX_set_max_proto_version(context, TLS1_VERSION);
SSL_CTX_set_cipher_list(context, "DHE-PSK-AES256-CBC-SHA:DHE-PSK-AES256-CBC-SHA384");
SSL_CTX_set_ciphersuites(context, "");
// End of section added later.
ssl_server->listen("0.0.0.0", 50051);
The section enclosed between comments has been added later, when I noticed the handshaking was picking more modern ciphers (TLS_CHACHA20_POLY1305_SHA256
and such), which won’t work in the final setup.
I understand a way to test the connection would be with openssl s_client
command:
<code>openssl s_client -connect localhost:50051 -psk ... -tls1 -cipher 'DHE-PSK-AES256-CBC-SHA:@SECLEVEL=0'
<code>openssl s_client -connect localhost:50051 -psk ... -tls1 -cipher 'DHE-PSK-AES256-CBC-SHA:@SECLEVEL=0'
</code>
openssl s_client -connect localhost:50051 -psk ... -tls1 -cipher 'DHE-PSK-AES256-CBC-SHA:@SECLEVEL=0'
Sadly, I get the following output:
<code>CONNECTED(00000003)
408764833A7B0000:error:0A000410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../ssl/record/rec_layer_s3.c:1599:SSL alert number 40
no peer certificate available
No client certificate CA names sent
SSL handshake has read 7 bytes and written 66 bytes
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Verify return code: 0 (ok)
Extended master secret: no
<code>CONNECTED(00000003)
408764833A7B0000:error:0A000410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../ssl/record/rec_layer_s3.c:1599:SSL alert number 40
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 66 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1733742579
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
---
</code>
CONNECTED(00000003)
408764833A7B0000:error:0A000410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../ssl/record/rec_layer_s3.c:1599:SSL alert number 40
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 66 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1733742579
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
---
If I start a test server with openssl s_server
command:
<code>openssl s_server -accept 50051 -nocert -psk ... -tls1 -cipher "DHE-PSK-AES256-CBC-SHA:@SECLEVEL=0"
<code>openssl s_server -accept 50051 -nocert -psk ... -tls1 -cipher "DHE-PSK-AES256-CBC-SHA:@SECLEVEL=0"
</code>
openssl s_server -accept 50051 -nocert -psk ... -tls1 -cipher "DHE-PSK-AES256-CBC-SHA:@SECLEVEL=0"
The openssl s_client
command gives me the following output (which I understand is the one I need for my server):
<code>CONNECTED(00000003)
Can't use SSL_get_servername
no peer certificate available
No client certificate CA names sent
Server Temp Key: DH, 3072 bits
SSL handshake has read 1131 bytes and written 541 bytes
New, SSLv3, Cipher is DHE-PSK-AES256-CBC-SHA
Secure Renegotiation IS supported
Cipher : DHE-PSK-AES256-CBC-SHA
Session-ID: 5651AD5A635DFB1E723C1CEE31769765C42930899431C4E8E55694BAA6193756
Master-Key: 6771FA4460BF6B1E5D96F4957F6C3B27AFCCDC2F7E3C2676775E02E9FE0DC9B1E3F5AD576AC3BE203D6362876E8347CB
PSK identity: Client_identity
TLS session ticket lifetime hint: 7200 (seconds)
0000 - ab 65 ec 02 38 eb 69 27-6e 1f 14 47 b3 aa 17 49 .e..8.i'n..G...I
0010 - b3 59 01 fb 54 33 e1 0a-71 14 d4 cc d8 be 50 e4 .Y..T3..q.....P.
0020 - 35 c1 9d 27 5f 73 60 b1-eb bb 8d 3f 46 50 b8 20 5..'_s`....?FP.
0030 - 44 fa da ff e9 1a cb 52-db 05 49 84 44 a4 e0 09 D......R..I.D...
0040 - 98 18 b0 78 2f c4 2d 89-cf 8a a1 10 5f eb a0 47 ...x/.-....._..G
0050 - 98 b0 c3 b0 51 ed 59 9b-7f 6c e4 40 45 91 13 b6 ....Q.Y..l.@E...
0060 - b8 4c 57 dc 3f 62 d4 aa-2d 39 75 43 16 ef f7 67 .LW.?b..-9uC...g
0070 - 6c e4 b2 1c 6b 70 f0 7d-72 7b 46 2f b0 6b a7 e5 l...kp.}r{F/.k..
0080 - 92 f7 25 1a 63 fa 0c 88-ed be 84 a5 e8 08 6a 60 ..%.c.........j`
0090 - 64 61 1b f1 ed cc 1e 5e-02 b3 02 55 cd c3 17 16 da.....^...U....
00a0 - 67 00 de f4 5e 0d 6f 2b-aa a0 5f fc 1d ce 3b f4 g...^.o+.._...;.
00b0 - ed 51 20 72 5b 0e 02 b6-1f 51 53 3a 8d 19 af dd .Q r[....QS:....
Verify return code: 0 (ok)
Extended master secret: yes
<code>CONNECTED(00000003)
Can't use SSL_get_servername
---
no peer certificate available
---
No client certificate CA names sent
Server Temp Key: DH, 3072 bits
---
SSL handshake has read 1131 bytes and written 541 bytes
Verification: OK
---
New, SSLv3, Cipher is DHE-PSK-AES256-CBC-SHA
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : DHE-PSK-AES256-CBC-SHA
Session-ID: 5651AD5A635DFB1E723C1CEE31769765C42930899431C4E8E55694BAA6193756
Session-ID-ctx:
Master-Key: 6771FA4460BF6B1E5D96F4957F6C3B27AFCCDC2F7E3C2676775E02E9FE0DC9B1E3F5AD576AC3BE203D6362876E8347CB
PSK identity: Client_identity
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - ab 65 ec 02 38 eb 69 27-6e 1f 14 47 b3 aa 17 49 .e..8.i'n..G...I
0010 - b3 59 01 fb 54 33 e1 0a-71 14 d4 cc d8 be 50 e4 .Y..T3..q.....P.
0020 - 35 c1 9d 27 5f 73 60 b1-eb bb 8d 3f 46 50 b8 20 5..'_s`....?FP.
0030 - 44 fa da ff e9 1a cb 52-db 05 49 84 44 a4 e0 09 D......R..I.D...
0040 - 98 18 b0 78 2f c4 2d 89-cf 8a a1 10 5f eb a0 47 ...x/.-....._..G
0050 - 98 b0 c3 b0 51 ed 59 9b-7f 6c e4 40 45 91 13 b6 ....Q.Y..l.@E...
0060 - b8 4c 57 dc 3f 62 d4 aa-2d 39 75 43 16 ef f7 67 .LW.?b..-9uC...g
0070 - 6c e4 b2 1c 6b 70 f0 7d-72 7b 46 2f b0 6b a7 e5 l...kp.}r{F/.k..
0080 - 92 f7 25 1a 63 fa 0c 88-ed be 84 a5 e8 08 6a 60 ..%.c.........j`
0090 - 64 61 1b f1 ed cc 1e 5e-02 b3 02 55 cd c3 17 16 da.....^...U....
00a0 - 67 00 de f4 5e 0d 6f 2b-aa a0 5f fc 1d ce 3b f4 g...^.o+.._...;.
00b0 - ed 51 20 72 5b 0e 02 b6-1f 51 53 3a 8d 19 af dd .Q r[....QS:....
Start Time: 1733744221
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: yes
---
</code>
CONNECTED(00000003)
Can't use SSL_get_servername
---
no peer certificate available
---
No client certificate CA names sent
Server Temp Key: DH, 3072 bits
---
SSL handshake has read 1131 bytes and written 541 bytes
Verification: OK
---
New, SSLv3, Cipher is DHE-PSK-AES256-CBC-SHA
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : DHE-PSK-AES256-CBC-SHA
Session-ID: 5651AD5A635DFB1E723C1CEE31769765C42930899431C4E8E55694BAA6193756
Session-ID-ctx:
Master-Key: 6771FA4460BF6B1E5D96F4957F6C3B27AFCCDC2F7E3C2676775E02E9FE0DC9B1E3F5AD576AC3BE203D6362876E8347CB
PSK identity: Client_identity
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - ab 65 ec 02 38 eb 69 27-6e 1f 14 47 b3 aa 17 49 .e..8.i'n..G...I
0010 - b3 59 01 fb 54 33 e1 0a-71 14 d4 cc d8 be 50 e4 .Y..T3..q.....P.
0020 - 35 c1 9d 27 5f 73 60 b1-eb bb 8d 3f 46 50 b8 20 5..'_s`....?FP.
0030 - 44 fa da ff e9 1a cb 52-db 05 49 84 44 a4 e0 09 D......R..I.D...
0040 - 98 18 b0 78 2f c4 2d 89-cf 8a a1 10 5f eb a0 47 ...x/.-....._..G
0050 - 98 b0 c3 b0 51 ed 59 9b-7f 6c e4 40 45 91 13 b6 ....Q.Y..l.@E...
0060 - b8 4c 57 dc 3f 62 d4 aa-2d 39 75 43 16 ef f7 67 .LW.?b..-9uC...g
0070 - 6c e4 b2 1c 6b 70 f0 7d-72 7b 46 2f b0 6b a7 e5 l...kp.}r{F/.k..
0080 - 92 f7 25 1a 63 fa 0c 88-ed be 84 a5 e8 08 6a 60 ..%.c.........j`
0090 - 64 61 1b f1 ed cc 1e 5e-02 b3 02 55 cd c3 17 16 da.....^...U....
00a0 - 67 00 de f4 5e 0d 6f 2b-aa a0 5f fc 1d ce 3b f4 g...^.o+.._...;.
00b0 - ed 51 20 72 5b 0e 02 b6-1f 51 53 3a 8d 19 af dd .Q r[....QS:....
Start Time: 1733744221
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: yes
---
I’ve been things for almost a week, but I wasn’t able to make it work with the desired cipher. My knowledge of openssl is just not enough for me to understand what I’m doing wrong. Is anybody able to help me, please?