Windows 10: Java JNA CredUnPackAuthenticationBufferW authentication dialog

Discus and support Java JNA CredUnPackAuthenticationBufferW authentication dialog in Windows Hello & Lockscreen to solve the problem; Hi, I try to prompt the Windows authentication dialog and to retrieve the credential entered by the user, in Java. The idea is to call... Discussion in 'Windows Hello & Lockscreen' started by SébHenn, Nov 20, 2018.

  1. SébHenn Win User

    Java JNA CredUnPackAuthenticationBufferW authentication dialog


    Hi,


    I try to prompt the Windows authentication dialog and to retrieve the credential entered by the user, in Java.

    The idea is to call CredUIPromptForWindowsCredentialsW and CredUnPackAuthenticationBufferW functions.

    In C++, that works perfectly:



    #include <string>
    #include <
    Windows.h>
    #include <wincred.h>

    int main()
    {
    CREDUI_INFOW credui = {};
    credui.pszMessageText = L
    "Hello1";
    credui.pszCaptionText = L
    "Hello2";
    credui.hwndParent = nullptr;
    credui.hbmBanner = nullptr;
    credui.cbSize =
    sizeof(credui);

    ULONG authPackage =
    0;
    LPVOID outCredBuffer = nullptr;
    ULONG outCredSize =
    0;
    BOOL save =
    false;

    int result = CredUIPromptForWindowsCredentialsW(
    &credui,
    0,
    &authPackage,
    NULL,
    0,
    &outCredBuffer,
    &outCredSize,
    &save,
    0x1);

    DWORD dwFlags =
    0x1;
    std::wstring pszUserName = L
    " ";
    std::wstring pszDomain = L
    " ";
    std::wstring pszPassword = L
    " ";

    DWORD domainSize =
    100;
    DWORD* pDomainSize = &domainSize;

    DWORD userNameSize =
    100;
    DWORD* pUserNameSize = &userNameSize;

    DWORD passwordSize =
    100;
    DWORD* pPasswordSize = &passwordSize;

    BOOL boolResult =
    CredUnPackAuthenticationBufferW(
    dwFlags,
    outCredBuffer,
    outCredSize,
    &pszUserName.at(
    0),
    pUserNameSize,
    &pszDomain.at(
    0),
    pDomainSize,
    &pszPassword.at(
    0),
    pPasswordSize);

    if (result == ERROR_SUCCESS) {
    printf(
    "getlasterror(): %d\n", GetLastError());
    }

    return 0;



    In Java with JNA, I can prompt the Windows authentication dialog but I can't retrieve the user credential:




    package testcredui;

    import com.sun.jna.Library;
    import com.sun.jna.Native;
    import com.sun.jna.Pointer;
    import com.sun.jna.Structure;
    import com.sun.jna.WString;
    import com.sun.jna.platform.win32.WinDef.HBITMAP;
    import com.sun.jna.platform.win32.WinDef.HWND;
    import com.sun.jna.platform.win32.WinDef.ULONG;
    import com.sun.jna.platform.win32.WinDef.ULONGByReference;
    import com.sun.jna.platform.win32.WTypes.LPWSTR;
    import com.sun.jna.platform.win32.WinDef;
    import com.sun.jna.ptr.IntByReference;
    import com.sun.jna.ptr.PointerByReference;
    import com.sun.jna.platform.win32.WinDef.DWORD;
    import com.sun.jna.platform.win32.WinDef.DWORDByReference;

    import java.util.Arrays;
    import java.util.List;

    public class TestCredui {

    public interface CInterface extends Library
    {
    CInterface INSTANCE = (CInterface) Native.load("Credui", CInterface.class);

    /*
    * CredUIPromptForWindowsCredentialsW
    * DWORD WINAPI CredUIPromptForWindowsCredentials(
    * PCREDUI_INFO pUiInfo,
    * DWORD dwAuthError,
    * ULONG *pulAuthPackage,
    * LPCVOID pvInAuthBuffer,
    * ULONG ulInAuthBufferSize,
    * LPVOID *ppvOutAuthBuffer,
    * ULONG *pulOutAuthBufferSize,
    * BOOL *pfSave,
    * DWORD dwFlags
    * )
    */

    int CredUIPromptForWindowsCredentialsW(
    CREDUI_INFO pUiInfo,
    int dwAuthError,
    ULONGByReference pulAuthPackage,
    Pointer pvInAuthBuffer,
    ULONG ulInAuthBufferSize,
    PointerByReference ppvOutAuthBuffer,
    ULONGByReference pulOutAuthBufferSize,
    IntByReference pfSave,
    int dwFlags
    );

    /*
    CREDUIAPI BOOL CredUnPackAuthenticationBufferW(
    DWORD dwFlags,
    PVOID pAuthBuffer,
    DWORD cbAuthBuffer,
    LPWSTR pszUserName,
    DWORD *pcchMaxUserName,
    LPWSTR pszDomainName,
    DWORD *pcchMaxDomainName,
    LPWSTR pszPassword,
    DWORD *pcchMaxPassword
    );
    */

    boolean CredUnPackAuthenticationBufferW(
    DWORD dwFlags,
    Pointer pAuthBuffer,
    DWORD cbAuthBuffer,
    LPWSTR pszUserName,
    DWORDByReference pcchlMaxUserName,
    LPWSTR pszDomainName,
    DWORDByReference pcchMaxDomainName,
    LPWSTR pszPassword,
    DWORDByReference pcchMaxPassword
    );

    /*
    * CREDUI_INFO
    *
    * typedef struct _CREDUI_INFO {
    * DWORD cbSize;
    * HWND hwndParent;
    * PCTSTR pszMessageText;
    * PCTSTR pszCaptionText;
    * HBITMAP hbmBanner;
    * } CREDUI_INFO, *PCREDUI_INFO;
    */

    public static class CREDUI_INFO extends Structure {

    public int cbSize;
    public HWND hwndParent;
    public WString pszMessageText;
    public WString pszCaptionText;
    public HBITMAP hbmBanner;

    /**
    * getFieldOrder
    * @return
    */

    @Override
    protected List getFieldOrder() {
    return Arrays.asList(new String[]{
    "cbSize",
    "hwndParent",
    "pszMessageText",
    "pszCaptionText",
    "hbmBanner",
    });
    }
    }
    }

    public static void main(String[] args)
    {
    CInterface.CREDUI_INFO info = new CInterface.CREDUI_INFO();

    info.pszCaptionText =
    new WString("captionText");
    info.pszMessageText =
    new WString("MessageText");
    info.cbSize = info.size();

    WinDef.ULONGByReference authPackage = new WinDef.ULONGByReference();
    authPackage.setValue(
    new ULONG(0));
    PointerByReference outCredBuffer = new PointerByReference();
    WinDef.ULONGByReference outCredSize = new WinDef.ULONGByReference();
    IntByReference save = new IntByReference(0);
    WinDef.ULONG ulInAuthBufferSize = new WinDef.ULONG(0);

    CInterface.INSTANCE.CredUIPromptForWindowsCredentialsW(
    info,
    0,
    authPackage,
    null,
    ulInAuthBufferSize,
    outCredBuffer,
    outCredSize,
    save,
    0x1
    );

    WinDef.DWORD dwordValue = new DWORD(100);

    LPWSTR username =
    new LPWSTR(" ");
    WinDef.DWORDByReference usernameSize = new WinDef.DWORDByReference();
    usernameSize.setValue(dwordValue);

    LPWSTR domain =
    new LPWSTR(" ");
    WinDef.DWORDByReference domainSize = new WinDef.DWORDByReference();
    domainSize.setValue(dwordValue);

    LPWSTR password =
    new LPWSTR(" ");
    WinDef.DWORDByReference passwordSize = new WinDef.DWORDByReference();
    passwordSize.setValue(dwordValue);

    WinDef.DWORD flags = new WinDef.DWORD(0x1);
    WinDef.DWORD bufferSize = new WinDef.DWORD(250);

    boolean r = CInterface.INSTANCE.CredUnPackAuthenticationBufferW(
    flags,
    outCredBuffer.getPointer(),
    bufferSize,
    username,
    usernameSize,
    domain,
    domainSize,
    password,
    passwordSize
    );

    System.out.println(username.getValue());

    if (r == false) {
    System.out.println(Native.getLastError());
    }
    }
    }




    The GetLastError function returns 50 -> ERROR_NOT_SUPPORTED -> "The authentication buffer is not of a supported type."

    It's a generic credential in plain text, it's supported by all Windows versions.

    I don't know why.

    Thanks for your precious help.

    :)
     
    SébHenn, Nov 20, 2018
    #1

  2. Internet explorer & java

    Hi,

    Thanks for posting your query on Microsoft Community.

    To assist you better, please provide few details.

    1) What exactly you are trying to do with java/ do you receive any error message related to java, while trying to open Microsoft Edge?

    2) Do you receive any error message when trying to open Internet Explorer?



    I would suggest you to follow the below steps and check if it helps.

    Step 1: Clear caches and cookies of Internet Explorer.

    Follow the steps below:


    • Press Shift + ctrl + Delete key on your keyboard.

    • Mark check on cache and cookies and click on Delete button.
    Step 2: Run Printer troubleshooter.


    • Type troubleshooting in the search area on the taskbar and select
      Troubleshooting.

    • Select Troubleshooting.

    • Select View all on the top left corner.

    • Click Printer.

    • Follow the on-screen instructions to run the troubleshooter.


    Hope it helps, reply to us with the status of your issue. We will be happy to assist you.
     
    Santosh_Rai, Nov 20, 2018
    #2
  3. WLagrue Win User
    Connecting Cortana to Gmail - won't pop up authentication dialog

    Hi all,

    I want to connect Cortana to my gmail account, mainly for calendar access. When I go into Notebook, then Manage Skills > Connected Services > Gmail > click Connect - nothing happens. I assume a dialog to authenticate or sign in to gmail is supposed to pop
    up, but nothing happens. Any suggestions?
     
    WLagrue, Nov 20, 2018
    #3
  4. Java JNA CredUnPackAuthenticationBufferW authentication dialog

    Java 8, IE 11.11, Windows 10 - Java won't verify. Java control panel won't open.

    Hi,

    Have you downloaded the latest Java version? Let's try to eliminate software conflicts by performing a clean boot. We suggest that you try accessing Java Control Panel in a clean boot environment and see if it makes any difference. If you are able to access
    Java Control Panel in a clean boot environment, the issue might be caused by application or service interferences. You may refer to this

    Microsoft article
    for more information. Follow the steps provided in the article on how to determine what is causing the problem by performing a clean boot.

    We also suggest that you start your PC in safe mode with networking, then try to verify Java in Internet Explorer. To start your PC is safe mode with networking, follow these steps:

    • Click on the Start button, then select Settings .
    • Select Update & security > Recovery .
    • Under Advanced startup, select Restart now.
    • After your PC restarts to the Choose an option screen, select
      Troubleshoot > Advanced options > Startup Settings >
      Restart.
    • After your PC restarts, you'll see a list of options. Select 5 or F5 for
      Safe Mode with Networking.

    Let us know if you need further assistance.
     
    Aileen Alf, Nov 20, 2018
    #4
