aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/qolmaccount.cpp10
-rw-r--r--lib/crypto/qolmaccount.h3
-rw-r--r--lib/crypto/qolmsession.cpp21
-rw-r--r--lib/crypto/qolmsession.h9
4 files changed, 41 insertions, 2 deletions
diff --git a/lib/crypto/qolmaccount.cpp b/lib/crypto/qolmaccount.cpp
index fc0fc1cf..76b0a263 100644
--- a/lib/crypto/qolmaccount.cpp
+++ b/lib/crypto/qolmaccount.cpp
@@ -197,6 +197,16 @@ QByteArray QOlmAccount::signOneTimeKey(const QString &key) const
return sign(j.toJson());
}
+std::optional<QOlmError> QOlmAccount::removeOneTimeKeys(const std::unique_ptr<QOlmSession> &session) const
+{
+ const auto error = olm_remove_one_time_keys(m_account, session->raw());
+
+ if (error == olm_error()) {
+ return lastError(m_account);
+ }
+ return std::nullopt;
+}
+
OlmAccount *Quotient::QOlmAccount::data()
{
return m_account;
diff --git a/lib/crypto/qolmaccount.h b/lib/crypto/qolmaccount.h
index b33e3768..4398214a 100644
--- a/lib/crypto/qolmaccount.h
+++ b/lib/crypto/qolmaccount.h
@@ -68,6 +68,9 @@ public:
SignedOneTimeKey signedOneTimeKey(const QByteArray &key, const QString &signature) const;
+ //! Remove the one time key used to create the supplied session.
+ [[nodiscard]] std::optional<QOlmError> removeOneTimeKeys(const std::unique_ptr<QOlmSession> &session) const;
+
//! Creates an inbound session for sending/receiving messages from a received 'prekey' message.
//!
//! \param message An Olm pre-key message that was encrypted for this account.
diff --git a/lib/crypto/qolmsession.cpp b/lib/crypto/qolmsession.cpp
index cfe21650..b901a440 100644
--- a/lib/crypto/qolmsession.cpp
+++ b/lib/crypto/qolmsession.cpp
@@ -213,7 +213,7 @@ bool QOlmSession::hasReceivedMessage() const
return olm_session_has_received_message(m_session);
}
-std::variant<bool, QOlmError> QOlmSession::matchesInboundSession(QOlmMessage &preKeyMessage)
+std::variant<bool, QOlmError> QOlmSession::matchesInboundSession(const QOlmMessage &preKeyMessage) const
{
Q_ASSERT(preKeyMessage.type() == QOlmMessage::Type::PreKey);
QByteArray oneTimeKeyBuf(preKeyMessage.data());
@@ -231,6 +231,25 @@ std::variant<bool, QOlmError> QOlmSession::matchesInboundSession(QOlmMessage &pr
return QOlmError::Unknown;
}
}
+std::variant<bool, QOlmError> QOlmSession::matchesInboundSessionFrom(const QString &theirIdentityKey, const QOlmMessage &preKeyMessage) const
+{
+ const auto theirIdentityKeyBuf = theirIdentityKey.toUtf8();
+ auto oneTimeKeyMessageBuf = preKeyMessage.toCiphertext();
+ const auto error = olm_matches_inbound_session_from(m_session, theirIdentityKeyBuf.data(), theirIdentityKeyBuf.length(),
+ oneTimeKeyMessageBuf.data(), oneTimeKeyMessageBuf.length());
+
+ if (error == olm_error()) {
+ return lastError(m_session);
+ }
+ switch (error) {
+ case 0:
+ return false;
+ case 1:
+ return true;
+ default:
+ return QOlmError::Unknown;
+ }
+}
QOlmSession::QOlmSession(OlmSession *session)
: m_session(session)
diff --git a/lib/crypto/qolmsession.h b/lib/crypto/qolmsession.h
index 6e13801e..0fc59e9e 100644
--- a/lib/crypto/qolmsession.h
+++ b/lib/crypto/qolmsession.h
@@ -50,7 +50,10 @@ public:
bool hasReceivedMessage() const;
//! Checks if the 'prekey' message is for this in-bound session.
- std::variant<bool, QOlmError> matchesInboundSession(QOlmMessage &preKeyMessage);
+ std::variant<bool, QOlmError> matchesInboundSession(const QOlmMessage &preKeyMessage) const;
+
+ //! Checks if the 'prekey' message is for this in-bound session.
+ std::variant<bool, QOlmError> matchesInboundSessionFrom(const QString &theirIdentityKey, const QOlmMessage &preKeyMessage) const;
friend bool operator<(const QOlmSession& lhs, const QOlmSession& rhs)
{
@@ -61,6 +64,10 @@ public:
return *lhs < *rhs;
}
+ OlmSession *raw() const
+ {
+ return m_session;
+ }
QOlmSession(OlmSession* session);
private:
//! Helper function for creating new sessions and handling errors.