Skip to content

Commit

Permalink
sipsecid: added cert verify option for time only
Browse files Browse the repository at this point in the history
- related to GH #32
  • Loading branch information
miconda committed Oct 18, 2024
1 parent 4992ca0 commit 9fec39c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions secsipid/secsipid.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ type SJWTLibOptions struct {
}

const (
CertVerifyOptTime = (1 << 0)
CertVerifyOptSysCA = (1 << 1)
CertVerifyOptCustCA = (1 << 2)
CertVerifyOptInterCA = (1 << 3)
CertVerifyOptCRL = (1 << 4)
CertVerifyOptTime = (1 << 0)
CertVerifyOptSysCA = (1 << 1)
CertVerifyOptCustCA = (1 << 2)
CertVerifyOptInterCA = (1 << 3)
CertVerifyOptCRL = (1 << 4)
CertVerifyOptTimeOnly = (1 << 5)
)

var globalLibOptions = SJWTLibOptions{
Expand Down Expand Up @@ -271,14 +272,18 @@ func SJWTPubKeyVerify(pubKey []byte) (int, error) {
return SJWTRetErrCertInvalidFormat, errors.New("failed to parse certificate PEM")
}

if (globalLibOptions.certVerify & CertVerifyOptTime) != 0 {
if (globalLibOptions.certVerify & (CertVerifyOptTime | CertVerifyOptTimeOnly)) != 0 {
if !time.Now().Before(certVal.NotAfter) {
return SJWTRetErrCertExpired, errors.New("certificate expired")
} else if !time.Now().After(certVal.NotBefore) {
return SJWTRetErrCertBeforeValidity, errors.New("certificate not valid yet")
}
}

if (globalLibOptions.certVerify & CertVerifyOptTimeOnly) != 0 {
return SJWTRetOK, nil
}

rootCAs = nil
interCAs = nil
if (globalLibOptions.certVerify & CertVerifyOptSysCA) != 0 {
Expand Down

0 comments on commit 9fec39c

Please sign in to comment.