|
22 | 22 | #include <QtCore/QJsonObject> |
23 | 23 | #include <QtCore/QtEndian> |
24 | 24 | #include <QtCore/QTemporaryFile> |
| 25 | +#include <QtCore/QUrlQuery> |
25 | 26 | #include <QtNetwork/QNetworkAccessManager> |
26 | 27 | #include <QtNetwork/QSslKey> |
27 | 28 | #include <QLoggingCategory> |
@@ -449,23 +450,55 @@ StreamListSource::next(std::string& name, int64_t& size) |
449 | 450 | return libcdoc::OK; |
450 | 451 | } |
451 | 452 |
|
| 453 | +static void |
| 454 | +recode_label(std::string& label, uint64_t& expiry) |
| 455 | +{ |
| 456 | + if(!label.starts_with("data:")) return; |
| 457 | + auto values = libcdoc::Lock::parseLabel(label); |
| 458 | + if (!values.contains("v") || !values.contains("type")) return; |
| 459 | + std::string v = values.at("v"); |
| 460 | + values.erase("v"); |
| 461 | + std::string type = values.at("type"); |
| 462 | + values.erase("type"); |
| 463 | + std::string expiry_str = values.at("server_exp"); |
| 464 | + values.erase("server_exp"); |
| 465 | + if (!expiry_str.empty()) expiry = std::stoll(expiry_str); |
| 466 | + QUrlQuery q; |
| 467 | + q.setQueryItems({ |
| 468 | + {QStringLiteral("v"), QString::number(1)}, |
| 469 | + {QStringLiteral("type"), QString::fromStdString(type)} |
| 470 | + }); |
| 471 | + for (const auto& [key, value] : values) { |
| 472 | + if (!value.empty()) |
| 473 | + q.addQueryItem(QString::fromStdString(key), QString::fromStdString(value)); |
| 474 | + } |
| 475 | + label = "data:" + q.query(QUrl::FullyEncoded).toStdString(); |
| 476 | +} |
| 477 | + |
452 | 478 | libcdoc::Recipient |
453 | 479 | makeFromLock(const libcdoc::Lock& lock, const std::string& server_id) |
454 | 480 | { |
| 481 | + uint64_t expiry_ts = 0; |
| 482 | + std::string label = lock.label; |
| 483 | + recode_label(label, expiry_ts); |
455 | 484 | switch (lock.type) { |
456 | 485 | case libcdoc::Lock::CDOC1: |
457 | 486 | if (!server_id.empty()) { |
458 | | - return libcdoc::Recipient::makeServer(lock.label, lock.getBytes(libcdoc::Lock::CERT), server_id); |
| 487 | + return libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::CERT), server_id); |
459 | 488 | } else { |
460 | | - return libcdoc::Recipient::makeCertificate(lock.label, lock.getBytes(libcdoc::Lock::CERT)); |
| 489 | + return libcdoc::Recipient::makeCertificate(label, lock.getBytes(libcdoc::Lock::CERT)); |
461 | 490 | } |
462 | 491 | case libcdoc::Lock::PUBLIC_KEY: |
463 | 492 | case libcdoc::Lock::SERVER: { |
464 | 493 | libcdoc::Recipient::PKType rcpt_type = (lock.pk_type == libcdoc::Lock::RSA) ? libcdoc::Recipient::RSA : libcdoc::Recipient::ECC; |
465 | 494 | if (!server_id.empty()) { |
466 | | - return libcdoc::Recipient::makeServer(lock.label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type, server_id); |
| 495 | + libcdoc::Recipient rcpt = libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type, server_id); |
| 496 | + rcpt.expiry_ts = expiry_ts; |
| 497 | + return rcpt; |
467 | 498 | } else { |
468 | | - return libcdoc::Recipient::makePublicKey(lock.label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type); |
| 499 | + libcdoc::Recipient rcpt = libcdoc::Recipient::makePublicKey(label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type); |
| 500 | + rcpt.expiry_ts = expiry_ts; |
| 501 | + return rcpt; |
469 | 502 | } |
470 | 503 | } |
471 | 504 | default: |
|
0 commit comments