admin: use hexadecimal certificate ID
This commit is contained in:
parent
6921431a77
commit
99e53ccfe6
5 changed files with 22 additions and 17 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -52,10 +53,10 @@ func init() {
|
||||||
if serials, err := pki.GetTeamSerials(TeamsDir, team.Id); err != nil {
|
if serials, err := pki.GetTeamSerials(TeamsDir, team.Id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
var certs []fic.Certificate
|
var certs []CertExported
|
||||||
for _, serial := range serials {
|
for _, serial := range serials {
|
||||||
if cert, err := fic.GetCertificate(serial); err == nil {
|
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 {
|
} else {
|
||||||
log.Println("Unable to get back certificate, whereas an association exists on disk: ", err)
|
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
|
// 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 {
|
type CertExported struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Creation time.Time `json:"creation"`
|
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"`
|
Revoked *time.Time `json:"revoked"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,14 +268,14 @@ func getCertificates(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||||
for _, cert := range certificates {
|
for _, cert := range certificates {
|
||||||
dstLinkPath := path.Join(TeamsDir, pki.GetCertificateAssociation(cert.Id))
|
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 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
|
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
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,9 +330,16 @@ func fileDependancyHandler(f func(fic.EFile, int64, []byte) (interface{}, error)
|
||||||
|
|
||||||
func certificateHandler(f func(fic.Certificate, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
func certificateHandler(f func(fic.Certificate, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||||
if certid, err := strconv.ParseUint(strings.TrimSuffix(string(ps.ByName("certid")), ".p12"), 10, 64); err != nil {
|
var cid uint64
|
||||||
return nil, err
|
var err error
|
||||||
} else if cert, err := fic.GetCertificate(certid); err != nil {
|
certid := strings.TrimSuffix(ps.ByName("certid"), ".p12")
|
||||||
|
if cid, err = strconv.ParseUint(certid, 10, 64); err != nil {
|
||||||
|
if cid, err = strconv.ParseUint(certid, 16, 64); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cert, err := fic.GetCertificate(cid); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
return f(cert, body)
|
return f(cert, body)
|
||||||
|
|
|
@ -601,11 +601,6 @@ angular.module("FICApp")
|
||||||
|
|
||||||
$scope.teams = Team.query();
|
$scope.teams = Team.query();
|
||||||
$scope.certificates = Certificate.query();
|
$scope.certificates = Certificate.query();
|
||||||
$scope.certificates.$promise.then(function(certificates) {
|
|
||||||
certificates.forEach(function(certificate, cid) {
|
|
||||||
certificate.serial = parseInt(certificate.id).toString(16);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$scope.ca = CACertificate.get();
|
$scope.ca = CACertificate.get();
|
||||||
|
|
||||||
$scope.revoke = function() {
|
$scope.revoke = function() {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="certificate in certificates | filter: query" ng-click="show(certificate.id)" ng-class="{'bg-danger': certificate.revoked}">
|
<tr ng-repeat="certificate in certificates | filter: query" ng-click="show(certificate.id)" ng-class="{'bg-danger': certificate.revoked}">
|
||||||
<td>{{ certificate.serial | uppercase }}</td>
|
<td>{{ certificate.id }}</td>
|
||||||
<td>{{ certificate.creation }}</td>
|
<td>{{ certificate.creation }}</td>
|
||||||
<td ng-if="certificate.id_team">
|
<td ng-if="certificate.id_team">
|
||||||
<span ng-repeat="team in teams" ng-if="team.id == certificate.id_team">
|
<span ng-repeat="team in teams" ng-if="team.id == certificate.id_team">
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
<button type="button" class="btn btn-sm btn-primary float-right" ng-click="dissociateCertificate(cert)">Dissocier</button>
|
<button type="button" class="btn btn-sm btn-primary float-right" ng-click="dissociateCertificate(cert)">Dissocier</button>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{ cert.serial | uppercase }}
|
{{ cert.id }}
|
||||||
<span class="badge badge-danger" ng-if="cert.revoked">Révoqué</span>
|
<span class="badge badge-danger" ng-if="cert.revoked">Révoqué</span>
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
|
|
Reference in a new issue