Skip to content

Commit 53afafa

Browse files
committed
Update gcenter.js
1 parent c411c48 commit 53afafa

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/Adapters/Auth/gcenter.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ async function getAppleCertificate(publicKeyUrl) {
5656
const cert_headers = await new Promise((resolve, reject) =>
5757
https.get(headOptions, res => resolve(res.headers)).on('error', reject)
5858
);
59+
const validContentTypes = ['application/x-x509-ca-cert', 'application/pkix-cert'];
5960
if (
60-
cert_headers['content-type'] !== 'application/pkix-cert' ||
61+
!validContentTypes.includes(cert_headers['content-type']) ||
6162
cert_headers['content-length'] == null ||
6263
cert_headers['content-length'] > 10000
6364
) {
@@ -66,7 +67,7 @@ async function getAppleCertificate(publicKeyUrl) {
6667
`Apple Game Center - invalid publicKeyUrl: ${publicKeyUrl}`
6768
);
6869
}
69-
const {certificate, headers} = await getCertificate(publicKeyUrl);
70+
const { certificate, headers } = await getCertificate(publicKeyUrl);
7071
if (headers['cache-control']) {
7172
const expire = headers['cache-control'].match(/max-age=([0-9]+)/);
7273
if (expire) {
@@ -90,15 +91,15 @@ function getCertificate(url, buffer) {
9091
});
9192
res.on('end', () => {
9293
if (buffer) {
93-
resolve({certificate: Buffer.concat(data), headers: res.headers});
94+
resolve({ certificate: Buffer.concat(data), headers: res.headers });
9495
return;
9596
}
9697
let cert = '';
9798
for (const chunk of data) {
9899
cert += chunk.toString('base64');
99100
}
100101
const certificate = convertX509CertToPEM(cert);
101-
resolve({certificate, headers: res.headers});
102+
resolve({ certificate, headers: res.headers });
102103
});
103104
})
104105
.on('error', reject);
@@ -132,7 +133,10 @@ function verifySignature(publicKey, authData) {
132133
function verifyPublicKeyIssuer(cert, publicKeyUrl) {
133134
const publicKeyCert = pki.certificateFromPem(cert);
134135
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+
);
136140
}
137141
try {
138142
if (!ca.cert.verify(publicKeyCert)) {
@@ -163,21 +167,25 @@ async function validateAuthData(authData) {
163167
// Returns a promise that fulfills if this app id is valid.
164168
async function validateAppId(appIds, authData, options = {}) {
165169
if (!options.rootCertificateUrl) {
166-
options.rootCertificateUrl = 'https://cacerts.digicert.com/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem'
170+
options.rootCertificateUrl =
171+
'https://cacerts.digicert.com/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem';
167172
}
168173
if (ca.url === options.rootCertificateUrl) {
169174
return;
170175
}
171-
const {certificate, headers} = await getCertificate(options.rootCertificateUrl, true);
176+
const { certificate, headers } = await getCertificate(options.rootCertificateUrl, true);
172177
if (
173178
headers['content-type'] !== 'application/x-pem-file' ||
174179
headers['content-length'] == null ||
175180
headers['content-length'] > 10000
176181
) {
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+
);
178186
}
179187
ca.cert = pki.certificateFromPem(certificate);
180-
ca.url = options.rootCertificateUrl
188+
ca.url = options.rootCertificateUrl;
181189
}
182190

183191
module.exports = {

0 commit comments

Comments
 (0)