Skip to content

Commit

Permalink
feat: rpc client tls cert create api for app
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Apr 4, 2024
1 parent 16d15fe commit c18148d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/api/controllers/app/keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/ncuhome/GeniusAuthoritarian/internal/api/callback"
"github.com/ncuhome/GeniusAuthoritarian/internal/global"
"github.com/ncuhome/GeniusAuthoritarian/internal/tools"
"github.com/ncuhome/GeniusAuthoritarian/pkg/keypair"
"time"
)

func ServerPublicKeys(c *gin.Context) {
Expand All @@ -19,3 +21,20 @@ func ServerPublicKeys(c *gin.Context) {
"ca": global.CaIssuer.CaCertPem,
})
}

func RpcClientCredential(c *gin.Context) {
appCode := tools.GetAppCode(c)

validBefore := time.Now().AddDate(0, 0, 7)
certPem, privatePem, err := global.CaIssuer.Issue([]string{appCode}, validBefore)
if err != nil {
callback.Error(c, callback.ErrUnexpected, err)
return
}

callback.Success(c, gin.H{
"cert": certPem,
"key": privatePem,
"validBefore": validBefore.Unix(),
})
}
1 change: 1 addition & 0 deletions internal/api/router/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ func Router(G *gin.RouterGroup) {

keypair := G.Group("keypair")
keypair.GET("server", controllers.ServerPublicKeys)
keypair.POST("rpc", controllers.RpcClientCredential)
}

0 comments on commit c18148d

Please sign in to comment.