-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a748aaa
commit f01e247
Showing
3 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cert | ||
|
||
import ( | ||
"bytes" | ||
"crypto/tls" | ||
"encoding/pem" | ||
) | ||
|
||
func FetchCert(addr string) ([]byte, error) { | ||
conn, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify: true}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer conn.Close() | ||
|
||
certs := conn.ConnectionState().PeerCertificates | ||
|
||
var buf bytes.Buffer | ||
for _, crt := range certs { | ||
b := pem.EncodeToMemory(&pem.Block{ | ||
Type: "CERTIFICATE", | ||
Bytes: crt.Raw, | ||
}) | ||
|
||
buf.Write(b) | ||
} | ||
|
||
return buf.Bytes(), nil | ||
} |