mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-04 18:08:50 +00:00
fix: prevent possible nil pointer panics (#11728)
# Which Problems Are Solved We found multiple cases where potentially a panic occurred or could occur: - when de/encrypting certain information - returning apps without any configuration type (?) - apple IdPs without a proper private key # How the Problems Are Solved - Added nil checks - Check private key format for apple IdPs - Added necessary helper function # Additional Changes Fixed i18n yaml where the IDP errors were indented under `org` instead of directly under `errors`. # Additional Context - requires backport to v4.x --------- Co-authored-by: Marco A. <[email protected]>
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package apple
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"crypto/ecdsa"
|
||||
"time"
|
||||
|
||||
"github.com/go-jose/go-jose/v4"
|
||||
"github.com/zitadel/oidc/v3/pkg/crypto"
|
||||
openid "github.com/zitadel/oidc/v3/pkg/oidc"
|
||||
|
||||
zcrypto "github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/idp"
|
||||
"github.com/zitadel/zitadel/internal/idp/providers/oidc"
|
||||
)
|
||||
@@ -42,9 +42,7 @@ func New(clientID, teamID, keyID, callbackURL string, key []byte, scopes []strin
|
||||
|
||||
// clientSecretFromPrivateKey uses the private key to create and sign a JWT, which has to be used as client_secret at Apple.
|
||||
func clientSecretFromPrivateKey(key []byte, teamID, clientID, keyID string) (string, error) {
|
||||
block, _ := pem.Decode(key)
|
||||
b := block.Bytes
|
||||
pk, err := x509.ParsePKCS8PrivateKey(b)
|
||||
pk, err := BytesToPrivateKey(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -66,3 +64,7 @@ func clientSecretFromPrivateKey(key []byte, teamID, clientID, keyID string) (str
|
||||
IssuedAt: openid.FromTime(iat),
|
||||
}, signer)
|
||||
}
|
||||
|
||||
func BytesToPrivateKey(key []byte) (*ecdsa.PrivateKey, error) {
|
||||
return zcrypto.BytesToPrivateKeyPKCS8[*ecdsa.PrivateKey](key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user