[machineid] Use entropy service

- Most of the code was error-checking, just replace the open-read
   with a call to the service instead.
 - It's not an error if /dev/urandom doesn't exist in the source system
   (there may be other good random sources, and otherwise we have the
   low-quality random fallback).
main
Adriaan de Groot 5 years ago
parent c971127b17
commit 5b987d4f33

@ -3,7 +3,7 @@
* Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
* Copyright 2016, Philip Müller <philm@manjaro.org>
* Copyright 2017, Alf Gaida <agaida@siduction.org>
* Copyright 2019, Adriaan de Groot <groot@kde.org>
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
*
* 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 <QFile>
@ -99,12 +100,6 @@ getUrandomPoolSize()
Calamares::JobResult
createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName )
{
QFile urandom( "/dev/urandom" );
if ( urandom.exists() && urandom.open( QIODevice::ReadOnly ) )
{
QByteArray data = urandom.read( poolSize );
urandom.close();
QFile entropyFile( rootMountPoint + fileName );
if ( entropyFile.exists() )
{
@ -117,6 +112,9 @@ createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fi
QObject::tr( "File not found" ),
QObject::tr( "Could not create new random file <pre>%1</pre>." ).arg( fileName ) );
}
QByteArray data;
CalamaresUtils::EntropySource source = CalamaresUtils::getEntropy( poolSize, data );
entropyFile.write( data );
entropyFile.close();
if ( entropyFile.size() < data.length() )
@ -127,11 +125,11 @@ createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fi
{
cWarning() << "Entropy data is" << data.length() << "bytes, rather than poolSize" << poolSize;
}
return Calamares::JobResult::ok();
if ( source != CalamaresUtils::EntropySource::URandom )
{
cWarning() << "Entropy data for pool is low-quality.";
}
return Calamares::JobResult::error(
QObject::tr( "File not found" ),
QObject::tr( "Could not read random file <pre>%1</pre>." ).arg( QStringLiteral( "/dev/urandom" ) ) );
return Calamares::JobResult::ok();
}

Loading…
Cancel
Save