snazy2000 / SnipeitPS

Powershell API Wrapper for Snipe-it
MIT License
181 stars 47 forks source link

Unable to access server once moved to https #272

Closed Christopheric1 closed 2 years ago

Christopheric1 commented 2 years ago

Context

Unable to use Connect-SnipeITPS to get to server

Your Environment

SnipeitPS Module version 1.10.220 Debian 11 bullseye SnipeIT v6.0.5 build 8229 (g94e723a88)

Expected Behavior

Should connect to Snipe-IT

Current Behavior

VERBOSE: Testing connection to https://server.domain.com. VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable VERBOSE: [Invoke-SnipeitMethod] Invoking method Get to URI VERBOSE: GET https://server.domain.com/api/v1/statuslabels?limit=1 with 0-byte payload VERBOSE: [Invoke-SnipeitMethod] Failed to get an answer from the server VERBOSE: [Invoke-SnipeitMethod] No Web result object was returned from. This is unusual! VERBOSE: [Invoke-SnipeitMethod] Function ended

I added this to the powershell script since I don't have a wildcard cert yet:

I double checked the site-enabled file and TLS12 is allowed. It is also pingable and I can access the ssh to the server. Just not sure where to go from here.

Thanks!

PetriAsi commented 2 years ago

How did you resolved this?

Christopheric1 commented 2 years ago

Sorry I meant to leave a comment, I added this to the top of my PS Script:

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;
        }
    }
"@ -ea SilentlyContinue -wa SilentlyContinue  

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

Along with this line I already had:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Then Connect-SnipeITPS worked fine

PetriAsi commented 2 years ago

Thanks for the info, new nice trick (atleast for me). As I read that code ,it's seems to workaround for untrusted server certificate, with that any server certificate will be trusted and connection made.