Changeset 4623
- Timestamp:
- 02/14/07 17:39:11 (2 years ago)
- Files:
-
- libwired/trunk/libwired/base/wi-assert.c (modified) (1 diff)
- libwired/trunk/libwired/base/wi-base.c (modified) (3 diffs)
- libwired/trunk/libwired/base/wi-error.c (modified) (2 diffs)
- libwired/trunk/libwired/base/wi-private.h (modified) (3 diffs)
- libwired/trunk/libwired/base/wi-tests.c (modified) (1 diff)
- libwired/trunk/libwired/base/wi-version.c (modified) (1 diff)
- libwired/trunk/libwired/collections/wi-array.c (modified) (1 diff)
- libwired/trunk/libwired/collections/wi-enumerator.c (modified) (1 diff)
- libwired/trunk/libwired/collections/wi-hash.c (modified) (2 diffs)
- libwired/trunk/libwired/collections/wi-set.c (modified) (1 diff)
- libwired/trunk/libwired/data/wi-data.c (modified) (5 diffs)
- libwired/trunk/libwired/data/wi-data.h (modified) (2 diffs)
- libwired/trunk/libwired/data/wi-number.c (modified) (1 diff)
- libwired/trunk/libwired/data/wi-regexp.c (modified) (1 diff)
- libwired/trunk/libwired/data/wi-settings.c (modified) (1 diff)
- libwired/trunk/libwired/data/wi-string.c (modified) (3 diffs)
- libwired/trunk/libwired/data/wi-string.h (modified) (1 diff)
- libwired/trunk/libwired/data/wi-url.c (modified) (1 diff)
- libwired/trunk/libwired/file/wi-file.c (modified) (2 diffs)
- libwired/trunk/libwired/net/wi-address.c (modified) (1 diff)
- libwired/trunk/libwired/net/wi-ip.c (modified) (1 diff)
- libwired/trunk/libwired/net/wi-socket.c (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-base.h (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-crypto.c (added)
- libwired/trunk/libwired/p7/wi-p7-crypto.h (added)
- libwired/trunk/libwired/p7/wi-p7-message.c (modified) (2 diffs)
- libwired/trunk/libwired/p7/wi-p7-message.h (modified) (2 diffs)
- libwired/trunk/libwired/p7/wi-p7-private.h (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-socket.c (modified) (26 diffs)
- libwired/trunk/libwired/p7/wi-p7-socket.h (modified) (4 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.c (modified) (16 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.h (modified) (1 diff)
- libwired/trunk/libwired/system/wi-log.c (modified) (1 diff)
- libwired/trunk/libwired/system/wi-process.c (modified) (1 diff)
- libwired/trunk/libwired/system/wi-terminal.c (modified) (1 diff)
- libwired/trunk/libwired/thread/wi-lock.c (modified) (5 diffs)
- libwired/trunk/libwired/thread/wi-thread.c (modified) (1 diff)
- libwired/trunk/libwired/thread/wi-timer.c (modified) (1 diff)
- libwired/trunk/libwired/wired.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/base/wi-assert.c
r4540 r4623 38 38 39 39 40 40 41 static void wi_assert_default_handler(wi_string_t *file, wi_uinteger_t line, wi_string_t *fmt, ...) { 41 42 wi_string_t *string; libwired/trunk/libwired/base/wi-base.c
r4590 r4623 51 51 52 52 53 53 54 void wi_initialize(void) { 54 55 wi_runtime_register(); … … 69 70 70 71 #ifdef WI_P7 72 wi_p7_crypto_register(); 71 73 wi_p7_message_register(); 72 74 wi_p7_socket_register(); … … 119 121 120 122 #ifdef WI_P7 123 wi_p7_crypto_initialize(); 121 124 wi_p7_message_initialize(); 122 125 wi_p7_socket_initialize(); libwired/trunk/libwired/base/wi-error.c
r4601 r4623 139 139 140 140 141 141 142 void wi_error_register(void) { 142 143 _wi_error_runtime_id = wi_runtime_register_class(&_wi_error_runtime_class); … … 148 149 #ifdef WI_SSL 149 150 SSL_load_error_strings(); 151 #endif 152 153 #ifdef WI_CRYPTO 154 ERR_load_crypto_strings(); 150 155 #endif 151 156 } libwired/trunk/libwired/base/wi-private.h
r4590 r4623 42 42 typedef void * wi_enumerator_func_t(wi_runtime_instance_t *, void *); 43 43 44 44 45 WI_EXPORT void wi_address_register(void); 45 46 WI_EXPORT void wi_array_register(void); … … 54 55 WI_EXPORT void wi_log_register(void); 55 56 WI_EXPORT void wi_number_register(void); 57 WI_EXPORT void wi_p7_crypto_register(void); 56 58 WI_EXPORT void wi_p7_message_register(void); 57 59 WI_EXPORT void wi_p7_socket_register(void); … … 85 87 WI_EXPORT void wi_log_initialize(void); 86 88 WI_EXPORT void wi_number_initialize(void); 89 WI_EXPORT void wi_p7_crypto_initialize(void); 87 90 WI_EXPORT void wi_p7_message_initialize(void); 88 91 WI_EXPORT void wi_p7_socket_initialize(void); libwired/trunk/libwired/base/wi-tests.c
r4562 r4623 75 75 76 76 77 77 78 void wi_test_register(void) { 78 79 _wi_test_runtime_id = wi_runtime_register_class(&_wi_test_runtime_class); libwired/trunk/libwired/base/wi-version.c
r4511 r4623 35 35 36 36 37 37 38 void wi_version_register(void) { 38 39 } libwired/trunk/libwired/collections/wi-array.c
r4575 r4623 151 151 _wi_array_hash 152 152 }; 153 153 154 154 155 libwired/trunk/libwired/collections/wi-enumerator.c
r4575 r4623 84 84 NULL 85 85 }; 86 86 87 87 88 libwired/trunk/libwired/collections/wi-hash.c
r4575 r4623 186 186 187 187 188 188 189 void wi_hash_register(void) { 189 190 _wi_hash_runtime_id = wi_runtime_register_class(&_wi_hash_runtime_class); … … 642 643 static void _wi_hash_bucket_remove(wi_hash_t *hash, _wi_hash_bucket_t *bucket) { 643 644 _WI_HASH_KEY_RELEASE(hash, bucket->key); 644 _WI_HASH_ KEY_RELEASE(hash, bucket->data);645 _WI_HASH_VALUE_RELEASE(hash, bucket->data); 645 646 646 647 bucket->link = hash->bucket_free_list; libwired/trunk/libwired/collections/wi-set.c
r4575 r4623 149 149 150 150 151 151 152 void wi_set_register(void) { 152 153 _wi_set_runtime_id = wi_runtime_register_class(&_wi_set_runtime_class); libwired/trunk/libwired/data/wi-data.c
r4610 r4623 54 54 wi_uinteger_t length; 55 55 wi_uinteger_t capacity; 56 wi_boolean_t free; 56 57 }; 57 58 … … 103 104 104 105 106 wi_data_t * wi_data_with_bytes(const void *bytes, wi_uinteger_t length) { 107 return wi_autorelease(wi_data_init_with_bytes(wi_data_alloc(), bytes, length)); 108 } 109 110 111 112 wi_data_t * wi_data_with_bytes_no_copy(void *bytes, wi_uinteger_t length, wi_boolean_t free) { 113 return wi_autorelease(wi_data_init_with_bytes_no_copy(wi_data_alloc(), bytes, length, free)); 114 } 115 116 117 105 118 wi_data_t * wi_data_with_random_bytes(wi_uinteger_t length) { 106 119 return wi_autorelease(wi_data_init_with_random_bytes(wi_data_alloc(), length)); … … 132 145 data->capacity = WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_DATA_MIN_SIZE); 133 146 data->bytes = wi_malloc(data->capacity); 147 data->free = true; 134 148 135 149 return data; … … 142 156 143 157 memcpy(data->bytes, bytes, length); 158 144 159 data->length = length; 160 161 return data; 162 } 163 164 165 166 wi_data_t * wi_data_init_with_bytes_no_copy(wi_data_t *data, void *bytes, wi_uinteger_t length, wi_boolean_t free) { 167 data->bytes = bytes; 168 data->capacity = length; 169 data->length = length; 170 data->free = free; 145 171 146 172 return data; … … 268 294 wi_data_t *data = instance; 269 295 270 wi_free(data->bytes); 296 if(data->free) 297 wi_free(data->bytes); 271 298 } 272 299 libwired/trunk/libwired/data/wi-data.h
r4610 r4623 39 39 40 40 WI_EXPORT wi_data_t * wi_data(void); 41 WI_EXPORT wi_data_t * wi_data_with_bytes(const void *, wi_uinteger_t); 42 WI_EXPORT wi_data_t * wi_data_with_bytes_no_copy(void *, wi_uinteger_t, wi_boolean_t); 43 WI_EXPORT wi_data_t * wi_data_with_random_bytes(wi_uinteger_t); 41 44 WI_EXPORT wi_data_t * wi_data_with_base64(wi_string_t *); 42 WI_EXPORT wi_data_t * wi_data_with_random_bytes(wi_uinteger_t);43 45 44 46 WI_EXPORT wi_data_t * wi_data_alloc(void); … … 46 48 WI_EXPORT wi_data_t * wi_data_init_with_capacity(wi_data_t *, wi_uinteger_t); 47 49 WI_EXPORT wi_data_t * wi_data_init_with_bytes(wi_data_t *, const void *, wi_uinteger_t); 50 WI_EXPORT wi_data_t * wi_data_init_with_bytes_no_copy(wi_data_t *, void *, wi_uinteger_t, wi_boolean_t); 48 51 WI_EXPORT wi_data_t * wi_data_init_with_random_bytes(wi_data_t *, wi_uinteger_t); 49 52 WI_EXPORT wi_data_t * wi_data_init_with_base64(wi_data_t *, wi_string_t *); libwired/trunk/libwired/data/wi-number.c
r4575 r4623 104 104 105 105 106 106 107 void wi_number_register(void) { 107 108 _wi_number_runtime_id = wi_runtime_register_class(&_wi_number_runtime_class); libwired/trunk/libwired/data/wi-regexp.c
r4511 r4623 72 72 73 73 74 74 75 void wi_regexp_register(void) { 75 76 _wi_regexp_runtime_id = wi_runtime_register_class(&_wi_regexp_runtime_class); libwired/trunk/libwired/data/wi-settings.c
r4511 r4623 103 103 104 104 105 105 106 void wi_settings_register(void) { 106 107 _wi_settings_runtime_id = wi_runtime_register_class(&_wi_settings_runtime_class); libwired/trunk/libwired/data/wi-string.c
r4617 r4623 158 158 159 159 160 160 161 void wi_string_register(void) { 161 162 _wi_string_runtime_id = wi_runtime_register_class(&_wi_string_runtime_class); … … 218 219 219 220 221 wi_string_t * wi_string_with_data(wi_data_t *data) { 222 return wi_autorelease(wi_string_init_with_data(wi_string_alloc(), data)); 223 } 224 225 226 220 227 wi_string_t * wi_string_with_bytes(const void *buffer, wi_uinteger_t size) { 221 228 return wi_autorelease(wi_string_init_with_bytes(wi_string_alloc(), buffer, size)); … … 327 334 328 335 wi_string_t * wi_string_init_with_contents_of_file(wi_string_t *string, wi_string_t *path) { 329 wi_file_t *file; 330 331 file = wi_file_for_reading(path); 332 333 if(!file) { 334 wi_release(string); 335 336 return NULL; 337 } 338 339 return wi_file_read_to_end_of_file(file); 336 wi_file_t *file; 337 338 wi_release(string); 339 340 file = wi_file_for_reading(path); 341 342 if(!file) 343 return NULL; 344 345 return wi_retain(wi_file_read_to_end_of_file(file)); 340 346 } 341 347 libwired/trunk/libwired/data/wi-string.h
r4617 r4623 56 56 WI_EXPORT wi_string_t * wi_string_with_cstring(const char *); 57 57 WI_EXPORT wi_string_t * wi_string_with_format(wi_string_t *, ...); 58 WI_EXPORT wi_string_t * wi_string_with_data(wi_data_t *); 58 59 WI_EXPORT wi_string_t * wi_string_with_bytes(const void *, wi_uinteger_t); 59 60 libwired/trunk/libwired/data/wi-url.c
r4511 r4623 75 75 76 76 77 77 78 void wi_url_register(void) { 78 79 _wi_url_runtime_id = wi_runtime_register_class(&_wi_url_runtime_class); libwired/trunk/libwired/file/wi-file.c
r4617 r4623 109 109 110 110 111 111 112 void wi_file_register(void) { 112 113 _wi_file_runtime_id = wi_runtime_register_class(&_wi_file_runtime_class); … … 789 790 wi_string_append_bytes(string, buffer, bytes); 790 791 791 if(bytes <= 0) {792 wi_release(string);793 794 string = NULL;795 }796 797 792 return wi_autorelease(string); 798 793 } libwired/trunk/libwired/net/wi-address.c
r4575 r4623 100 100 101 101 102 102 103 void wi_address_register(void) { 103 104 _wi_address_runtime_id = wi_runtime_register_class(&_wi_address_runtime_class); libwired/trunk/libwired/net/wi-ip.c
r4437 r4623 52 52 53 53 54 54 55 wi_uinteger_t wi_ip_version(wi_string_t *ip) { 55 56 struct sockaddr_in sa_in; libwired/trunk/libwired/net/wi-socket.c
r4590 r4623 143 143 NULL 144 144 }; 145 145 146 146 147 libwired/trunk/libwired/p7/wi-p7-base.h
r4578 r4623 34 34 typedef struct _wi_p7_spec wi_p7_spec_t; 35 35 36 #endif 36 #endif /* WI_ARRAY_H */ libwired/trunk/libwired/p7/wi-p7-message.c
r4614 r4623 94 94 #pragma mark - 95 95 96 wi_p7_message_t * wi_p7_message_with_name(wi_string_t *message_name, wi_p7_socket_t *p7_socket) { 97 return wi_autorelease(wi_p7_message_init_with_name(wi_p7_message_alloc(), message_name, p7_socket)); 98 } 99 100 101 102 #pragma mark - 103 96 104 wi_p7_message_t * wi_p7_message_alloc(void) { 97 105 return wi_runtime_create_instance(_wi_p7_message_runtime_id, sizeof(wi_p7_message_t)); … … 208 216 wi_string_append_string(description, WI_STR(")}")); 209 217 210 return description;218 return wi_autorelease(description); 211 219 } 212 220 libwired/trunk/libwired/p7/wi-p7-message.h
r4601 r4623 74 74 WI_EXPORT wi_runtime_id_t wi_p7_message_runtime_id(void); 75 75 76 WI_EXPORT wi_p7_message_t * wi_p7_message_with_name(wi_string_t *, wi_p7_socket_t *); 77 76 78 WI_EXPORT wi_p7_message_t * wi_p7_message_alloc(void); 77 79 WI_EXPORT wi_p7_message_t * wi_p7_message_init_with_name(wi_p7_message_t *, wi_string_t *, wi_p7_socket_t *); … … 108 110 WI_EXPORT wi_date_t * wi_p7_message_date_for_name(wi_p7_message_t *, wi_string_t *); 109 111 110 #endif 112 #endif /* WI_ARRAY_H */ libwired/trunk/libwired/p7/wi-p7-private.h
r4614 r4623 66 66 WI_EXPORT wi_integer_t wi_p7_xml_integer_for_attribute(xmlNodePtr, wi_string_t *); 67 67 68 #endif 68 #endif /* WI_ARRAY_H */ libwired/trunk/libwired/p7/wi-p7-socket.c
r4620 r4623 34 34 #include <wired/wi-log.h> 35 35 #include <wired/wi-p7-base.h> 36 #include <wired/wi-p7-crypto.h> 36 37 #include <wired/wi-p7-message.h> 37 38 #include <wired/wi-p7-socket.h> … … 57 58 #define _WI_P7_SOCKET_BINARY_MAGIC_LENGTH 52 58 59 59 #define _WI_P7_SOCKET_OPTIONS_ENCRYPTION_ENABLED(options) \ 60 (((options) & WI_P7_ENCRYPTION_RSA_AES) || ((options) & WI_P7_ENCRYPTION_RSA_BF)) 60 #define _WI_P7_SOCKET_OPTIONS_ENCRYPTION_ENABLED(options) \ 61 (((options) & WI_P7_ENCRYPTION_RSA_AES_256) || \ 62 ((options) & WI_P7_ENCRYPTION_RSA_BF_128)) 61 63 62 64 … … 72 74 73 75 wi_boolean_t encryption_enabled; 74 EVP_PKEY *private_key; 75 EVP_PKEY *public_key; 76 RSA *rsa_key; 77 const EVP_CIPHER *cipher; 78 EVP_CIPHER_CTX cipher_ctx; 76 wi_p7_rsa_t *rsa; 77 wi_p7_cipher_t *cipher; 79 78 80 79 wi_boolean_t compression_enabled; … … 91 90 _WI_P7_SOCKET_DECOMPRESS, 92 91 }; 93 typedef enum _wi_p7_socket_compression _wi_p7_socket_compression_t; 94 95 96 static void _wi_p7_socket_dealloc(wi_runtime_instance_t *); 97 static wi_string_t * _wi_p7_socket_description(wi_runtime_instance_t *); 98 99 static wi_boolean_t _wi_p7_socket_connect_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_p7_options_t); 100 static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_p7_options_t); 101 static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *, wi_string_t *); 102 static wi_boolean_t _wi_p7_socket_accept_key_exchange(wi_p7_socket_t *, wi_time_interval_t); 103 static wi_boolean_t _wi_p7_socket_send_compatibility_check(wi_p7_socket_t *, wi_time_interval_t); 104 static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *, wi_time_interval_t); 105 static const EVP_CIPHER * _wi_p7_socket_cipher(wi_p7_socket_t *); 106 static void _wi_p7_socket_configure_cipher_ctx(wi_p7_socket_t *); 107 static wi_boolean_t _wi_p7_socket_public_encrypt_buffer(wi_p7_socket_t *, const void *, uint32_t, void **, uint32_t *); 108 static wi_boolean_t _wi_p7_socket_public_decrypt_buffer(wi_p7_socket_t *, const void *, uint32_t, void **, uint32_t *); 109 static wi_boolean_t _wi_p7_socket_private_encrypt_buffer(wi_p7_socket_t *, const void *, uint32_t, void **, uint32_t *); 110 static wi_boolean_t _wi_p7_socket_private_decrypt_buffer(wi_p7_socket_t *, const void *, uint32_t, void **, uint32_t *); 111 static wi_boolean_t _wi_p7_socket_configure_compression_streams(wi_p7_socket_t *); 112 static wi_boolean_t _wi_p7_socket_xcompress_buffer(wi_p7_socket_t *, _wi_p7_socket_compression_t, const void *, uint32_t, void **, uint32_t *); 113 static int _wi_p7_socket_xflate_buffer(z_stream *, _wi_p7_socket_compression_t, const void *, uint32_t, uint32_t *, void *, uint32_t *); 114 static wi_p7_message_t * _wi_p7_socket_read_binary_message(wi_p7_socket_t *, wi_time_interval_t, uint32_t); 115 static wi_p7_message_t * _wi_p7_socket_read_xml_message(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *); 116 117 118 wi_p7_socket_password_provider_func_t *wi_p7_socket_password_provider = NULL; 119 120 static wi_runtime_id_t _wi_p7_socket_runtime_id = WI_RUNTIME_ID_NULL; 121 static wi_runtime_class_t _wi_p7_socket_runtime_class = { 92 typedef enum _wi_p7_socket_compression _wi_p7_socket_compression_t; 93 94 95 static void _wi_p7_socket_dealloc(wi_runtime_instance_t *); 96 static wi_string_t * _wi_p7_socket_description(wi_runtime_instance_t *); 97 98 static wi_boolean_t _wi_p7_socket_connect_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_p7_options_t); 99 static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_p7_options_t); 100 static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *, wi_string_t *); 101 static wi_boolean_t _wi_p7_socket_accept_key_exchange(wi_p7_socket_t *, wi_time_interval_t); 102 static wi_boolean_t _wi_p7_socket_send_compatibility_check(wi_p7_socket_t *, wi_time_interval_t); 103 static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *, wi_time_interval_t); 104 static wi_p7_cipher_type_t _wi_p7_socket_cipher(wi_p7_socket_t *); 105 static wi_boolean_t _wi_p7_socket_configure_compression_streams(wi_p7_socket_t *); 106 static wi_boolean_t _wi_p7_socket_xcompress_buffer(wi_p7_socket_t *, _wi_p7_socket_compression_t, const void *, uint32_t, void **, uint32_t *); 107 static int _wi_p7_socket_xflate_buffer(z_stream *, _wi_p7_socket_compression_t, const void *, uint32_t, uint32_t *, void *, uint32_t *); 108 static wi_p7_message_t * _wi_p7_socket_read_binary_message(wi_p7_socket_t *, wi_time_interval_t, uint32_t); 109 static wi_p7_message_t * _wi_p7_socket_read_xml_message(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *); 110 111 112 wi_p7_socket_password_provider_func_t *wi_p7_socket_password_provider = NULL; 113 114 static wi_runtime_id_t _wi_p7_socket_runtime_id = WI_RUNTIME_ID_NULL; 115 static wi_runtime_class_t _wi_p7_socket_runtime_class = { 122 116 "wi_p7_socket_t", 123 117 _wi_p7_socket_dealloc, … … 179 173 180 174 wi_release(p7_socket->socket); 181 182 if(p7_socket->private_key) 183 EVP_PKEY_free(p7_socket->private_key); 184 185 if(p7_socket->public_key) 186 EVP_PKEY_free(p7_socket->public_key); 187 188 if(p7_socket->rsa_key) 189 RSA_free(p7_socket->rsa_key); 175 wi_release(p7_socket->rsa); 176 wi_release(p7_socket->cipher); 190 177 } 191 178 … … 206 193 #pragma mark - 207 194 208 void wi_p7_socket_set_private_key(wi_p7_socket_t *p7_socket, void *key) { 209 if(EVP_PKEY_type(((EVP_PKEY *) key)->type) != EVP_PKEY_RSA) 210 wi_log_warn(WI_STR("private key must be RSA")); 211 212 p7_socket->private_key = key; 213 p7_socket->rsa_key = EVP_PKEY_get1_RSA(p7_socket->private_key); 214 } 215 216 217 218 void * wi_p7_socket_private_key(wi_p7_socket_t *p7_socket) { 219 return p7_socket->private_key; 195 void wi_p7_socket_set_private_rsa(wi_p7_socket_t *p7_socket, wi_p7_rsa_t *p7_rsa) { 196 wi_retain(p7_rsa); 197 wi_release(p7_socket->rsa); 198 199 p7_socket->rsa = p7_rsa; 200 } 201 202 203 204 wi_p7_rsa_t * wi_p7_socket_private_rsa(wi_p7_socket_t *p7_socket) { 205 return p7_socket->rsa; 220 206 } 221 207 … … 256 242 wi_p7_uint32_t compression, encryption; 257 243 258 p7_message = wi_ autorelease(wi_p7_message_init_with_name(wi_p7_message_alloc(), WI_STR("p7.handshake"), p7_socket));244 p7_message = wi_p7_message_with_name(WI_STR("p7.handshake"), p7_socket); 259 245 260 246 if(!p7_message) … … 269 255 wi_log_info(WI_STR("should set %u for encryption"), wi_p7_spec_enum_value(p7_socket->spec, 4, WI_STR("p7.handshake.encryption.rsa_aes_256"))); 270 256 271 if(options & WI_P7_ENCRYPTION_RSA_AES )257 if(options & WI_P7_ENCRYPTION_RSA_AES_256) 272 258 wi_p7_message_set_enum_for_name(p7_message, 0, WI_STR("p7.handshake.encryption")); 273 else if(options & WI_P7_ENCRYPTION_RSA_BF )259 else if(options & WI_P7_ENCRYPTION_RSA_BF_128) 274 260 wi_p7_message_set_enum_for_name(p7_message, 1, WI_STR("p7.handshake.encryption")); 275 261 … … 316 302 if(wi_p7_message_get_uint32_for_name(p7_message, &encryption, WI_STR("p7.handshake.encryption"))) { 317 303 if(encryption == 0) 318 p7_socket->options |= WI_P7_ENCRYPTION_RSA_AES ;304 p7_socket->options |= WI_P7_ENCRYPTION_RSA_AES_256; 319 305 else if(encryption == 1) 320 p7_socket->options |= WI_P7_ENCRYPTION_RSA_BF ;306 p7_socket->options |= WI_P7_ENCRYPTION_RSA_BF_128; 321 307 } 322 308 … … 324 310 p7_socket->remote_compatibility_check = false; 325 311 326 p7_message = wi_ autorelease(wi_p7_message_init_with_name(wi_p7_message_alloc(), WI_STR("p7.handshake.acknowledge"), p7_socket));312 p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.acknowledge"), p7_socket); 327 313 328 314 if(!p7_message) … … 388 374 wi_log_info(WI_STR("should get %@ for %u"), wi_p7_spec_enum_name(p7_socket->spec, 4, encryption), encryption); 389 375 390 if(encryption == 0 && options & WI_P7_ENCRYPTION_RSA_AES )391 p7_socket->options |= WI_P7_ENCRYPTION_RSA_AES ;392 else if(encryption == 1 && options & WI_P7_ENCRYPTION_RSA_BF )393 p7_socket->options |= WI_P7_ENCRYPTION_RSA_BF ;394 } 395 396 p7_message = wi_ autorelease(wi_p7_message_init_with_name(wi_p7_message_alloc(), WI_STR("p7.handshake.reply"), p7_socket));376 if(encryption == 0 && options & WI_P7_ENCRYPTION_RSA_AES_256) 377 p7_socket->options |= WI_P7_ENCRYPTION_RSA_AES_256; 378 else if(encryption == 1 && options & WI_P7_ENCRYPTION_RSA_BF_128) 379 p7_socket->options |= WI_P7_ENCRYPTION_RSA_BF_128; 380 } 381 382 p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.reply"), p7_socket); 397 383 398 384 if(!p7_message) … … 405 391 wi_p7_message_set_uint32_for_name(p7_message, 0, WI_STR("p7.handshake.compression")); 406 392 407 if(p7_socket->options & WI_P7_ENCRYPTION_RSA_AES )393 if(p7_socket->options & WI_P7_ENCRYPTION_RSA_AES_256) 408 394 wi_p7_message_set_uint32_for_name(p7_message, 0, WI_STR("p7.handshake.encryption")); 409 else if(p7_socket->options & WI_P7_ENCRYPTION_RSA_BF )395 else if(p7_socket->options & WI_P7_ENCRYPTION_RSA_BF_128) 410 396 wi_p7_message_set_uint32_for_name(p7_message, 1, WI_STR("p7.handshake.encryption")); 411 397 … … 441 427 442 428 443 static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_string_t *username _string, wi_string_t *password_string) {429 static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_string_t *username, wi_string_t *password) { 444 430 wi_p7_message_t *p7_message; 445 431 wi_data_t *data, *rsa_data; 446 wi_string_t *client_password_string1, *client_password_string2, *server_password_string; 447 unsigned char *rsa_buffer, *cipher_key, *iv; 448 void *username, *server_password, *client_password; 449 uint32_t username_length, client_password_length, server_password_length; 450 int32_t iv_length; 451 int cipher_key_length; 452 453 username = server_password = client_password = cipher_key = iv = NULL; 454 432 wi_string_t *client_password1, *client_password2, *server_password; 433 455 434 p7_message = wi_p7_socket_read_message(p7_socket, timeout); 456 435 457 436 if(!p7_message) 458 goto end;437 return false; 459 438 460 439 if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption"))) { 461 440 wi_log_warn(WI_STR("wrong message")); 462 441 463 goto end;442 return false; 464 443 } 465 444 … … 469 448 wi_log_warn(WI_STR("no certificate")); 470 449 471 goto end; 472 } 473 474 rsa_buffer = (unsigned char *) wi_data_bytes(rsa_data); 475 p7_socket->rsa_key = d2i_RSA_PUBKEY(NULL, &rsa_buffer, wi_data_length(rsa_data)); 476 477 if(!p7_socket->rsa_key) { 478 ERR_print_errors_fp(stderr); 479 480 goto end; 481 } 482 483 p7_socket->public_key = EVP_PKEY_new(); 484 EVP_PKEY_assign_RSA(p7_socket->public_key, p7_socket->rsa_key); 485 486 p7_socket->cipher = _wi_p7_socket_cipher(p7_socket); 487 cipher_key = wi_malloc(EVP_PKEY_size(p7_socket->public_key)); 488 iv_length = EVP_CIPHER_iv_length(p7_socket->cipher); 489 iv = wi_malloc(iv_length); 490 491 if(EVP_SealInit(&p7_socket->cipher_ctx, p7_socket->cipher, NULL, NULL, NULL, NULL, 1) != 1) { 492 ERR_print_errors_fp(stderr); 493 494 goto end; 495 } 496 497 _wi_p7_socket_configure_cipher_ctx(p7_socket); 498 499 if(EVP_SealInit(&p7_socket->cipher_ctx, 500 NULL, 501 &cipher_key, 502 &cipher_key_length, 503 iv, 504 &p7_socket->public_key, 505 1) != 1) { 506 ERR_print_errors_fp(stderr); 507 508 goto end; 509 } 510 511 if(!_wi_p7_socket_public_encrypt_buffer(p7_socket, 512 wi_string_cstring(username_string), 513 wi_string_length(username_string), 514 &username, 515 &username_length)) 516 goto end; 517 518 client_password_string1 = wi_data_sha1(wi_data_by_appending_data(wi_string_data(wi_string_sha1(password_string)), rsa_data)); 519 client_password_string2 = wi_data_sha1(wi_data_by_appending_data(rsa_data, wi_string_data(wi_string_sha1(password_string)))); 520 521 if(!_wi_p7_socket_public_encrypt_buffer(p7_socket, 522 wi_string_cstring(client_password_string1), 523 wi_string_length(client_password_string1), 524 &client_password, 525 &client_password_length)) 526 goto end; 527 528 p7_message = wi_autorelease(wi_p7_message_init_with_name(wi_p7_message_alloc(), WI_STR("p7.encryption.reply"), p7_socket)); 450 return false; 451 } 452 453 p7_socket->rsa = wi_p7_rsa_init_with_public_key_data(wi_p7_rsa_alloc(), rsa_data); 454 455 if(!p7_socket->rsa) { 456 wi_log_info(WI_STR("could not create rsa")); 457 458 return false; 459 } 460 461 p7_socket->cipher = wi_p7_cipher_init_with_public_rsa(wi_p7_cipher_alloc(), 462 _wi_p7_socket_cipher(p7_socket), 463 &nbs
