OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 #include <limits.h> | 9 #include <limits.h> |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <sys/time.h> | 12 #include <sys/time.h> |
13 #include <sys/wait.h> | 13 #include <sys/wait.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
15 #include "secrng.h" | 15 #include "secrng.h" |
16 #include "secerr.h" | 16 #include "secerr.h" |
17 #include "prerror.h" | 17 #include "prerror.h" |
18 #include "prthread.h" | 18 #include "prthread.h" |
19 #include "prprf.h" | 19 #include "prprf.h" |
| 20 #include "prenv.h" |
20 | 21 |
21 size_t RNG_FileUpdate(const char *fileName, size_t limit); | 22 size_t RNG_FileUpdate(const char *fileName, size_t limit); |
22 | 23 |
23 /* | 24 /* |
24 * When copying data to the buffer we want the least signicant bytes | 25 * When copying data to the buffer we want the least signicant bytes |
25 * from the input since those bits are changing the fastest. The address | 26 * from the input since those bits are changing the fastest. The address |
26 * of least significant byte depends upon whether we are running on | 27 * of least significant byte depends upon whether we are running on |
27 * a big-endian or little-endian machine. | 28 * a big-endian or little-endian machine. |
28 * | 29 * |
29 * Does this mean the least signicant bytes are the most significant | 30 * Does this mean the least signicant bytes are the most significant |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 /* Give in system information */ | 882 /* Give in system information */ |
882 if (gethostname(buf, sizeof(buf)) == 0) { | 883 if (gethostname(buf, sizeof(buf)) == 0) { |
883 RNG_RandomUpdate(buf, strlen(buf)); | 884 RNG_RandomUpdate(buf, strlen(buf)); |
884 } | 885 } |
885 GiveSystemInfo(); | 886 GiveSystemInfo(); |
886 | 887 |
887 /* grab some data from system's PRNG before any other files. */ | 888 /* grab some data from system's PRNG before any other files. */ |
888 bytes = RNG_FileUpdate("/dev/urandom", SYSTEM_RNG_SEED_COUNT); | 889 bytes = RNG_FileUpdate("/dev/urandom", SYSTEM_RNG_SEED_COUNT); |
889 | 890 |
890 /* If the user points us to a random file, pass it through the rng */ | 891 /* If the user points us to a random file, pass it through the rng */ |
891 randfile = getenv("NSRANDFILE"); | 892 randfile = PR_GetEnvSecure("NSRANDFILE"); |
892 if ( ( randfile != NULL ) && ( randfile[0] != '\0') ) { | 893 if ( ( randfile != NULL ) && ( randfile[0] != '\0') ) { |
893 » char *randCountString = getenv("NSRANDCOUNT"); | 894 » char *randCountString = PR_GetEnvSecure("NSRANDCOUNT"); |
894 int randCount = randCountString ? atoi(randCountString) : 0; | 895 int randCount = randCountString ? atoi(randCountString) : 0; |
895 if (randCount != 0) { | 896 if (randCount != 0) { |
896 RNG_FileUpdate(randfile, randCount); | 897 RNG_FileUpdate(randfile, randCount); |
897 } else { | 898 } else { |
898 RNG_FileForRNG(randfile); | 899 RNG_FileForRNG(randfile); |
899 } | 900 } |
900 } | 901 } |
901 | 902 |
902 /* pass other files through */ | 903 /* pass other files through */ |
903 for (cp = files; *cp; cp++) | 904 for (cp = files; *cp; cp++) |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 | 1080 |
1080 #define entry_dir entry.dir | 1081 #define entry_dir entry.dir |
1081 #else | 1082 #else |
1082 struct dirent entry, firstEntry; | 1083 struct dirent entry, firstEntry; |
1083 #define entry_dir entry | 1084 #define entry_dir entry |
1084 #endif | 1085 #endif |
1085 | 1086 |
1086 int i, error = -1; | 1087 int i, error = -1; |
1087 | 1088 |
1088 if (fd == NULL) { | 1089 if (fd == NULL) { |
1089 » dir = getenv("HOME"); | 1090 » dir = PR_GetEnvSecure("HOME"); |
1090 if (dir) { | 1091 if (dir) { |
1091 fd = opendir(dir); | 1092 fd = opendir(dir); |
1092 } | 1093 } |
1093 } | 1094 } |
1094 if (fd == NULL) { | 1095 if (fd == NULL) { |
1095 return 1; | 1096 return 1; |
1096 } | 1097 } |
1097 | 1098 |
1098 for (i=0; i <= fileToRead; i++) { | 1099 for (i=0; i <= fileToRead; i++) { |
1099 struct dirent *result = NULL; | 1100 struct dirent *result = NULL; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 } | 1184 } |
1184 fclose(file); | 1185 fclose(file); |
1185 if (fileBytes != maxLen) { | 1186 if (fileBytes != maxLen) { |
1186 fprintf(stderr, "[ERROR:%s(%d)] NSS failed to read from /dev/urandom. " | 1187 fprintf(stderr, "[ERROR:%s(%d)] NSS failed to read from /dev/urandom. " |
1187 "Abort process.\n", __FILE__, __LINE__); | 1188 "Abort process.\n", __FILE__, __LINE__); |
1188 fflush(stderr); | 1189 fflush(stderr); |
1189 abort(); | 1190 abort(); |
1190 } | 1191 } |
1191 return fileBytes; | 1192 return fileBytes; |
1192 } | 1193 } |
OLD | NEW |