LCOV - code coverage report
Current view: top level - dom/webauthn - NSSU2FTokenRemote.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 80 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       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 "mozilla/dom/ContentChild.h"
       8             : 
       9             : #include "NSSU2FTokenRemote.h"
      10             : 
      11             : using mozilla::dom::ContentChild;
      12             : 
      13           0 : NS_IMPL_ISUPPORTS(NSSU2FTokenRemote, nsIU2FToken)
      14             : 
      15             : static mozilla::LazyLogModule gWebauthLog("webauth_u2f");
      16             : 
      17           0 : NSSU2FTokenRemote::NSSU2FTokenRemote()
      18           0 : {}
      19             : 
      20           0 : NSSU2FTokenRemote::~NSSU2FTokenRemote()
      21           0 : {}
      22             : 
      23             : NS_IMETHODIMP
      24           0 : NSSU2FTokenRemote::IsCompatibleVersion(const nsAString& aVersionString,
      25             :                                        bool* aIsCompatible)
      26             : {
      27           0 :   NS_ENSURE_ARG_POINTER(aIsCompatible);
      28             : 
      29           0 :   ContentChild* cc = ContentChild::GetSingleton();
      30           0 :   MOZ_ASSERT(cc);
      31           0 :   if (!cc->SendNSSU2FTokenIsCompatibleVersion(
      32           0 :         nsString(aVersionString), aIsCompatible)) {
      33           0 :     return NS_ERROR_FAILURE;
      34             :   }
      35           0 :   return NS_OK;
      36             : }
      37             : 
      38             : NS_IMETHODIMP
      39           0 : NSSU2FTokenRemote::IsRegistered(uint8_t* aKeyHandle, uint32_t aKeyHandleLen,
      40             :                                 uint8_t* aAppParam, uint32_t aAppParamLen,
      41             :                                 bool* aIsRegistered)
      42             : {
      43           0 :   NS_ENSURE_ARG_POINTER(aKeyHandle);
      44           0 :   NS_ENSURE_ARG_POINTER(aAppParam);
      45           0 :   NS_ENSURE_ARG_POINTER(aIsRegistered);
      46             : 
      47           0 :   nsTArray<uint8_t> keyHandle;
      48           0 :   if (!keyHandle.ReplaceElementsAt(0, keyHandle.Length(), aKeyHandle,
      49             :                                    aKeyHandleLen)) {
      50           0 :     return NS_ERROR_OUT_OF_MEMORY;
      51             :   }
      52             : 
      53           0 :   nsTArray<uint8_t> appParam;
      54           0 :   if (!appParam.ReplaceElementsAt(0, appParam.Length(), aAppParam,
      55             :                                   aAppParamLen)) {
      56           0 :     return NS_ERROR_OUT_OF_MEMORY;
      57             :   }
      58             : 
      59           0 :   ContentChild* cc = ContentChild::GetSingleton();
      60           0 :   MOZ_ASSERT(cc);
      61           0 :   if (!cc->SendNSSU2FTokenIsRegistered(keyHandle, appParam, aIsRegistered)) {
      62           0 :     return NS_ERROR_FAILURE;
      63             :   }
      64           0 :   return NS_OK;
      65             : }
      66             : 
      67             : NS_IMETHODIMP
      68           0 : NSSU2FTokenRemote::Register(uint8_t* aApplication,
      69             :                             uint32_t aApplicationLen,
      70             :                             uint8_t* aChallenge,
      71             :                             uint32_t aChallengeLen,
      72             :                             uint8_t** aRegistration,
      73             :                             uint32_t* aRegistrationLen)
      74             : {
      75           0 :   NS_ENSURE_ARG_POINTER(aApplication);
      76           0 :   NS_ENSURE_ARG_POINTER(aChallenge);
      77           0 :   NS_ENSURE_ARG_POINTER(aRegistration);
      78           0 :   NS_ENSURE_ARG_POINTER(aRegistrationLen);
      79             : 
      80           0 :   nsTArray<uint8_t> application;
      81           0 :   if (!application.ReplaceElementsAt(0, application.Length(), aApplication,
      82             :                                      aApplicationLen)) {
      83           0 :     return NS_ERROR_OUT_OF_MEMORY;
      84             :   }
      85           0 :   nsTArray<uint8_t> challenge;
      86           0 :   if (!challenge.ReplaceElementsAt(0, challenge.Length(), aChallenge,
      87             :                                    aChallengeLen)) {
      88           0 :     return NS_ERROR_OUT_OF_MEMORY;
      89             :   }
      90             : 
      91           0 :   nsTArray<uint8_t> registrationBuffer;
      92           0 :   ContentChild* cc = ContentChild::GetSingleton();
      93           0 :   MOZ_ASSERT(cc);
      94           0 :   if (!cc->SendNSSU2FTokenRegister(application, challenge,
      95             :                                    &registrationBuffer)) {
      96           0 :     return NS_ERROR_FAILURE;
      97             :   }
      98             : 
      99           0 :   size_t dataLen = registrationBuffer.Length();
     100           0 :   uint8_t* tmp = reinterpret_cast<uint8_t*>(moz_xmalloc(dataLen));
     101           0 :   if (NS_WARN_IF(!tmp)) {
     102           0 :     return NS_ERROR_OUT_OF_MEMORY;
     103             :   }
     104             : 
     105           0 :   memcpy(tmp, registrationBuffer.Elements(), dataLen);
     106           0 :   *aRegistration = tmp;
     107           0 :   *aRegistrationLen = dataLen;
     108           0 :   return NS_OK;
     109             : }
     110             : 
     111             : NS_IMETHODIMP
     112           0 : NSSU2FTokenRemote::Sign(uint8_t* aApplication, uint32_t aApplicationLen,
     113             :                         uint8_t* aChallenge, uint32_t aChallengeLen,
     114             :                         uint8_t* aKeyHandle, uint32_t aKeyHandleLen,
     115             :                         uint8_t** aSignature, uint32_t* aSignatureLen)
     116             : {
     117           0 :   NS_ENSURE_ARG_POINTER(aApplication);
     118           0 :   NS_ENSURE_ARG_POINTER(aChallenge);
     119           0 :   NS_ENSURE_ARG_POINTER(aKeyHandle);
     120           0 :   NS_ENSURE_ARG_POINTER(aSignature);
     121           0 :   NS_ENSURE_ARG_POINTER(aSignatureLen);
     122             : 
     123           0 :   nsTArray<uint8_t> application;
     124           0 :   if (!application.ReplaceElementsAt(0, application.Length(), aApplication,
     125             :                                      aApplicationLen)) {
     126           0 :     return NS_ERROR_OUT_OF_MEMORY;
     127             :   }
     128             : 
     129           0 :   nsTArray<uint8_t> challenge;
     130           0 :   if (!challenge.ReplaceElementsAt(0, challenge.Length(), aChallenge,
     131             :                                    aChallengeLen)) {
     132           0 :     return NS_ERROR_OUT_OF_MEMORY;
     133             :   }
     134           0 :   nsTArray<uint8_t> keyHandle;
     135           0 :   if (!keyHandle.ReplaceElementsAt(0, keyHandle.Length(), aKeyHandle,
     136             :                                    aKeyHandleLen)) {
     137           0 :     return NS_ERROR_OUT_OF_MEMORY;
     138             :   }
     139             : 
     140           0 :   nsTArray<uint8_t> signatureBuffer;
     141           0 :   ContentChild* cc = ContentChild::GetSingleton();
     142           0 :   MOZ_ASSERT(cc);
     143           0 :   if (!cc->SendNSSU2FTokenSign(application, challenge, keyHandle,
     144             :                                &signatureBuffer)) {
     145           0 :     return NS_ERROR_FAILURE;
     146             :   }
     147             : 
     148           0 :   size_t dataLen = signatureBuffer.Length();
     149           0 :   uint8_t* tmp = reinterpret_cast<uint8_t*>(moz_xmalloc(dataLen));
     150           0 :   if (NS_WARN_IF(!tmp)) {
     151           0 :     return NS_ERROR_OUT_OF_MEMORY;
     152             :   }
     153             : 
     154           0 :   memcpy(tmp, signatureBuffer.Elements(), dataLen);
     155           0 :   *aSignature = tmp;
     156           0 :   *aSignatureLen = dataLen;
     157           0 :   return NS_OK;
     158             : }

Generated by: LCOV version 1.13