aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/px5g-standalone/src/library
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-10-27 11:07:38 +0000
committerJo-Philipp Wich <jow@openwrt.org>2014-10-27 11:07:38 +0000
commit9b1ad94f1c73ad6cfc8e96aaeb08288efeceba24 (patch)
tree42c25ec6b8c8cd7f49f3e2f1d6673a1fab457f60 /package/utils/px5g-standalone/src/library
parente6da32c086c3cb22be14c348be7821e0c98a7566 (diff)
downloadupstream-9b1ad94f1c73ad6cfc8e96aaeb08288efeceba24.tar.gz
upstream-9b1ad94f1c73ad6cfc8e96aaeb08288efeceba24.tar.bz2
upstream-9b1ad94f1c73ad6cfc8e96aaeb08288efeceba24.zip
px5g-standalone: use /dev/urandom to initialize serial (#18232)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> SVN-Revision: 43080
Diffstat (limited to 'package/utils/px5g-standalone/src/library')
-rw-r--r--package/utils/px5g-standalone/src/library/x509write.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/package/utils/px5g-standalone/src/library/x509write.c b/package/utils/px5g-standalone/src/library/x509write.c
index fabee20ea6..1091568745 100644
--- a/package/utils/px5g-standalone/src/library/x509write.c
+++ b/package/utils/px5g-standalone/src/library/x509write.c
@@ -1000,6 +1000,26 @@ static int x509write_make_sign(x509_raw *chain, rsa_context *privkey)
}
/*
+ * Create a random serial
+ */
+static int get_random_serial(void)
+{
+ int random = 0;
+ FILE *fd;
+
+ fd = fopen("/dev/urandom", "r");
+
+ if (fd) {
+ if (fread(&random, 1, sizeof(random), fd) != sizeof(random))
+ random = 0;
+
+ fclose(fd);
+ }
+
+ return random;
+}
+
+/*
* Create a self signed certificate
*/
int x509write_create_sign(x509_raw *chain, rsa_context *privkey)
@@ -1020,8 +1040,11 @@ int x509write_create_sign(x509_raw *chain, rsa_context *privkey)
/*
* CertificateSerialNumber ::= INTEGER
*/
- srand((unsigned int) time(NULL));
- serial = rand();
+ serial = get_random_serial();
+
+ if (serial == 0)
+ return 1;
+
if ((ret = asn1_add_int(serial, &chain->serial)) != 0)
return ret;