@@ -13,8 +13,8 @@ internal enum ClientType
13
13
{
14
14
Sharing ,
15
15
Bidstream ,
16
- LegacyWithoutDomainCheck ,
17
- LegacyWithDomainCheck
16
+ LegacyWithoutDomainOrAppNameCheck ,
17
+ LegacyWithDomainOrAppNameCheck
18
18
}
19
19
20
20
internal static class UID2Encryption
@@ -26,7 +26,7 @@ internal static class UID2Encryption
26
26
private static char [ ] BASE64_URL_SPECIAL_CHARS = { '-' , '_' } ;
27
27
28
28
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 )
30
30
{
31
31
if ( token . Length < 4 )
32
32
{
@@ -39,24 +39,24 @@ internal static DecryptionResponse Decrypt(string token, KeyContainer keys, Date
39
39
40
40
if ( data [ 0 ] == 2 )
41
41
{
42
- return DecryptV2 ( Convert . FromBase64String ( token ) , keys , now , domainName , clientType ) ;
42
+ return DecryptV2 ( Convert . FromBase64String ( token ) , keys , now , domainOrAppName , clientType ) ;
43
43
}
44
44
45
45
if ( data [ 1 ] == ( int ) AdvertisingTokenVersion . V3 )
46
46
{
47
- return DecryptV3 ( Convert . FromBase64String ( token ) , keys , now , identityScope , 3 , domainName , clientType ) ;
47
+ return DecryptV3 ( Convert . FromBase64String ( token ) , keys , now , identityScope , 3 , domainOrAppName , clientType ) ;
48
48
}
49
49
50
50
if ( data [ 1 ] == ( int ) AdvertisingTokenVersion . V4 )
51
51
{
52
52
//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 ) ;
54
54
}
55
55
56
56
return DecryptionResponse . MakeError ( DecryptionStatus . VersionNotSupported ) ;
57
57
}
58
58
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 )
60
60
{
61
61
if ( encryptedId . Length != TOKEN_V2_LENGTH )
62
62
{
@@ -118,9 +118,9 @@ private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer key
118
118
return new DecryptionResponse ( DecryptionStatus . UserOptedOut , null , established , siteId , siteKey . SiteId , null , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
119
119
}
120
120
121
- if ( ! IsDomainNameAllowedForSite ( clientType , privacyBits , siteId , domainName , keys ) )
121
+ if ( ! IsDomainOrAppNameAllowedForSite ( clientType , privacyBits , siteId , domainOrAppName , keys ) )
122
122
{
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 ) ;
124
124
}
125
125
126
126
if ( ! DoesTokenHaveValidLifetime ( clientType , keys , now , expiry , now ) )
@@ -129,7 +129,7 @@ private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer key
129
129
return new DecryptionResponse ( DecryptionStatus . Success , idString , established , siteId , siteKey . SiteId , null , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
130
130
}
131
131
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 )
133
133
{
134
134
if ( encryptedId . Length < TOKEN_V3_MIN_LENGTH )
135
135
{
@@ -203,9 +203,9 @@ private static DecryptionResponse DecryptV3(byte[] encryptedId, KeyContainer key
203
203
return new DecryptionResponse ( DecryptionStatus . UserOptedOut , null , established , siteId , siteKey . SiteId , identityType , advertisingTokenVersion , privacyBits . IsClientSideGenerated , expiry ) ;
204
204
}
205
205
206
- if ( ! IsDomainNameAllowedForSite ( clientType , privacyBits , siteId , domainName , keys ) )
206
+ if ( ! IsDomainOrAppNameAllowedForSite ( clientType , privacyBits , siteId , domainOrAppName , keys ) )
207
207
{
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 ) ;
209
209
}
210
210
211
211
if ( ! DoesTokenHaveValidLifetime ( clientType , keys , generated , expiry , now ) )
@@ -242,15 +242,15 @@ private static bool DoesTokenHaveValidLifetimeImpl(DateTime generatedOrNow, Date
242
242
return ( generatedOrNow - now ) . TotalSeconds <= allowClockSkewSeconds ; //returns false if token generated too far in the future
243
243
}
244
244
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 )
246
246
{
247
247
if ( ! privacyBits . IsClientSideGenerated )
248
248
return true ;
249
249
250
- if ( clientType != ClientType . Bidstream && clientType != ClientType . LegacyWithDomainCheck )
250
+ if ( clientType != ClientType . Bidstream && clientType != ClientType . LegacyWithDomainOrAppNameCheck )
251
251
return true ;
252
252
253
- return keys . IsDomainNameAllowedForSite ( siteId , domainName ) ;
253
+ return keys . IsDomainOrAppNameAllowedForSite ( siteId , domainOrAppName ) ;
254
254
}
255
255
256
256
internal static EncryptionDataResponse Encrypt ( string rawUid , KeyContainer keys , IdentityScope identityScope , DateTime now )
@@ -327,8 +327,8 @@ internal static EncryptionDataResponse EncryptData(EncryptionDataRequest request
327
327
{
328
328
try
329
329
{
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 ) ;
332
332
if ( ! decryptedToken . Success )
333
333
{
334
334
return EncryptionDataResponse . MakeError ( EncryptionStatus . TokenDecryptFailure ) ;
0 commit comments