Example #1
0
void
TtbDialog::finishSettings(QNetworkReply *reply)
{
    progressBar->setValue(4);

    TtbSettingsParser handler;
    QXmlInputSource source( reply );

    QXmlSimpleReader reader;
    reader.setContentHandler( &handler );

    if( ! reader.parse( source ) ){
        progressLabel->setText(tr("failed to parse Settings response: ")
            +handler.errorString());
        closeButton->setText(tr("&Close"));
        return;
    }

    if( handler.error.length() > 0 ){
        progressLabel->setText(tr("failed to get settings: ")
            +handler.error );
        closeButton->setText(tr("&Close"));
        return;
    }

    sessionId = handler.session;
    proMember = handler.pro;

    if( sessionId.length() == 0 ){
        requestSession();
    } else {
        requestUpload();
    }
}
Example #2
0
void FbxAPI::requestLoginFinished()
{
    QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
    QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

    if(parseResult(doc)) {
        requestSession();
    }


}
Example #3
0
void CNcdNodeLink::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const
    {
    DLTRACEIN((""));

    // Decrease the reference count for this object.
    // When the reference count reaches zero, this object will be destroyed
    // and removed from the session.
    MCatalogsSession& requestSession( aMessage.Session() );
    TInt handle( aMessage.Handle() );
    aMessage.CompleteAndRelease( KErrNone );
    requestSession.RemoveObject( handle );
        
    DLTRACEOUT((""));
    }    
void
VeloHeroUploader::upload()
{
    uploadSuccessful = false;
    requestSession();

    if( !uploadSuccessful ){
        parent->progressLabel->setText(tr("Error uploading to VeloHero"));

    } else {
        parent->progressLabel->setText(tr("successfully uploaded to VeloHero as %1")
            .arg(exerciseId));

        ride->ride()->setTag("VeloHeroExercise", exerciseId );
        ride->setDirty(true);
    }
}
void CNcdNodeFolder::NodeSeenFolderHandleRequestL( MCatalogsBaseMessage& aMessage ) const
    {
    DLTRACEIN((("this-ptr: %x"), this));
    DASSERT( iNodeSeenFolder );
    
    // Get the session that will contain the handle of the node seen folder object
    MCatalogsSession& requestSession( aMessage.Session() );

    // Add the node seen folder object to the session and get the handle.
    // If the object already existed in the session we will still
    // get a new handle to the same object.
    TInt32 handle( requestSession.AddObjectL( iNodeSeenFolder ) );

    DLINFO(("Node seen folder handle: %d", handle ));
        
    // Send the information to the client side
    // If this leaves, ReceiveMessage will complete the message.
    aMessage.CompleteAndReleaseL( handle, KErrNone );
    }
Example #6
0
 void WhiteboardManager::handleUIEvent(std::shared_ptr<UIEvent> event) {
     std::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = std::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event);
     if (requestWhiteboardEvent) {
         requestSession(requestWhiteboardEvent->getContact());
     }
     std::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = std::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event);
     if (sessionAcceptEvent) {
         acceptSession(sessionAcceptEvent->getContact());
     }
     std::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = std::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event);
     if (sessionCancelEvent) {
         cancelSession(sessionCancelEvent->getContact());
     }
     std::shared_ptr<ShowWhiteboardUIEvent> showWindowEvent = std::dynamic_pointer_cast<ShowWhiteboardUIEvent>(event);
     if (showWindowEvent) {
         WhiteboardWindow* window = findWhiteboardWindow(showWindowEvent->getContact());
         if (window != nullptr) {
             window->activateWindow();
         }
     }
 }
