hyperboloide/lk

Retrieving data from license

Closed this issue · 1 comments

I am using this debugging code to test creating & importing a license.

licenseRead, openErr := ioutil.ReadFile("./license.pem")
if openErr == nil {
	license,_ = lk.LicenseFromB64String(string(licenseRead))
	fmt.Println(string(licenseRead), license.Data)
	
	if ok, err := license.Verify(licensePubKey); err != nil {
		fmt.Println(err)
	} else if ok {
		fmt.Println("Valid license")
		if jsDecErr := json.Unmarshal(license.Data, &licenseData); jsDecErr != nil {
			fmt.Println("unmarshal error", jsDecErr)
		}
		fmt.Println("unmarshal success", string(license.Data), licenseData)
	} else {
		fmt.Println("Invalid license")
	}
} else {
	licenseData = &licenseStruct{os.Args[1], time.Now().Add(time.Hour * 24 * time.Duration(runtime)), runtime}
	licenseBytes,_ := json.Marshal(licenseData)
	license,_ = lk.NewLicense(privateKey, licenseBytes)
	exportLicense,_ := license.ToB64String()
	
	ioutil.WriteFile("./license.pem", []byte(exportLicense), 0644)
	fmt.Println("License generated & saved")
}
fmt.Println("Your license data", licenseData)

While this works for the generation of the license (outputs the struct correctly in that instance), the struct is always empty when trying to read the license back in. No function returns any errors and I verified that the raw data of the license on export & import is identical. There is no documentation on how to get the data out of the license again, but according to the source files it's supposed to be the .Data attribute.

Log of generation

License generated & saved
Your license data &{test@example.com {63647040171 98409900 0x7df480} 100}

License file

LP+BAwEBB0xpY2Vuc2UB/4IAAQMBBERhdGEBCgABAVIB/4QAAQFTAf+EAAAACv+DBQEC/4YAAABt/4IBAnt9ATECSXUDye1UQejYyqP9iwSnkSxOGDgpM2fJuGLFHkemhbPtTXA6unPA1fbhn4H+WulmATEC9Do4X225WMaX7QiEvotT76Uel1AoArlJmvs8BybBi5330A0kKGpBPTS8wJW6bz/6AA==

Log of Import

LP+BAwEBB0xpY2Vuc2UB/4IAAQMBBERhdGEBCgABAVIB/4QAAQFTAf+EAAAACv+DBQEC/4YAAABt/4IBAnt9ATECSXUDye1UQejYyqP9iwSnkSxOGDgpM2fJuGLFHkemhbPtTXA6unPA1fbhn4H+WulmATEC9Do4X225WMaX7QiEvotT76Uel1AoArlJmvs8BybBi5330A0kKGpBPTS8wJW6bz/6AA== [123 125]
&{ {0 0 } 0}
Valid license
unmarshal success {} &{ {0 0 } 0}
Your license data &{ {0 0 } 0}

It had nothing to do with the plugin, I didn't know that all fields of a struct that are supposed to be exported need to be uppercase - see here.