Skip to content

Commit

Permalink
Encode player's key pair also in preferred by Minecraft format
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed Jun 20, 2024
1 parent 64602e6 commit 3d4f247
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/http/profilecerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,21 @@ func (s *ProfilesCertificatesApi) getCertificatesHandler(c *gin.Context) {
profileCert, err := s.ProfileCertificatesService.GetKeypairForUser(c.Request.Context(), uuid)
if err != nil {
c.Error(fmt.Errorf("unable to retrieve a private key for user: %w", err))
return
}

privateKeyPKCS8, _ := x509.MarshalPKCS8PrivateKey(profileCert.Key)
privateKeyBlock := &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(profileCert.Key),
Bytes: privateKeyPKCS8,
}
privateKeyPem := pem.EncodeToMemory(privateKeyBlock)

publicKey := &profileCert.Key.PublicKey
publicKeyPCIX, _ := x509.MarshalPKIXPublicKey(publicKey)
publicKeyBlock := &pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: x509.MarshalPKCS1PublicKey(publicKey),
Bytes: publicKeyPCIX,
}
publicKeyPem := pem.EncodeToMemory(publicKeyBlock)

Expand Down Expand Up @@ -136,16 +140,12 @@ func (s *ProfilesCertificatesApi) getPublicKeysHandler(c *gin.Context) {
return
}

encodedPublicKey, err := x509.MarshalPKIXPublicKey(publicKey)
if err != nil {
c.Error(fmt.Errorf("unable to encode public key: %w", err))
return
}
publicKeyPKIX, _ := x509.MarshalPKIXPublicKey(publicKey)

c.JSON(http.StatusOK, gin.H{
"playerCertificateKeys": []map[string][]byte{
{
"publicKey": encodedPublicKey,
"publicKey": publicKeyPKIX,
},
},
})
Expand Down

0 comments on commit 3d4f247

Please sign in to comment.