| 73 char filename[256], file_public_key[256], file_private_key[256]; |
73 char filename[256], file_public_key[256], file_private_key[256]; |
| 74 char servfilename[256], clientfilename[256], friendsfilename[256]; |
74 char servfilename[256], clientfilename[256], friendsfilename[256]; |
| 75 char pkd[256], prd[256]; |
75 char pkd[256], prd[256]; |
| 76 struct stat st; |
76 struct stat st; |
| 77 struct passwd *pw; |
77 struct passwd *pw; |
| |
78 int fd; |
| 78 |
79 |
| 79 pw = getpwuid(getuid()); |
80 pw = getpwuid(getuid()); |
| 80 if (!pw) { |
81 if (!pw) { |
| 81 gaim_debug_error("silc", "silc: %s\n", strerror(errno)); |
82 gaim_debug_error("silc", "silc: %s\n", strerror(errno)); |
| 82 return FALSE; |
83 return FALSE; |
| 223 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
224 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
| 224 return FALSE; |
225 return FALSE; |
| 225 } |
226 } |
| 226 #endif |
227 #endif |
| 227 |
228 |
| |
229 fd = open(file_private_key, O_RDONLY); |
| 228 if ((g_stat(file_private_key, &st)) == -1) { |
230 if ((g_stat(file_private_key, &st)) == -1) { |
| 229 /* If file doesn't exist */ |
231 /* If file doesn't exist */ |
| 230 if (errno == ENOENT) { |
232 if (errno == ENOENT) { |
| 231 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
233 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 232 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
234 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
| 233 SILCGAIM_DEF_PKCS_LEN, |
235 SILCGAIM_DEF_PKCS_LEN, |
| 234 file_public_key, file_private_key, NULL, |
236 file_public_key, file_private_key, NULL, |
| 235 (gc->password == NULL) ? "" : gc->password, |
237 (gc->password == NULL) ? "" : gc->password, |
| 236 NULL, NULL, NULL, FALSE); |
238 NULL, NULL, NULL, FALSE); |
| |
239 if (fd != -1) |
| |
240 close(fd); |
| |
241 fd = open(file_private_key, O_RDONLY); |
| 237 g_stat(file_private_key, &st); |
242 g_stat(file_private_key, &st); |
| 238 } else { |
243 } else { |
| 239 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
244 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 240 file_private_key, strerror(errno)); |
245 file_private_key, strerror(errno)); |
| |
246 if (fd != -1) |
| |
247 close(fd); |
| 241 return FALSE; |
248 return FALSE; |
| 242 } |
249 } |
| 243 } |
250 } |
| 244 |
251 |
| 245 #ifndef _WIN32 |
252 #ifndef _WIN32 |
| 246 /* Check the owner of the private key */ |
253 /* Check the owner of the private key */ |
| 247 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
254 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
| 248 gaim_debug_error("silc", "You don't seem to own your private key!?\n"); |
255 gaim_debug_error("silc", "You don't seem to own your private key!?\n"); |
| |
256 if (fd != -1) |
| |
257 close(fd); |
| 249 return FALSE; |
258 return FALSE; |
| 250 } |
259 } |
| 251 |
260 |
| 252 /* Check the permissions for the private key */ |
261 /* Check the permissions for the private key */ |
| 253 if ((st.st_mode & 0777) != 0600) { |
262 if ((st.st_mode & 0777) != 0600) { |
| 254 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
263 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
| 255 "Trying to change them ... ", file_private_key); |
264 "Trying to change them ...\n", file_private_key); |
| 256 if ((chmod(file_private_key, 0600)) == -1) { |
265 if ((fd != -1) && (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
| 257 gaim_debug_error("silc", |
266 gaim_debug_error("silc", |
| 258 "Failed to change permissions for private key file!\n" |
267 "Failed to change permissions for private key file!\n" |
| 259 "Permissions for your private key file must be 0600.\n"); |
268 "Permissions for your private key file must be 0600.\n"); |
| |
269 if (fd != -1) |
| |
270 close(fd); |
| 260 return FALSE; |
271 return FALSE; |
| 261 } |
272 } |
| 262 gaim_debug_warning("silc", "Done.\n\n"); |
273 gaim_debug_warning("silc", "Done.\n\n"); |
| 263 } |
274 } |
| 264 #endif |
275 #endif |
| |
276 |
| |
277 if (fd != -1) |
| |
278 close(fd); |
| 265 |
279 |
| 266 return TRUE; |
280 return TRUE; |
| 267 } |
281 } |
| 268 |
282 |
| 269 #ifdef _WIN32 |
283 #ifdef _WIN32 |