Skip to content

Commit

Permalink
Airplay: Clean up old data structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Apr 13, 2023
1 parent 3042a8a commit 055f4dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
22 changes: 7 additions & 15 deletions mythtv/libs/libmythtv/AirPlay/mythraopconnection.cpp
Expand Up @@ -36,7 +36,6 @@
#define LOC QString("RAOP Conn: ")
static constexpr size_t MAX_PACKET_SIZE { 2048 };

RSA *MythRAOPConnection::g_rsa = nullptr;
EVP_PKEY *MythRAOPConnection::g_devPrivKey = nullptr;
QString MythRAOPConnection::g_rsaLastError;

Expand Down Expand Up @@ -81,7 +80,6 @@ MythRAOPConnection::MythRAOPConnection(QObject *parent, QTcpSocket *socket,
m_dataPort(port)
{
m_id = GetNotificationCenter()->Register(this);
memset(&m_aesKey, 0, sizeof(m_aesKey));
#if OPENSSL_VERSION_NUMBER < 0x030000000L
m_cipher = EVP_aes_128_cbc();
#else
Expand Down Expand Up @@ -1188,8 +1186,6 @@ void MythRAOPConnection::ProcessRequest(const QStringList &header,
// SUCCESS
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
"Successfully decrypted AES key from RSA.");
AES_set_decrypt_key(m_sessionKey.data(),
128, &m_aesKey);
}
else
{
Expand Down Expand Up @@ -1586,23 +1582,22 @@ void MythRAOPConnection::FinishResponse(RaopNetStream *stream, QTcpSocket *socke
* The RSA key is resident in memory for the entire duration of the application
* as such RSA_free is never called on it.
*/
RSA *MythRAOPConnection::LoadKey(void)
bool MythRAOPConnection::LoadKey(void)
{
static QMutex s_lock;
QMutexLocker locker(&s_lock);

if (g_rsa)
return g_rsa;
if (g_devPrivKey)
return true;

QString sName( "/RAOPKey.rsa" );
FILE *file = fopen(GetConfDir().toUtf8() + sName.toUtf8(), "rb");

if ( !file )
{
g_rsaLastError = tr("Failed to read key from: %1").arg(GetConfDir() + sName);
g_rsa = nullptr;
LOG(VB_PLAYBACK, LOG_ERR, LOC + g_rsaLastError);
return nullptr;
return false;
}

g_devPrivKey = PEM_read_PrivateKey(file, nullptr, nullptr, nullptr);
Expand All @@ -1617,20 +1612,17 @@ RSA *MythRAOPConnection::LoadKey(void)
g_rsaLastError = tr("Key is not a RSA private key.");
EVP_PKEY_free(g_devPrivKey);
g_devPrivKey = nullptr;
g_rsa = nullptr;
LOG(VB_PLAYBACK, LOG_ERR, LOC + g_rsaLastError);
return nullptr;
return false;
}
g_rsaLastError = "";
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + "Loaded RSA private key");
g_rsa = EVP_PKEY_get1_RSA(g_devPrivKey);
return g_rsa;
return true;
}

g_rsaLastError = tr("Failed to load RSA private key.");
g_rsa = nullptr;
LOG(VB_PLAYBACK, LOG_ERR, LOC + g_rsaLastError);
return nullptr;
return false;
}

RawHash MythRAOPConnection::FindTags(const QStringList &lines)
Expand Down
4 changes: 1 addition & 3 deletions mythtv/libs/libmythtv/AirPlay/mythraopconnection.h
Expand Up @@ -58,7 +58,7 @@ class MTV_PUBLIC MythRAOPConnection : public QObject
int GetDataPort() const { return m_dataPort; }
bool HasAudio() { return m_audio; }
static QMap<QString,QString> decodeDMAP(const QByteArray &dmap);
static RSA *LoadKey(void);
static bool LoadKey(void);
static QString RSALastError(void) { return g_rsaLastError; }

private slots:
Expand Down Expand Up @@ -139,7 +139,6 @@ class MTV_PUBLIC MythRAOPConnection : public QObject
QMap<uint16_t,std::chrono::milliseconds> m_resends;
// crypto
QByteArray m_aesIV;
AES_KEY m_aesKey {};
static EVP_PKEY *g_devPrivKey;
std::vector<uint8_t> m_sessionKey;
#if OPENSSL_VERSION_NUMBER < 0x030000000L
Expand All @@ -148,7 +147,6 @@ class MTV_PUBLIC MythRAOPConnection : public QObject
EVP_CIPHER *m_cipher {nullptr};
#endif
EVP_CIPHER_CTX *m_cctx {nullptr};
static RSA *g_rsa;
static QString g_rsaLastError;
// audio out
AudioOutput *m_audio {nullptr};
Expand Down

0 comments on commit 055f4dc

Please sign in to comment.