Thema:

Java JNA CredUnPackAuthenticationBufferW authentication dialog

Loading...
  1. Java JNA CredUnPackAuthenticationBufferW authentication dialog - Similar Threads - Java JNA CredUnPackAuthenticationBufferW

  2. I bought Minecraft java edition but it says Failed to log in authenticated are currently...

    in Windows 10 Gaming
    I bought Minecraft java edition but it says Failed to log in authenticated are currently...: I bought Minecraft java edition but it says Failed to log in authenticated are currently not reachable please try again. P.S I had cracked Minecraft....
  3. I bought Minecraft java edition but it says Failed to log in authenticated are currently...

    in Windows 10 Software and Apps
    I bought Minecraft java edition but it says Failed to log in authenticated are currently...: I bought Minecraft java edition but it says Failed to log in authenticated are currently not reachable please try again. P.S I had cracked Minecraft....
  4. Usability of FIDO2 dialog box with Platform Authenticator TPM backed AND Security Keys e.g....

    in AntiVirus, Firewalls and System Security
    Usability of FIDO2 dialog box with Platform Authenticator TPM backed AND Security Keys e.g....: When setting up FIDO2 on a WebAuthn enabled site at least with Firefox all recent versions, you will get an OS level popup for the WebAuthn/FIDO2 request.The first one that comes up is for the Windows Hello Platform Authenticator. If this is what you intend to use, all well...
  5. Usability of FIDO2 dialog box with Platform Authenticator TPM backed AND Security Keys e.g....

    in Windows 10 Gaming
    Usability of FIDO2 dialog box with Platform Authenticator TPM backed AND Security Keys e.g....: When setting up FIDO2 on a WebAuthn enabled site at least with Firefox all recent versions, you will get an OS level popup for the WebAuthn/FIDO2 request.The first one that comes up is for the Windows Hello Platform Authenticator. If this is what you intend to use, all well...
  6. Usability of FIDO2 dialog box with Platform Authenticator TPM backed AND Security Keys e.g....

    in Windows 10 Software and Apps
    Usability of FIDO2 dialog box with Platform Authenticator TPM backed AND Security Keys e.g....: When setting up FIDO2 on a WebAuthn enabled site at least with Firefox all recent versions, you will get an OS level popup for the WebAuthn/FIDO2 request.The first one that comes up is for the Windows Hello Platform Authenticator. If this is what you intend to use, all well...
  7. authenticator is asking me to authenticate using authenticator to use authenticator

    in Windows 10 Software and Apps
    authenticator is asking me to authenticate using authenticator to use authenticator: So first of all... Why is "microsoft Authenticator" not an option in the "Products" dropdown when choosing where this post should go? I'm just going to choose "Windows"... Sorry not sorry.Also, I can't take a screenshot on the microsoft Authenticator app without it capturing...
  8. authenticator is asking me to authenticate using authenticator to use authenticator

    in Windows 10 Gaming
    authenticator is asking me to authenticate using authenticator to use authenticator: So first of all... Why is "Microsoft Authenticator" not an option in the "Products" dropdown when choosing where this post should go? I'm just going to choose "Windows"... Sorry not sorry.Also, I can't take a screenshot on the Microsoft Authenticator app without it capturing...
  9. Authentication servers are down for maintenanceMinecraft Java

    in Windows 10 Gaming
    Authentication servers are down for maintenanceMinecraft Java: Hello One of my friends made a Minecraft server and all of my friends with mojang accounts can connect but i cant connect i have a Microsoft account. What is the solution to this?...
  10. jna dll files in my temp folder

    in AntiVirus, Firewalls and System Security
    jna dll files in my temp folder: does anybody know what this is? https://gyazo.com/c26ed524316f7c6748eb1f39dc11f15d https://answers.microsoft.com/en-us/protect/forum/all/jna-dll-files-in-my-temp-folder/be74337a-44f9-4f8a-b410-358c86f53f96