| 232 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
232 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
| 233 return FALSE; |
233 return FALSE; |
| 234 } |
234 } |
| 235 #endif |
235 #endif |
| 236 |
236 |
| 237 fd = open(file_private_key, O_RDONLY); |
237 if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { |
| 238 if ((g_stat(file_private_key, &st)) == -1) { |
238 if ((fstat(fd, &st)) == -1) { |
| |
239 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| |
240 file_private_key, strerror(errno)); |
| |
241 close(fd); |
| |
242 return FALSE; |
| |
243 } |
| |
244 } else if ((g_stat(file_private_key, &st)) == -1) { |
| 239 /* If file doesn't exist */ |
245 /* If file doesn't exist */ |
| 240 if (errno == ENOENT) { |
246 if (errno == ENOENT) { |
| 241 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
247 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 242 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
248 if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, |
| 243 SILCGAIM_DEF_PKCS_LEN, |
249 SILCGAIM_DEF_PKCS_LEN, |
| 244 file_public_key, file_private_key, NULL, |
250 file_public_key, file_private_key, NULL, |
| 245 (gc->password == NULL) ? "" : gc->password, |
251 (gc->password == NULL) ? "" : gc->password, |
| 246 NULL, NULL, NULL, FALSE); |
252 NULL, NULL, NULL, FALSE)) { |
| 247 if (fd != -1) |
253 gaim_debug_error("silc", "Couldn't create key pair\n"); |
| 248 close(fd); |
254 return FALSE; |
| 249 fd = open(file_private_key, O_RDONLY); |
255 } |
| 250 g_stat(file_private_key, &st); |
256 |
| |
257 if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { |
| |
258 if ((fstat(fd, &st)) == -1) { |
| |
259 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| |
260 file_private_key, strerror(errno)); |
| |
261 close(fd); |
| |
262 return FALSE; |
| |
263 } |
| |
264 } |
| |
265 /* This shouldn't really happen because silc_create_key_pair() |
| |
266 * will set the permissions */ |
| |
267 else if ((g_stat(file_private_key, &st)) == -1) { |
| |
268 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| |
269 file_private_key, strerror(errno)); |
| |
270 return FALSE; |
| |
271 } |
| 251 } else { |
272 } else { |
| 252 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
273 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 253 file_private_key, strerror(errno)); |
274 file_private_key, strerror(errno)); |
| 254 if (fd != -1) |
|
| 255 close(fd); |
|
| 256 return FALSE; |
275 return FALSE; |
| 257 } |
276 } |
| 258 } |
277 } |
| 259 |
278 |
| 260 #ifndef _WIN32 |
279 #ifndef _WIN32 |
| 268 |
287 |
| 269 /* Check the permissions for the private key */ |
288 /* Check the permissions for the private key */ |
| 270 if ((st.st_mode & 0777) != 0600) { |
289 if ((st.st_mode & 0777) != 0600) { |
| 271 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
290 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
| 272 "Trying to change them ...\n", file_private_key); |
291 "Trying to change them ...\n", file_private_key); |
| 273 if ((fd != -1) && (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
292 if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
| 274 gaim_debug_error("silc", |
293 gaim_debug_error("silc", |
| 275 "Failed to change permissions for private key file!\n" |
294 "Failed to change permissions for private key file!\n" |
| 276 "Permissions for your private key file must be 0600.\n"); |
295 "Permissions for your private key file must be 0600.\n"); |
| 277 if (fd != -1) |
296 if (fd != -1) |
| 278 close(fd); |
297 close(fd); |