CLI මෙවලම් භාවිතයෙන් දුරස්ථ SSL සහතික විස්තර පෙන්වීම


221

Chrome හි, හරිත HTTPS අගුළු නිරූපකය මත ක්ලික් කිරීමෙන් සහතික විස්තර සහිත කවුළුවක් විවෘත වේ:

රූප විස්තරය මෙහි ඇතුළත් කරන්න

මම කර්ල් සමඟ එය උත්සාහ කළ විට, මට ලැබුණේ තොරතුරු කිහිපයක් පමණි:

$ curl -vvI https://gnupg.org
* Rebuilt URL to: https://gnupg.org/
* Hostname was NOT found in DNS cache
*   Trying 217.69.76.60...
* Connected to gnupg.org (217.69.76.60) port 443 (#0)
* TLS 1.2 connection using TLS_DHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate: gnupg.org
* Server certificate: Gandi Standard SSL CA
* Server certificate: UTN-USERFirst-Hardware
> HEAD / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: gnupg.org
> Accept: */*

සම්පූර්ණ සහතික තොරතුරු විධාන රේඛා මෙවලමක් (cURL හෝ වෙනත්) ලබා ගන්නේ කෙසේද?


1
මෙයද බලන්න stackoverflow.com/questions/7885785/...
Vadzim

බොහෝ විට අනුවාදය මත ද රඳා පවතී. curlධජය සහිත මගේ ධාරාව --verboseසම්පූර්ණ සේවාදායක සහතික අන්තර්ගතය පෙන්වයි.
පැට්‍රික් මෙව්සෙක්

Answers:


314

ඔබේ අරමුණු සඳහා OpenSSL භාවිතා කිරීමට ඔබට හැකි විය යුතුය:

echo | openssl s_client -showcerts -servername gnupg.org -connect gnupg.org:443 2>/dev/null | openssl x509 -inform pem -noout -text

එම විධානය අපේක්ෂිත වෙබ් අඩවියට සම්බන්ධ වන අතර සහතිකය PEM ආකෘතියෙන් වෙනත් opensl විධානයකට සම්බන්ධ කර විස්තර කියවා විග්‍රහ කරයි.

( SNI සහාය ඇතිව ඉල්ලීමක් -servernameකිරීමට "අතිරික්ත" පරාමිතිය අවශ්‍ය බව opensslසලකන්න.)


මෙම විධානයෙහි දෝෂයක් ඇති බව පෙනේ:OpenSSL> openssl:Error: 'CONNECTED(00000003)' is an invalid command.
ඇඩම් මාතාන්

2
P ඇඩම්මාතන් දෙවන පයිප්පයෙන් පසුව ඔබ සම්පූර්ණ විධානය ඇතුළත් කළාද? දෝෂ පණිවිඩය දෙවන opensl ආයාචනය අන්තර්ක්‍රියාකාරී ආකාරයෙන් ක්‍රියාත්මක වන බව පෙනේ (එනම් opensslඑදිරිව openssl x509 -inform pem -noout -text). පේද්‍රෝ ලියූ දෙය මට හොඳ ය.
හොකන් ලින්ඩ්ක්විස්ට්

4
S_client මුළු දාමය මුද්‍රණය කරන අතර, අවසාන පයිප්ප විධානය මඟින් මුද්‍රණය කරන්නේ පළමු සහතිකය පිළිබඳ තොරතුරු පමණි.
chutz

1
echoඑයම සමාන වේ echo ''.. එය හිස් නූලක් stdout වෙත යවයි. cat /dev/null |එසේම වැඩ කරන අතර එය තව ටිකක් ස්වයං පැහැදිලි කිරීමකි.
කංසා

2
ඔබ දැන ගැනීමට කැමති නම්, කල් ඉකුත් වීමේ දිනය , ඔබ විස්ථාපනය කල හැකි -textසමග -enddate, වෙනත් විකල්ප සඳහා පරීක්ෂා ( openssl x509 help).
ඇඩ්‍රියන්

74

සරල විසඳුමක්

එය මගේ එදිනෙදා පිටපතයි:

curl --insecure -v https://www.google.com 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }'

ප්‍රතිදානය:

* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
*    server certificate verification SKIPPED
*    server certificate status verification SKIPPED
*    common name: www.google.com (matched)
*    server certificate expiration date OK
*    server certificate activation date OK
*    certificate public key: RSA
*    certificate version: #3
*    subject: C=US,ST=California,L=Mountain View,O=Google Inc,CN=www.google.com
*    start date: Wed, 24 May 2017 17:39:15 GMT
*    expire date: Wed, 16 Aug 2017 17:13:00 GMT
*    issuer: C=US,O=Google Inc,CN=Google Internet Authority G2
*    compression: NULL
* ALPN, server accepted to use http/1.1
* Connection #0 to host www.google.com left intact

5
මට වැඩ කරන්නේ නැත, ආරම්භක / කල් ඉකුත් වීමේ දිනයන් ඇතුළත් නොවේ.
ලුන්ඩ්බර්ග්

5
මෑතදී කරකැවීමේ යම් වෙනසක් (49 ත් 52 ත් අතර) ඇති බැවින් මෙය සහතිකය පිළිබඳ කිසිවක් පෙන්වන්නේ නැත. :(
රොස් ප්‍රෙස්සර්

1
2> & 1 ඉවත් කරන්න
ජෙෂාන් බබූවා

මෙයද එම සහතිකයේ ඇති විකල්ප නම් පෙන්වන්නේ නැත.
දිමිත්‍රි කේ

31

ඔබට අවශ්‍ය තොරතුරු මොනවාද යන්න මත රඳා පවතී, නමුත්:

openssl s_client -showcerts -connect gnupg.org:443

ක්‍රෝම් ඉදිරිපත් කරන තරම් මිනිසුන්ට කියවිය නොහැකි තරම් හොඳ වුවත්, ඔබට බොහෝ දේ ලබා දිය යුතුය.


1
අවාසනාවකට මෙන්, එම විධානය මඟින් සහතික දත්ත ඉතා සුළු ප්‍රමාණයක් මිනිස් කියවිය හැකි ආකෘතියෙන් ඉදිරිපත් කරයි.
හොකන් ලින්ඩ්ක්විස්ට්

9
මම කලින් අදහස් දැක්වීමට එකඟ නොවෙමි, මෙම විධානය මට දැනගත යුතු දේ පවසන අතර එය ඉතා ප්‍රයෝජනවත් වේ. පිළිතුර සඳහා +1.
camdixon

ඔබට විශේෂයෙන් TLS 1.2 සඳහා පරීක්ෂා කිරීමට අවශ්‍ය නම් ඔබට -tls1_2
camdixon

27
nmap -p 443 --script ssl-cert gnupg.org

මෙම -p 443ස්කෑන් වරාය 443 පමණක් නියම කරනු ලබයි. සියලුම වරායන් මඟ හැරී ඇත්නම් එය පරිලෝකනය කරනු ලබන අතර, සොයාගත් ඕනෑම SSL සේවාවක් සඳහා සහතික තොරතුරු පෙන්වනු ඇත. මෙම --script ssl-certකියනවා, Nmap විධානාවලි එන්ජින් පමණක් ක්රියාත්මක කිරීමට ssl-certතිර රචනය. ලේඛනයෙන්, මෙම ස්ක්‍රිප්ට් "(r) සේවාදායකයේ SSL සහතිකය ලබා ගනී. සහතිකය පිළිබඳ මුද්‍රණය කර ඇති තොරතුරු ප්‍රමාණය වාචික මට්ටම මත රඳා පවතී."

නියැදි ප්‍රතිදානය:

Starting Nmap 7.40 ( https://nmap.org ) at 2017-11-01 13:35 PDT
Nmap scan report for gnupg.org (217.69.76.60)
Host is up (0.16s latency).
Other addresses for gnupg.org (not scanned): (null)
rDNS record for 217.69.76.60: www.gnupg.org
PORT    STATE SERVICE
443/tcp open  https
| ssl-cert: Subject: commonName=gnupg.org
| Subject Alternative Name: DNS:gnupg.org, DNS:www.gnupg.org
| Issuer: commonName=Gandi Standard SSL CA 2/organizationName=Gandi/stateOrProvinceName=Paris/countryName=FR
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2015-12-21T00:00:00
| Not valid after:  2018-03-19T23:59:59
| MD5:   c3a7 e0ed 388f 87cb ec7f fd3e 71f2 1c3e
|_SHA-1: 5196 ecf5 7aed 139f a511 735b bfb5 7534 df63 41ba

Nmap done: 1 IP address (1 host up) scanned in 2.31 seconds

ඔබට සහතිකයේ ඇඟිලි සලකුණු දැකීමට අවශ්‍ය නම් මෙම විධානය curl -vවෙනත් පිළිතුරු වල ඇති යෝජනා වලට වඩා හොඳය .
බාර්ට් බී

13

සම්පූර්ණත්වය සඳහා: ඔබ ඔබේ පද්ධතියේ ජාවා 7 හෝ ඊට වැඩි ස්ථාපනය කර ඇත්නම්

 keytool -printcert -sslserver $host[:$port]

සෑම විස්තරයක්ම පාහේ බොහෝ දුරට අවලස්සන ආකෘතියකින් දාමය (සේවය කළ පරිදි) පෙන්වයි .

ඔබ ඔබේ පද්ධතියේ ජාවා ස්ථාපනය කර තිබිය යුතුද යන්න මම පිළිතුරු නොදෙමි.


1
openssl (විකේතනය අවශ්‍ය) වලට වඩා දීප්තිමත්, වඩා ප්‍රයෝජනවත් පෙරනිමි ප්‍රතිදානය.
සිමොන්

Ssl-cert `keytool -printcert -sslserver smth.yourdomain.com | සහාය දක්වන සියලුම වසම් පරීක්ෂා කිරීමට පහසුම ක්‍රමය මෙය බව පෙනේ. grep -E 'හිමිකරු | DNSName' මෙය සහතිකයේ "පෙරනිමි ඩොමේන් නාමය" සහ සහතිකයේ විකල්ප වසම් නාම පෙන්වනු ඇත
ඩිමිට්‍රි කේ

6

එස්එස්එල් සහතික විස්තර පරීක්ෂා කිරීම සඳහා, එය ලබා ගත හැකි දින සිට මම පහත විධාන රේඛා මෙවලම භාවිතා කරමි:

https://github.com/azet/tls_tools

එය දෙගුණ-පරීක්ෂා කිරීමට ඔබ නැවත නිකුත්-certs හෝ මාෙර පවතින අය සඳහා, සහ ද පරායත්තයන් කිහිපයක් ලෙස නිවැරදි සියලු තොරතුරු ඉමහත් ය සහ එය කිසිදු පිහිටුවීම් අවශ්ය වේ.

ප්‍රතිදානයේ පළමු පේළි කිහිපය මෙයයි:

$ ./check_certificate_chain.py gnupg.org 443

>> Certificate Chain:

 [+]*       OU=Domain Control Validated, OU=Gandi Standard SSL, CN=gnupg.org
 [+]**      C=FR, O=GANDI SAS, CN=Gandi Standard SSL CA
 [+]***     C=US, ST=UT, L=Salt Lake City, O=The USERTRUST Network, OU=http://www.usertrust.com, CN=UTN-USERFirst-Hardware

>> Certificate Information:

................................................................................
- [Subject]:        OU=Domain Control Validated, OU=Gandi Standard SSL, CN=gnupg.org
- [Issuer]:     C=FR, O=GANDI SAS, CN=Gandi Standard SSL CA
- [Valid from]:     Mar 18 00:00:00 2014 GMT
- [Valid until]:    Mar 18 23:59:59 2016 GMT
- [Authority]:      Is not a CA
- [Version]:        2
- [Serial No.]:     43845251655098616578492338727643475746
- [X.509 Extension Details]:
  -- [x509_authorityKeyIdentifier]:
       keyid:B6:A8:FF:A2:A8:2F:D0:A6:CD:4B:B1:68:F3:E7:50:10:31:A7:79:21 

එම ප්‍රතිදානය සම්පූර්ණ සහතික දාමය එකම මට්ටමේ විස්තරාත්මකව අනුගමනය කරයි.

Opensl හි s_client වැනි එස්එස්එල්-කේන්ද්‍රීය ක්ලයි මෙවලමක් වෙනුවට මා එයට කැමති දේ, මෙය බොහෝ විට අපට අවශ්‍ය එක් කාර්යයක් කිරීමට උත්සාහ කරයි. ඇත්ත වශයෙන්ම opensl වඩාත් නම්‍යශීලී වේ (එනම් සේවාදායකයින් පරීක්ෂා කිරීම, අමුතු වරායන් මත ඉම්පැප් ආදිය) - නමුත් මට එය සැමවිටම අවශ්‍ය නොවේ.

විකල්පයක් ලෙස, ඔබට තවත් විශේෂාංග හෑරීමට සහ සැකසීමට හෝ අගය කිරීමට කාලය තිබේ නම්, විශාල මෙවලමක් ඇත sslyze (පරායත්තතාවයේ සිට එය භාවිතා නොකිරීම සහ ස්ථාපනය කිරීම ...)


5

ඔබට මෙය වින්ඩෝස් හි කිරීමට අවශ්‍ය නම් පහත සඳහන් ශ්‍රිතය සමඟ ඔබට පවර්ෂෙල් භාවිතා කළ හැකිය:

function Retrieve-ServerCertFromSocket ($hostname, $port=443, $SNIHeader, [switch]$FailWithoutTrust)
{
    if (!$SNIHeader) {
        $SNIHeader = $hostname
    }

    $cert = $null
    try {
        $tcpclient = new-object System.Net.Sockets.tcpclient
        $tcpclient.Connect($hostname,$port)

        #Authenticate with SSL
        if (!$FailWithoutTrust) {
            $sslstream = new-object System.Net.Security.SslStream -ArgumentList $tcpclient.GetStream(),$false, {$true}
        } else {
            $sslstream = new-object System.Net.Security.SslStream -ArgumentList $tcpclient.GetStream(),$false
        }

        $sslstream.AuthenticateAsClient($SNIHeader)
        $cert =  [System.Security.Cryptography.X509Certificates.X509Certificate2]($sslstream.remotecertificate)

     } catch {
        throw "Failed to retrieve remote certificate from $hostname`:$port because $_"
     } finally {
        #cleanup
        if ($sslStream) {$sslstream.close()}
        if ($tcpclient) {$tcpclient.close()}        
     }    
    return $cert
}

මෙය ඔබට වැනි පිළිවෙලට දේවල් කිරීමට ඉඩ සලසයි

#Save to file and open 
Retrieve-ServerCertFromSocket www.wrish.com 443 | Export-Certificate -FilePath C:\temp\test.cer ; start c:\temp\test.cer

#Display the cert details
Retrieve-ServerCertFromSocket www.wrish.com 443 | fl subject,*not*,Thumb*,ser*

4

මම මේ සඳහා ෂෙල් ස්ක්‍රිප්ට් එකක් භාවිතා කරමි. එය Opensl විධානය වටා එතීම පමණක් වන අතර එය වාක්‍ය ඛණ්ඩය මතක තබා ගැනීමෙන් මාව ගලවා ගනී.

මා සාමාන්‍යයෙන් උනන්දුවක් දක්වන සහතික තොරතුරු බොහොමයක් විග්‍රහ කිරීම සඳහා එය විකල්ප සපයයි, නැතහොත් අමු විවෘත ප්‍රතිදානය පෙන්වයි.

දේශීය සහතික ගොනුවක් හෝ දුරස්ථ සේවාදායකයක් විමසීමට හැකිය.

භාවිතය:

$ ssl-cert-info --help
Usage: ssl-cert-info [options]

This shell script is a simple wrapper around the openssl binary. It uses
s_client to get certificate information from remote hosts, or x509 for local
certificate files. It can parse out some of the openssl output or just dump all
of it as text.

Options:

  --all-info   Print all output, including boring things like Modulus and 
               Exponent.

  --alt        Print Subject Alternative Names. These will be typically be 
               additional hostnames that the certificate is valid for.

  --cn         Print commonName from Subject. This is typically the host for 
               which the certificate was issued.

  --debug      Print additional info that might be helpful when debugging this
               script.

  --end        Print certificate expiration date. For additional functionality
               related to certificate expiration, take a look at this script:
               "http://prefetch.net/code/ssl-cert-check".

  --dates      Print start and end dates of when the certificate is valid.

  --file       Use a local certificate file for input.

  --help       Print this help message.

  --host       Fetch the certificate from this remote host.

  --issuer     Print the certificate issuer.

  --most-info  Print almost everything. Skip boring things like Modulus and
               Exponent.

  --option     Pass any openssl option through to openssl to get its raw
               output.

  --port       Use this port when conneting to remote host. If ommitted, port
               defaults to 443.

  --subject    Print the certificate Subject -- typically address and org name.

Examples:

  1. Print a list of all hostnames that the certificate used by amazon.com 
     is valid for.

     ssl-cert-info --host amazon.com --alt
     DNS:uedata.amazon.com
     DNS:amazon.com
     DNS:amzn.com
     DNS:www.amzn.com
     DNS:www.amazon.com

  2. Print issuer of certificate used by smtp.gmail.com. Fetch certficate info
     over port 465.

     ssl-cert-info --host smtp.gmail.com --port 465 --issuer
     issuer= 
         countryName               = US
         organizationName          = Google Inc
         commonName                = Google Internet Authority G2

  3. Print valid dates for the certificate, using a local file as the source of 
     certificate data. Dates are formatted using the date command and display
     time in your local timezone instead of GMT.

     ssl-cert-info --file /path/to/file.crt --dates
     valid from: 2014-02-04 16:00:00 PST
     valid till: 2017-02-04 15:59:59 PST


  4. Print certificate serial number. This script doesn't have a special option
     to parse out the serial number, so will use the generic --option flag to
     pass '-serial' through to openssl.

     ssl-cert-info --host gmail.com --option -serial
     serial=4BF004B4DDC9C2F8

ඔබට මෙහි පිටපත ලබා ගත හැකිය: https://web.archive.org/web/20190528035412/http://giantdorks.org/alain/shell-script-to-check-ssl-certificate-info-like-expiration-date සහ විෂය /


සබැඳිය මිය ගොස් ඇත.
ඇඩම් මාතාන්

3
nmap -sV -sC google.com -p 443

3
මේ සඳහා තවත් බොහෝ පැහැදිලි කිරීම් අවශ්‍ය වේ.
ස්වේන්

පැහැදිලි කිරීමේ අවශ්‍යතාව සමඟ එකඟ වන්න, නමුත් එය මට ප්‍රයෝජනවත් වේ, එබැවින් +1
ජෙෆ්

3

ඔබට අවශ්‍ය වන්නේ කල් ඉකුත් වීමේ දිනය පමණි (එය හරියටම පිළිතුර නොවන නමුත් 9/10 යනු මිනිසුන් ක්‍රෝම් සහතික තොරතුරු භාවිතා කරන්නේ), ඔබට භාවිතා කළ හැකිය:

echo | openssl s_client -connect google.com:443 2>/dev/null | openssl x509 -noout -enddate

ස්ක්‍රිප්ට් ආදිය සඳහා ප්‍රයෝජනවත් වේ.

c4urself@eos ~ → which ssl_expiry
ssl_expiry () {
  echo | openssl s_client -connect ${1}:443 2> /dev/null | openssl x509 -noout -enddate
}
c4urself@eos ~ → ssl_expiry google.com
notAfter=Jun 12 16:54:00 2018 GMT
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.