Skip to content

Commit

Permalink
feat: add license type and expire_at
Browse files Browse the repository at this point in the history
  • Loading branch information
jclab-joseph committed Dec 6, 2024
1 parent 2a21641 commit 0624520
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 37 deletions.
8 changes: 8 additions & 0 deletions java/jclab-license-model/src/main/proto/jclab-license.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ message TimecenseKey {
bytes key = 4;
}

enum LicenseType {
kUnknownLicenseType = 0;
kTermMaintenance = 1;
kSubscribe = 2;
}

message LicensePack {
// unix epoch time as milliseconds
int64 issued_at = 1;
Expand All @@ -21,6 +27,8 @@ message LicensePack {
string licensee_email = 11;

repeated string licensed_product = 20;
LicenseType license_type = 21;
int64 license_expire_at = 22;

int32 timecense_max_version = 30;
repeated TimecenseKey timecense_key = 31;
Expand Down
153 changes: 117 additions & 36 deletions license_proto/jclab-license.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
"go.mozilla.org/pkcs7"
"google.golang.org/protobuf/proto"
"strings"
"time"
)

type Result struct {
*license_proto.LicensePack
// Expired subscription has expired
Expired bool
}

//go:embed internal/jclabconstant/jclab_license_authority.der
Expand Down Expand Up @@ -61,7 +64,13 @@ func Verify(input []byte) (Result, error) {
if err = proto.Unmarshal(p7.Content, result.LicensePack); err != nil {
return result, err
}
_ = signerCert

now := time.Now()
if result.GetLicenseType() == license_proto.LicenseType_kSubscribe {
expireAt := time.UnixMicro(result.LicenseExpireAt)
result.Expired = now.After(expireAt)
}

return result, nil
}

Expand Down

0 comments on commit 0624520

Please sign in to comment.