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.

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인