UA_StatusCode
processOPNResponseAsync(void *application, UA_Connection *connection,
                        UA_ByteString *chunk) {
    UA_Client *client = (UA_Client*) application;
    UA_StatusCode retval = UA_SecureChannel_decryptAddChunk(&client->channel, chunk, true);
    client->connectStatus = retval;
    if(retval != UA_STATUSCODE_GOOD)
        goto error;
    UA_SecureChannel_processCompleteMessages(&client->channel, client, processDecodedOPNResponseAsync);
    
    if(client->state < UA_CLIENTSTATE_SECURECHANNEL) {
        retval = UA_STATUSCODE_BADSECURECHANNELCLOSED;
        goto error;
    }

    retval = UA_SecureChannel_persistIncompleteMessages(&client->channel);
    if(retval != UA_STATUSCODE_GOOD)
        goto error;

    retval = UA_SecureChannel_generateNewKeys(&client->channel);
    if(retval != UA_STATUSCODE_GOOD)
        goto error;

    /* Following requests and responses */
    UA_UInt32 reqId;
    if(client->endpointsHandshake)
        retval = requestGetEndpoints (client, &reqId);
    else
        retval = requestSession (client, &reqId);

    if(retval != UA_STATUSCODE_GOOD)
        goto error;

    return retval;

error:
    UA_Client_disconnect(client);

    return retval;
}
void
TrainingstagebuchUploader::finishSettings(QNetworkReply *reply)
{
    parent->progressBar->setValue(parent->progressBar->value()+5/parent->shareSiteCount);

    TtbSettingsParser handler;
    QXmlInputSource source( reply );

    QXmlSimpleReader reader;
    reader.setContentHandler( &handler );

    if( ! reader.parse( source ) ){
        parent->errorLabel->setText(tr("failed to parse Settings response: ")
            +handler.errorString());

        eventLoop.quit();
        return;
    }

    if( handler.error.length() > 0 ){
        parent->errorLabel->setText(tr("failed to get settings: ")
            +handler.error );

        eventLoop.quit();
        return;
    }

    sessionId = handler.session;
    proMember = handler.pro;

    if( sessionId.length() == 0 ){
        requestSession();
    } else {
        requestUpload();
    }
}
/* Combination of UA_Client_getEndpointsInternal and getEndpoints */
static void
responseGetEndpoints(UA_Client *client, void *userdata, UA_UInt32 requestId,
                     void *response) {
    UA_EndpointDescription* endpointArray = NULL;
    size_t endpointArraySize = 0;
    UA_GetEndpointsResponse* resp;
    resp = (UA_GetEndpointsResponse*)response;

    if (resp->responseHeader.serviceResult != UA_STATUSCODE_GOOD) {
        client->connectStatus = resp->responseHeader.serviceResult;
        UA_LOG_ERROR(&client->config.logger, UA_LOGCATEGORY_CLIENT,
                     "GetEndpointRequest failed with error code %s",
                     UA_StatusCode_name (client->connectStatus));
        UA_GetEndpointsResponse_deleteMembers(resp);
        return;
    }
    endpointArray = resp->endpoints;
    endpointArraySize = resp->endpointsSize;
    resp->endpoints = NULL;
    resp->endpointsSize = 0;

    UA_Boolean endpointFound = false;
    UA_Boolean tokenFound = false;
    UA_String securityNone = UA_STRING("http://opcfoundation.org/UA/SecurityPolicy#None");
    UA_String binaryTransport = UA_STRING("http://opcfoundation.org/UA-Profile/"
                                          "Transport/uatcp-uasc-uabinary");

    // TODO: compare endpoint information with client->endpointUri
    for(size_t i = 0; i < endpointArraySize; ++i) {
        UA_EndpointDescription* endpoint = &endpointArray[i];
        /* look out for binary transport endpoints */
        /* Note: Siemens returns empty ProfileUrl, we will accept it as binary */
        if(endpoint->transportProfileUri.length != 0
                && !UA_String_equal (&endpoint->transportProfileUri,
                                     &binaryTransport))
            continue;

        /* Look for an endpoint corresponding to the client security policy */
        if(!UA_String_equal(&endpoint->securityPolicyUri, &client->channel.securityPolicy->policyUri))
            continue;

        endpointFound = true;

        /* Look for a user token policy with an anonymous token */
        for(size_t j = 0; j < endpoint->userIdentityTokensSize; ++j) {
            UA_UserTokenPolicy* userToken = &endpoint->userIdentityTokens[j];

            /* Usertokens also have a security policy... */
            if(userToken->securityPolicyUri.length > 0 &&
               !UA_String_equal(&userToken->securityPolicyUri, &securityNone))
                continue;

            /* Does the token type match the client configuration? */
            if((userToken->tokenType == UA_USERTOKENTYPE_ANONYMOUS &&
                client->config.userIdentityToken.content.decoded.type !=
                &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN] &&
                client->config.userIdentityToken.content.decoded.type != NULL) ||
               (userToken->tokenType == UA_USERTOKENTYPE_USERNAME &&
                client->config.userIdentityToken.content.decoded.type !=
                &UA_TYPES[UA_TYPES_USERNAMEIDENTITYTOKEN]) ||
               (userToken->tokenType == UA_USERTOKENTYPE_CERTIFICATE &&
                client->config.userIdentityToken.content.decoded.type !=
                &UA_TYPES[UA_TYPES_X509IDENTITYTOKEN]) ||
               (userToken->tokenType == UA_USERTOKENTYPE_ISSUEDTOKEN &&
                client->config.userIdentityToken.content.decoded.type !=
                &UA_TYPES[UA_TYPES_ISSUEDIDENTITYTOKEN]))
                continue;

            /* Endpoint with matching usertokenpolicy found */
            tokenFound = true;
            UA_EndpointDescription_deleteMembers(&client->config.endpoint);
            UA_EndpointDescription_copy(endpoint, &client->config.endpoint);
            UA_UserTokenPolicy_deleteMembers(&client->config.userTokenPolicy);
            UA_UserTokenPolicy_copy(userToken, &client->config.userTokenPolicy);
            break;
        }
    }

    UA_Array_delete(endpointArray, endpointArraySize,
                    &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);

    if(!endpointFound) {
        UA_LOG_ERROR(&client->config.logger, UA_LOGCATEGORY_CLIENT,
                     "No suitable endpoint found");
        client->connectStatus = UA_STATUSCODE_BADINTERNALERROR;
    } else if(!tokenFound) {
        UA_LOG_ERROR(&client->config.logger, UA_LOGCATEGORY_CLIENT,
                     "No suitable UserTokenPolicy found for the possible endpoints");
        client->connectStatus = UA_STATUSCODE_BADINTERNALERROR;
    }
    requestSession(client, &requestId);
}
Example #10
0
Result
DoOCSPRequest(PLArenaPool* arena, const char* url,
              const SECItem* encodedRequest, PRIntervalTime timeout,
              bool useGET,
      /*out*/ SECItem*& encodedResponse)
{
  if (!arena || !url || !encodedRequest || !encodedRequest->data) {
    return Result::FATAL_ERROR_INVALID_ARGS;
  }
  uint32_t urlLen = PL_strlen(url);
  if (urlLen > static_cast<uint32_t>(std::numeric_limits<int32_t>::max())) {
    return Result::FATAL_ERROR_INVALID_ARGS;
  }

  nsCOMPtr<nsIURLParser> urlParser = do_GetService(NS_STDURLPARSER_CONTRACTID);
  if (!urlParser) {
    return Result::FATAL_ERROR_LIBRARY_FAILURE;
  }

  uint32_t schemePos;
  int32_t schemeLen;
  uint32_t authorityPos;
  int32_t authorityLen;
  uint32_t pathPos;
  int32_t pathLen;
  nsresult nsrv = urlParser->ParseURL(url, static_cast<int32_t>(urlLen),
                                      &schemePos, &schemeLen,
                                      &authorityPos, &authorityLen,
                                      &pathPos, &pathLen);
  if (NS_FAILED(nsrv)) {
    return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
  }
  if (schemeLen < 0 || authorityLen < 0) {
    return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
  }
  nsAutoCString scheme(url + schemePos,
                       static_cast<nsAutoCString::size_type>(schemeLen));
  if (!scheme.LowerCaseEqualsLiteral("http")) {
    // We don't support HTTPS to avoid loops. See Bug 92923.
    // We also in general only support HTTP.
    return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
  }

  uint32_t hostnamePos;
  int32_t hostnameLen;
  int32_t port;
  // We ignore user:password sections: if one is present, we send an OCSP
  // request to the URL as normal without sending the username or password.
  nsrv = urlParser->ParseAuthority(url + authorityPos, authorityLen,
                                   nullptr, nullptr, nullptr, nullptr,
                                   &hostnamePos, &hostnameLen, &port);
  if (NS_FAILED(nsrv)) {
    return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
  }
  if (hostnameLen < 0) {
    return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
  }
  if (port == -1) {
    port = 80;
  } else if (port < 0 || port > 0xffff) {
    return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
  }
  nsAutoCString
    hostname(url + authorityPos + hostnamePos,
             static_cast<nsACString_internal::size_type>(hostnameLen));

  SEC_HTTP_SERVER_SESSION serverSessionPtr = nullptr;
  Result rv = nsNSSHttpInterface::createSessionFcn(
    hostname.BeginReading(), static_cast<uint16_t>(port), &serverSessionPtr);
  if (rv != Success) {
    return rv;
  }
  UniqueHTTPServerSession serverSession(
    reinterpret_cast<nsNSSHttpServerSession*>(serverSessionPtr));

  nsAutoCString path;
  if (pathLen > 0) {
    path.Assign(url + pathPos, static_cast<nsAutoCString::size_type>(pathLen));
  } else {
    path.Assign("/");
  }
  MOZ_LOG(gCertVerifierLog, LogLevel::Debug,
         ("Setting up OCSP request: pre all path =%s  pathlen=%d\n", path.get(),
          pathLen));
  nsAutoCString method("POST");
  if (useGET) {
    method.Assign("GET");
    if (!StringEndsWith(path, NS_LITERAL_CSTRING("/"))) {
      path.Append("/");
    }
    nsresult nsrv = AppendEscapedBase64Item(encodedRequest, path);
    if (NS_WARN_IF(NS_FAILED(nsrv))) {
      return Result::FATAL_ERROR_LIBRARY_FAILURE;
    }
  }

  SEC_HTTP_REQUEST_SESSION requestSessionPtr;
  rv = nsNSSHttpInterface::createFcn(serverSession.get(), "http", path.get(),
                                     method.get(), timeout, &requestSessionPtr);
  if (rv != Success) {
    return rv;
  }

  UniqueHTTPRequestSession requestSession(
    reinterpret_cast<nsNSSHttpRequestSession*>(requestSessionPtr));

  if (!useGET) {
    rv = nsNSSHttpInterface::setPostDataFcn(
      requestSession.get(), reinterpret_cast<char*>(encodedRequest->data),
      encodedRequest->len, "application/ocsp-request");
    if (rv != Success) {
      return rv;
    }
  }

  uint16_t httpResponseCode;
  const char* httpResponseData;
  uint32_t httpResponseDataLen = 0; // 0 means any response size is acceptable
  rv = nsNSSHttpInterface::trySendAndReceiveFcn(requestSession.get(), nullptr,
                                                &httpResponseCode, nullptr,
                                                nullptr, &httpResponseData,
                                                &httpResponseDataLen);
  if (rv != Success) {
    return rv;
  }

  if (httpResponseCode != 200) {
    return Result::ERROR_OCSP_SERVER_ERROR;
  }

  encodedResponse = SECITEM_AllocItem(arena, nullptr, httpResponseDataLen);
  if (!encodedResponse) {
    return Result::FATAL_ERROR_NO_MEMORY;
  }

  memcpy(encodedResponse->data, httpResponseData, httpResponseDataLen);
  return Success;
}