Skip to content

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

@bfoster68

Description

@bfoster68

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions