add PGP data

master
Matthew 2021-07-02 16:57:38 -04:00
parent e42ad33a86
commit e9696a58c2
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 69 additions and 1 deletions

View File

@ -11,6 +11,7 @@ func main() {
router.GET("/", routes.GetCertificateInfo) router.GET("/", routes.GetCertificateInfo)
router.GET("/tls", routes.GetCertificateInfo) router.GET("/tls", routes.GetCertificateInfo)
router.POST("/parse", routes.GetCertificateInformationEncoded) router.POST("/parse", routes.GetCertificateInformationEncoded)
router.POST("/pgp", routes.GetOpenPGPInformationEncoded)
router.Run() router.Run()
} }

2
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/ugorji/go v1.2.1 // indirect github.com/ugorji/go v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 // indirect golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
golang.org/x/sys v0.0.0-20201211002650-1f0c578a6b29 // indirect golang.org/x/sys v0.0.0-20201211002650-1f0c578a6b29 // indirect
google.golang.org/protobuf v1.25.0 // indirect google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect

View File

@ -1,6 +1,9 @@
package routes package routes
import ( import (
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/packet"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/ed25519" "crypto/ed25519"
"crypto/rsa" "crypto/rsa"
@ -11,10 +14,74 @@ import (
"encoding/pem" "encoding/pem"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type PGPKey struct {
FullName, Name, Comment, Email string
CreationTime time.Time
PublicKeyAlgorithm packet.PublicKeyAlgorithm
Fingerprint [20]byte
KeyID uint16
}
func GetOpenPGPInformationEncoded(c *gin.Context) {
query := c.Copy().Request.Body
block, err := armor.Decode(query)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"status": false,
"message": "Unable to parse body.",
})
return
}
pkt := packet.NewReader(block.Body)
entity, err := openpgp.ReadEntity(pkt)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"status": false,
"message": "Unable to parse body.",
})
return
}
if len(entity.Identities) > 1 {
c.JSON(http.StatusBadRequest, gin.H{
"status": false,
"message": "No identities found in PGP key.",
})
return
}
var key *PGPKey
for name, identity := range entity.Identities {
key = &PGPKey{
FullName: name,
Name: identity.UserId.Name,
Comment: identity.UserId.Comment,
Email: identity.UserId.Email,
CreationTime: entity.PrimaryKey.CreationTime,
PublicKeyAlgorithm: entity.PrimaryKey.PubKeyAlgo,
Fingerprint: entity.PrimaryKey.Fingerprint,
KeyID: uint16(entity.PrimaryKey.KeyId),
}
break
}
c.JSON(http.StatusOK, gin.H{
"status": true,
"fullName": key.FullName,
"name": key.Name,
"comment": key.Comment,
"email": key.Email,
"creationTime": key.CreationTime,
"publicKeyAlgorithm": key.PublicKeyAlgorithm,
"fingerprint": hex.EncodeToString(key.Fingerprint[:]),
"keyID": key.KeyID,
})
}
// GetCertificateInformationEncoded handler function for providing raw data to be parsed // GetCertificateInformationEncoded handler function for providing raw data to be parsed
func GetCertificateInformationEncoded(c *gin.Context) { func GetCertificateInformationEncoded(c *gin.Context) {
query := c.Copy().Request.Body query := c.Copy().Request.Body