| 222 | | if(certificate) { |
|---|
| 223 | | if(!wi_socket_tls_set_certificate(wd_control_socket_tls, certificate) || |
|---|
| 224 | | !wi_socket_tls_set_certificate(wd_transfer_socket_tls, certificate)) { |
|---|
| 225 | | wi_log_err(WI_STR("Could not set TLS certificate: %m")); |
|---|
| 226 | | } |
|---|
| 227 | | |
|---|
| 228 | | wi_release(certificate); |
|---|
| 229 | | } else { |
|---|
| 230 | | wi_log_err(WI_STR("Could not load certificate %@: %m"), |
|---|
| 231 | | wd_settings.certificate); |
|---|
| 232 | | } |
|---|
| 233 | | |
|---|
| 234 | | private_key = wi_rsa_init_with_pem_file(wi_rsa_alloc(), wd_settings.certificate); |
|---|
| 235 | | |
|---|
| 236 | | if(private_key) { |
|---|
| 237 | | if(!wi_socket_tls_set_private_key(wd_control_socket_tls, private_key) || |
|---|
| 238 | | !wi_socket_tls_set_private_key(wd_transfer_socket_tls, private_key)) { |
|---|
| 239 | | wi_log_err(WI_STR("Could not set TLS private key: %m")); |
|---|
| 240 | | } |
|---|
| 241 | | |
|---|
| 242 | | wi_release(private_key); |
|---|
| 243 | | } else { |
|---|
| 244 | | wi_log_err(WI_STR("Could not load private key %@: %m"), |
|---|
| 245 | | wd_settings.certificate); |
|---|
| 246 | | } |
|---|
| 247 | | } |
|---|
| | 228 | if(!certificate) |
|---|
| | 229 | wi_log_warn(WI_STR("Could not find certificate in %@, creating one..."), wd_settings.certificate); |
|---|
| | 230 | } |
|---|
| | 231 | |
|---|
| | 232 | if(!private_key) { |
|---|
| | 233 | private_key = wi_rsa_init_with_bits(wi_rsa_alloc(), 1024); |
|---|
| | 234 | |
|---|
| | 235 | if(private_key) |
|---|
| | 236 | wi_log_info(WI_STR("Created 1024-bit RSA key")); |
|---|
| | 237 | else |
|---|
| | 238 | wi_log_err(WI_STR("Could not create RSA key: %m")); |
|---|
| | 239 | } |
|---|
| | 240 | |
|---|
| | 241 | if(!certificate) { |
|---|
| | 242 | hostname = wi_process_hostname(wi_process()); |
|---|
| | 243 | certificate = wi_x509_init_with_common_name(wi_x509_alloc(), private_key, hostname); |
|---|
| | 244 | |
|---|
| | 245 | if(certificate) |
|---|
| | 246 | wi_log_info(WI_STR("Created self-signed certificate for %@"), hostname); |
|---|
| | 247 | else |
|---|
| | 248 | wi_log_err(WI_STR("Could not create self-signed certificate: %m")); |
|---|
| | 249 | } |
|---|
| | 250 | |
|---|
| | 251 | if(!wi_socket_tls_set_private_key(wd_control_socket_tls, private_key) || |
|---|
| | 252 | !wi_socket_tls_set_private_key(wd_transfer_socket_tls, private_key)) { |
|---|
| | 253 | wi_log_err(WI_STR("Could not set TLS private key: %m")); |
|---|
| | 254 | } |
|---|
| | 255 | |
|---|
| | 256 | if(!wi_socket_tls_set_certificate(wd_control_socket_tls, certificate) || |
|---|
| | 257 | !wi_socket_tls_set_certificate(wd_transfer_socket_tls, certificate)) { |
|---|
| | 258 | wi_log_err(WI_STR("Could not set TLS certificate: %m")); |
|---|
| | 259 | } |
|---|
| | 260 | |
|---|
| | 261 | wi_release(private_key); |
|---|
| | 262 | wi_release(certificate); |
|---|