@@ -13,8 +13,8 @@ internal enum ClientType
1313 {
1414 Sharing ,
1515 Bidstream ,
16- LegacyWithoutDomainCheck ,
17- LegacyWithDomainCheck
16+ LegacyWithoutDomainOrAppNameCheck ,
17+ LegacyWithDomainOrAppNameCheck
1818 }
1919
2020 internal static class UID2Encryption
@@ -26,7 +26,7 @@ internal static class UID2Encryption
2626 private static char [ ] BASE64_URL_SPECIAL_CHARS = { '-' , '_' } ;
2727
2828
29- internal static DecryptionResponse Decrypt ( string token , KeyContainer keys , DateTime now , string domainName , IdentityScope identityScope , ClientType clientType )
29+ internal static DecryptionResponse Decrypt ( string token , KeyContainer keys , DateTime now , string domainOrAppName , IdentityScope identityScope , ClientType clientType )
3030 {
3131 if ( token . Length < 4 )
3232 {
@@ -39,24 +39,24 @@ internal static DecryptionResponse Decrypt(string token, KeyContainer keys, Date
3939
4040 if ( data [ 0 ] == 2 )
4141 {
42- return DecryptV2 ( Convert . FromBase64String ( token ) , keys , now , domainName , clientType ) ;
42+ return DecryptV2 ( Convert . FromBase64String ( token ) , keys , now , domainOrAppName , clientType ) ;
4343 }
4444
4545 if ( data [ 1 ] == ( int ) AdvertisingTokenVersion . V3 )
4646 {
47- return DecryptV3 ( Convert . FromBase64String ( token ) , keys , now , identityScope , 3 , domainName , clientType ) ;
47+ return DecryptV3 ( Convert . FromBase64String ( token ) , keys , now , identityScope , 3 , domainOrAppName , clientType ) ;
4848 }
4949
5050 if ( data [ 1 ] == ( int ) AdvertisingTokenVersion . V4 )
5151 {
5252 //same as V3 but use Base64URL encoding
53- return DecryptV3 ( UID2Base64UrlCoder . Decode ( token ) , keys , now , identityScope , 4 , domainName , clientType ) ;
53+ return DecryptV3 ( UID2Base64UrlCoder . Decode ( token ) , keys , now , identityScope , 4 , domainOrAppName , clientType ) ;
5454 }
5555
5656 return DecryptionResponse . MakeError ( DecryptionStatus . VersionNotSupported ) ;
5757 }
5858
59- private static DecryptionResponse DecryptV2 ( byte [ ] encryptedId , KeyContainer keys , DateTime now , string domainName , ClientType clientType )
59+ private static DecryptionResponse DecryptV2 ( byte [ ] encryptedId , KeyContainer keys , DateTime now , string domainOrAppName , ClientType clientType )
6060 {
6161 if ( encryptedId . Length != TOKEN_V2_LENGTH )
6262 {
@@ -118,9 +118,9 @@ private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer key
118118 return new DecryptionResponse ( DecryptionStatus . UserOptedOut , null , established , siteId , siteKey . SiteId , null , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
119119 }
120120
121- if ( ! IsDomainNameAllowedForSite ( clientType , privacyBits , siteId , domainName , keys ) )
121+ if ( ! IsDomainOrAppNameAllowedForSite ( clientType , privacyBits , siteId , domainOrAppName , keys ) )
122122 {
123- return new DecryptionResponse ( DecryptionStatus . DomainNameCheckFailed , null , established , siteId , siteKey . SiteId , null , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
123+ return new DecryptionResponse ( DecryptionStatus . DomainOrAppNameCheckFailed , null , established , siteId , siteKey . SiteId , null , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
124124 }
125125
126126 if ( ! DoesTokenHaveValidLifetime ( clientType , keys , now , expiry , now ) )
@@ -129,7 +129,7 @@ private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer key
129129 return new DecryptionResponse ( DecryptionStatus . Success , idString , established , siteId , siteKey . SiteId , null , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
130130 }
131131
132- private static DecryptionResponse DecryptV3 ( byte [ ] encryptedId , KeyContainer keys , DateTime now , IdentityScope identityScope , int advertisingTokenVersion , string domainName , ClientType clientType )
132+ private static DecryptionResponse DecryptV3 ( byte [ ] encryptedId , KeyContainer keys , DateTime now , IdentityScope identityScope , int advertisingTokenVersion , string domainOrAppName , ClientType clientType )
133133 {
134134 if ( encryptedId . Length < TOKEN_V3_MIN_LENGTH )
135135 {
@@ -203,9 +203,9 @@ private static DecryptionResponse DecryptV3(byte[] encryptedId, KeyContainer key
203203 return new DecryptionResponse ( DecryptionStatus . UserOptedOut , null , established , siteId , siteKey . SiteId , identityType , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
204204 }
205205
206- if ( ! IsDomainNameAllowedForSite ( clientType , privacyBits , siteId , domainName , keys ) )
206+ if ( ! IsDomainOrAppNameAllowedForSite ( clientType , privacyBits , siteId , domainOrAppName , keys ) )
207207 {
208- return new DecryptionResponse ( DecryptionStatus . DomainNameCheckFailed , null , established , siteId , siteKey . SiteId , identityType , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
208+ return new DecryptionResponse ( DecryptionStatus . DomainOrAppNameCheckFailed , null , established , siteId , siteKey . SiteId , identityType , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
209209 }
210210
211211 if ( ! DoesTokenHaveValidLifetime ( clientType , keys , generated , expiry , now ) )
@@ -242,15 +242,15 @@ private static bool DoesTokenHaveValidLifetimeImpl(DateTime generatedOrNow, Date
242242 return ( generatedOrNow - now ) . TotalSeconds <= allowClockSkewSeconds ; //returns false if token generated too far in the future
243243 }
244244
245- private static bool IsDomainNameAllowedForSite ( ClientType clientType , PrivacyBits privacyBits , int siteId , string domainName , KeyContainer keys )
245+ private static bool IsDomainOrAppNameAllowedForSite ( ClientType clientType , PrivacyBits privacyBits , int siteId , string domainOrAppName , KeyContainer keys )
246246 {
247247 if ( ! privacyBits . IsClientSideGenerated )
248248 return true ;
249249
250- if ( clientType != ClientType . Bidstream && clientType != ClientType . LegacyWithDomainCheck )
250+ if ( clientType != ClientType . Bidstream && clientType != ClientType . LegacyWithDomainOrAppNameCheck )
251251 return true ;
252252
253- return keys . IsDomainNameAllowedForSite ( siteId , domainName ) ;
253+ return keys . IsDomainOrAppNameAllowedForSite ( siteId , domainOrAppName ) ;
254254 }
255255
256256 internal static EncryptionDataResponse Encrypt ( string rawUid , KeyContainer keys , IdentityScope identityScope , DateTime now )
@@ -327,8 +327,8 @@ internal static EncryptionDataResponse EncryptData(EncryptionDataRequest request
327327 {
328328 try
329329 {
330- // if the enableDomainNameCheck param is enabled , the caller would have to provide siteId as part of the EncryptionDataRequest.
331- DecryptionResponse decryptedToken = Decrypt ( request . AdvertisingToken , keys , now , domainName : null , identityScope , ClientType . LegacyWithoutDomainCheck ) ;
330+ // if the enableDomainOrAppNameCheck param is enabled , the caller would have to provide siteId as part of the EncryptionDataRequest.
331+ DecryptionResponse decryptedToken = Decrypt ( request . AdvertisingToken , keys , now , domainOrAppName : null , identityScope , ClientType . LegacyWithoutDomainOrAppNameCheck ) ;
332332 if ( ! decryptedToken . Success )
333333 {
334334 return EncryptionDataResponse . MakeError ( EncryptionStatus . TokenDecryptFailure ) ;
0 commit comments