Cognito - CustomSMSSender InvalidCiphertextException: null on Code Decrypt (Golang)

1

Hi, i followed this document to customize cognito SMS delivery flow https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-sms-sender.html

I'm not working on a Javascript environment so wrote this Go snippet:

package main

import (
	"context"
	golog "log"
	"os"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/kms"
)

// USING THIS TYPES BECAUSE AWS-SDK-GO DOES NOT SUPPORTS THIS

// CognitoEventUserPoolsCustomSmsSender is sent by AWS Cognito User Pools before each mail to send.
type CognitoEventUserPoolsCustomSmsSender struct {
	events.CognitoEventUserPoolsHeader
	Request  CognitoEventUserPoolsCustomSmsSenderRequest  `json:"request"`
}

// CognitoEventUserPoolsCustomSmsSenderRequest contains the request portion of a CustomSmsSender event
type CognitoEventUserPoolsCustomSmsSenderRequest struct {
	UserAttributes map[string]interface{} `json:"userAttributes"`
	Code           string                 `json:"code"`
	ClientMetadata map[string]string      `json:"clientMetadata"`
	Type           string                 `json:"type"`
}

func main() {
	lambda.Start(sendCustomSms)
}

func sendCustomSms(ctx context.Context, event *CognitoEventUserPoolsCustomSmsSender) error {
	golog.Printf("received event=%+v", event)
	golog.Printf("received ctx=%+v", ctx)
	
	config := aws.NewConfig().WithRegion(os.Getenv("AWS_REGION"))
	session, err := session.NewSession(config)
	if err != nil {
		return err
	}

	kmsProvider := kms.New(session)	
	smsCode, err := kmsProvider.Decrypt(&kms.DecryptInput{
		KeyId: aws.String("a8a566c5-796a-4ba1-8715-c9c17c6f0cb5"),
		CiphertextBlob: []byte(event.Request.Code),
	})
	if err != nil {
		return err
	}

	golog.Printf("decrypted code %v", smsCode.Plaintext)
	
	return nil
}


i'm always getting InvalidCiphertextException: : InvalidCiphertextException null, can someone help?

This is how lambda config looks on my user pool:

"LambdaConfig": {
   "CustomSMSSender": {
        "LambdaVersion": "V1_0",
        "LambdaArn": "arn:aws:lambda:eu-west-1:...:function:cognito-custom-auth-sms-sender-dev"
    },
     "KMSKeyID": "arn:aws:kms:eu-west-1:...:key/a8a566c5-796a-4ba1-8715-c9c17c6f0cb5"
},
2 個答案
0

I'm facing same issue but unfortunately couldn't find any solution. There is no enough documentation as well. My assumption is something about encryptionContext. If you found the solution, please let me know. Thanks.

Fatih
已回答 2 年前
0

Is there not a solution for this? I have the same issue.

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南