Python OpenSSL: How to create an X509Name object - pyopenssl

I need to filter incoming X509 certificates by issuer, and I am using Pyhton's OpenSSL.crypto for this. However, I did not find how to create an X509Name object as a constant, which I need to compare with the value I get from cert.get_issuer().

Best thing I can think of, for you to create a new X509Name is to use
name = crypto.X509Name(crypto.X509().get_subject())
and subsequently populate the attributes via
name.__setattr__(att_name, attr_value)
However, for comparison alone, better to use the hash() builtin function of the class, that returns a hash for the whole name, or do a per-attribute comparison

Related

How can I encrypt the parameters of a panel in the same way as Genexus?

We need to encrypt a string in the same way that Genexus (17U10 and csharp if it's important) encrypts the parameters of a panel using the site key.
To better understand, the first is the url with unencrypted parameters, the second is the same url with parameters encrypted via site key
http://localhost/TestVersione17U10.NETFrameworkEnvironment/webpanel3.aspx?par1=hello
http://localhost/TestVersione17U10.NETFrameworkEnvironment/webpanel3.aspx?ROndRLvw5t80mViNc0wdKO7XYc-OgWL61k9lDimrqI0
Reading in the wiki, I believe that genexus uses the key stored in the application.key file and uses the twofish algorithm.
7E2E22D26FF2989E2444852A85E57867
This is the key I have in the file, I tried in every way to get the second string starting from the first, but without success.
The native Encrypt64 method gave no results, the generated string is different.
I also noticed that the same parameters are encrypted differently when I call another panel, so I believe it somehow uses the panel name as well.
( webpanel2.aspx?mY8XtkZ-3eBJKsDIFk-zX3DP2PuQC2LHIkqwFtE1CZw )
What am I doing wrong? Is the key wrong? Do you use any other way to encrypt other than Encrypt64?
I’m not sure what you really want to implement. I mean, do you want storage this link? Do you need it in order to call from a “non GX application”?
Anyway, as you said, object name is included in the algorithm to URL encryption.
This algorithm is not available as a “function” to be used by GX developers directly. However, there are two ways to do something like that in Genexus:
To use “link” function. https://wiki.genexus.com/commwiki/servlet/wiki?8444,Link%20Function
To use non standard functions. Suppose you have “webpanel3.aspx par1=hello,par2=world” then the code could be something like:
&GXKey = GetSiteKey()
&GXEncryptionTmp = "webpanel3.aspx"+UrlEncode("hello”) + "," + UrlEncode("world")
&EncryptedParms= "?" + UriEncrypt64( &GXEncryptionTmp + CheckSum(&GXEncryptionTmp, 6), &GXKey))
Note: You must enable “non standard functions” (https://wiki.genexus.com/commwiki/servlet/wiki?8013,Standard%20Functions%20property%20at%20Object%20level)
If you need to call from a non GX application, there are to options:
To use a GX generated program as “proxy”. This object receive not encrypted parms and returns the encrypted URL or directly encrypt the parameters and call the corresponding object
To explore object generated in order to mimic that code in your solution/code. This includes exploring GXClassses (i.e. https://github.com/genexuslabs/DotNetClasses)

macOS command line app - User Defaults dictionaryRepresentation shows too many values

I a developing a macOS commandline application in Xcode, which uses User Defaults. I have the following code for my User Defaults
if let configDefaults = UserDefaults.init(suiteName: "com.tests.configuration") {
configDefaults.set("myStringValue", forKey: "stringKey")
configDefaults.synchronize()
print(configDefaults.dictionaryRepresentation())
}
This will create my own .plist file in the ~/Library/Preferences folder. If I look into the file, I can see only my single value which I added, which is perfectly fine. But when I call dictionaryRepresentation() on my UserDefaults object, the there are a lot of other attributes (I guess from the shared UserDefaults object), like
com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture or AKLastEmailListRequestDateKey
Looking into the documentation of UserDefaults, it seems that this has to do with the search list of UserDefaults and that the standard object is in the search list:
func dictionaryRepresentation() -> [String : Any]
Returns a dictionary that contains a union of all key-value pairs in the domains in the search list.
There are also the methods addSuite and removeSuite for a UserDefaults object, so I am guessing I need to remove the .standard suite from my configDefaults object, but I don't know the name, which should be used for that in the method.
Is it possible to remove the .standard defaults from the dictionary representation? I basically just want all of my own data in a dictionary, nothing more.
The reason I am trying to get only my values from the UserDefaults, is that a have a number of object of a custom type Connection (which store the configuration to connect to a server), which are saved in the UserDefaults. On program start I want to be able to load all objects into my app. Therefore I thought I could use dictionaryRepresentation(), as it would return all elements in the UserDefaults. But then there should be only my Connection objects in the dictionary, so that I can cast it to [String: Connection].
Given your purpose (in your latest edit of your question), what you should do is store a collection of Connection objects under a single key. Then, look up that key to get the collection.
It's not clear if the collection should be an array of Connection objects or a dictionary mapping strings to Connections. That's a choice you can make.
But, in any case, you shouldn't rely on the defaults being empty of everything else.
In other words, you would do:
UserDefaults.standard.set(yourStringToConnectionDictionary, forKey:"yourSingleKey")
and later:
let connectionMap = UserDefaults.dictionary(forKey:"yourSingleKey")
then look up Connections in the connectionMap by their name/ID/whatever.
Though the other solution proposed by Ken Thomases may be better from a design standpoint, I've found a solution that does exactly what I initially wanted. Calling
UserDefaults.standard.persistentDomain(forName: "com.company.TestApp.configuration")
Returns a dictionary containing only the values I've added to the domain com.company.TestApp.configuration, using
let configs = UserDefaults.init(suiteName: "com.company.TestApp.configuration")!
configs.set(someData, forKey: someKey)
Strangely in the Apple documentation says this about persistentDomain(forName:):
Calling this method is equivalent to initializing a user defaults object with init(suiteName:) passing domainName and calling the dictionaryRepresentation() method on it.
But this is not the case (see my question). Clarification on that subject is more than welcome.

In Polkadot-js is there a method to create HD wallet addresses

I am using Polkadot-js api and wondered if there is an API to generate hierarchical deterministic wallet addresses from a given seed?
I see that there is some mention of soft and hard derivation paths, in Substrate's subkey documentation but do not know if this has been ported to Polkadot-js or how it could be invoked.
SURI are supported by Polkadot-js using createFromUri or addFromUri to create or add a new account to your keyring.
You can import keyring from '#polkadot/ui-keyring' and then use it:
keyring.createFromUri(`${phrase.trim()}${derivePath}`, {}, pairType)
Here is the definition of the function
edit: The derive path could be any combination of /[soft], //[hard], that can be repeated and don't have to be in this order, on top of this, you can have an additional ///[password].
So you can pass as argument to the createFromUri function, something like:[mnemonic phrase]//Kusama//DAO/1 or [mnemonic phrase]//MyMainFunds/0///ThisIsMyPassword.

How do you query Active record with enums

I am trying this query and it is not working:
OrderFulfillment.where(shopper_id: shopper.id, fulfillment_status: [:fulfillment_requested_assignment, :fulfillment_assigned, :fulfillment_shopping])
I am not sure why but I am unable to get querying using enums to work
OrderFulfillment.where(shopper_id: shopper.id,
fulfillment_status: OrderFulfillment
.fulfillment_statuses
.values_at([:fulfillment_requested_assignment,
:fulfillment_assigned,
:fulfillment_shopping]))
Rails isn't smart enough to know that you are passing keys and not values, so when you were passing the statuses straight like that it was looking for the wrong values (it changed them to null because it didn't understand). The enums are physically stored as integers, so that's what you actually need to use in the query. Therefore, you can use the Rails-provided fulfillment_statuses method to grab a hash of the key/value pairs of the enum, and then the values_at method of the hash to get the values for the array of keys you pass in.

IShellFolder2.GetDefaultColumn aways fails with E_NOTIMPL

I'm trying to use the IShellFolder2.GetDefaultColumn function to get the default sort column that is recommended for a specific shell folder. But unfortunately, the function always fails with E_NOTIMPL (HResult -2147467263).
The method call looks like this:
hr := ishellfolder2.GetDefaultColumn(0, sortColumn, displayColumn);
The IShellFolder object is queried by using
SHBindToParent
or
ShellFolder.BindToObject
afterwards it's casted to an IShellFolder2.
The object is valid because it's successfully used for e.g. querying GetDetailsOf.
Is there anything I`m missing?
Thank you and best regards
Answer from Microsoft:
The reason why IShellFolder2.GetDefaultColumn always returns E_NOTIMPL is following:
Almost no shell folder implements this method. This means that this folder does not want to overwrite the defaut sort order. If this method succeeds, it returns a custom sort column that differs from the default sort column.

Resources