Skip to content

Conversation

@lauris71
Copy link
Contributor

Create locks even if capsule type is not supported

Signed-off-by: Lauris Kaplinski lauris@raulwalter.com

Lauris Kaplinski and others added 3 commits January 23, 2026 16:42
Comment on lines +506 to +620
switch(recipient.capsule_type())
{
case Capsule::recipients_ECCPublicKeyCapsule:
if(const auto *key = recipient.capsule_as_recipients_ECCPublicKeyCapsule()) {
if(key->curve() == EllipticCurve::secp384r1) {
lock.type = Lock::Type::PUBLIC_KEY;
lock.pk_type = Lock::PKType::ECC;
lock.setBytes(Lock::Params::RCPT_KEY, std::vector<uint8_t>(key->recipient_public_key()->cbegin(), key->recipient_public_key()->cend()));
lock.setBytes(Lock::Params::KEY_MATERIAL, std::vector<uint8_t>(key->sender_public_key()->cbegin(), key->sender_public_key()->cend()));
LOG_DBG("Load PK: {}", toHex(lock.getBytes(Lock::Params::RCPT_KEY)));
} else {
LOG_ERROR("Unsupported ECC curve: skipping");
}
}
return;
case Capsule::recipients_RSAPublicKeyCapsule:
if(const auto *key = recipient.capsule_as_recipients_RSAPublicKeyCapsule())
{
lock.type = Lock::Type::PUBLIC_KEY;
lock.pk_type = Lock::PKType::RSA;
lock.setBytes(Lock::Params::RCPT_KEY, std::vector<uint8_t>(key->recipient_public_key()->cbegin(), key->recipient_public_key()->cend()));
lock.setBytes(Lock::Params::KEY_MATERIAL, std::vector<uint8_t>(key->encrypted_kek()->cbegin(), key->encrypted_kek()->cend()));
}
return;
case Capsule::recipients_KeyServerCapsule:
if (const KeyServerCapsule *server = recipient.capsule_as_recipients_KeyServerCapsule()) {
KeyDetailsUnion details = server->recipient_key_details_type();
switch (details) {
case KeyDetailsUnion::EccKeyDetails:
if(const EccKeyDetails *eccDetails = server->recipient_key_details_as_EccKeyDetails()) {
if(eccDetails->curve() != EllipticCurve::secp384r1) {
LOG_ERROR("Unsupported elliptic curve key type");
return;
}
lock.pk_type = Lock::PKType::ECC;
lock.setBytes(Lock::Params::RCPT_KEY, std::vector<uint8_t>(eccDetails->recipient_public_key()->cbegin(), eccDetails->recipient_public_key()->cend()));
} else {
LOG_ERROR("Invalid file format");
return;
}
break;
case KeyDetailsUnion::RsaKeyDetails:
if(const RsaKeyDetails *rsaDetails = server->recipient_key_details_as_RsaKeyDetails()) {
lock.pk_type = Lock::PKType::RSA;
lock.setBytes(Lock::Params::RCPT_KEY, std::vector<uint8_t>(rsaDetails->recipient_public_key()->cbegin(), rsaDetails->recipient_public_key()->cend()));
} else {
LOG_ERROR("Invalid file format");
return;
}
break;
default:
LOG_ERROR("Unsupported Key Server Details: skipping");
return;
}
lock.type = Lock::Type::SERVER;
lock.setString(Lock::Params::KEYSERVER_ID, server->keyserver_id()->str());
lock.setString(Lock::Params::TRANSACTION_ID, server->transaction_id()->str());
} else {
LOG_ERROR("Invalid file format");
}
return;
case Capsule::recipients_SymmetricKeyCapsule:
if(const auto *capsule = recipient.capsule_as_recipients_SymmetricKeyCapsule())
{
lock.type = Lock::SYMMETRIC_KEY;
lock.setBytes(Lock::SALT, std::vector<uint8_t>(capsule->salt()->cbegin(), capsule->salt()->cend()));
}
return;
case Capsule::recipients_PBKDF2Capsule:
if(const auto *capsule = recipient.capsule_as_recipients_PBKDF2Capsule()) {
KDFAlgorithmIdentifier kdf_id = capsule->kdf_algorithm_identifier();
if (kdf_id != KDFAlgorithmIdentifier::PBKDF2WithHmacSHA256) {
LOG_ERROR("Unsupported KDF algorithm: skipping");
return;
}
lock.type = Lock::PASSWORD;
lock.setBytes(Lock::SALT, std::vector<uint8_t>(capsule->salt()->cbegin(), capsule->salt()->cend()));
lock.setBytes(Lock::PW_SALT, std::vector<uint8_t>(capsule->password_salt()->cbegin(), capsule->password_salt()->cend()));
lock.setInt(Lock::KDF_ITER, capsule->kdf_iterations());
}
return;
case Capsule::recipients_KeySharesCapsule:
if (const auto *capsule = recipient.capsule_as_recipients_KeySharesCapsule()) {
if (capsule->recipient_type() != cdoc20::recipients::KeyShareRecipientType::SID_MID) {
LOG_ERROR("Invalid keyshare recipient type: {}", (int) capsule->recipient_type());
return;
}
if (capsule->shares_scheme() != cdoc20::recipients::SharesScheme::N_OF_N) {
LOG_ERROR("Invalid keyshare scheme type: {}", (int) capsule->shares_scheme());
return;
}
/* url,share_id;url,share_id... */
std::vector<std::string> strs;
for (auto cshare = capsule->shares()->cbegin(); cshare != capsule->shares()->cend(); ++cshare) {
std::string id = cshare->share_id()->str();
std::string url = cshare->server_base_url()->str();
std::string str = url + "," + id;
LOG_DBG("Keyshare: {}", str);
strs.push_back(std::move(str));
}
std::string urls = join(strs, ";");
LOG_DBG("Keyshare urls: {}", urls);
std::vector<uint8_t> salt(capsule->salt()->cbegin(), capsule->salt()->cend());
LOG_DBG("Keyshare salt: {}", toHex(salt));
std::string recipient_id = capsule->recipient_id()->str();
LOG_DBG("Keyshare recipient id: {}", recipient_id);
lock.type = Lock::SHARE_SERVER;
lock.setString(Lock::SHARE_URLS, urls);
lock.setBytes(Lock::SALT, salt);
lock.setString(Lock::RECIPIENT_ID, recipient_id);
}
return;
default:
LOG_ERROR("Unsupported Key Details: skipping");
}

Check notice

Code scanning / CodeQL

Long switch case Note

Switch has at least one case that is too long:
recipients_KeyServerCapsule (36 lines)
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant