Skip to content

Commit 6120932

Browse files
Enhance bindings for Crypt32 and fix bindings for array attributes
The implementations of the rgAttribute, rgCTLEntry and rgExtension attributes are not in line with the observed behaviour of the API. At least in part they are documented to be pointers to arrays of pointers to structures. This is not correct, as segfaults were observed and testing shows, that they are in fact pointers to arrays of structures. In addition it was observed, that the bindings of CTL_INFO#getRgCTLEntry and CTL_INFO#getRgExtension method names were inverted. The bindings for CERT_EXTENSIONS#getRgExtension and CTL_INFO#getRgExtension are untested as but assumed to be implemented identically to the tested bindings. The functions - CertEnumCertificatesInStore - CertEnumCTLsInStore - CertEnumCRLsInStore - CryptQueryObject from `c.s.j.p.win32.Crypt32` were bound to be able to excercise the accessors.
1 parent dbc6298 commit 6120932

4 files changed

Lines changed: 590 additions & 42 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Features
1717
Bug Fixes
1818
---------
1919
* [#1244](https://github.com/java-native-access/jna/issues/1244): Fix building on GCC 10 - [@matthiasblaesing](https://github.com/matthiasblaesing).
20+
* [#1252](https://github.com/java-native-access/jna/issues/1252): - Fix bindings of `CTL_ENTRY#getRgAttribute`, `CTL_INFO#getRgCTLEntry`, `CTL_INFO#getRgExtension`, `CERT_EXTENSIONS#getRgExtension`, `CERT_INFO#getRgExtension`, `CRL_INFO#getRgCRLEntry`, `CRL_INFO#getRgExtension`, `CRL_ENTRY#getRgExtension`. Add bindings for `CertEnumCertificatesInStore`, `CertEnumCTLsInStore`, `CertEnumCRLsInStore` and `CryptQueryObject` in `c.s.j.p.win32.Crypt32`.<br> *WARNING:* The signatures for `CTL_INFO#getRgCTLEntry` and `CTL_INFO#getRgExtension` were changed - as the original signatures were obviously wrong and read the wrong attributes, it is not considered an API break - [@matthiasblaesing](https://github.com/matthiasblaesing).
2021

2122
Release 5.6.0
2223
=============

contrib/platform/src/com/sun/jna/platform/win32/Crypt32.java

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,170 @@ CERT_CONTEXT.ByReference CertFindCertificateInStore(HCERTSTORE hCertStore, int d
501501
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa387314(v=vs.85).aspx">MSDN</a>
502502
*/
503503
HCERTSTORE PFXImportCertStore(DATA_BLOB pPFX, WTypes.LPWSTR szPassword, int dwFlags);
504+
505+
/**
506+
* The CertEnumCertificatesInStore function retrieves the first or next
507+
* certificate in a certificate store. Used in a loop, this function can
508+
* retrieve in sequence all certificates in a certificate store.
509+
*
510+
* @param hCertStore A handle of a certificate store.
511+
* @param pPrefCertContext A pointer to the {@link CERT_CONTEXT} of the
512+
* previous certificate context found.
513+
* <p>
514+
* This parameter must be NULL to begin the enumeration and get the first
515+
* certificate in the store. Successive certificates are enumerated by
516+
* setting {@code pPrevCertContext} to the pointer returned by a previous
517+
* call to the function. This function frees the {@link CERT_CONTEXT}
518+
* referenced by non-NULL values of this parameter.</p>
519+
*
520+
* <p>
521+
* For logical stores, including collection stores, a duplicate of the
522+
* pCertContext returned by this function cannot be used to begin a new
523+
* subsequence of enumerations because the duplicated certificate loses the
524+
* initial enumeration state. The enumeration skips any certificate
525+
* previously deleted by CertDeleteCertificateFromStore.</p>
526+
*
527+
* @return If the function succeeds, the function returns a pointer to the
528+
* next {@link CERT_CONTEXT} in the store. If no more certificates
529+
* exist in the store, the function returns {@code NULL}.
530+
*
531+
* <p>
532+
* For extended error information, call GetLastError. Some possible error
533+
* codes follow.</p>
534+
*
535+
* <table>
536+
* <tr><th>Value</th><th>Description</th></tr>
537+
* <tr><td>E_INVALIDARG</td><td>The handle in the {@code hCertStore}
538+
* parameter is not the same as that in the certificate context pointed to
539+
* by {@code pPrevCertContext}.</td></tr>
540+
* <tr><td>CRYPT_E_NOT_FOUND</td><td>No certificates were found. This
541+
* happens if the store is empty or if the function reached the end of the
542+
* store's list.</td></tr>
543+
* <tr><td>ERROR_NO_MORE_FILES</td><td>Applies to external stores. No
544+
* certificates were found. This happens if the store is empty or if the
545+
* function reached the end of the store's list. </td></tr>
546+
* </table>
547+
*
548+
* @see <a href=
549+
* "https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certenumcertificatesinstore">MSDN</a>
550+
*/
551+
CERT_CONTEXT.ByReference CertEnumCertificatesInStore(HCERTSTORE hCertStore, Pointer pPrefCertContext);
552+
553+
/**
554+
* The CertEnumCTLsInStore function retrieves the first or next certificate
555+
* trust list (CTL) context in a certificate store. Used in a loop, this
556+
* function can retrieve in sequence all CTL contexts in a certificate
557+
* store.
558+
*
559+
* @param hCertStore A handle of a certificate store.
560+
* @param pPrevCtlContext A pointer to the previous {@link CTL_CONTEXT}
561+
* structure found. It must be {@code NULL} to get
562+
* the first CTL in the store. Successive CTLs are
563+
* enumerated by setting {@code pPrevCtlContext} to
564+
* the pointer returned by a previous call. This
565+
* function frees the {@link CTL_CONTEXT} referenced
566+
* by non-NULL values of this parameter. The
567+
* enumeration skips any CTLs previously deleted by
568+
* CertDeleteCTLFromStore.
569+
*
570+
* @return If the function succeeds, the return value is a pointer to a
571+
* read-only CTL_CONTEXT.
572+
*
573+
* <p>
574+
* If the function fails and a CTL is not found, the return value is NULL.
575+
* For extended error information, call GetLastError.</p>
576+
*
577+
* <table>
578+
* <tr><th>Value</th><th>Description</th></tr>
579+
* <tr><td>E_INVALIDARG</td><td>The handle in the {@code hCertStore}
580+
* parameter is not the same as that in the CTL context pointed to by the
581+
* {@code pPrevCtlContext} parameter. </td></tr>
582+
* <tr><td>CRYPT_E_NOT_FOUND</td><td>Either no CTLs exist in the store, or
583+
* the function reached the end of the store's list.</td></tr>
584+
* </table>
585+
*
586+
* @see <a href=
587+
* "https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certenumctlsinstore">MSDN</a>
588+
*/
589+
CTL_CONTEXT.ByReference CertEnumCTLsInStore(HCERTSTORE hCertStore, Pointer pPrevCtlContext);
590+
591+
/**
592+
* The CertEnumCRLsInStore function retrieves the first or next certificate
593+
* revocation list (CRL) context in a certificate store. Used in a loop,
594+
* this function can retrieve in sequence all CRL contexts in a certificate
595+
* store. store.
596+
*
597+
* @param hCertStore A handle of a certificate store.
598+
* @param pPrevCrlContext A pointer to the previous {@link CRL_CONTEXT}
599+
* structure found. The {@code code pPrevCrlContext}
600+
* parameter must be {@code NULL} to get the first
601+
* CRL in the store. Successive CRLs are enumerated
602+
* by setting {@code pPrevCrlContext} to the pointer
603+
* returned by a previous call to the function. This
604+
* function frees the CRL_CONTEXT referenced by
605+
* non-NULL values of this parameter. The enumeration
606+
* skips any CRLs previously deleted by
607+
* CertDeleteCRLFromStore.
608+
*
609+
* @return If the function succeeds, the return value is a pointer to the
610+
* next {@link CRL_CONTEXT} in the store.
611+
*
612+
* <p>
613+
* {@code NULL} is returned if the function fails. For extended error
614+
* information, call GetLastError. Some possible error codes follow.</p>
615+
*
616+
* <table>
617+
* <tr><th>Value</th><th>Description</th></tr>
618+
* <tr><td>E_INVALIDARG</td><td>The handle in the {code hCertStore}
619+
* parameter is not the same as that in the certificate context pointed to
620+
* by {@code pPrevCrlContext}.</td></tr>
621+
* <tr><td>CRYPT_E_NOT_FOUND</td><td>No CRL was found. This happens if the
622+
* store is empty or the end of the store's list is reached. </td></tr>
623+
* </table>
624+
*
625+
* @see <a href=
626+
* "https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certenumcrlsinstore">MSDN</a>
627+
*/
628+
CRL_CONTEXT.ByReference CertEnumCRLsInStore(HCERTSTORE hCertStore, Pointer pPrevCrlContext);
629+
630+
/**
631+
* The CryptQueryObject function retrieves information about the contents of
632+
* a cryptography API object, such as a certificate, a certificate
633+
* revocation list, or a certificate trust list. The object can either
634+
* reside in a structure in memory or be contained in a file.
635+
*
636+
* @param dwObjectType
637+
* @param pvObject
638+
* @param dwExpectedContentTypeFlags
639+
* @param dwExpectedFormatTypeFlags
640+
* @param dwFlags
641+
* @param pdwMsgAndCertEncodingType
642+
* @param pdwContentType
643+
* @param pdwFormatType
644+
* @param phCertStore
645+
* @param phMsg
646+
* @param ppvContext
647+
*
648+
* @return If the function succeeds, the function returns nonzero.
649+
*
650+
* <p>
651+
* If the function fails, it returns zero. For extended error information,
652+
* call GetLastError.</p>
653+
*
654+
* @see <a href=
655+
* "https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptqueryobject">MSDN</a>
656+
*/
657+
boolean CryptQueryObject(
658+
int dwObjectType,
659+
Pointer pvObject,
660+
int dwExpectedContentTypeFlags,
661+
int dwExpectedFormatTypeFlags,
662+
int dwFlags,
663+
IntByReference pdwMsgAndCertEncodingType,
664+
IntByReference pdwContentType,
665+
IntByReference pdwFormatType,
666+
PointerByReference phCertStore,
667+
PointerByReference phMsg,
668+
PointerByReference ppvContext
669+
);
504670
}

0 commit comments

Comments
 (0)