Skip to content

Commit

Permalink
Fix cyclic dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
intUnderflow committed Feb 3, 2022
1 parent 41cab3a commit 6980718
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions hashing/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import (
"crypto/x509"
"encoding/base64"
"github.com/monzo/terrors"
verified_sms "github.com/monzo/verifiedsms"
"golang.org/x/crypto/hkdf"
"io"
)

// GetHashForSMSMessage returns the hash for a given SMS message sent by a given agent to a user with a given public key
func GetHashForSMSMessage(publicKeyString string, agent *verified_sms.Agent, smsMessage []byte) ([]byte, error) {
func GetHashForSMSMessage(publicKeyString string, agentPrivateKey *ecdsa.PrivateKey, smsMessage []byte) ([]byte, error) {
publicKey, err := getPublicKeyFromPublicKeyPayload(publicKeyString)
if err != nil {
return nil, terrors.Propagate(err)
}

sharedSecret, err := ecdhDeriveSecret(agent.PrivateKey, publicKey)
sharedSecret, err := ecdhDeriveSecret(agentPrivateKey, publicKey)
if err != nil {
return nil, terrors.Propagate(err)
}
Expand Down
5 changes: 2 additions & 3 deletions oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"encoding/pem"
"github.com/monzo/terrors"
verified_sms "github.com/monzo/verifiedsms"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"net/http"
Expand All @@ -17,9 +16,9 @@ const (

// GetHttpClient returns a *http.Client which performs requests using the identity of the verified_sms.Partner
// service account
func GetHttpClient(ctx context.Context, partner verified_sms.Partner) (*http.Client, error) {
func GetHttpClient(ctx context.Context, serviceAccountJSON string) (*http.Client, error) {
serviceAccount := serviceAccountDetails{}
err := json.Unmarshal([]byte(partner.ServiceAccountJSONFile), &serviceAccount)
err := json.Unmarshal([]byte(serviceAccountJSON), &serviceAccount)

if err != nil {
return nil, terrors.Propagate(err)
Expand Down
6 changes: 3 additions & 3 deletions verified-sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (partner Partner) MarkSMSAsVerified(ctx context.Context, phoneNumber string

for _, publicKey := range publicKeys {
for _, smsMessageEntry := range smsMessages {
hash, err := hashing.GetHashForSMSMessage(publicKey, agent, []byte(smsMessageEntry))
hash, err := hashing.GetHashForSMSMessage(publicKey, agent.PrivateKey, []byte(smsMessageEntry))
if err != nil {
return false, terrors.Propagate(err)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func (partner Partner) MarkSMSAsVerified(ctx context.Context, phoneNumber string
request.Header.Set("Content-Type", ContentTypeHeader)
request.Header.Set("User-Agent", UserAgentHeader)

client, err := oauth2.GetHttpClient(ctx, partner)
client, err := oauth2.GetHttpClient(ctx, partner.ServiceAccountJSONFile)
if err != nil {
return false, terrors.Propagate(err)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (partner Partner) GetPhoneNumberPublicKeys(ctx context.Context, phoneNumber
request.Header.Set("Content-Type", ContentTypeHeader)
request.Header.Set("User-Agent", UserAgentHeader)

client, err := oauth2.GetHttpClient(ctx, partner)
client, err := oauth2.GetHttpClient(ctx, partner.ServiceAccountJSONFile)
if err != nil {
return nil, terrors.Propagate(err)
}
Expand Down

0 comments on commit 6980718

Please sign in to comment.