Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scraped enums used in CryptQueryObject contain wrong members, are misleadingly named and incorrectly assigned. #343

Closed
krzysdz opened this issue Mar 13, 2021 · 0 comments
Labels
broken api An API is inaccurate and could lead to runtime failure usability Touch-up to improve the user experience for a language projection

Comments

@krzysdz
Copy link

krzysdz commented Mar 13, 2021

There are multiple issues with the automatically generated enums after #327 (previously there were no enums at all).
Currently (10.0.19041.5-preview.51) the CryptQueryObject declaration looks like this:

[DllImport("CRYPT32", ExactSpelling = true, SetLastError = true)]
public unsafe static extern BOOL CryptQueryObject(
	[In] CryptQueryObject_dwObjectTypeFlags dwObjectType, // This enum does not contain flags (and has no
	                                                      // [Flags] attribute), but has "Flags" in name
	[In][Const] void* pvObject,
	[In] CERT_QUERY_FLAGS dwExpectedContentTypeFlags, // Contains invalid "flags", it should contain only
	                                                  // the CERT_QUERY_CONTENT_FLAG_* ones
	[In] CERT_QUERY_FORMAT_FLAGS dwExpectedFormatTypeFlags,
	[In] uint dwFlags,
	[Optional][Out] CertOpenStore_dwEncodingType* pdwMsgAndCertEncodingType,
	[Optional][Out] CERT_QUERY_FLAGS* pdwContentType, // The enum contains too many values and should not be
	                                                  // marked with the [Flags] attribute. This enum should
							  // contain only /CERT_QUERY_CONTENT_(?!FLAG_)\w+/
							  // values.
	[Optional][Out] CERT_QUERY_FORMAT_TYPE* pdwFormatType,
	[Optional][Out] void** phCertStore,
	[Optional][Out] void** phMsg,
	[Optional][Out][Const] void** ppvContext);

The issues are:

  • The first parameter type is named CryptQueryObject_dwObjectTypeFlags, but it doesn't contain flags (just two constants with values 1 and 2) and (correctly) has no [Flags] attribute. The Flags part in the name is misleading.
  • The third parameter is of CERT_QUERY_FLAGS type, which contains too many members. It should contain only flags - CERT_QUERY_CONTENT_FLAG_ prefixed constants, but contains all CERT_QUERY_CONTENT_ ones.
    CERT_QUERY_FLAGS enum content
  • The type CertOpenStore_dwEncodingType (type of the sixth parameter) contains PKCS_7_ASN_ENCODING and X509_ASN_ENCODING constants, which as a result are not available as loose constants in the Windows.Win32.Security.Apis namespace. The dwCertEncodingType member of the EFS_CERTIFICATE_BLOB struct should contain one of the following values:
    • CRYPT_ASN_ENCODING
    • CRYPT_NDR_ENCODING
    • X509_ASN_ENCODING
    • X509_NDR_ENCODING
      The fact that two of these constants can be accessed only through a completely unrelated enum makes working with this struct harder.
  • The type of the seventh parameter should be different than the type of the third one.
    • It should be of a pointer type (DWORD * is replaced with enum (not pointer) #337) (fixed)
    • It should not have the [Flags] attribute
    • It should contain only constants, which match the /CERT_QUERY_CONTENT_(?!FLAG_)\w+/ regular expressions - CERT_QUERY_CONTENT_ prefixed constants, which are not flags for the dwExpectedContentTypeFlags parameter (these have an additional FLAG_ part in their names).
@mikebattista mikebattista added broken api An API is inaccurate and could lead to runtime failure usability Touch-up to improve the user experience for a language projection labels Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

2 participants