diff --git a/src/modules/machineid/Workers.cpp b/src/modules/machineid/Workers.cpp index cfee6f179..fefaf24b9 100644 --- a/src/modules/machineid/Workers.cpp +++ b/src/modules/machineid/Workers.cpp @@ -3,7 +3,7 @@ * Copyright 2014, Kevin Kofler * Copyright 2016, Philip Müller * Copyright 2017, Alf Gaida - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ #include "Workers.h" #include "utils/CalamaresUtilsSystem.h" +#include "utils/Entropy.h" #include "utils/Logger.h" #include @@ -83,7 +84,7 @@ getUrandomPoolSize() { if ( v.endsWith( '\n' ) ) { - v.chop(1); + v.chop( 1 ); } bool ok = false; poolSize = v.toInt( &ok ); @@ -93,45 +94,42 @@ getUrandomPoolSize() } } } - return (poolSize >= minimumPoolSize) ? poolSize : minimumPoolSize; + return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize; } Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName ) { - QFile urandom( "/dev/urandom" ); - if ( urandom.exists() && urandom.open( QIODevice::ReadOnly ) ) + QFile entropyFile( rootMountPoint + fileName ); + if ( entropyFile.exists() ) { - QByteArray data = urandom.read( poolSize ); - urandom.close(); + cWarning() << "Entropy file" << ( rootMountPoint + fileName ) << "already exists."; + return Calamares::JobResult::ok(); // .. anyway + } + if ( !entropyFile.open( QIODevice::WriteOnly ) ) + { + return Calamares::JobResult::error( + QObject::tr( "File not found" ), + QObject::tr( "Could not create new random file
%1
." ).arg( fileName ) ); + } - QFile entropyFile( rootMountPoint + fileName ); - if ( entropyFile.exists() ) - { - cWarning() << "Entropy file" << ( rootMountPoint + fileName ) << "already exists."; - return Calamares::JobResult::ok(); // .. anyway - } - if ( !entropyFile.open( QIODevice::WriteOnly ) ) - { - return Calamares::JobResult::error( - QObject::tr( "File not found" ), - QObject::tr( "Could not create new random file
%1
." ).arg( fileName ) ); - } - entropyFile.write( data ); - entropyFile.close(); - if ( entropyFile.size() < data.length() ) - { - cWarning() << "Entropy file is" << entropyFile.size() << "bytes, random data was" << data.length(); - } - if ( data.length() < poolSize ) - { - cWarning() << "Entropy data is" << data.length() << "bytes, rather than poolSize" << poolSize; - } - return Calamares::JobResult::ok(); + QByteArray data; + CalamaresUtils::EntropySource source = CalamaresUtils::getEntropy( poolSize, data ); + entropyFile.write( data ); + entropyFile.close(); + if ( entropyFile.size() < data.length() ) + { + cWarning() << "Entropy file is" << entropyFile.size() << "bytes, random data was" << data.length(); } - return Calamares::JobResult::error( - QObject::tr( "File not found" ), - QObject::tr( "Could not read random file
%1
." ).arg( QStringLiteral( "/dev/urandom" ) ) ); + if ( data.length() < poolSize ) + { + cWarning() << "Entropy data is" << data.length() << "bytes, rather than poolSize" << poolSize; + } + if ( source != CalamaresUtils::EntropySource::URandom ) + { + cWarning() << "Entropy data for pool is low-quality."; + } + return Calamares::JobResult::ok(); }