11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Linq ;
45using System . Runtime . InteropServices ;
6+ using System . Security . Cryptography . X509Certificates ;
7+ using System . Text ;
8+ using System . Xml ;
9+ using System . Xml . Linq ;
10+ using System . Xml . Serialization ;
511using NetLicensingClient . Entities ;
12+ using NetLicensingClient . Utils ;
613
714namespace NetLicensingClient
815{
@@ -262,7 +269,7 @@ static int Main(string[] args)
26226915OWo6dArRCyNUeROu+9Jp4tET+2RA/PuqQbWW6EbJWBhpkqNdzi9CYuhuUjvk8m
263270dwIDAQAB
264271-----END PUBLIC KEY-----" ;
265- string publicKey_wrong = @"-----BEGIN PUBLIC KEY-----
272+ string publicKeyWrong = @"-----BEGIN PUBLIC KEY-----
266273MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtq96itv1m00/czFD7IzE
267274mLiXPpvok1vjqB9VU6kTkq6QFGAfJF1G+m1fbK5NvpiDCsfuofdCFuhVnvLnzrpd
268275xUlse8erWEr9p9RAyh25NMK9/v0MAEAYV7zRa+ZOh31G54DwR7zk0TxyVzxKpjPi
@@ -273,7 +280,7 @@ static int Main(string[] args)
273280-----END PUBLIC KEY-----" ;
274281 Console . WriteLine ( "loaded privateKey: {0}" , privateKey ) ;
275282 Console . WriteLine ( "loaded publicKey: {0}" , publicKey ) ;
276- Console . WriteLine ( "loaded publicKey_wrong: {0}" , publicKey_wrong ) ;
283+ Console . WriteLine ( "loaded publicKey_wrong: {0}" , publicKeyWrong ) ;
277284
278285 //NetLicensing supports API Key Identification to allow limited API access on vendor's behalf.
279286 //See: https://netlicensing.io/wiki/security for details.
@@ -337,7 +344,7 @@ static int Main(string[] args)
337344
338345 // Validate using APIKey wrongly signed
339346 context . securityMode = SecurityMode . APIKEY_IDENTIFICATION ;
340- context . publicKey = publicKey_wrong ;
347+ context . publicKey = publicKeyWrong ;
341348 try
342349 {
343350 validationResult = LicenseeService . validate ( context , demoLicenseeNumber , validationParameters ) ;
@@ -354,6 +361,30 @@ static int Main(string[] args)
354361
355362 #endregion
356363
364+ #region ****************** Offline validation
365+ Context offlineContext = new Context ( ) ;
366+ offlineContext . publicKey = publicKey ;
367+
368+ string validationFile = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><ns2:netlicensing xmlns=""http://www.w3.org/2000/09/xmldsig#"" xmlns:ns2=""http://netlicensing.labs64.com/schema/context"" ttl=""2020-12-28T22:53:06.681Z""><Signature><SignedInfo><CanonicalizationMethod Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments""/><SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#rsa-sha1""/><Reference URI=""""><Transforms><Transform Algorithm=""http://www.w3.org/2000/09/xmldsig#enveloped-signature""/></Transforms><DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1""/><DigestValue>ICC1F7ZKeQoayrzn1iGtw7Zt96s=</DigestValue></Reference></SignedInfo><SignatureValue>jYb0aGBPR9Rn4HVRJhBsIRafzW1k3D/GF7GZ62nT8dwvJszGB0kEXdFrXTj7FhUeiBcBlqxcsEUUKA5XbE7LGbNm+V+f5xZu/+n/d/miufKPAIk6CN5xoZQLDRGRSruW0LiKJsnkbzHvIF4u6G/HUyQpUfrxwiqXb+tYFpiaMgcSHL5xGzRq5Mqusw21Cdq81MhUb9oUoujgisIZWqNyebOqWuzOjNJOy0y2uml4I5U5tBAL1OlrQKjfPUiy369HwMl37A7dR9oVcahb6/YPI039xeLTn+WzyFPIV7f41o6Ytq4Iefl6swj/elNKTHi9bYzcnjmM7ebOd+hinm8feA==</SignatureValue></Signature><ns2:infos/><ns2:items><ns2:item type=""ProductModuleValidation""><ns2:property name=""productModuleNumber"">Msb-DEMO</ns2:property><ns2:property name=""valid"">true</ns2:property><ns2:property name=""expires"">2021-04-21T20:15:45.694Z</ns2:property><ns2:property name=""productModuleName"">Module using ""Subscription"" licensing model</ns2:property><ns2:property name=""licensingModel"">Subscription</ns2:property></ns2:item></ns2:items></ns2:netlicensing>" ;
369+
370+ Console . WriteLine ( "Offline validation file: {0}" , validationFile ) ;
371+
372+ ValidationResult validationOfflineResult = ValidationService . validateOffline ( offlineContext , validationFile ) ;
373+ ConsoleWriter . WriteEntity ( "Offline validation result (Basic Auth):" , validationOfflineResult ) ;
374+
375+ offlineContext . publicKey = publicKeyWrong ;
376+
377+ try
378+ {
379+ validationOfflineResult = ValidationService . validateOffline ( offlineContext , validationFile ) ;
380+ }
381+ catch ( NetLicensingException e )
382+ {
383+ Console . WriteLine ( "Offline validation result exception (APIKey / wrongly signed): {0}" , e ) ;
384+ }
385+
386+ #endregion
387+
357388 #region ****************** Transfer
358389
359390 Licensee transferLicensee = new Licensee ( ) ;
0 commit comments