-
Notifications
You must be signed in to change notification settings - Fork 5
Preserve unsupported locks #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lauris71
wants to merge
3
commits into
open-eid:master
Choose a base branch
from
lauris71:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+148
−143
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Lauris Kaplinski <lauris@raulwalter.com>
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)
Error loading related location
Loading
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Create locks even if capsule type is not supported
Signed-off-by: Lauris Kaplinski lauris@raulwalter.com