Fixing keyset errors on the neuron

If you have trouble setting up your neuron and see in the event logs, which you can see in IoT Gateway/Events/ get one of the errors:

  • “Unable to get access to cryptographic key for database file C:\ProgramData\IoT Gateway\Data\<FILE_NAME>. (Object already exists.) Was the database created using another user?”
  • “Unable to get access to cryptographic key for database file C:\ProgramData\IoT Gateway\Data\<FILE_NAME>. (Keyset does not exist.) Was the database created using another user?”
  • “Unable to get access to cryptographic key for database file C:\ProgramData\IoT Gateway\Data\<FILE_NAME>. (Access denied.) Was the database created using another user?”

You installed the neuron in a bad way. What happened to me was that I had run the installer as administrator. This then creates the encryption keys, and then when the neuron starts running, it does not have the privileges to read them.

I recommend reading all the steps once before beginning the restoration. And always be careful, I figured out these steps on a computer that did not have any sensitive or important data so was not worried about breaking anything. Lastly, I would not consider myself deeply knowledgeable about the windows operating system so take everything with a grain of salt and preferably double check that what you are doing is correct.

What to do:

  1. Uninstall the neuron
  2. Delete everything in IoT Gateway/Data (be careful as this will delete all persistence files/data on the neuron)
  3. Go to ProgramData/Microsoft/Crypto/RSA/MachineKeys
  4. What we need to do here is to delete all the keys created by the installer, these keys are the persistence encryption keys generated by the installer. There probably are multiple ways of finding the correct files to delete but one way is to find every file containing any file path relating to /Iot Gateway. To do this download and extract the windows utility tools at https\://learn.microsoft.com/en-gb/sysinternals/downloads/psexec .
  5. Run PowerShell as administrator and navigate to the folder containing the tools.
  6. Run “./PsExec.exe -i -s C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe”. This will start a PowerShell instance running as the SYSTEM user (this is neccesary to later read the machine keyset files).
  7. Accept the terms and conditions of the external tool. Now you need to be careful since you now have a PowerShell logged in as the SYSTEM.
  8. Navigate to C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
  9. Run the command: “findstr /s /m “IoT Gateway” /*” This will list all the files containing the string “IoT Gateway” in its content. You should be good to go to delete all those files (you can do that with the file explorer as a normal administrator) but be careful to not delete any other files. If you are comfortable, you could create a script to delete these files, but it should not take too long to do it manually, especially if you only have the Files.master file in /Data (every file there got its own encryption keyset). A few tips to speed up the process of deleting the keys are:
  • The keys are usually concurrent when sorting by Date modified in the windows explorer
  • Whenever you see a long time step in date modified, look in both files to see if they are a part of the IoT Gateway keysets, (run Get-Content <filename> in the PowerShell running as SYSTEM) Or check that the files are in the file list outputted by the findstr
  1. Then lastly reinstall the neuron as normal.

Now it should work as normal again.

Notes:

  • These instructions could also be useful if you manually deleted all the files in /Data and when trying to reinstall the neuron get one of these errors.
  • Other ways of finding out which files you should delete if you don’t want to use these external tools, you could find the keys created at the same time as you installed the neuron, and make yourself the owner of the file, give you read permission to see if they are the correct one (do this with the first and the last in the time period when sorting by date modified to find which “block” of keys where created by the installer). Though i would recommend doing the first way explained since it contains fewer risks regarding not potentially delete or changing permissions on unwanted files.

#neuron, #tutorial, #install, #troubleshooting, #error


Agent API Javascript NPM package

Currently, there is no package on the public npm package registry, but you can still add the package as a dependency in your package.json. You just add

“agent-api”: “https:confused face:/github.com/Trust-Anchor-Group/AgentApiJavascript.gitnpm-package”

to your dependencies. Though, note that this might require that you have the newest version of the AgentApi on your neuron (which may require the newest neuron version). This is because the repo is designed for the latest version, which means that it might be different since the AgentApi is ever evolving. And at last, there currently is only one version, which if it is updated, and you later install your dependencies, the package might have changed. So if you for some reason do not plan to update the neuron or your code, it might be better to copy the code in the package. For those curious, there is currently not a package for the typescript version.

In The Code

if you use ES6 import syntax just use : `js import AgentAPI from "agent-api" AgentApi.Legal.CreateContract()

or if you use CommonJs: `js const AgentAPI = require("agent-api") AgentApi.Legal.CreateContract()

The Github Repository

As you may see, the package is located in the npm-package branch on the AgentApiJavascript repository on Github. If you notice that the main branch have got some important commits that the npm-package does not, please consider rebasing the npm-package branch to the main branch. If you are not sure how to rebase, consider learning more about it, absolutely use something like Sourcetree to check that you did it right, and if you are worried, make a backup of the repo.

#javascript, #npm, #package, #agentapi


Error while installing a neuron

When installing the neuron you might get an error like this:

If you click on log file and open it in a text editor and see text like this:

You need to uninstall Microsoft Visual C++ 2015-2022 Redistributable (x64). I do not know why but it have always worked at least.

You can uninstall it on the controll panel at “Control Panel\Programs\Programs and Features”

After this, you should be good to go and can try to install it once again.


How to upload a create-react-app project to a subdirectory on a neuron

When running the build script for a create react app, it generates a single .html file where all the server request needs to be redirected, a static folder containing javascript and other imported assets (such as css and images) and all files and folders in your public directory. By default, when building, it assumes you will be deploying to the root of a webpage and when deploying to a subdirectory some things need to be set up in your code and your operating neuron.

App Setup

Static content

Static content in react create app is all the content which is imported in your actual code, things such as javascript, images and css (not assets in your public folder which are used with a href or src). For these to be properly linked. By linking I mean to make sure react gets the correct urls to query for the resources, to do this you need to set “homepage”: “/subdirectory/” in your package.json, however, you could instead set it to “.” . This makes sure that all paths are relative to index.html insted.

Public folder

To fix assets imported with a url you need to add <base href=”%PUBLIC_URL%”/> to your index.html then in your environment variables add PUBLIC_URL=’/path/to/subdirectory’. Finally make every such url is relative (they will be relative to the PUBLIC_URL) ex: <img src=”./images/test.png”>

React Router Dom

If your app uses react-router-dom, you need to specify base path in your BrowserRouter. Specifically, you need the base path attribute set to whatever subdirectory you are deploying to, or just the PUBLIC_URL environment variable. Here is an example: <BrowserRouter basepath={process.env.PUBLIC_URL} > … </BrowserRouter>

Quick Build Tip

To make development or deployment easier, set your projects BUILD_PATH environment variable to the correct folder/subdirectory in the neurons Root folder.

Neuron Setup

Vanity Resources

First of all, you need to redirect all request made to ‘/sub/directory/{path}’ to ‘/sub/directory/index.html’, this is because if a user clicks a link wich redirects to any other folder than index.html, even though it is defined in the browser router, it will return a 404 since the neuron does not know any such folder, it is the index.html folder which programmatically (with the browser router) determine which “page” to render. To fix this you need to add this vanity resource to your gateway.config folder: <VanityResource regex=”\/{SUB_DIRECTORY}\/[^\.]*?(\?.*$|$)” url=”/{DIRECTORY_IN_ROOT}/index.html”/>. Note that this only redirects all requests without a file extension to the index.html (not any .png or .extention). This is because any assets in the public directory need to be available when requested. If you are familiar with regex, the extra fuff in the expression is to pass request such as “/subdirectory/example_page?test=uri.data” to be passed to index.html.

#neuron, #react, #tutorial


Posts by user

No more posts authored by the user could be found. You can go back to the main view by selecting Home in the menu above.