-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SC-7143 endpoint lookup and error handling #104
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,76 @@ | ||
package rvasp | ||
|
||
import ( | ||
"crypto/rsa" | ||
"fmt" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/trisacrypto/trisa/pkg/trisa/peers" | ||
) | ||
|
||
// TODO: The peers cache needs to be flushed periodically to prevent the situation | ||
// where remote peers change their endpoints or certificates and the rVASPs are stuck | ||
// using the old info. | ||
|
||
// fetchPeer returns the peer with the common name from the cache and performs a lookup | ||
// against the directory service if the peer does not have an endpoint. | ||
func (s *Server) fetchPeer(commonName string) (peer *peers.Peer, err error) { | ||
// Retrieve or create the peer from the cache | ||
if peer, err = s.peers.Get(commonName); err != nil { | ||
log.Error().Err(err).Msg("could not create or fetch peer") | ||
return nil, fmt.Errorf("could not create or fetch peer: %s", err) | ||
} | ||
|
||
// Ensure that the remote peer has an endpoint to connect to | ||
if err = s.resolveEndpoint(peer); err != nil { | ||
log.Warn().Err(err).Msg("could not fetch endpoint from remote peer") | ||
return nil, fmt.Errorf("could not fetch endpoint from remote peer: %s", err) | ||
} | ||
|
||
return peer, nil | ||
} | ||
|
||
// fetchSigningKey returns the signing key for the peer, performing an endpoint lookup | ||
// and key exchange if necessary. | ||
func (s *Server) fetchSigningKey(peer *peers.Peer) (key *rsa.PublicKey, err error) { | ||
// Ensure that the remote peer has an endpoint to connect to | ||
if err = s.resolveEndpoint(peer); err != nil { | ||
log.Warn().Err(err).Msg("could not fetch endpoint from remote peer") | ||
return nil, fmt.Errorf("could not fetch endpoint from remote peer: %s", err) | ||
} | ||
|
||
if peer.SigningKey() == nil { | ||
// If no key is available, perform a key exchange with the remote peer | ||
if peer.ExchangeKeys(true); err != nil { | ||
log.Warn().Str("common_name", peer.String()).Err(err).Msg("could not exchange keys with remote peer") | ||
return nil, fmt.Errorf("could not exchange keys with remote peer: %s", err) | ||
} | ||
|
||
// Verify the key is now available on the peer | ||
if peer.SigningKey() == nil { | ||
log.Error().Str("common_name", peer.String()).Msg("peer has no key after key exchange") | ||
return nil, fmt.Errorf("peer has no key after key exchange") | ||
} | ||
} | ||
|
||
return peer.SigningKey(), nil | ||
} | ||
|
||
// resolveEndpoint ensures that the peer has an endpoint to connect to, and performs a | ||
// lookup against the directory service to set the endpoint on the peer if necessary. | ||
func (s *Server) resolveEndpoint(peer *peers.Peer) (err error) { | ||
// If the endpoint is not in the peer, do the lookup to fetch the endpoint | ||
if peer.Info().Endpoint == "" { | ||
var remote *peers.Peer | ||
if remote, err = s.peers.Lookup(peer.String()); err != nil { | ||
log.Warn().Str("peer", peer.String()).Err(err).Msg("could not lookup peer") | ||
return fmt.Errorf("could not lookup peer: %s", err) | ||
} | ||
|
||
if remote.Info().Endpoint == "" { | ||
log.Error().Str("peer", peer.String()).Msg("peer has no endpoint after lookup") | ||
return fmt.Errorf("peer has no endpoint after lookup") | ||
} | ||
} | ||
return nil | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbengfort @DanielSollis This might cause some issues when people get new certificates, I suppose we could just reboot the rVASPs but for the long term do we need to just have the rVASPs always do the lookup or manually flush the cache periodically?