@@ -56,8 +56,9 @@ async function getAppleCertificate(publicKeyUrl) {
56
56
const cert_headers = await new Promise ( ( resolve , reject ) =>
57
57
https . get ( headOptions , res => resolve ( res . headers ) ) . on ( 'error' , reject )
58
58
) ;
59
+ const validContentTypes = [ 'application/x-x509-ca-cert' , 'application/pkix-cert' ] ;
59
60
if (
60
- cert_headers [ 'content-type' ] !== 'application/pkix-cert' ||
61
+ ! validContentTypes . includes ( cert_headers [ 'content-type' ] ) ||
61
62
cert_headers [ 'content-length' ] == null ||
62
63
cert_headers [ 'content-length' ] > 10000
63
64
) {
@@ -66,7 +67,7 @@ async function getAppleCertificate(publicKeyUrl) {
66
67
`Apple Game Center - invalid publicKeyUrl: ${ publicKeyUrl } `
67
68
) ;
68
69
}
69
- const { certificate, headers} = await getCertificate ( publicKeyUrl ) ;
70
+ const { certificate, headers } = await getCertificate ( publicKeyUrl ) ;
70
71
if ( headers [ 'cache-control' ] ) {
71
72
const expire = headers [ 'cache-control' ] . match ( / m a x - a g e = ( [ 0 - 9 ] + ) / ) ;
72
73
if ( expire ) {
@@ -90,15 +91,15 @@ function getCertificate(url, buffer) {
90
91
} ) ;
91
92
res . on ( 'end' , ( ) => {
92
93
if ( buffer ) {
93
- resolve ( { certificate : Buffer . concat ( data ) , headers : res . headers } ) ;
94
+ resolve ( { certificate : Buffer . concat ( data ) , headers : res . headers } ) ;
94
95
return ;
95
96
}
96
97
let cert = '' ;
97
98
for ( const chunk of data ) {
98
99
cert += chunk . toString ( 'base64' ) ;
99
100
}
100
101
const certificate = convertX509CertToPEM ( cert ) ;
101
- resolve ( { certificate, headers : res . headers } ) ;
102
+ resolve ( { certificate, headers : res . headers } ) ;
102
103
} ) ;
103
104
} )
104
105
. on ( 'error' , reject ) ;
@@ -132,7 +133,10 @@ function verifySignature(publicKey, authData) {
132
133
function verifyPublicKeyIssuer ( cert , publicKeyUrl ) {
133
134
const publicKeyCert = pki . certificateFromPem ( cert ) ;
134
135
if ( ! ca . cert ) {
135
- throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , 'Apple Game Center auth adapter parameter `rootCertificateURL` is invalid.' ) ;
136
+ throw new Parse . Error (
137
+ Parse . Error . OBJECT_NOT_FOUND ,
138
+ 'Apple Game Center auth adapter parameter `rootCertificateURL` is invalid.'
139
+ ) ;
136
140
}
137
141
try {
138
142
if ( ! ca . cert . verify ( publicKeyCert ) ) {
@@ -163,21 +167,25 @@ async function validateAuthData(authData) {
163
167
// Returns a promise that fulfills if this app id is valid.
164
168
async function validateAppId ( appIds , authData , options = { } ) {
165
169
if ( ! options . rootCertificateUrl ) {
166
- options . rootCertificateUrl = 'https://cacerts.digicert.com/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem'
170
+ options . rootCertificateUrl =
171
+ 'https://cacerts.digicert.com/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem' ;
167
172
}
168
173
if ( ca . url === options . rootCertificateUrl ) {
169
174
return ;
170
175
}
171
- const { certificate, headers} = await getCertificate ( options . rootCertificateUrl , true ) ;
176
+ const { certificate, headers } = await getCertificate ( options . rootCertificateUrl , true ) ;
172
177
if (
173
178
headers [ 'content-type' ] !== 'application/x-pem-file' ||
174
179
headers [ 'content-length' ] == null ||
175
180
headers [ 'content-length' ] > 10000
176
181
) {
177
- throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , 'Apple Game Center auth adapter parameter `rootCertificateURL` is invalid.' ) ;
182
+ throw new Parse . Error (
183
+ Parse . Error . OBJECT_NOT_FOUND ,
184
+ 'Apple Game Center auth adapter parameter `rootCertificateURL` is invalid.'
185
+ ) ;
178
186
}
179
187
ca . cert = pki . certificateFromPem ( certificate ) ;
180
- ca . url = options . rootCertificateUrl
188
+ ca . url = options . rootCertificateUrl ;
181
189
}
182
190
183
191
module . exports = {
0 commit comments