box: fix panic when decoding corrupted PEM from JWT file

See: https://forum.rclone.org/t/box-jwt-config-erroring-panic/40685/
This commit is contained in:
Nick Craig-Wood 2023-08-09 11:05:35 +01:00
parent 0cccda61db
commit 02d643f782

View File

@ -241,6 +241,9 @@ func getQueryParams(boxConfig *api.ConfigJSON) map[string]string {
func getDecryptedPrivateKey(boxConfig *api.ConfigJSON) (key *rsa.PrivateKey, err error) {
block, rest := pem.Decode([]byte(boxConfig.BoxAppSettings.AppAuth.PrivateKey))
if block == nil {
return nil, errors.New("box: failed to PEM decode private key")
}
if len(rest) > 0 {
return nil, fmt.Errorf("box: extra data included in private key: %w", err)
}