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

Add WinRM client certificate authentication support #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rveznaver
Copy link

Hello,
I have added a couple of lines of code to support client certificate-based authentication as per http://msdn.microsoft.com/en-us/library/aa384295.aspx
Please note that I am not a Java programmer, so any suggestions and help is welcomed. I have not managed to run the integration tests (overcast), so I have tested using the following code:

import static com.xebialabs.overthere.ConnectionOptions.ADDRESS;
import static com.xebialabs.overthere.ConnectionOptions.OPERATING_SYSTEM;
import static com.xebialabs.overthere.ConnectionOptions.PASSWORD;
import static com.xebialabs.overthere.ConnectionOptions.USERNAME;
import static com.xebialabs.overthere.OperatingSystemFamily.WINDOWS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CONNECTION_TYPE;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_ENABLE_HTTPS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_CLIENT_CERTIFICATE;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_HTTPS_CERTIFICATE_TRUST_STRATEGY;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_HTTPS_HOSTNAME_VERIFICATION_STRATEGY;
import static com.xebialabs.overthere.cifs.CifsConnectionType.WINRM_INTERNAL;

import com.xebialabs.overthere.CmdLine;
import com.xebialabs.overthere.ConnectionOptions;
import com.xebialabs.overthere.Overthere;
import com.xebialabs.overthere.OverthereConnection;
import com.xebialabs.overthere.cifs.WinrmHttpsCertificateTrustStrategy;
import com.xebialabs.overthere.cifs.WinrmHttpsHostnameVerificationStrategy;

public class main {
    public static void main(String[] args) {
        ConnectionOptions options = new ConnectionOptions();
        options.set(OPERATING_SYSTEM, WINDOWS);
        options.set(CONNECTION_TYPE, WINRM_INTERNAL);
        options.set(ADDRESS, "localhost");
        options.set(USERNAME, "/home/user/client.pfx");
        options.set(PASSWORD, "password");
        options.set(WINRM_CLIENT_CERTIFICATE, true);
        options.set(WINRM_ENABLE_HTTPS, true);
        options.set(WINRM_HTTPS_CERTIFICATE_TRUST_STRATEGY, WinrmHttpsCertificateTrustStrategy.ALLOW_ALL);
        options.set(WINRM_HTTPS_HOSTNAME_VERIFICATION_STRATEGY, WinrmHttpsHostnameVerificationStrategy.ALLOW_ALL);
        OverthereConnection connection = Overthere.getConnection("cifs", options);
        try {
            connection.execute(CmdLine.build("type", "\\windows\\system32\\drivers\\etc\\hosts"));
        } finally {
            connection.close();
        }
    }
}

I have used the USERNAME field for storing the certificate location as it required the minimum refactoring.

The Windows (WinRM) server was set up using:

winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{CertificateThumbprint="S3rv3rThum8pr1n7"}
winrm set winrm/config/service @{AllowUnencrypted="False"}
winrm set winrm/config/service/auth @{Basic="False"}
winrm set winrm/config/service/auth @{Certificate="True"}
winrm create winrm/config/service/certmapping?Issuer=Cl13ntThum8pr1n7+Subject=*+URI=* @{UserName="LocalUser";Password="LocalPassword"}

@buildhive
Copy link

XebiaLabs » overthere #245 SUCCESS
This pull request looks good
(what's this?)

@rveznaver rveznaver changed the title Add client certificate authentication support Add WinRM client certificate authentication support Jan 20, 2015
@buildhive
Copy link

XebiaLabs » overthere #246 SUCCESS
This pull request looks good
(what's this?)

@hierynomus
Copy link
Contributor

Also missing hte documentation updates and unit/integration tests.

@rveznaver
Copy link
Author

I can add documentation about the client certificate authentication. However, I have not been able to set up integration tests. Do you have some documentation on setting up the tests?

@hierynomus
Copy link
Contributor

I have not, but it would be good to add to the readme indeed... And provide some scripts to setup the environment..

@buildhive
Copy link

XebiaLabs » overthere #285 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

XebiaLabs » overthere #286 FAILURE
Looks like there's a problem with this pull request
(what's this?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants