Skip to content

Commit

Permalink
refactor: drop old golang-jwt/jwt dependency
Browse files Browse the repository at this point in the history
We are only using a small method that has nothing to do with jwt, it's better
to copy the method and drop the dependency.
  • Loading branch information
kruskall committed Jun 8, 2024
1 parent 35f8d09 commit 0a3475d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
38 changes: 19 additions & 19 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17540,25 +17540,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



--------------------------------------------------------------------------------
Dependency : github.com/golang-jwt/jwt/v5
Version: v5.0.0
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/golang-jwt/jwt/v5@v5.0.0/LICENSE:

Copyright (c) 2012 Dave Grijalva
Copyright (c) 2021 golang-jwt maintainers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



--------------------------------------------------------------------------------
Dependency : github.com/golang/mock
Version: v1.6.0
Expand Down Expand Up @@ -40825,6 +40806,25 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI



--------------------------------------------------------------------------------
Dependency : github.com/golang-jwt/jwt/v5
Version: v5.0.0
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/golang-jwt/jwt/v5@v5.0.0/LICENSE:

Copyright (c) 2012 Dave Grijalva
Copyright (c) 2021 golang-jwt maintainers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



--------------------------------------------------------------------------------
Dependency : github.com/golang-sql/civil
Version: v0.0.0-20190719163853-cb61b32ac6fe
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ require (
github.com/foxcpp/go-mockdns v0.0.0-20201212160233-ede2f9158d15
github.com/g8rswimmer/go-sfdc v0.0.0-00010101000000-000000000000
github.com/go-ldap/ldap/v3 v3.4.6
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/cel-go v0.19.0
github.com/googleapis/gax-go/v2 v2.12.0
github.com/gorilla/handlers v1.5.1
Expand Down Expand Up @@ -307,6 +306,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/godror/knownpb v0.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down
27 changes: 25 additions & 2 deletions x-pack/filebeat/input/salesforce/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ package salesforce
import (
"bytes"
"context"
"crypto/rsa"
"crypto/x509"
"encoding/csv"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
Expand All @@ -20,7 +23,6 @@ import (
"github.com/g8rswimmer/go-sfdc/credentials"
"github.com/g8rswimmer/go-sfdc/session"
"github.com/g8rswimmer/go-sfdc/soql"
"github.com/golang-jwt/jwt/v5"
"github.com/hashicorp/go-retryablehttp"
"go.uber.org/zap"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -409,7 +411,7 @@ func (s *salesforceInput) getSFDCConfig(cfg *config) (*sfdc.Configuration, error
return nil, fmt.Errorf("problem with client key path for JWT auth: %w", err)
}

signKey, err := jwt.ParseRSAPrivateKeyFromPEM(pemBytes)
signKey, err := parseRSAPrivateKeyFromPEM(pemBytes)
if err != nil {
return nil, fmt.Errorf("problem with client key for JWT auth: %w", err)
}
Expand Down Expand Up @@ -454,6 +456,27 @@ func (s *salesforceInput) getSFDCConfig(cfg *config) (*sfdc.Configuration, error
}, nil
}

func parseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) {
// Parse PEM block
var block *pem.Block
if block, _ = pem.Decode(key); block == nil {
return nil, errors.New("Invalid Key: Key must be a PEM encoded PKCS1 or PKCS8 key")
}

if parsedKey, err := x509.ParsePKCS1PrivateKey(block.Bytes); err == nil {
return parsedKey, nil
}

if parsedKey, err := x509.ParsePKCS8PrivateKey(block.Bytes); err == nil {
if pkey, ok := parsedKey.(*rsa.PrivateKey); ok {
return pkey, nil
}

}

return nil, errors.New("Key is not a valid RSA private key")
}

// retryLog is a shim for the retryablehttp.Client.Logger.
type retryLog struct{ log *logp.Logger }

Expand Down

0 comments on commit 0a3475d

Please sign in to comment.