Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERR] tls: failed to verify certificate: x509: certificate signed by unknown authority #404

Closed
FawenYo opened this issue Dec 18, 2023 · 1 comment
Labels

Comments

@FawenYo
Copy link

FawenYo commented Dec 18, 2023

System Informations

  • Go version: 1.21.4
  • OS: scratch

Expected Behavior

Reply/Push messages successfully

Current Behavior

{"component":"main","level":"info","msg":"Post \"https://api.line.me/v2/bot/message/reply\": tls: failed to verify certificate: x509: certificate signed by unknown authority","time":"2023-12-18T10:36:06Z"}

Steps to Reproduce

Here is part of my code

package line

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
	"github.com/line/line-bot-sdk-go/v8/linebot/webhook"
)

var (
	log = utils.GetLogger()
)

func LINEHandler(c *gin.Context) {
	path := c.Param("action")

	// Use a switch case to redirect to different functions
	switch path {
	case "/callback":
		callback(c)
	default:
		c.JSON(http.StatusNotFound, gin.H{"message": "Not found"})
	}
}

func callback(c *gin.Context) {
	bot, err := messaging_api.NewMessagingApiAPI(utils.GetLINEConfig().LINEChannelAccessToken)
	if err != nil {
		log.WithField("component", "line").Errorf("Failed to create new bot: %s", err)
		c.JSON(http.StatusInternalServerError, gin.H{"message": "Internal server error"})
		return
	}

	cb, err := webhook.ParseRequest(utils.GetLINEConfig().LINEChannelSecret, c.Request)
	if err != nil {
		log.WithField("component", "line").Errorf("Failed to parse request: %s", err)
		if err == webhook.ErrInvalidSignature {
			c.JSON(http.StatusBadRequest, gin.H{"message": "Invalid signature"})
		} else {
			c.JSON(http.StatusInternalServerError, gin.H{"message": "Internal server error"})
		}
		return
	}

	for _, event := range cb.Events {
		switch e := event.(type) {
		case webhook.MessageEvent:
			switch message := e.Message.(type) {
			case webhook.TextMessageContent:
				if _, err = bot.ReplyMessage(
					&messaging_api.ReplyMessageRequest{
						ReplyToken: e.ReplyToken,
						Messages: []messaging_api.MessageInterface{
							messaging_api.TextMessage{
								Text: message.Text,
							},
						},
					},
				); err != nil {
					log.Print(err)
				} else {
					log.Println("Sent text reply.")
				}
			default:
				log.WithField("component", "line").Errorf("Unsupported message: %T\n", message)
			}
		default:
			log.WithField("component", "line").Errorf("Unsupported event: %T\n", event)
		}
	}

}

It seems my code can get the message event correctly, but I just couldn't send the message. Any help is appreciated.

@FawenYo FawenYo added the bug label Dec 18, 2023
@FawenYo
Copy link
Author

FawenYo commented Dec 18, 2023

OK... so I found where the problem is. The error is caused by not copy SSL certificates to /etc/ssl/certs/ca-certificates.crt, and copying it to the path will solve this error. Issue closed.

@FawenYo FawenYo closed this as completed Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant