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 Answers
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
answered 2 years ago
0

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

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions