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

Netscaler login via rest api fails using self signed certificate #100

Open
bfoster68 opened this issue Jul 10, 2019 · 1 comment
Open

Netscaler login via rest api fails using self signed certificate #100

bfoster68 opened this issue Jul 10, 2019 · 1 comment

Comments

@bfoster68
Copy link

Expected Behavior

Current Behavior

When trying to create a Netscaler session. I received this error

Invoke-RestMethod : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
At C:\Program Files\WindowsPowerShell\Modules\NetScaler\1.7.0\Public\Connect-NetScaler.ps1:115 char:21

  •     $response = Invoke-RestMethod @params
    
  •                 ~~~~~~~~~~~~~~~~~~~~~~~~~
    
  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Possible Solution

This workaround works, however, I think there are security implications to this but it allowed me to get past the issue.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

Steps to Reproduce (for bugs)

Use Netscaler generated cert or Self signed cert.

  1. $Nsip, $Username, $Password = "10.10.10.10", "nsroot", "nsroot"
    $SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
    $Credential = New-Object System.Management.Automation.PSCredential ($Username,
    $SecurePassword)
    $Session = Connect-Netscaler -Hostname $Nsip -Credential $Credential -https -PassThru

Context

Your Environment

  • Module version used: 1.7.0
  • Operating System and PowerShell version: Windows 10 1803 and Powershell 5.1
@iainbrighton
Copy link
Collaborator

Hi @bfoster68 - you will need to ensure that the certificate installed on the NetScaler admin interface is trusted by the client. In addition, the subject name on the certificate will need to match the request URL. What subject name is your certificate issued to?

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

No branches or pull requests

2 participants