2011-07-04 01:29:09 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Transport Layer Security
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2011-08-29 00:46:36 +04:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-04 01:29:09 +04:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <freerdp/utils/stream.h>
|
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
|
|
|
|
#include "tls.h"
|
|
|
|
|
2012-02-12 22:05:56 +04:00
|
|
|
static CryptoCert tls_get_certificate(rdpTls* tls)
|
|
|
|
{
|
|
|
|
CryptoCert cert;
|
|
|
|
X509* server_cert;
|
|
|
|
|
|
|
|
server_cert = SSL_get_peer_certificate(tls->ssl);
|
|
|
|
|
|
|
|
if (!server_cert)
|
|
|
|
{
|
|
|
|
printf("ssl_verify: failed to get the server SSL certificate\n");
|
|
|
|
cert = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cert = xmalloc(sizeof(*cert));
|
|
|
|
cert->px509 = server_cert;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cert;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tls_free_certificate(CryptoCert cert)
|
|
|
|
{
|
|
|
|
|
|
|
|
X509_free(cert->px509);
|
|
|
|
xfree(cert);
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:11:12 +04:00
|
|
|
boolean tls_connect(rdpTls* tls)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
2012-02-12 22:05:56 +04:00
|
|
|
CryptoCert cert;
|
2011-07-04 01:29:09 +04:00
|
|
|
int connection_status;
|
|
|
|
|
2011-08-19 09:35:29 +04:00
|
|
|
tls->ctx = SSL_CTX_new(TLSv1_client_method());
|
|
|
|
|
|
|
|
if (tls->ctx == NULL)
|
|
|
|
{
|
|
|
|
printf("SSL_CTX_new failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is necessary, because the Microsoft TLS implementation is not perfect.
|
|
|
|
* SSL_OP_ALL enables a couple of workarounds for buggy TLS implementations,
|
|
|
|
* but the most important workaround being SSL_OP_TLS_BLOCK_PADDING_BUG.
|
|
|
|
* As the size of the encrypted payload may give hints about its contents,
|
|
|
|
* block padding is normally used, but the Microsoft TLS implementation
|
|
|
|
* won't recognize it and will disconnect you after sending a TLS alert.
|
|
|
|
*/
|
|
|
|
SSL_CTX_set_options(tls->ctx, SSL_OP_ALL);
|
|
|
|
|
2011-07-04 01:29:09 +04:00
|
|
|
tls->ssl = SSL_new(tls->ctx);
|
|
|
|
|
|
|
|
if (tls->ssl == NULL)
|
|
|
|
{
|
2012-02-12 21:07:34 +04:00
|
|
|
SSL_CTX_free(tls->ctx);
|
2011-07-04 01:29:09 +04:00
|
|
|
printf("SSL_new failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SSL_set_fd(tls->ssl, tls->sockfd) < 1)
|
|
|
|
{
|
2012-02-12 21:07:34 +04:00
|
|
|
SSL_free(tls->ssl);
|
|
|
|
SSL_CTX_free(tls->ctx);
|
2011-07-04 01:29:09 +04:00
|
|
|
printf("SSL_set_fd failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-08-19 09:35:29 +04:00
|
|
|
connection_status = SSL_connect(tls->ssl);
|
|
|
|
|
|
|
|
if (connection_status <= 0)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
2011-08-19 09:35:29 +04:00
|
|
|
if (tls_print_error("SSL_connect", tls->ssl, connection_status))
|
2012-02-12 21:07:34 +04:00
|
|
|
{
|
|
|
|
SSL_free(tls->ssl);
|
|
|
|
SSL_CTX_free(tls->ctx);
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2012-02-12 21:07:34 +04:00
|
|
|
}
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2012-02-12 22:05:56 +04:00
|
|
|
cert = tls_get_certificate(tls);
|
2012-02-12 21:46:53 +04:00
|
|
|
|
2012-02-12 22:05:56 +04:00
|
|
|
if (cert == NULL)
|
2012-02-12 21:46:53 +04:00
|
|
|
{
|
|
|
|
printf("tls_connect: tls_get_certificate failed to return the server certificate.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-12 22:05:56 +04:00
|
|
|
if (!crypto_cert_get_public_key(cert, &tls->public_key))
|
2012-02-12 21:46:53 +04:00
|
|
|
{
|
|
|
|
printf("tls_connect: crypto_cert_get_public_key failed to return the server public key.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-12 22:05:56 +04:00
|
|
|
if (!tls_verify_certificate(tls, cert, tls->settings->hostname))
|
2012-02-12 21:46:53 +04:00
|
|
|
tls_disconnect(tls);
|
|
|
|
|
2012-02-12 22:05:56 +04:00
|
|
|
tls_free_certificate(cert);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file)
|
|
|
|
{
|
|
|
|
int connection_status;
|
|
|
|
|
|
|
|
tls->ctx = SSL_CTX_new(TLSv1_server_method());
|
|
|
|
|
|
|
|
if (tls->ctx == NULL)
|
|
|
|
{
|
|
|
|
printf("SSL_CTX_new failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-08-19 09:35:29 +04:00
|
|
|
if (SSL_CTX_use_RSAPrivateKey_file(tls->ctx, privatekey_file, SSL_FILETYPE_PEM) <= 0)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
2011-08-19 09:35:29 +04:00
|
|
|
printf("SSL_CTX_use_RSAPrivateKey_file failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
tls->ssl = SSL_new(tls->ctx);
|
|
|
|
|
|
|
|
if (tls->ssl == NULL)
|
|
|
|
{
|
|
|
|
printf("SSL_new failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SSL_use_certificate_file(tls->ssl, cert_file, SSL_FILETYPE_PEM) <= 0)
|
|
|
|
{
|
|
|
|
printf("SSL_use_certificate_file failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SSL_set_fd(tls->ssl, tls->sockfd) < 1)
|
|
|
|
{
|
|
|
|
printf("SSL_set_fd failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-19 09:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
connection_status = SSL_accept(tls->ssl);
|
|
|
|
|
|
|
|
if (connection_status <= 0)
|
|
|
|
{
|
|
|
|
if (tls_print_error("SSL_accept", tls->ssl, connection_status))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-08-19 09:35:29 +04:00
|
|
|
printf("TLS connection accepted\n");
|
2011-07-04 01:29:09 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-07-07 22:11:12 +04:00
|
|
|
boolean tls_disconnect(rdpTls* tls)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
2011-08-26 14:14:34 +04:00
|
|
|
SSL_shutdown(tls->ssl);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-07-10 23:34:43 +04:00
|
|
|
int tls_read(rdpTls* tls, uint8* data, int length)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2011-08-01 18:21:06 +04:00
|
|
|
status = SSL_read(tls->ssl, data, length);
|
|
|
|
|
|
|
|
switch (SSL_get_error(tls->ssl, status))
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
2011-08-01 18:21:06 +04:00
|
|
|
case SSL_ERROR_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSL_ERROR_WANT_READ:
|
2011-08-19 09:35:29 +04:00
|
|
|
case SSL_ERROR_WANT_WRITE:
|
2011-08-01 18:21:06 +04:00
|
|
|
status = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-08-19 09:35:29 +04:00
|
|
|
tls_print_error("SSL_read", tls->ssl, status);
|
2011-08-01 18:21:06 +04:00
|
|
|
status = -1;
|
|
|
|
break;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-08-01 18:21:06 +04:00
|
|
|
return status;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2011-07-10 23:34:43 +04:00
|
|
|
int tls_write(rdpTls* tls, uint8* data, int length)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
2011-07-10 23:34:43 +04:00
|
|
|
int status;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
2011-08-01 11:04:07 +04:00
|
|
|
status = SSL_write(tls->ssl, data, length);
|
2011-07-04 01:29:09 +04:00
|
|
|
|
2011-08-01 11:04:07 +04:00
|
|
|
switch (SSL_get_error(tls->ssl, status))
|
|
|
|
{
|
|
|
|
case SSL_ERROR_NONE:
|
|
|
|
break;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
2011-08-19 09:35:29 +04:00
|
|
|
case SSL_ERROR_WANT_READ:
|
2011-08-01 11:04:07 +04:00
|
|
|
case SSL_ERROR_WANT_WRITE:
|
|
|
|
status = 0;
|
|
|
|
break;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
2011-08-01 11:04:07 +04:00
|
|
|
default:
|
|
|
|
tls_print_error("SSL_write", tls->ssl, status);
|
|
|
|
status = -1;
|
2011-08-07 22:37:26 +04:00
|
|
|
break;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
2011-07-10 23:34:43 +04:00
|
|
|
|
2011-08-01 11:04:07 +04:00
|
|
|
return status;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 03:20:02 +04:00
|
|
|
boolean tls_print_error(char* func, SSL* connection, int value)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
|
|
|
switch (SSL_get_error(connection, value))
|
|
|
|
{
|
|
|
|
case SSL_ERROR_ZERO_RETURN:
|
|
|
|
printf("%s: Server closed TLS connection\n", func);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
|
printf("SSL_ERROR_WANT_READ\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
|
|
|
case SSL_ERROR_WANT_WRITE:
|
|
|
|
printf("SSL_ERROR_WANT_WRITE\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
|
|
|
case SSL_ERROR_SYSCALL:
|
|
|
|
printf("%s: I/O error\n", func);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
|
|
|
case SSL_ERROR_SSL:
|
|
|
|
printf("%s: Failure in SSL library (protocol error?)\n", func);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-04 01:29:09 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
printf("%s: Unknown error\n", func);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-04 01:29:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
boolean tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
|
2011-08-29 00:46:36 +04:00
|
|
|
{
|
2012-02-03 03:20:02 +04:00
|
|
|
int match;
|
2012-02-04 11:21:39 +04:00
|
|
|
int index;
|
|
|
|
char* common_name;
|
2012-02-08 07:16:57 +04:00
|
|
|
int common_name_length;
|
2012-02-04 11:21:39 +04:00
|
|
|
char** alt_names;
|
|
|
|
int alt_names_count;
|
2012-02-08 07:16:57 +04:00
|
|
|
int* alt_names_lengths;
|
2012-02-05 00:04:03 +04:00
|
|
|
boolean certificate_status;
|
2012-02-04 11:21:39 +04:00
|
|
|
boolean hostname_match = false;
|
2012-02-05 00:04:03 +04:00
|
|
|
rdpCertificateData* certificate_data;
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* ignore certificate verification if user explicitly required it (discouraged) */
|
|
|
|
if (tls->settings->ignore_certificate)
|
|
|
|
return true; /* success! */
|
2011-08-30 20:20:36 +04:00
|
|
|
|
2012-02-05 00:16:41 +04:00
|
|
|
/* if user explicitly specified a certificate name, use it instead of the hostname */
|
|
|
|
if (tls->settings->certificate_name)
|
|
|
|
hostname = tls->settings->certificate_name;
|
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* attempt verification using OpenSSL and the ~/.freerdp/certs certificate store */
|
|
|
|
certificate_status = x509_verify_certificate(cert, tls->certificate_store->path);
|
2011-12-10 20:23:48 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* verify certificate name match */
|
|
|
|
certificate_data = crypto_get_certificate_data(cert->px509, hostname);
|
2011-08-30 20:20:36 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* extra common name and alternative names */
|
2012-02-08 07:16:57 +04:00
|
|
|
common_name = crypto_cert_subject_common_name(cert->px509, &common_name_length);
|
|
|
|
alt_names = crypto_cert_subject_alt_name(cert->px509, &alt_names_count, &alt_names_lengths);
|
2012-02-03 03:20:02 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* compare against common name */
|
2012-02-08 07:16:57 +04:00
|
|
|
|
|
|
|
if (common_name != NULL)
|
|
|
|
{
|
|
|
|
if (strlen(hostname) == common_name_length)
|
|
|
|
{
|
|
|
|
if (memcmp((void*) hostname, (void*) common_name, common_name_length) == 0)
|
|
|
|
hostname_match = true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-04 11:21:39 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* compare against alternative names */
|
2012-02-08 07:16:57 +04:00
|
|
|
|
|
|
|
if (alt_names != NULL)
|
2012-02-05 00:04:03 +04:00
|
|
|
{
|
2012-02-08 07:16:57 +04:00
|
|
|
for (index = 0; index < alt_names_count; index++)
|
|
|
|
{
|
|
|
|
if (strlen(hostname) == alt_names_lengths[index])
|
|
|
|
{
|
|
|
|
if (memcmp((void*) hostname, (void*) alt_names[index], alt_names_lengths[index]) == 0)
|
|
|
|
hostname_match = true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 00:04:03 +04:00
|
|
|
}
|
2012-02-04 11:21:39 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* if the certificate is valid and the certificate name matches, verification succeeds */
|
|
|
|
if (certificate_status && hostname_match)
|
|
|
|
return true; /* success! */
|
|
|
|
|
|
|
|
/* if the certificate is valid but the certificate name does not match, warn user, do not accept */
|
|
|
|
if (certificate_status && !hostname_match)
|
|
|
|
tls_print_certificate_name_mismatch_error(hostname, common_name, alt_names, alt_names_count);
|
2012-02-04 11:21:39 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* verification could not succeed with OpenSSL, use known_hosts file and prompt user for manual verification */
|
|
|
|
|
|
|
|
if (!certificate_status)
|
|
|
|
{
|
|
|
|
char* issuer;
|
|
|
|
char* subject;
|
|
|
|
char* fingerprint;
|
|
|
|
boolean accept_certificate = false;
|
|
|
|
boolean verification_status = false;
|
2011-08-30 20:20:36 +04:00
|
|
|
|
2011-12-10 20:23:48 +04:00
|
|
|
issuer = crypto_cert_issuer(cert->px509);
|
|
|
|
subject = crypto_cert_subject(cert->px509);
|
|
|
|
fingerprint = crypto_cert_fingerprint(cert->px509);
|
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
/* search for matching entry in known_hosts file */
|
|
|
|
match = certificate_data_match(tls->certificate_store, certificate_data);
|
|
|
|
|
2012-02-03 03:20:02 +04:00
|
|
|
if (match == 1)
|
2011-08-29 00:46:36 +04:00
|
|
|
{
|
2012-02-05 00:04:03 +04:00
|
|
|
/* no entry was found in known_hosts file, prompt user for manual verification */
|
2011-12-10 20:23:48 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
freerdp* instance = (freerdp*) tls->settings->instance;
|
2011-10-19 11:42:53 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
if (!hostname_match)
|
|
|
|
tls_print_certificate_name_mismatch_error(hostname, common_name, alt_names, alt_names_count);
|
2011-10-19 11:42:53 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
if (instance->VerifyCertificate)
|
|
|
|
accept_certificate = instance->VerifyCertificate(instance, subject, issuer, fingerprint);
|
2011-10-18 19:02:05 +04:00
|
|
|
|
2011-12-10 20:23:48 +04:00
|
|
|
if (!accept_certificate)
|
2012-02-05 00:04:03 +04:00
|
|
|
{
|
|
|
|
/* user did not accept, abort and do not add entry in known_hosts file */
|
|
|
|
verification_status = false; /* failure! */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* user accepted certificate, add entry in known_hosts file */
|
|
|
|
certificate_data_print(tls->certificate_store, certificate_data);
|
|
|
|
verification_status = true; /* success! */
|
|
|
|
}
|
2011-08-29 00:46:36 +04:00
|
|
|
}
|
2012-02-03 03:20:02 +04:00
|
|
|
else if (match == -1)
|
2011-08-29 00:46:36 +04:00
|
|
|
{
|
2012-02-05 00:04:03 +04:00
|
|
|
/* entry was found in known_hosts file, but fingerprint does not match */
|
2012-02-03 03:20:02 +04:00
|
|
|
tls_print_certificate_error(hostname, fingerprint);
|
2012-02-05 00:04:03 +04:00
|
|
|
verification_status = false; /* failure! */
|
2011-08-29 00:46:36 +04:00
|
|
|
}
|
2012-02-05 00:04:03 +04:00
|
|
|
else if (match == 0)
|
|
|
|
{
|
|
|
|
verification_status = true; /* success! */
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree(issuer);
|
|
|
|
xfree(subject);
|
|
|
|
xfree(fingerprint);
|
|
|
|
|
|
|
|
return verification_status;
|
2011-08-29 00:46:36 +04:00
|
|
|
}
|
2011-08-30 20:20:36 +04:00
|
|
|
|
2012-02-05 00:04:03 +04:00
|
|
|
return false;
|
2011-08-29 00:46:36 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 03:20:02 +04:00
|
|
|
void tls_print_certificate_error(char* hostname, char* fingerprint)
|
2011-08-26 07:10:49 +04:00
|
|
|
{
|
2011-12-10 20:23:48 +04:00
|
|
|
printf("The host key for %s has changed\n", hostname);
|
|
|
|
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
|
|
|
|
printf("@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n");
|
|
|
|
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
|
|
|
|
printf("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n");
|
|
|
|
printf("Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n");
|
|
|
|
printf("It is also possible that a host key has just been changed.\n");
|
|
|
|
printf("The fingerprint for the host key sent by the remote host is\n%s\n", fingerprint);
|
|
|
|
printf("Please contact your system administrator.\n");
|
|
|
|
printf("Add correct host key in ~/.freerdp/known_hosts to get rid of this message.\n");
|
|
|
|
printf("Host key for %s has changed and you have requested strict checking.\n", hostname);
|
|
|
|
printf("Host key verification failed.\n");
|
2011-08-26 07:10:49 +04:00
|
|
|
}
|
2011-07-04 01:29:09 +04:00
|
|
|
|
2012-02-04 11:21:39 +04:00
|
|
|
void tls_print_certificate_name_mismatch_error(char* hostname, char* common_name, char** alt_names, int alt_names_count)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
|
|
|
|
printf("@ WARNING: CERTIFICATE NAME MISMATCH! @\n");
|
|
|
|
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
|
|
|
|
printf("The hostname used for this connection (%s) \n", hostname);
|
|
|
|
|
|
|
|
if (alt_names_count < 1)
|
|
|
|
{
|
|
|
|
printf("does not match the name given in the certificate:\n");
|
|
|
|
printf("%s\n", common_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("does not match the names given in the certificate:\n");
|
|
|
|
printf("%s", common_name);
|
|
|
|
|
|
|
|
for (index = 0; index < alt_names_count; index++)
|
|
|
|
{
|
|
|
|
printf(", %s", alt_names[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("A valid certificate for the wrong name should NOT be trusted!\n");
|
|
|
|
}
|
|
|
|
|
2012-02-03 03:20:02 +04:00
|
|
|
rdpTls* tls_new(rdpSettings* settings)
|
|
|
|
{
|
|
|
|
rdpTls* tls;
|
|
|
|
|
|
|
|
tls = (rdpTls*) xzalloc(sizeof(rdpTls));
|
|
|
|
|
|
|
|
if (tls != NULL)
|
|
|
|
{
|
|
|
|
SSL_load_error_strings();
|
|
|
|
SSL_library_init();
|
|
|
|
|
|
|
|
tls->settings = settings;
|
|
|
|
tls->certificate_store = certificate_store_new(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tls;
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:11:12 +04:00
|
|
|
void tls_free(rdpTls* tls)
|
2011-07-04 01:29:09 +04:00
|
|
|
{
|
|
|
|
if (tls != NULL)
|
|
|
|
{
|
2011-08-25 09:45:43 +04:00
|
|
|
if (tls->ssl)
|
|
|
|
SSL_free(tls->ssl);
|
2012-02-03 03:20:02 +04:00
|
|
|
|
2011-08-25 09:45:43 +04:00
|
|
|
if (tls->ctx)
|
|
|
|
SSL_CTX_free(tls->ctx);
|
2012-02-03 03:20:02 +04:00
|
|
|
|
2012-02-12 21:46:53 +04:00
|
|
|
freerdp_blob_free(&tls->public_key);
|
|
|
|
|
2012-02-03 03:20:02 +04:00
|
|
|
certificate_store_free(tls->certificate_store);
|
|
|
|
|
2011-07-04 01:29:09 +04:00
|
|
|
xfree(tls);
|
|
|
|
}
|
|
|
|
}
|