Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Pull x509 cert from DC remotely to import into java keystore
Author Summary
TurnItOff_OnAgain is in District of Columbia
Post Body

Trying to automate pulling the DC certificate to import into a java keystore for LDAPS auth in a web app. The kicker is I want to do with with only built in windows tools. Trolled around and found some pieces, but it doesn't work. Here is what I have for now

$TcpSocket = New-Object Net.Sockets.TcpClient($DC1IP,$Port)
$tcpstream = $TcpSocket.GetStream()
$Callback = {param($sender,$cert,$chain,$errors) return $true}
$SSLStream = New-Object -TypeName System.Net.Security.SSLStream -ArgumentList @($tcpstream, $True, $Callback)
$SSLStream.AuthenticateAsClient($IPAddress)
$Certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($SSLStream.RemoteCertificate)
$SSLStream.Dispose()
$PublicCertInPemFormatPrep = "-----BEGIN CERTIFICATE-----`n"   
    [System.Convert]::ToBase64String($certificate.RawData, [System.Base64FormattingOptions]::InsertLineBreaks)   
    "`n-----END CERTIFICATE-----"
$DC1Cert = $PublicCertInPemFormatPrep -split "`n"
$DC1cert | out-file c:\temp\DC1.cer

Trying to import that with keytool gives the error that is in the PEM format and it needs to be x509. It looks identical to the export I get when manually exporting from the DC itself in base64 x509 though.

I guess I could install openssl on the servers that will need this. Would prefer not to though.

EDIT:

I got it. I checked out the certificate in a hex editor and it didn't match the cert I exported from the DC. After playing around with the exporting I found I needed to encode it as OEM

$DC1cert | out-file c:\temp\DC1.cer -Encoding oem

That fixed it.

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
64,617
Link Karma
1,006
Comment Karma
63,277
Profile updated: 3 days ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago