Scoping of keys in vscode extension global scope - visual-studio-code

The context of a vscode extension provides access to globalState which is a Memento object with key/value pairs. My question is: does each extension get its own memento object, or is there one shared by all extensions? Just wondering whether I need to make my keys more specific (e.g., my.extension.foo), or if I can keep the keys simple (e.g., foo).

It's scoped to your extension, so you can keep them simple:
However, when an extension uses storage, it will always get it's data stored under 1 key (the extension name + extension ID). We never allow to write directly into storage under a key that could conflict with other keys.
(source)

Related

Swift: Access struct/class variables by string name

I would like to access a variables by its literal name in string form.
So far I've found two ways:
https://stackoverflow.com/a/51090177/2330482 which doesn't let me write to the variables
Doing https://stackoverflow.com/a/44461705/2330482 which crashes the app if the key is not found (I don't want to run that risk). If there is a way to check if the key exists first, that would likely resolve my problem. I could combine this with Mirror in the first linked answer to get all keys (and therefore know they exist) before accessing them via .value(forKey) but this seems a bit unsafe. Is there another way to catch the crash if there is no key, or another way for NSObject to first make sure the key doesn't exist?
The reason why I want to do this is to make a struct fallback to default values if an incomplete JSON is fed. If I'm able to safely access variables by their name I could probably solve this problem without having to write Codable implementations for each variable in the struct.

Disabling Key object usage in PKCS#11

I wanted to know if there is a way a disable a particular operation on a PKCS#11 Object. For instance, I create an Object (AES Key) using C_CreateObject. I would want to set some property in this object that pauses/ disables the use of this object for any encryption/ decryption use. Is this possible ? Can we set the CKA_DECRYPT value to CK_FALSE to disable Decrypt operations? Also can this be changed multiple times using C_SetAttributeValue
Theoretically PKCS#11 standard don't restrict your from changing values of properties.
Practically your possibility to change the values after object created dependent on your PKCS#11 provider.
My suggestion that this property is immutable.
Try to set this values during creation of key or change values during copying of key object using C_CopyObject.
Another solution is to implement your own PKCS#11 proxy library with custom logic inside of PKCS#11 exported functions.

How do I create persistent path variables?

I've found that the $HOME variable can be rather useful for keyboard-only navigation in PowerShell. It would be nice to have a number of shortcuts stored as persistent path variables that can be accessed using the same syntax. I've seen the method $env:MyTestVariable = "My temporary test variable." but the result isn't persistent and still has to be accessed by typing $env:MyTestVariable which is not as succinct as the desired $MyTestVariable.
How can I create such variables and control what level has access to them (aka User, Machine, and Process)?

Extract CKA_Value from Key or data Object in PKCS11

I would like to read Key value from a KEY/Data object of PKCS11 into a local variable.
I observe that Key is stored in CKA_VALUE of Key object.
Which is the ideal function to be used to get this value to my local variable?
I have used C_GetAttributeValue it but doesn't help.
Please guide me.
Thanks
Harsha
Private keys of assymmetric algorithms and symmetric keys usually can not be extracted from the hardware device. This is a protection measure. That's why you can't get the value.
There exist exceptions (some implementations allow you to add the key and explicitly mark it as not protected, in which case the key can be read later) but this reduces security and other user benefits, so this not popular.
In some implementation, if you set the CKA.CKA_SENSITIVE to false, yes you can read the value.
If CKA_EXTRACTABLE is set to CK_FALSE on a key then the value cannot be extracted using PKCS#11.
IF CKA_SENSITIVE is set to CK_TRUE then a key cannot be extracted in plain text.
However,
If CKA_EXTRACTABLE is CK_TRUE, and CKA_SENSITIVE is CK_FALSE the key can be extracted using CKA_VALUE.
If CKA_EXTRACTABLE is CK_TRUE, and CKA_SENSITIVE is CK_TRUE the key can be extracted by wrapping the key using C_WrapKey, then unwrapping the wrapped key outside the unit.

How to get registry Key name from an open Key Handle in Perl?

I have a perl function that takes an open registry key object. Now, I want to get the name of the key this object represents. How do I get the key Name?
I am using Win32::Registry module.
Browsing through the source, it doesn't look like Win32::Registry will let you take the handle and get back to the Key. I see three ways around this:
Maintain a list of returned objects from Open and the path to them yourself.
Hack the module (subclass it, change the source) to do #1 for you.
Or extend the Win32::Registry API to do what's shown in this stackoverflow answer: Determine path to registry key from HKEY handle in C++