Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-tls
Commits
71f35a4b
Commit
71f35a4b
authored
Jul 29, 2019
by
Marten Seemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expose the function to derive the peer's public key from the cert chain
parent
b3618ca6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
6 deletions
+4
-6
crypto.go
crypto.go
+4
-6
No files found.
crypto.go
View file @
71f35a4b
...
...
@@ -66,9 +66,7 @@ func (i *Identity) ConfigForAny() (*tls.Config, <-chan ic.PubKey) {
//
// It should be used to create a new tls.Config before securing either an
// incoming or outgoing connection.
func
(
i
*
Identity
)
ConfigForPeer
(
remote
peer
.
ID
,
)
(
*
tls
.
Config
,
<-
chan
ic
.
PubKey
)
{
func
(
i
*
Identity
)
ConfigForPeer
(
remote
peer
.
ID
)
(
*
tls
.
Config
,
<-
chan
ic
.
PubKey
)
{
keyCh
:=
make
(
chan
ic
.
PubKey
,
1
)
// We need to check the peer ID in the VerifyPeerCertificate callback.
// The tls.Config it is also used for listening, and we might also have concurrent dials.
...
...
@@ -88,7 +86,7 @@ func (i *Identity) ConfigForPeer(
chain
[
i
]
=
cert
}
pubKey
,
err
:=
getRemotePubKey
(
chain
)
pubKey
,
err
:=
PubKeyFromCertChain
(
chain
)
if
err
!=
nil
{
return
err
}
...
...
@@ -101,8 +99,8 @@ func (i *Identity) ConfigForPeer(
return
conf
,
keyCh
}
//
getRemotePubKey derives the remote's public key from the certificate chain
.
func
getRemotePubKey
(
chain
[]
*
x509
.
Certificate
)
(
ic
.
PubKey
,
error
)
{
//
PubKeyFromCertChain verifies the certificate chain and extract the remote's public key
.
func
PubKeyFromCertChain
(
chain
[]
*
x509
.
Certificate
)
(
ic
.
PubKey
,
error
)
{
if
len
(
chain
)
!=
1
{
return
nil
,
errors
.
New
(
"expected one certificates in the chain"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment