From 771627a0da25743893e898097d20eea15a6ce049 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 5 Feb 2019 02:38:43 +0100 Subject: [PATCH] pki: fix team association, complement to 68e5c4cd2b9e120967674c464eb95dbd6bd98488 The fix introduced in the referenced commit was not working. This time, it has been tested with the following commands: # Associate all certificate to a team curl http://localhost:8081/api/certs/ | jq -r .[].id | while read CERTID; do curl -X PUT -d '{"id_team":1}' http://localhost:8081/api/certs/$CERTID; done # For each certificate associated with the team, try to connect to the server with each certificate. Report failing certificates. curl -s http://localhost:8081/api/teams/1/certificates | jq -r '.[] | .id + " " + .password' | while read CERTID PASSWORD; do curl -sf --cert-type P12 --cert $CERTID.p12:$PASSWORD https://fic.srs.epita.fr/my.json > /dev/null || echo $CERTID; done --- admin/pki/team.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/pki/team.go b/admin/pki/team.go index 2263e32c..6aa5c75c 100644 --- a/admin/pki/team.go +++ b/admin/pki/team.go @@ -3,6 +3,7 @@ package pki import ( "fmt" "io/ioutil" + "math" "os" "path" "strconv" @@ -12,7 +13,7 @@ import ( const SymlinkPrefix = "_AUTH_ID_" func GetCertificateAssociation(serial uint64) string { - return fmt.Sprintf(SymlinkPrefix + "%0X", serial) + return fmt.Sprintf(SymlinkPrefix + "%0[2]*[1]X", serial, int(math.Ceil(math.Log2(float64(serial))/8)*2)) } func GetAssociations(dirname string) (assocs []string, err error) {