| 48 |
#define DEATTACK_DETECTED 1 |
#define DEATTACK_DETECTED 1 |
| 49 |
|
|
| 50 |
/* |
/* |
| 51 |
* $Id: crypt.c,v 1.9 2007-08-08 16:04:08 maya Exp $ Cryptographic attack |
* $Id: crypt.c,v 1.10 2007-08-13 22:30:03 maya Exp $ Cryptographic attack |
| 52 |
* detector for ssh - source code (C)1998 CORE-SDI, Buenos Aires Argentina |
* detector for ssh - source code (C)1998 CORE-SDI, Buenos Aires Argentina |
| 53 |
* Ariel Futoransky(futo@core-sdi.com) <http://www.core-sdi.com> |
* Ariel Futoransky(futo@core-sdi.com) <http://www.core-sdi.com> |
| 54 |
*/ |
*/ |
| 230 |
|
|
| 231 |
if (bytes % block_size) { |
if (bytes % block_size) { |
| 232 |
char tmp[80]; |
char tmp[80]; |
| 233 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_AES128_ENCRYPT_ERROR1", pvar, |
| 234 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "AES128 encrypt error(1): bytes %d (%d)", _TRUNCATE); |
"AES128 encrypt error(1): bytes %d (%d)"); |
|
UTIL_get_lang_msg("MSG_AES128_ENCRYPT_ERROR1", pvar); |
|
| 235 |
_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, |
_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, |
| 236 |
pvar->ts->UIMsg, bytes, block_size); |
pvar->ts->UIMsg, bytes, block_size); |
|
#else |
|
|
_snprintf(tmp, sizeof(tmp), "AES128 encrypt error(1): bytes %d (%d)", bytes, block_size); |
|
|
#endif |
|
| 237 |
notify_fatal_error(pvar, tmp); |
notify_fatal_error(pvar, tmp); |
| 238 |
goto error; |
goto error; |
| 239 |
} |
} |
| 240 |
|
|
| 241 |
if (EVP_Cipher(&pvar->evpcip[MODE_OUT], newbuf, buf, bytes) == 0) { |
if (EVP_Cipher(&pvar->evpcip[MODE_OUT], newbuf, buf, bytes) == 0) { |
| 242 |
// TODO: failure |
// TODO: failure |
| 243 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_AES128_ENCRYPT_ERROR2", pvar, |
| 244 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "AES128 encrypt error(1): bytes %d (%d)", _TRUNCATE); |
"AES128 encrypt error(1): bytes %d (%d)"); |
|
UTIL_get_lang_msg("MSG_AES128_ENCRYPT_ERROR2", pvar); |
|
| 245 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
#else |
|
|
notify_fatal_error(pvar, "AES128 encrypt error(2)"); |
|
|
#endif |
|
| 246 |
|
|
| 247 |
} else { |
} else { |
| 248 |
//memcpy(key, pvar->ssh2_keys[MODE_OUT].enc.key, AES128_KEYLEN); |
//memcpy(key, pvar->ssh2_keys[MODE_OUT].enc.key, AES128_KEYLEN); |
| 277 |
|
|
| 278 |
if (bytes % block_size) { |
if (bytes % block_size) { |
| 279 |
char tmp[80]; |
char tmp[80]; |
| 280 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_AES128_DECRYPT_ERROR1", pvar, |
| 281 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "AES128 decrypt error(1): bytes %d (%d)", _TRUNCATE); |
"AES128 decrypt error(1): bytes %d (%d)"); |
|
UTIL_get_lang_msg("MSG_AES128_DECRYPT_ERROR1", pvar); |
|
| 282 |
_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, pvar->ts->UIMsg, bytes, block_size); |
_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, pvar->ts->UIMsg, bytes, block_size); |
|
#else |
|
|
_snprintf(tmp, sizeof(tmp), "AES128 decrypt error(1): bytes %d (%d)", bytes, block_size); |
|
|
#endif |
|
| 283 |
notify_fatal_error(pvar, tmp); |
notify_fatal_error(pvar, tmp); |
| 284 |
goto error; |
goto error; |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
if (EVP_Cipher(&pvar->evpcip[MODE_IN], newbuf, buf, bytes) == 0) { |
if (EVP_Cipher(&pvar->evpcip[MODE_IN], newbuf, buf, bytes) == 0) { |
| 288 |
// TODO: |
// TODO: |
| 289 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_AES128_DECRYPT_ERROR2", pvar, |
| 290 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "AES128 decrypt error(2)", _TRUNCATE); |
"AES128 decrypt error(2)"); |
|
UTIL_get_lang_msg("MSG_AES128_DECRYPT_ERROR2", pvar); |
|
| 291 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
#else |
|
|
notify_fatal_error(pvar, "AES128 decrypt error(2)"); |
|
|
#endif |
|
| 292 |
|
|
| 293 |
} else { |
} else { |
| 294 |
#if 0 |
#if 0 |
| 585 |
} |
} |
| 586 |
|
|
| 587 |
if (key == NULL || key->e == NULL || key->n == NULL) { |
if (key == NULL || key->e == NULL || key->n == NULL) { |
| 588 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_RSAKEY_SETUP_ERROR", pvar, |
| 589 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "Error setting up RSA keys", _TRUNCATE); |
"Error setting up RSA keys"); |
|
UTIL_get_lang_msg("MSG_RSAKEY_SETUP_ERROR", pvar); |
|
| 590 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
#else |
|
|
notify_fatal_error(pvar, "Error setting up RSA keys"); |
|
|
#endif |
|
| 591 |
|
|
| 592 |
if (key != NULL) { |
if (key != NULL) { |
| 593 |
if (key->e != NULL) { |
if (key->e != NULL) { |
| 663 |
pvar->crypt_state.supported_receiver_ciphers = receiver_ciphers; |
pvar->crypt_state.supported_receiver_ciphers = receiver_ciphers; |
| 664 |
|
|
| 665 |
if (sender_ciphers == 0) { |
if (sender_ciphers == 0) { |
| 666 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_UNAVAILABLE_CIPHERS_ERROR", pvar, |
| 667 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), |
"The server does not support any of the TTSSH encryption algorithms.\n" |
| 668 |
"The server does not support any of the TTSSH encryption algorithms.\n" |
"A secure connection cannot be made in the TTSSH-to-server direction.\n" |
| 669 |
"A secure connection cannot be made in the TTSSH-to-server direction.\n" |
"The connection will be closed."); |
|
"The connection will be closed.", |
|
|
_TRUNCATE); |
|
|
UTIL_get_lang_msg("MSG_UNAVAILABLE_CIPHERS_ERROR", pvar); |
|
| 670 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
|
|
|
#else |
|
|
notify_fatal_error(pvar, |
|
|
"The server does not support any of the TTSSH encryption algorithms.\n" |
|
|
"A secure connection cannot be made in the TTSSH-to-server direction.\n" |
|
|
"The connection will be closed."); |
|
|
#endif |
|
| 671 |
return FALSE; |
return FALSE; |
| 672 |
} else if (receiver_ciphers == 0) { |
} else if (receiver_ciphers == 0) { |
| 673 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_UNAVAILABLE_CIPHERS_ERROR", pvar, |
| 674 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), |
"The server does not support any of the TTSSH encryption algorithms.\n" |
| 675 |
"The server does not support any of the TTSSH encryption algorithms.\n" |
"A secure connection cannot be made in the TTSSH-to-server direction.\n" |
| 676 |
"A secure connection cannot be made in the TTSSH-to-server direction.\n" |
"The connection will be closed."); |
|
"The connection will be closed.", |
|
|
_TRUNCATE); |
|
|
UTIL_get_lang_msg("MSG_UNAVAILABLE_CIPHERS_ERROR", pvar); |
|
| 677 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
|
|
|
#else |
|
|
notify_fatal_error(pvar, |
|
|
"The server does not support any of the TTSSH encryption algorithms.\n" |
|
|
"A secure connection cannot be made in the server-to-TTSSH direction.\n" |
|
|
"The connection will be closed."); |
|
|
#endif |
|
| 678 |
return FALSE; |
return FALSE; |
| 679 |
} else { |
} else { |
| 680 |
return TRUE; |
return TRUE; |
| 841 |
|
|
| 842 |
if (pvar->crypt_state.sender_cipher == SSH_CIPHER_NONE |
if (pvar->crypt_state.sender_cipher == SSH_CIPHER_NONE |
| 843 |
|| pvar->crypt_state.receiver_cipher == SSH_CIPHER_NONE) { |
|| pvar->crypt_state.receiver_cipher == SSH_CIPHER_NONE) { |
| 844 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_CHIPHER_NONE_ERROR", pvar, |
| 845 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), |
"All the encryption algorithms that this program and the server both understand have been disabled.\n" |
| 846 |
"All the encryption algorithms that this program and the server both understand have been disabled.\n" |
"To communicate with this server, you will have to enable some more ciphers\n" |
| 847 |
"To communicate with this server, you will have to enable some more ciphers\n" |
"in the TTSSH Setup dialog box when you run Teraterm again.\n" |
| 848 |
"in the TTSSH Setup dialog box when you run Teraterm again.\n" |
"This connection will now close."); |
|
"This connection will now close.", |
|
|
_TRUNCATE); |
|
|
UTIL_get_lang_msg("MSG_CHIPHER_NONE_ERROR", pvar); |
|
| 849 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
#else |
|
|
notify_fatal_error(pvar, |
|
|
"All the encryption algorithms that this program and the server both understand have been disabled.\n" |
|
|
"To communicate with this server, you will have to enable some more ciphers\n" |
|
|
"in the TTSSH Setup dialog box when you run Teraterm again.\n" |
|
|
"This connection will now close."); |
|
|
#endif |
|
| 850 |
return FALSE; |
return FALSE; |
| 851 |
} else { |
} else { |
| 852 |
return TRUE; |
return TRUE; |
| 888 |
} |
} |
| 889 |
|
|
| 890 |
if (bit_delta < 128 || server_key_bits < 512 || host_key_bits < 512) { |
if (bit_delta < 128 || server_key_bits < 512 || host_key_bits < 512) { |
| 891 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_RASKEY_TOOWEAK_ERROR", pvar, |
| 892 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), |
"Server RSA keys are too weak. A secure connection cannot be established."); |
|
"Server RSA keys are too weak. A secure connection cannot be established.", |
|
|
_TRUNCATE); |
|
|
UTIL_get_lang_msg("MSG_RASKEY_TOOWEAK_ERROR", pvar); |
|
| 893 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
#else |
|
|
notify_fatal_error(pvar, |
|
|
"Server RSA keys are too weak. A secure connection cannot be established."); |
|
|
#endif |
|
| 894 |
return 0; |
return 0; |
| 895 |
} else { |
} else { |
| 896 |
/* following Goldberg's code, I'm using MD5(servkey->n || hostkey->n || cookie) |
/* following Goldberg's code, I'm using MD5(servkey->n || hostkey->n || cookie) |
| 1228 |
|
|
| 1229 |
|
|
| 1230 |
if (!isOK) { |
if (!isOK) { |
| 1231 |
#ifndef NO_I18N |
UTIL_get_lang_msg("MSG_CHPHER_NOTSELECTED_ERROR", pvar, |
| 1232 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "No cipher selected!", _TRUNCATE); |
"No cipher selected!"); |
|
UTIL_get_lang_msg("MSG_CHPHER_NOTSELECTED_ERROR", pvar); |
|
| 1233 |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
notify_fatal_error(pvar, pvar->ts->UIMsg); |
|
#else |
|
|
notify_fatal_error(pvar, "No cipher selected!"); /* should never get here! */ |
|
|
#endif |
|
| 1234 |
return FALSE; |
return FALSE; |
| 1235 |
} else { |
} else { |
| 1236 |
memset(encryption_key, 0, CRYPT_KEY_LENGTH); |
memset(encryption_key, 0, CRYPT_KEY_LENGTH); |
| 1282 |
|
|
| 1283 |
void CRYPT_get_cipher_info(PTInstVar pvar, char FAR * dest, int len) |
void CRYPT_get_cipher_info(PTInstVar pvar, char FAR * dest, int len) |
| 1284 |
{ |
{ |
| 1285 |
#ifndef NO_I18N |
UTIL_get_lang_msg("DLG_ABOUT_CIPHER_INFO", pvar, |
| 1286 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "%s to server, %s from server", _TRUNCATE); |
"%s to server, %s from server"); |
|
UTIL_get_lang_msg("DLG_ABOUT_CIPHER_INFO", pvar); |
|
| 1287 |
_snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, |
_snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, |
| 1288 |
get_cipher_name(pvar->crypt_state.sender_cipher), |
get_cipher_name(pvar->crypt_state.sender_cipher), |
| 1289 |
get_cipher_name(pvar->crypt_state.receiver_cipher)); |
get_cipher_name(pvar->crypt_state.receiver_cipher)); |
|
#else |
|
|
_snprintf(dest, len, "%s to server, %s from server", |
|
|
get_cipher_name(pvar->crypt_state.sender_cipher), |
|
|
get_cipher_name(pvar->crypt_state.receiver_cipher)); |
|
|
#endif |
|
|
dest[len - 1] = 0; |
|
| 1290 |
} |
} |
| 1291 |
|
|
| 1292 |
void CRYPT_get_server_key_info(PTInstVar pvar, char FAR * dest, int len) |
void CRYPT_get_server_key_info(PTInstVar pvar, char FAR * dest, int len) |
| 1294 |
if (SSHv1(pvar)) { |
if (SSHv1(pvar)) { |
| 1295 |
if (pvar->crypt_state.server_key.RSA_key == NULL |
if (pvar->crypt_state.server_key.RSA_key == NULL |
| 1296 |
|| pvar->crypt_state.host_key.RSA_key == NULL) { |
|| pvar->crypt_state.host_key.RSA_key == NULL) { |
| 1297 |
#ifndef NO_I18N |
UTIL_get_lang_msg("DLG_ABOUT_KEY_NONE", pvar, "None"); |
|
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "None", _TRUNCATE); |
|
|
UTIL_get_lang_msg("DLG_ABOUT_KEY_NONE", pvar); |
|
| 1298 |
strncpy_s(dest, len, pvar->ts->UIMsg, _TRUNCATE); |
strncpy_s(dest, len, pvar->ts->UIMsg, _TRUNCATE); |
|
#else |
|
|
strncpy(dest, "None", len); |
|
|
#endif |
|
| 1299 |
} else { |
} else { |
| 1300 |
#ifndef NO_I18N |
UTIL_get_lang_msg("DLG_ABOUT_KEY_INFO", pvar, |
| 1301 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "%d-bit server key, %d-bit host key", _TRUNCATE); |
"%d-bit server key, %d-bit host key"); |
|
UTIL_get_lang_msg("DLG_ABOUT_KEY_INFO", pvar); |
|
| 1302 |
_snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, |
_snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, |
| 1303 |
BN_num_bits(pvar->crypt_state.server_key.RSA_key->n), |
BN_num_bits(pvar->crypt_state.server_key.RSA_key->n), |
| 1304 |
BN_num_bits(pvar->crypt_state.host_key.RSA_key->n)); |
BN_num_bits(pvar->crypt_state.host_key.RSA_key->n)); |
|
#else |
|
|
_snprintf(dest, len, "%d-bit server key, %d-bit host key", |
|
|
BN_num_bits(pvar->crypt_state.server_key.RSA_key->n), |
|
|
BN_num_bits(pvar->crypt_state.host_key.RSA_key->n)); |
|
|
#endif |
|
| 1305 |
} |
} |
|
|
|
| 1306 |
} else { // SSH2 |
} else { // SSH2 |
| 1307 |
#ifndef NO_I18N |
UTIL_get_lang_msg("DLG_ABOUT_KEY_INFO", pvar, |
| 1308 |
strncpy_s(pvar->ts->UIMsg, sizeof(pvar->ts->UIMsg), "%d-bit server key, %d-bit host key", _TRUNCATE); |
"%d-bit server key, %d-bit host key"); |
|
UTIL_get_lang_msg("DLG_ABOUT_KEY_INFO", pvar); |
|
| 1309 |
_snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, |
_snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, |
| 1310 |
pvar->server_key_bits, |
pvar->server_key_bits, |
| 1311 |
pvar->client_key_bits); |
pvar->client_key_bits); |
|
#else |
|
|
_snprintf(dest, len, "%d-bit server key, %d-bit host key", |
|
|
pvar->server_key_bits, |
|
|
pvar->client_key_bits); |
|
|
#endif |
|
|
|
|
| 1312 |
} |
} |
|
|
|
|
dest[len - 1] = 0; |
|
| 1313 |
} |
} |
| 1314 |
|
|
| 1315 |
static void destroy_public_key(CRYPTPublicKey FAR * key) |
static void destroy_public_key(CRYPTPublicKey FAR * key) |
| 1443 |
|
|
| 1444 |
/* |
/* |
| 1445 |
* $Log: not supported by cvs2svn $ |
* $Log: not supported by cvs2svn $ |
| 1446 |
|
* Revision 1.9 2007/08/08 16:04:08 maya |
| 1447 |
|
* 安全な関数を使用するように変更した。 |
| 1448 |
|
* |
| 1449 |
* Revision 1.8 2007/06/06 14:10:12 maya |
* Revision 1.8 2007/06/06 14:10:12 maya |
| 1450 |
* プリプロセッサにより構造体が変わってしまうので、INET6 と I18N の #define を逆転させた。 |
* プリプロセッサにより構造体が変わってしまうので、INET6 と I18N の #define を逆転させた。 |
| 1451 |
* |
* |