admin: use hexadecimal certificate ID

This commit is contained in:
nemunaire 2020-01-21 13:14:19 +01:00
parent 6921431a77
commit 99e53ccfe6
5 changed files with 22 additions and 17 deletions

View file

@ -12,6 +12,7 @@ import (
"fmt"
"io/ioutil"
"log"
"math"
"math/big"
"os"
"path"
@ -52,10 +53,10 @@ func init() {
if serials, err := pki.GetTeamSerials(TeamsDir, team.Id); err != nil {
return nil, err
} else {
var certs []fic.Certificate
var certs []CertExported
for _, serial := range serials {
if cert, err := fic.GetCertificate(serial); err == nil {
certs = append(certs, cert)
certs = append(certs, CertExported{fmt.Sprintf("%0[2]*[1]X", cert.Id, int(math.Ceil(math.Log2(float64(cert.Id))/8)*2)), cert.Creation, cert.Password, &team.Id, cert.Revoked})
} else {
log.Println("Unable to get back certificate, whereas an association exists on disk: ", err)
}
@ -247,13 +248,15 @@ func generateClientCert(_ httprouter.Params, _ []byte) (interface{}, error) {
}
// Save in DB
return fic.RegisterCertificate(serial, password)
cert, err := fic.RegisterCertificate(serial, password)
return CertExported{fmt.Sprintf("%0[2]*[1]X", cert.Id, int(math.Ceil(math.Log2(float64(cert.Id))/8)*2)), cert.Creation, cert.Password, nil, cert.Revoked}, err
}
type CertExported struct {
Id string `json:"id"`
Creation time.Time `json:"creation"`
IdTeam *uint64 `json:"id_team"`
Password string `json:"password,omitempty"`
IdTeam *int64 `json:"id_team"`
Revoked *time.Time `json:"revoked"`
}
@ -265,14 +268,14 @@ func getCertificates(_ httprouter.Params, _ []byte) (interface{}, error) {
for _, cert := range certificates {
dstLinkPath := path.Join(TeamsDir, pki.GetCertificateAssociation(cert.Id))
var idTeam *uint64 = nil
var idTeam *int64 = nil
if lnk, err := os.Readlink(dstLinkPath); err == nil {
if tid, err := strconv.ParseUint(lnk, 10, 64); err == nil {
if tid, err := strconv.ParseInt(lnk, 10, 64); err == nil {
idTeam = &tid
}
}
ret = append(ret, CertExported{fmt.Sprintf("%d", cert.Id), cert.Creation, idTeam, cert.Revoked})
ret = append(ret, CertExported{fmt.Sprintf("%0[2]*[1]X", cert.Id, int(math.Ceil(math.Log2(float64(cert.Id))/8)*2)), cert.Creation, "", idTeam, cert.Revoked})
}
return ret, nil
}