|
1 | 1 | #include "socket.h" |
2 | 2 | #include "jpsock.h" |
3 | 3 | #include "jconf.h" |
| 4 | +#include "console.h" |
| 5 | +#include "executor.h" |
4 | 6 |
|
5 | 7 | #include <openssl/ssl.h> |
6 | 8 | #include <openssl/err.h> |
@@ -169,7 +171,10 @@ void tls_socket::init_ctx() |
169 | 171 | if(ctx == nullptr) |
170 | 172 | return; |
171 | 173 |
|
172 | | - SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION); |
| 174 | + if(jconf::inst()->TlsSecureAlgos()) |
| 175 | + { |
| 176 | + SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_COMPRESSION); |
| 177 | + } |
173 | 178 | } |
174 | 179 |
|
175 | 180 | bool tls_socket::set_hostname(const char* sAddr) |
@@ -203,11 +208,15 @@ bool tls_socket::set_hostname(const char* sAddr) |
203 | 208 | return false; |
204 | 209 | } |
205 | 210 |
|
206 | | - /*if(SSL_set_cipher_list(ssl, "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4") != 1) |
| 211 | + if(jconf::inst()->TlsSecureAlgos()) |
207 | 212 | { |
208 | | - print_error(); |
209 | | - return false; |
210 | | - }*/ |
| 213 | + if(SSL_set_cipher_list(ssl, "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4:!SHA1") != 1) |
| 214 | + { |
| 215 | + print_error(); |
| 216 | + return false; |
| 217 | + } |
| 218 | + } |
| 219 | + |
211 | 220 | return true; |
212 | 221 | } |
213 | 222 |
|
@@ -241,18 +250,50 @@ bool tls_socket::connect() |
241 | 250 | if(digest == nullptr) |
242 | 251 | { |
243 | 252 | print_error(); |
244 | | - false; |
| 253 | + return false; |
245 | 254 | } |
246 | 255 |
|
247 | 256 | if(X509_digest(cert, digest, md, &dlen) != 1) |
248 | 257 | { |
| 258 | + X509_free(cert); |
249 | 259 | print_error(); |
250 | | - false; |
| 260 | + return false; |
251 | 261 | } |
252 | 262 |
|
253 | | - for(size_t i=0; i < dlen; i++) |
254 | | - printf("%.2X:", md[i]); |
255 | | - printf("\n"); |
| 263 | + if(pCallback->pool_id != executor::dev_pool_id) |
| 264 | + { |
| 265 | + //Base64 encode digest |
| 266 | + BIO *bmem, *b64; |
| 267 | + b64 = BIO_new(BIO_f_base64()); |
| 268 | + bmem = BIO_new(BIO_s_mem()); |
| 269 | + |
| 270 | + BIO_puts(bmem, "SHA256:"); |
| 271 | + b64 = BIO_push(b64, bmem); |
| 272 | + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); |
| 273 | + BIO_write(b64, md, dlen); |
| 274 | + BIO_flush(b64); |
| 275 | + |
| 276 | + const char* conf_md = jconf::inst()->GetTlsFingerprint(); |
| 277 | + char *b64_md = nullptr; |
| 278 | + size_t b64_len = BIO_get_mem_data(bmem, &b64_md); |
| 279 | + |
| 280 | + if(strlen(conf_md) == 0) |
| 281 | + { |
| 282 | + printer::inst()->print_msg(L1, "Server fingerprint: %.*s", (int)b64_len, b64_md); |
| 283 | + } |
| 284 | + else if(strncmp(b64_md, conf_md, b64_len) != 0) |
| 285 | + { |
| 286 | + printer::inst()->print_msg(L0, "FINGERPRINT FAILED CHECK: %.*s was given, %s was configured", |
| 287 | + (int)b64_len, b64_md, conf_md); |
| 288 | + |
| 289 | + pCallback->set_socket_error("FINGERPRINT FAILED CHECK"); |
| 290 | + BIO_free_all(b64); |
| 291 | + X509_free(cert); |
| 292 | + return false; |
| 293 | + } |
| 294 | + |
| 295 | + BIO_free_all(b64); |
| 296 | + } |
256 | 297 |
|
257 | 298 | X509_free(cert); |
258 | 299 | return true; |
|
0 commit comments