tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MLSTransactionParent.cpp (22141B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "MLSTransactionParent.h"
      8 
      9 #include "MLSLogging.h"
     10 #include "MLSTransactionMessage.h"
     11 #include "mozilla/Base64.h"
     12 #include "mozilla/dom/quota/QuotaManager.h"
     13 #include "mozilla/security/mls/mls_gk_ffi_generated.h"
     14 #include "nsCOMPtr.h"
     15 #include "nsIFile.h"
     16 #include "nsIPrincipal.h"
     17 #include "nsString.h"
     18 
     19 using mozilla::dom::quota::QuotaManager;
     20 
     21 namespace mozilla::dom {
     22 
     23 /* static */ nsresult MLSTransactionParent::CreateDirectoryIfNotExists(
     24    nsIFile* aDir) {
     25  nsresult rv = aDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
     26  if (rv == NS_ERROR_FILE_ALREADY_EXISTS) {
     27    // Evaluate if the file is a directory
     28    bool isDirectory = false;
     29    rv = aDir->IsDirectory(&isDirectory);
     30    if (NS_WARN_IF(NS_FAILED(rv))) {
     31      return rv;
     32    }
     33 
     34    // Check if the file is actually a directory
     35    if (!isDirectory) {
     36      return NS_ERROR_FILE_NOT_DIRECTORY;
     37    }
     38    return NS_OK;
     39  }
     40  return rv;
     41 }
     42 
     43 /* static */ nsresult MLSTransactionParent::ConstructDatabasePrefixPath(
     44    nsCOMPtr<nsIFile>& aFile) {
     45  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
     46          ("MLSTransactionParent::ConstructDatabasePath()"));
     47 
     48  // Get the base path from the quota manager
     49  QuotaManager* quotaManager = QuotaManager::Get();
     50  if (NS_WARN_IF(!quotaManager)) {
     51    return NS_ERROR_FAILURE;
     52  }
     53 
     54  // Create an nsIFile object from the path
     55  nsresult rv =
     56      NS_NewLocalFile(quotaManager->GetBasePath(), getter_AddRefs(aFile));
     57  if (NS_WARN_IF(NS_FAILED(rv))) {
     58    return rv;
     59  }
     60 
     61  // Append the hardcoded "mls" directory name to the path
     62  rv = aFile->AppendNative("mls"_ns);
     63  if (NS_WARN_IF(NS_FAILED(rv))) {
     64    return rv;
     65  }
     66 
     67  return NS_OK;
     68 }
     69 
     70 /* static */ nsresult MLSTransactionParent::ConstructDatabaseFullPath(
     71    nsCOMPtr<nsIFile>& aFile, nsIPrincipal* aPrincipal,
     72    nsCString& aDatabasePath) {
     73  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
     74          ("MLSTransactionParent::ConstructDatabaseFullPath()"));
     75 
     76  // Get StorageOriginKey
     77  nsAutoCString originKey;
     78  nsresult rv = aPrincipal->GetStorageOriginKey(originKey);
     79  if (NS_WARN_IF(NS_FAILED(rv))) {
     80    return rv;
     81  }
     82 
     83  // Get OriginSuffix
     84  nsAutoCString originAttrSuffix;
     85  rv = aPrincipal->GetOriginSuffix(originAttrSuffix);
     86  if (NS_WARN_IF(NS_FAILED(rv))) {
     87    return rv;
     88  }
     89 
     90  // Set the base path and origin
     91  nsAutoCString origin = originKey + originAttrSuffix;
     92 
     93  // Encode the origin with its suffix
     94  nsAutoCString encodedOrigin;
     95  rv = mozilla::Base64Encode(origin, encodedOrigin);
     96  if (NS_WARN_IF(NS_FAILED(rv))) {
     97    return rv;
     98  }
     99 
    100  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    101          ("MLSTransactionParent::ConstructDatabasePath() - origin: %s",
    102           origin.get()));
    103 
    104  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    105          ("MLSTransactionParent::ConstructDatabasePath() - encodedOrigin: "
    106           "%s",
    107           encodedOrigin.get()));
    108 
    109  // Append the origin to the path
    110  rv = aFile->AppendNative(encodedOrigin);
    111  if (NS_WARN_IF(NS_FAILED(rv))) {
    112    return rv;
    113  }
    114 
    115  // Get the updated path back into the nsCString
    116  nsAutoString databasePathUTF16;
    117  rv = aFile->GetPath(databasePathUTF16);
    118  if (NS_WARN_IF(NS_FAILED(rv))) {
    119    return rv;
    120  }
    121 
    122  aDatabasePath = NS_ConvertUTF16toUTF8(databasePathUTF16);
    123  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    124          ("MLSTransactionParent::ConstructDatabasePath() - databasePath: %s",
    125           aDatabasePath.get()));
    126 
    127  return NS_OK;
    128 }
    129 
    130 void MLSTransactionParent::ActorDestroy(ActorDestroyReason) {
    131  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    132          ("MLSTransactionParent::ActorDestroy()"));
    133 }
    134 
    135 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestStateDelete(
    136    RequestStateDeleteResolver&& aResolver) {
    137  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    138          ("MLSTransactionParent::RecvRequestStateDelete()"));
    139 
    140  // Call to the MLS rust code
    141  nsresult rv = security::mls::mls_state_delete(&mDatabasePath);
    142 
    143  aResolver(NS_SUCCEEDED(rv));
    144  return IPC_OK();
    145 }
    146 
    147 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupStateDelete(
    148    const nsTArray<uint8_t>& aGroupIdentifier,
    149    const nsTArray<uint8_t>& aIdentifier,
    150    RequestGroupStateDeleteResolver&& aResolver) {
    151  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    152          ("MLSTransactionParent::RecvRequestGroupStateDelete()"));
    153 
    154  // Call to the MLS rust code
    155  security::mls::GkGroupIdEpoch groupIdEpoch;
    156  nsresult rv = security::mls::mls_state_delete_group(
    157      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    158      aIdentifier.Elements(), aIdentifier.Length(), &groupIdEpoch);
    159 
    160  // Return Nothing if failed
    161  if (NS_WARN_IF(NS_FAILED(rv))) {
    162    aResolver(Nothing());
    163    return IPC_OK();
    164  }
    165 
    166  // Return the result if success
    167  aResolver(Some(std::move(groupIdEpoch)));
    168  return IPC_OK();
    169 }
    170 
    171 mozilla::ipc::IPCResult
    172 MLSTransactionParent::RecvRequestGenerateIdentityKeypair(
    173    RequestGenerateIdentityKeypairResolver&& aResolver) {
    174  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    175          ("MLSTransactionParent::RecvRequestGenerateIdentityKeypair()"));
    176 
    177  // Call to the MLS rust code
    178  nsTArray<uint8_t> identity;
    179  nsresult rv = security::mls::mls_generate_identity(&mDatabasePath, &identity);
    180 
    181  // Return Nothing if failed
    182  if (NS_WARN_IF(NS_FAILED(rv))) {
    183    aResolver(Nothing());
    184    return IPC_OK();
    185  }
    186 
    187  // Return the result if success
    188  aResolver(Some(RawBytes{std::move(identity)}));
    189  return IPC_OK();
    190 }
    191 
    192 mozilla::ipc::IPCResult
    193 MLSTransactionParent::RecvRequestGenerateCredentialBasic(
    194    const nsTArray<uint8_t>& aCredContent,
    195    RequestGenerateCredentialBasicResolver&& aResolver) {
    196  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    197          ("MLSTransactionParent::RecvRequestGenerateCredentialBasic()"));
    198 
    199  // Call to the MLS rust code
    200  nsTArray<uint8_t> credential;
    201  nsresult rv = security::mls::mls_generate_credential_basic(
    202      aCredContent.Elements(), aCredContent.Length(), &credential);
    203 
    204  // Return Nothing if failed
    205  if (NS_WARN_IF(NS_FAILED(rv))) {
    206    aResolver(Nothing());
    207    return IPC_OK();
    208  }
    209 
    210  // Return the result if success
    211  aResolver(Some(RawBytes{std::move(credential)}));
    212 
    213  return IPC_OK();
    214 }
    215 
    216 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGenerateKeyPackage(
    217    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aCredential,
    218    RequestGenerateKeyPackageResolver&& aResolver) {
    219  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    220          ("MLSTransactionParent::RecvRequestGenerateKeyPackage()"));
    221 
    222  // Call to the MLS rust code
    223  nsTArray<uint8_t> keyPackage;
    224  nsresult rv = security::mls::mls_generate_keypackage(
    225      &mDatabasePath, aIdentifier.Elements(), aIdentifier.Length(),
    226      aCredential.Elements(), aCredential.Length(), &keyPackage);
    227 
    228  // Return Nothing if failed
    229  if (NS_FAILED(rv)) {
    230    aResolver(Nothing());
    231    return IPC_OK();
    232  }
    233 
    234  // Return the result if success
    235  aResolver(Some(RawBytes{std::move(keyPackage)}));
    236 
    237  return IPC_OK();
    238 }
    239 
    240 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupCreate(
    241    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aCredential,
    242    const nsTArray<uint8_t>& aInOptGroupIdentifier,
    243    RequestGroupCreateResolver&& aResolver) {
    244  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    245          ("MLSTransactionParent::RecvRequestGroupCreate()"));
    246 
    247  // Call to the MLS rust code
    248  security::mls::GkGroupIdEpoch groupIdEpoch;
    249  nsresult rv = security::mls::mls_group_create(
    250      &mDatabasePath, aIdentifier.Elements(), aIdentifier.Length(),
    251      aCredential.Elements(), aCredential.Length(),
    252      aInOptGroupIdentifier.Elements(), aInOptGroupIdentifier.Length(),
    253      &groupIdEpoch);
    254 
    255  // Return Nothing if failed
    256  if (NS_WARN_IF(NS_FAILED(rv))) {
    257    aResolver(Nothing());
    258    return IPC_OK();
    259  }
    260 
    261  // Return the result if success
    262  aResolver(Some(std::move(groupIdEpoch)));
    263 
    264  return IPC_OK();
    265 }
    266 
    267 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupJoin(
    268    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aWelcome,
    269    RequestGroupJoinResolver&& aResolver) {
    270  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    271          ("MLSTransactionParent::RecvRequestGroupJoin()"));
    272 
    273  // Call to the MLS rust code
    274  security::mls::GkGroupIdEpoch groupIdEpoch;
    275  nsresult rv = security::mls::mls_group_join(
    276      &mDatabasePath, aIdentifier.Elements(), aIdentifier.Length(),
    277      aWelcome.Elements(), aWelcome.Length(), &groupIdEpoch);
    278 
    279  // Return Nothing if failed
    280  if (NS_WARN_IF(NS_FAILED(rv))) {
    281    aResolver(Nothing());
    282    return IPC_OK();
    283  }
    284 
    285  // Return the result if success
    286  aResolver(Some(std::move(groupIdEpoch)));
    287 
    288  return IPC_OK();
    289 }
    290 
    291 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupAdd(
    292    const nsTArray<uint8_t>& aGroupIdentifier,
    293    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aKeyPackage,
    294    RequestGroupAddResolver&& aResolver) {
    295  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    296          ("MLSTransactionParent::RecvRequestGroupAdd()"));
    297 
    298  // Call to the MLS rust code
    299  security::mls::GkMlsCommitOutput commitOutput;
    300  nsresult rv = security::mls::mls_group_add(
    301      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    302      aIdentifier.Elements(), aIdentifier.Length(), aKeyPackage.Elements(),
    303      aKeyPackage.Length(), &commitOutput);
    304 
    305  // Return Nothing if failed
    306  if (NS_WARN_IF(NS_FAILED(rv))) {
    307    aResolver(Nothing());
    308    return IPC_OK();
    309  }
    310 
    311  // Return the result if success
    312  aResolver(Some(std::move(commitOutput)));
    313 
    314  return IPC_OK();
    315 }
    316 
    317 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupProposeAdd(
    318    const nsTArray<uint8_t>& aGroupIdentifier,
    319    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aKeyPackage,
    320    RequestGroupProposeAddResolver&& aResolver) {
    321  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    322          ("MLSTransactionParent::RecvRequestGroupProposeAdd()"));
    323 
    324  // Call to the MLS rust code
    325  nsTArray<uint8_t> proposal;
    326  nsresult rv = security::mls::mls_group_propose_add(
    327      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    328      aIdentifier.Elements(), aIdentifier.Length(), aKeyPackage.Elements(),
    329      aKeyPackage.Length(), &proposal);
    330 
    331  // Return Nothing if failed
    332  if (NS_WARN_IF(NS_FAILED(rv))) {
    333    aResolver(Nothing());
    334    return IPC_OK();
    335  }
    336 
    337  // Return the result if success
    338  aResolver(Some(RawBytes{std::move(proposal)}));
    339 
    340  return IPC_OK();
    341 }
    342 
    343 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupRemove(
    344    const nsTArray<uint8_t>& aGroupIdentifier,
    345    const nsTArray<uint8_t>& aIdentifier,
    346    const nsTArray<uint8_t>& aRemIdentifier,
    347    RequestGroupRemoveResolver&& aResolver) {
    348  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    349          ("MLSTransactionParent::RecvRequestGroupRemove()"));
    350 
    351  // Call to the MLS rust code
    352  security::mls::GkMlsCommitOutput commitOutput;
    353  nsresult rv = security::mls::mls_group_remove(
    354      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    355      aIdentifier.Elements(), aIdentifier.Length(), aRemIdentifier.Elements(),
    356      aRemIdentifier.Length(), &commitOutput);
    357 
    358  // Return Nothing if failed
    359  if (NS_WARN_IF(NS_FAILED(rv))) {
    360    aResolver(Nothing());
    361    return IPC_OK();
    362  }
    363 
    364  // Return the result if success
    365  aResolver(Some(std::move(commitOutput)));
    366 
    367  return IPC_OK();
    368 }
    369 
    370 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupProposeRemove(
    371    const nsTArray<uint8_t>& aGroupIdentifier,
    372    const nsTArray<uint8_t>& aIdentifier,
    373    const nsTArray<uint8_t>& aRemIdentifier,
    374    RequestGroupProposeRemoveResolver&& aResolver) {
    375  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    376          ("MLSTransactionParent::RecvRequestGroupProposeRemove()"));
    377 
    378  nsTArray<uint8_t> proposal;
    379  nsresult rv = security::mls::mls_group_propose_remove(
    380      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    381      aIdentifier.Elements(), aIdentifier.Length(), aRemIdentifier.Elements(),
    382      aRemIdentifier.Length(), &proposal);
    383 
    384  // Return Nothing if failed
    385  if (NS_WARN_IF(NS_FAILED(rv))) {
    386    aResolver(Nothing());
    387    return IPC_OK();
    388  }
    389 
    390  // Return the result if success
    391  aResolver(Some(RawBytes{std::move(proposal)}));
    392 
    393  return IPC_OK();
    394 }
    395 
    396 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupClose(
    397    const nsTArray<uint8_t>& aGroupIdentifier,
    398    const nsTArray<uint8_t>& aIdentifier,
    399    RequestGroupCloseResolver&& aResolver) {
    400  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    401          ("MLSTransactionParent::RecvRequestGroupClose()"));
    402 
    403  // Call to the MLS rust code
    404  security::mls::GkMlsCommitOutput commitOutput;
    405  nsresult rv = security::mls::mls_group_close(
    406      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    407      aIdentifier.Elements(), aIdentifier.Length(), &commitOutput);
    408 
    409  // Return Nothing if failed
    410  if (NS_WARN_IF(NS_FAILED(rv))) {
    411    aResolver(Nothing());
    412    return IPC_OK();
    413  }
    414 
    415  // Return the result if success
    416  aResolver(Some(std::move(commitOutput)));
    417 
    418  return IPC_OK();
    419 }
    420 
    421 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGroupDetails(
    422    const nsTArray<uint8_t>& aGroupIdentifier,
    423    const nsTArray<uint8_t>& aIdentifier,
    424    RequestGroupDetailsResolver&& aResolver) {
    425  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    426          ("MLSTransactionParent::RecvRequestGroupDetails()"));
    427 
    428  // Call to the MLS rust code
    429  security::mls::GkGroupDetails details;
    430  nsresult rv = security::mls::mls_group_details(
    431      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    432      aIdentifier.Elements(), aIdentifier.Length(), &details);
    433 
    434  // Return Nothing if failed
    435  if (NS_WARN_IF(NS_FAILED(rv))) {
    436    aResolver(Nothing());
    437    return IPC_OK();
    438  }
    439 
    440  // Return the result if success
    441  aResolver(Some(std::move(details)));
    442 
    443  return IPC_OK();
    444 }
    445 
    446 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestSend(
    447    const nsTArray<uint8_t>& aGroupIdentifier,
    448    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aMessage,
    449    RequestSendResolver&& aResolver) {
    450  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    451          ("MLSTransactionParent::RecvRequestSend()"));
    452 
    453  // Call to the MLS rust code
    454  nsTArray<uint8_t> outputMessage;
    455  nsresult rv = security::mls::mls_send(
    456      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    457      aIdentifier.Elements(), aIdentifier.Length(), aMessage.Elements(),
    458      aMessage.Length(), &outputMessage);
    459 
    460  // Return Nothing if failed
    461  if (NS_WARN_IF(NS_FAILED(rv))) {
    462    aResolver(Nothing());
    463    return IPC_OK();
    464  }
    465 
    466  // Return the result if success
    467  aResolver(Some(RawBytes{std::move(outputMessage)}));
    468 
    469  return IPC_OK();
    470 }
    471 
    472 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestReceive(
    473    const nsTArray<uint8_t>& aClientIdentifier,
    474    const nsTArray<uint8_t>& aMessage, RequestReceiveResolver&& aResolver) {
    475  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    476          ("MLSTransactionParent::RecvRequestReceive()"));
    477 
    478  // Call to the MLS rust code
    479  GkReceived received;
    480  nsTArray<uint8_t> group_id_bytes;
    481 
    482  nsresult rv = security::mls::mls_receive(
    483      &mDatabasePath, aClientIdentifier.Elements(), aClientIdentifier.Length(),
    484      aMessage.Elements(), aMessage.Length(), &group_id_bytes, &received);
    485 
    486  // Return Nothing if failed
    487  if (NS_WARN_IF(NS_FAILED(rv))) {
    488    aResolver(GkReceived());
    489    return IPC_OK();
    490  }
    491 
    492  // Return the result if success
    493  aResolver(received);
    494 
    495  return IPC_OK();
    496 }
    497 
    498 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestHasPendingProposals(
    499    const nsTArray<uint8_t>& aGroupIdentifier,
    500    const nsTArray<uint8_t>& aClientIdentifier,
    501    RequestHasPendingProposalsResolver&& aResolver) {
    502  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    503          ("MLSTransactionParent::RecvRequestHasPendingProposals()"));
    504 
    505  // Call to the MLS rust code
    506  bool received = true;
    507  nsresult rv = security::mls::mls_has_pending_proposals(
    508      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    509      aClientIdentifier.Elements(), aClientIdentifier.Length(), &received);
    510 
    511  // Return Nothing if failed
    512  if (NS_WARN_IF(NS_FAILED(rv))) {
    513    aResolver(received);
    514    return IPC_OK();
    515  }
    516 
    517  // Return the result if success
    518  aResolver(received);
    519 
    520  return IPC_OK();
    521 }
    522 
    523 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestClearPendingProposals(
    524    const nsTArray<uint8_t>& aGroupIdentifier,
    525    const nsTArray<uint8_t>& aClientIdentifier,
    526    RequestClearPendingProposalsResolver&& aResolver) {
    527  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    528          ("MLSTransactionParent::RecvRequestCleanPendingProposals()"));
    529 
    530  // Call to the MLS rust code
    531  bool received = true;
    532  nsresult rv = security::mls::mls_clear_pending_proposals(
    533      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    534      aClientIdentifier.Elements(), aClientIdentifier.Length(), &received);
    535 
    536  // Return Nothing if failed
    537  if (NS_WARN_IF(NS_FAILED(rv))) {
    538    aResolver(received);
    539    return IPC_OK();
    540  }
    541 
    542  // Return the result if success
    543  aResolver(received);
    544 
    545  return IPC_OK();
    546 }
    547 
    548 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestHasPendingCommit(
    549    const nsTArray<uint8_t>& aGroupIdentifier,
    550    const nsTArray<uint8_t>& aClientIdentifier,
    551    RequestHasPendingCommitResolver&& aResolver) {
    552  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    553          ("MLSTransactionParent::RecvRequestHasPendingCommit()"));
    554 
    555  // Call to the MLS rust code
    556  bool received = true;
    557  nsresult rv = security::mls::mls_has_pending_commit(
    558      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    559      aClientIdentifier.Elements(), aClientIdentifier.Length(), &received);
    560 
    561  // Return Nothing if failed
    562  if (NS_WARN_IF(NS_FAILED(rv))) {
    563    aResolver(received);
    564    return IPC_OK();
    565  }
    566 
    567  // Return the result if success
    568  aResolver(received);
    569 
    570  return IPC_OK();
    571 }
    572 
    573 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestClearPendingCommit(
    574    const nsTArray<uint8_t>& aGroupIdentifier,
    575    const nsTArray<uint8_t>& aClientIdentifier,
    576    RequestClearPendingCommitResolver&& aResolver) {
    577  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    578          ("MLSTransactionParent::RecvRequestCleanPendingCommit()"));
    579 
    580  // Call to the MLS rust code
    581  bool received = true;
    582  nsresult rv = security::mls::mls_clear_pending_commit(
    583      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    584      aClientIdentifier.Elements(), aClientIdentifier.Length(), &received);
    585 
    586  // Return Nothing if failed
    587  if (NS_WARN_IF(NS_FAILED(rv))) {
    588    aResolver(received);
    589    return IPC_OK();
    590  }
    591 
    592  // Return the result if success
    593  aResolver(received);
    594 
    595  return IPC_OK();
    596 }
    597 
    598 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestApplyPendingCommit(
    599    const nsTArray<uint8_t>& aGroupIdentifier,
    600    const nsTArray<uint8_t>& aClientIdentifier,
    601    RequestApplyPendingCommitResolver&& aResolver) {
    602  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    603          ("MLSTransactionParent::RecvRequestApplyPendingCommit()"));
    604 
    605  // Call to the MLS rust code
    606  GkReceived received;
    607  nsresult rv = security::mls::mls_apply_pending_commit(
    608      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    609      aClientIdentifier.Elements(), aClientIdentifier.Length(), &received);
    610 
    611  // Return Nothing if failed
    612  if (NS_WARN_IF(NS_FAILED(rv))) {
    613    aResolver(GkReceived());
    614    return IPC_OK();
    615  }
    616 
    617  // Return the result if success
    618  aResolver(received);
    619 
    620  return IPC_OK();
    621 }
    622 
    623 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestExportSecret(
    624    const nsTArray<uint8_t>& aGroupIdentifier,
    625    const nsTArray<uint8_t>& aIdentifier, const nsTArray<uint8_t>& aLabel,
    626    const nsTArray<uint8_t>& aContext, uint64_t aLen,
    627    RequestExportSecretResolver&& aResolver) {
    628  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    629          ("MLSTransactionParent::RecvRequestExportSecret()"));
    630 
    631  // Call to the MLS rust code
    632  security::mls::GkExporterOutput exporterOutput;
    633  nsresult rv = security::mls::mls_derive_exporter(
    634      &mDatabasePath, aGroupIdentifier.Elements(), aGroupIdentifier.Length(),
    635      aIdentifier.Elements(), aIdentifier.Length(), aLabel.Elements(),
    636      aLabel.Length(), aContext.Elements(), aContext.Length(), aLen,
    637      &exporterOutput);
    638 
    639  // Return Nothing if failed
    640  if (NS_WARN_IF(NS_FAILED(rv))) {
    641    aResolver(Nothing());
    642    return IPC_OK();
    643  }
    644 
    645  // Return the result if success
    646  aResolver(Some(std::move(exporterOutput)));
    647 
    648  return IPC_OK();
    649 }
    650 
    651 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGetGroupIdentifier(
    652    const nsTArray<uint8_t>& aMessage,
    653    RequestGetGroupIdentifierResolver&& aResolver) {
    654  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    655          ("MLSTransactionParent::RecvRequestGetGroupIdentifier()"));
    656 
    657  nsTArray<uint8_t> groupId;
    658  nsresult rv = security::mls::mls_get_group_id(aMessage.Elements(),
    659                                                aMessage.Length(), &groupId);
    660 
    661  // Return Nothing if failed
    662  if (NS_WARN_IF(NS_FAILED(rv))) {
    663    aResolver(Nothing());
    664    return IPC_OK();
    665  }
    666 
    667  // Return the result if success
    668  aResolver(Some(RawBytes{std::move(groupId)}));
    669 
    670  return IPC_OK();
    671 }
    672 
    673 mozilla::ipc::IPCResult MLSTransactionParent::RecvRequestGetGroupEpoch(
    674    const nsTArray<uint8_t>& aMessage,
    675    RequestGetGroupIdentifierResolver&& aResolver) {
    676  MOZ_LOG(gMlsLog, mozilla::LogLevel::Debug,
    677          ("MLSTransactionParent::RecvRequestGetGroupEpoch()"));
    678 
    679  nsTArray<uint8_t> groupEpoch;
    680  nsresult rv = security::mls::mls_get_group_epoch(
    681      aMessage.Elements(), aMessage.Length(), &groupEpoch);
    682 
    683  // Return Nothing if failed
    684  if (NS_WARN_IF(NS_FAILED(rv))) {
    685    aResolver(Nothing());
    686    return IPC_OK();
    687  }
    688 
    689  // Return the result if success
    690  aResolver(Some(RawBytes{std::move(groupEpoch)}));
    691 
    692  return IPC_OK();
    693 }
    694 
    695 }  // namespace mozilla::dom