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

Support custom SSL #164

Merged
merged 1 commit into from
Oct 9, 2018
Merged

Support custom SSL #164

merged 1 commit into from
Oct 9, 2018

Conversation

klimisa
Copy link
Contributor

@klimisa klimisa commented Oct 1, 2018

I've added support for custom SSL, issue 159.

To test you need to do the following steps,

Step 1. Generate a custom SSL certificate

The simplest way to generate a private key and self-signed certificate for localhost is with this openssl command:

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

The above script will generate two files:

  • localhost.crt
  • localhost.key

Ref. certificates-for-localhost.

Step 2. Add Certificate to Certificate Store

For windows, import the localhost.crt to the 'Trust Root Certification Authorities' of the Current User Certificates.

Step 3. Test sample changes

Change ConsumerEventApiPact#L15

public string MockProviderServiceBaseUri => $"http://localhost:{MockServerPort}";

To

public string MockProviderServiceBaseUri => $"https://localhost:{MockServerPort}";

Change ConsumerEventApiPact#L28

MockProviderService = PactBuilder.MockService(MockServerPort, false, IPAddress.Any);

To

var sslCrt = @"<PathTo>\localhost.crt";
var sslKey = @"<PathTo>\localhost.key";
MockProviderService = PactBuilder.MockService(MockServerPort, sslCrt, sslKey, true, IPAddress.Any);

Hope it's written clear enough!

@neilcampbell
Copy link
Member

Nice one, thanks for this! I'll get this reviewed in the next couple of days.

@neilcampbell neilcampbell merged commit d15ccb7 into pact-foundation:master Oct 9, 2018
@neilcampbell
Copy link
Member

Merged!
Thanks very much for this. The PR was documented amazingly well!
This will be released in 2.4.3 which I will build now.

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.

None yet

2 participants