diff --git a/jwt_verification.ts b/jwt_verification.ts index 1d94329..e2ce194 100644 --- a/jwt_verification.ts +++ b/jwt_verification.ts @@ -85,7 +85,12 @@ export class SignedDataVerifier { * @throws VerificationException Thrown if the data could not be verified */ async verifyAndDecodeRenewalInfo(signedRenewalInfo: string): Promise { - return this.verifyJWT(signedRenewalInfo, this.JWSRenewalInfoDecodedPayloadValidator, this.extractSignedDate); + const decodedRenewalInfo: JWSRenewalInfoDecodedPayload = await this.verifyJWT(signedRenewalInfo, this.JWSRenewalInfoDecodedPayloadValidator, this.extractSignedDate); + const environment = decodedRenewalInfo.environment + if (this.environment !== environment) { + throw new VerificationException(VerificationStatus.INVALID_ENVIRONMENT) + } + return decodedRenewalInfo } /** @@ -100,7 +105,7 @@ export class SignedDataVerifier { const appAppleId = decodedJWT.data ? decodedJWT.data.appAppleId : (decodedJWT.summary ? decodedJWT.summary.appAppleId : null) const bundleId = decodedJWT.data ? decodedJWT.data.bundleId : (decodedJWT.summary ? decodedJWT.summary.bundleId : null) const environment = decodedJWT.data ? decodedJWT.data.environment : (decodedJWT.summary ? decodedJWT.summary.environment : null) - if (this.bundleId !== bundleId || (this.environment === "Production" && this.appAppleId !== appAppleId)) { + if (this.bundleId !== bundleId || (this.environment === Environment.PRODUCTION && this.appAppleId !== appAppleId)) { throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER) } if (this.environment !== environment) { @@ -118,7 +123,7 @@ export class SignedDataVerifier { async verifyAndDecodeAppTransaction(signedAppTransaction: string): Promise { const decodedAppTransaction: AppTransaction = await this.verifyJWT(signedAppTransaction, this.appTransactionValidator, t => t.receiptCreationDate === undefined ? new Date() : new Date(t.receiptCreationDate)); const environment = decodedAppTransaction.receiptType - if (this.bundleId !== decodedAppTransaction.bundleId || (this.environment === "Production" && this.appAppleId !== decodedAppTransaction.appAppleId)) { + if (this.bundleId !== decodedAppTransaction.bundleId || (this.environment === Environment.PRODUCTION && this.appAppleId !== decodedAppTransaction.appAppleId)) { throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER) } if (this.environment !== environment) { @@ -129,27 +134,33 @@ export class SignedDataVerifier { protected async verifyJWT(jwt: string, validator: Validator, signedDateExtractor: (decodedJWT: T) => Date): Promise { let certificateChain; + let decodedJWT try { - const header = jwt.split('.')[0] - const decodedHeader = base64url.decode(header) - const headerObj = JSON.parse(decodedHeader) - const chain: string[] = headerObj['x5c'] ?? [] - if (chain.length != 3) { - throw new VerificationException(VerificationStatus.INVALID_CHAIN_LENGTH) - } - certificateChain = chain.slice(0, 2).map(cert => new X509Certificate(Buffer.from(cert, 'base64'))) - } catch (error) { - if (error instanceof Error) { - throw new VerificationException(VerificationStatus.INVALID_CERTIFICATE, error) - } - throw new VerificationException(VerificationStatus.INVALID_CERTIFICATE) - } - try { - const decodedJWT = jsonwebtoken.decode(jwt) + decodedJWT = jsonwebtoken.decode(jwt) if (!validator.validate(decodedJWT)) { throw new VerificationException(VerificationStatus.FAILURE) } - const effectiveDate = this.enableOnlineChecks ? new Date() : signedDateExtractor(decodedJWT) + if (this.environment === Environment.XCODE || this.environment === Environment.LOCAL_TESTING) { + // Data is not signed by the App Store, and verification should be skipped + // The environment MUST be checked in the public method calling this + return decodedJWT + } + try { + const header = jwt.split('.')[0] + const decodedHeader = base64url.decode(header) + const headerObj = JSON.parse(decodedHeader) + const chain: string[] = headerObj['x5c'] ?? [] + if (chain.length != 3) { + throw new VerificationException(VerificationStatus.INVALID_CHAIN_LENGTH) + } + certificateChain = chain.slice(0, 2).map(cert => new X509Certificate(Buffer.from(cert, 'base64'))) + } catch (error) { + if (error instanceof Error) { + throw new VerificationException(VerificationStatus.INVALID_CERTIFICATE, error) + } + throw new VerificationException(VerificationStatus.INVALID_CERTIFICATE) + } + const effectiveDate = this.enableOnlineChecks ? new Date() : signedDateExtractor(decodedJWT) const publicKey = await this.verifyCertificateChain(this.rootCertificates, certificateChain[0], certificateChain[1], effectiveDate); const encodedKey = publicKey.export({ type: "spki", diff --git a/models/Environment.ts b/models/Environment.ts index 8f943b0..9be7b41 100644 --- a/models/Environment.ts +++ b/models/Environment.ts @@ -10,6 +10,8 @@ import { Validator } from "./Validator"; export enum Environment { SANDBOX = "Sandbox", PRODUCTION = "Production", + XCODE = "Xcode", + LOCAL_TESTING = "LocalTesting", } export class EnvironmentValidator implements Validator { diff --git a/receipt_utility.ts b/receipt_utility.ts index 019d46b..f9ac867 100644 --- a/receipt_utility.ts +++ b/receipt_utility.ts @@ -15,26 +15,57 @@ export class ReceiptUtility { * @returns A transaction id from the array of in-app purchases, null if the receipt contains no in-app purchases */ extractTransactionIdFromAppReceipt(appReceipt: string): string | null { - const receiptInfo = ASN1HEX.getVbyList(Buffer.from(appReceipt, 'base64').toString('hex'), 0, [1, 0, 2, 1, 0]) as string - let index = 0; - while(ASN1HEX.getVbyList(receiptInfo, 0, [index, 0])) { - const val = ASN1HEX.getVbyList(receiptInfo, 0, [index, 0]) as string - if (IN_APP_TYPE_ID === parseInt(val, 16)) { - const inAppInfo = ASN1HEX.getVbyList(receiptInfo, 0, [index, 2]) as string - let inAppIndex = 0; - while(ASN1HEX.getVbyList(inAppInfo, 0, [inAppIndex, 0])) { - const val = ASN1HEX.getVbyList(inAppInfo, 0, [inAppIndex, 0]) as string - if (TRANSACTION_IDENTIFIER_TYPE_ID === parseInt(val, 16) || ORIGINAL_TRANSACTION_IDENTIFIER_TYPE_ID === parseInt(val, 16)) { - const transactionIdUTF8String = ASN1HEX.getVbyList(inAppInfo, 0, [inAppIndex, 2]) as string - const transactionId = ASN1HEX.getVbyList(transactionIdUTF8String, 0, []) as string - return Buffer.from(transactionId, 'hex').toString() + // Xcode receipts use indefinite length encoding, not supported by all parsers + // Indefinite length encoding is only entered, but never left during parsing for receipts + // We therefore round up indefinite length encoding to be the remaining length + const prevGetVblenFunction = ASN1HEX.getVblen + ASN1HEX.getVblen = function(s, idx) { + const c = ASN1HEX.getL(s, idx) + const oldResult = prevGetVblenFunction(s, idx) + // Round up to the remaining length in the string, measured in bytes (2 hex values per byte) + if (oldResult === 0 && c === '80') { + return (s.length - idx) / 2 + } + return oldResult + } + const prevGetLblen = ASN1HEX.getLblen + ASN1HEX.getLblen = function(s, idx) { + const oldResult = prevGetLblen(s, idx) + // The length for the length byte for 80 00 is 1 + if (oldResult == -1) { + return 1 + } + return oldResult + } + try { + let receiptInfo = ASN1HEX.getVbyList(Buffer.from(appReceipt, 'base64').toString('hex'), 0, [1, 0, 2, 1, 0]) as string + if (receiptInfo.length > 2 && receiptInfo.startsWith('04')) { + // We are still in an Octet String, Xcode wraps with an extra Octet, decode it here + receiptInfo = ASN1HEX.getV(receiptInfo, 0) + } + let index = 0; + while(ASN1HEX.getVbyList(receiptInfo, 0, [index, 0])) { + const val = ASN1HEX.getVbyList(receiptInfo, 0, [index, 0]) as string + if (IN_APP_TYPE_ID === parseInt(val, 16)) { + const inAppInfo = ASN1HEX.getVbyList(receiptInfo, 0, [index, 2]) as string + let inAppIndex = 0; + while(ASN1HEX.getVbyList(inAppInfo, 0, [inAppIndex, 0])) { + const val = ASN1HEX.getVbyList(inAppInfo, 0, [inAppIndex, 0]) as string + if (TRANSACTION_IDENTIFIER_TYPE_ID === parseInt(val, 16) || ORIGINAL_TRANSACTION_IDENTIFIER_TYPE_ID === parseInt(val, 16)) { + const transactionIdUTF8String = ASN1HEX.getVbyList(inAppInfo, 0, [inAppIndex, 2]) as string + const transactionId = ASN1HEX.getVbyList(transactionIdUTF8String, 0, []) as string + return Buffer.from(transactionId, 'hex').toString() + } + inAppIndex = inAppIndex + 1 } - inAppIndex = inAppIndex + 1 } + index = index + 1 } - index = index + 1 + return null + } finally { + ASN1HEX.getLblen = prevGetLblen + ASN1HEX.getVblen = prevGetVblenFunction } - return null } /** diff --git a/tests/resources/certs/testCA.der b/tests/resources/certs/testCA.der new file mode 100644 index 0000000..54a42b6 Binary files /dev/null and b/tests/resources/certs/testCA.der differ diff --git a/tests/resources/certs/testSigningKey.p8 b/tests/resources/certs/testSigningKey.p8 new file mode 100644 index 0000000..0622800 --- /dev/null +++ b/tests/resources/certs/testSigningKey.p8 @@ -0,0 +1,5 @@ +-----BEGIN PRIVATE KEY----- +MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgSpP55ELdXswj9JRZ +APRwtTfS4CNRqpKIs+28rNHiPAqhRANCAASs8nLES7b+goKslppNVOurf0MonZdw +3pb6TxS8Z/5j+UNY1sWK1ChxpuwNS9I3R50cfdQo/lA9PPhw6XIg8ytd +-----END PRIVATE KEY----- diff --git a/tests/resources/mock_signed_data/legacyTransaction b/tests/resources/mock_signed_data/legacyTransaction new file mode 100644 index 0000000..534391d --- /dev/null +++ b/tests/resources/mock_signed_data/legacyTransaction @@ -0,0 +1 @@ +ewoicHVyY2hhc2UtaW5mbyIgPSAiZXdvaWRISmhibk5oWTNScGIyNHRhV1FpSUQwZ0lqTXpPVGt6TXprNUlqc0tmUW89IjsKfQo= \ No newline at end of file diff --git a/tests/resources/mock_signed_data/missingX5CHeaderClaim b/tests/resources/mock_signed_data/missingX5CHeaderClaim new file mode 100644 index 0000000..b4112b4 --- /dev/null +++ b/tests/resources/mock_signed_data/missingX5CHeaderClaim @@ -0,0 +1 @@ +eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsIng1Y3dyb25nIjpbIk1JSUJvRENDQVVhZ0F3SUJBZ0lCRERBS0JnZ3Foa2pPUFFRREF6QkZNUXN3Q1FZRFZRUUdFd0pWVXpFTE1Ba0dBMVVFQ0F3Q1EwRXhFakFRQmdOVkJBY01DVU4xY0dWeWRHbHViekVWTUJNR0ExVUVDZ3dNU1c1MFpYSnRaV1JwWVhSbE1CNFhEVEl6TURFd05USXhNekV6TkZvWERUTXpNREV3TVRJeE16RXpORm93UFRFTE1Ba0dBMVVFQmhNQ1ZWTXhDekFKQmdOVkJBZ01Ba05CTVJJd0VBWURWUVFIREFsRGRYQmxjblJwYm04eERUQUxCZ05WQkFvTUJFeGxZV1l3V1RBVEJnY3Foa2pPUFFJQk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mock_signed_data/renewalInfo b/tests/resources/mock_signed_data/renewalInfo new file mode 100644 index 0000000..d14a20d --- /dev/null +++ b/tests/resources/mock_signed_data/renewalInfo @@ -0,0 +1 @@ +eyJ4NWMiOlsiTUlJQm9EQ0NBVWFnQXdJQkFnSUJEREFLQmdncWhrak9QUVFEQXpCRk1Rc3dDUVlEVlFRR0V3SlZVekVMTUFrR0ExVUVDQXdDUTBFeEVqQVFCZ05WQkFjTUNVTjFjR1Z5ZEdsdWJ6RVZNQk1HQTFVRUNnd01TVzUwWlhKdFpXUnBZWFJsTUI0WERUSXpNREV3TlRJeE16RXpORm9YRFRNek1ERXdNVEl4TXpFek5Gb3dQVEVMTUFrR0ExVUVCaE1DVlZNeEN6QUpCZ05WQkFnTUFrTkJNUkl3RUFZRFZRUUhEQWxEZFhCbGNuUnBibTh4RFRBTEJnTlZCQW9NQkV4bFlXWXdXVEFUQmdjcWhrak9QUUlCQmdncWhrak9QUU1CQndOQ0FBVGl0WUhFYVlWdWM4ZzlBalRPd0VyTXZHeVB5a1BhK3B1dlRJOGhKVEhaWkRMR2FzMnFYMStFcnhnUVRKZ1ZYdjc2bm1MaGhSSkgrajI1QWlBSThpR3NveTh3TFRBSkJnTlZIUk1FQWpBQU1BNEdBMVVkRHdFQi93UUVBd0lIZ0RBUUJnb3Foa2lHOTJOa0Jnc0JCQUlGQURBS0JnZ3Foa2pPUFFRREF3TklBREJGQWlCWDRjK1QwRnA1bko1UVJDbFJmdTVQU0J5UnZOUHR1YVRzazB2UEIzV0FJQUloQU5nYWF1QWovWVA5czBBa0VoeUpoeFFPLzZRMnpvdVorSDFDSU9laG5NelEiLCJNSUlCbnpDQ0FVV2dBd0lCQWdJQkN6QUtCZ2dxaGtqT1BRUURBekEyTVFzd0NRWURWUVFHRXdKVlV6RVRNQkVHQTFVRUNBd0tRMkZzYVdadmNtNXBZVEVTTUJBR0ExVUVCd3dKUTNWd1pYSjBhVzV2TUI0WERUSXpNREV3TlRJeE16RXdOVm9YRFR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jR3REFZRFZSMFRCQVV3QXdFQi96QU9CZ05WSFE4QkFmOEVCQU1DQVFZd0NnWUlLb1pJemowRUF3TURSd0F3UkFJZ2VtV1FYbk1BZFRhZDJKREpXbmc5VTR1QkJMNW1BN1dJMDVIN29IN2M2aVFDSUhpUnFNak5melVBeWl1OWg2ck9VL0sraVRSMEkvM1kvTlNXc1hIWCthY2MiXSwidHlwIjoiSldUIiwiYWxnIjoiRVMyNTYifQ.eyJlbnZpcm9ubWVudCI6IlNhbmRib3giLCJzaWduZWREYXRlIjoxNjcyOTU2MTU0MDAwfQ.FbK2OL-t6l4892W7fzWyus_g9mIl2CzWLbVt7Kgcnt6zzVulF8bzovgpe0v_y490blROGixy8KDoe2dSU53-Xw \ No newline at end of file diff --git a/tests/resources/mock_signed_data/testNotification b/tests/resources/mock_signed_data/testNotification new file mode 100644 index 0000000..7bb78cf --- /dev/null +++ b/tests/resources/mock_signed_data/testNotification @@ -0,0 +1 @@ +eyJ4NWMiOlsiTUlJQm9EQ0NBVWFnQXdJQkFnSUJDekFLQmdncWhrak9QUVFEQWpCTk1Rc3dDUVlEVlFRR0V3SlZVekVUTUJFR0ExVUVDQXdLUTJGc2FXWnZjbTVwWVRFU01CQUdBMVVFQnd3SlEzVndaWEowYVc1dk1SVXdFd1lEVlFRS0RBeEpiblJsY20xbFpHbGhkR1V3SGhjTk1qTXdNVEEwTVRZek56TXhXaGNOTXpJeE1qTXhNVFl6TnpNeFdqQkZNUXN3Q1FZRFZRUUdFd0pWVXpFVE1CRUdBMVVFQ0F3S1EyRnNhV1p2Y201cFlURVNNQkFHQTFVRUJ3d0pRM1Z3WlhKMGFXNXZNUTB3Q3dZRFZRUUtEQVJNWldGbU1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRTRyV0J4R21GYm5QSVBRSTB6c0JLekx4c2o4cEQydnFicjB5UElTVXgyV1F5eG1yTnFsOWZoSzhZRUV5WUZWNysrcDVpNFlVU1Ivbzl1UUlnQ1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UNBd0tRMkZzYVdadmNtNXBZVEVTTUJBR0ExVUVCd3dKUTNWd1pYSjBhVzV2TUI0WERUSXpNREV3TkRFMk1qQXpNbG9YRFRNek1ERXdNVEUyTWpBek1sb3dOakVMTUFrR0ExVUVCaE1DVlZNeEV6QVJCZ05WQkFnTUNrTmhiR2xtYjNKdWFXRXhFakFRQmdOVkJBY01DVU4xY0dWeWRHbHViekJaTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEEwSUFCSFB2d1pmb0tMS2FPclgvV2U0cU9iWFNuYTVUZFdIVlo2aElSQTF3MG9jM1FDVDBJbzJwbHlEQjMvTVZsazJ0YzRLR0U4VGlxVzdpYlE2WmM5VjY0azB3Q2dZSUtvWkl6ajBFQXdNRFNBQXdSUUloQU1USGhXdGJBUU4waFN4SVhjUDRDS3JEQ0gvZ3N4V3B4NmpUWkxUZVorRlBBaUIzNW53azVxMHpjSXBlZnZZSjBNVS95R0dIU1dlejBicTBwRFlVTy9ubUR3PT0iXSwidHlwIjoiSldUIiwiYWxnIjoiRVMyNTYifQ.eyJkYXRhIjp7ImFwcEFwcGxlSWQiOjEyMzQsImVudmlyb25tZW50IjoiU2FuZGJveCIsImJ1bmRsZUlkIjoiY29tLmV4YW1wbGUifSwibm90aWZpY2F0aW9uVVVJRCI6IjlhZDU2YmQyLTBiYzYtNDJlMC1hZjI0LWZkOTk2ZDg3YTFlNiIsInNpZ25lZERhdGUiOjE2ODEzMTQzMjQwMDAsIm5vdGlmaWNhdGlvblR5cGUiOiJURVNUIn0.VVXYwuNm2Y3XsOUva-BozqatRCsDuykA7xIe_CCRw6aIAAxJ1nb2sw871jfZ6dcgNhUuhoZ93hfbc1v_5zB7Og \ No newline at end of file diff --git a/tests/resources/mock_signed_data/transactionInfo b/tests/resources/mock_signed_data/transactionInfo new file mode 100644 index 0000000..3ddf0b0 --- /dev/null +++ b/tests/resources/mock_signed_data/transactionInfo @@ -0,0 +1 @@ +eyJ4NWMiOlsiTUlJQm9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T0iXSwidHlwIjoiSldUIiwiYWxnIjoiRVMyNTYifQ.eyJlbnZpcm9ubWVudCI6IlNhbmRib3giLCJidW5kbGVJZCI6ImNvbS5leGFtcGxlIiwic2lnbmVkRGF0ZSI6MTY3Mjk1NjE1NDAwMH0.PnHWpeIJZ8f2Q218NSGLo_aR0IBEJvC6PxmxKXh-qfYTrZccx2suGl223OSNAX78e4Ylf2yJCG2N-FfU-NIhZQ \ No newline at end of file diff --git a/tests/resources/mock_signed_data/wrongBundleId b/tests/resources/mock_signed_data/wrongBundleId new file mode 100644 index 0000000..cc7091e --- /dev/null +++ b/tests/resources/mock_signed_data/wrongBundleId @@ -0,0 +1 @@ +eyJ4NWMiOlsiTUlJQm9EQ0NBVWFnQXdJQkFnSUJEREFLQmdncWhrak9QUVFEQXpCRk1Rc3dDUVlEVlFRR0V3SlZVekVMTUFrR0ExVUVDQXdDUTBFeEVqQVFCZ05WQkFjTUNVTjFjR1Z5ZEdsdWJ6RVZNQk1HQTFVRUNnd01TVzUwWlhKdFpXUnBZWFJsTUI0WERUSXpNREV3TlRJeE16RXpORm9YRFRNek1ERXdNVEl4TXpFek5Gb3dQVEVMTUFrR0ExVUVCaE1DVlZNeEN6QUpCZ05WQkFnTUFrTkJNUkl3RUFZRFZRUUhEQWxEZFhCbGNuUnBibTh4RFRBTEJnTlZCQW9NQkV4bFlXWXdXVEFUQmdjcWhrak9QUUlCQmdncWhrak9QUU1CQndOQ0FBVGl0WUhFYVlWdWM4ZzlBalRPd0VyTXZHeVB5a1BhK3B1dlRJOGhKVEhaWkRMR2FzMnFYMStFcnhnUVRKZ1ZYdjc2bm1MaGhSSkgrajI1QWlBSThpR3NveTh3TFRBSkJnTlZIUk1FQWpBQU1BNEdBMVVkRHdFQi93UUVBd0lIZ0RBUUJnb3Foa2lHOTJOa0Jnc0JCQUlGQURBS0JnZ3Foa2pPUFFRREF3TklBREJGQWlCWDRjK1QwRnA1bko1UVJDbFJmdTVQU0J5UnZOUHR1YVRzazB2U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dDUVlEVlFRR0V3SlZVekVUTUJFR0ExVUVDQXdLUTJGc2FXWnZjbTVwWVRFU01CQUdBMVVFQnd3SlEzVndaWEowYVc1dk1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRWMrL0JsK2dvc3BvNnRmOVo3aW81dGRLZHJsTjFZZFZucUVoRURYRFNoemRBSlBRaWphbVhJTUhmOHhXV1RhMXpnb1lUeE9LcGJ1SnREcGx6MVhyaVRhTWdNQjR3REFZRFZSMFRCQVV3QXdFQi96QU9CZ05WSFE4QkFmOEVCQU1DQVFZd0NnWUlLb1pJemowRUF3TURSd0F3UkFJZ2VtV1FYbk1BZFRhZDJKREpXbmc5VTR1QkJMNW1BN1dJMDVIN29IN2M2aVFDSUhpUnFNak5melVBeWl1OWg2ck9VL0sraVRSMEkvM1kvTlNXc1hIWCthY2MiXSwidHlwIjoiSldUIiwiYWxnIjoiRVMyNTYifQ.eyJkYXRhIjp7ImJ1bmRsZUlkIjoiY29tLmV4YW1wbGUud3JvbmcifSwibm90aWZpY2F0aW9uVVVJRCI6IjlhZDU2YmQyLTBiYzYtNDJlMC1hZjI0LWZkOTk2ZDg3YTFlNiIsIm5vdGlmaWNhdGlvblR5cGUiOiJURVNUIn0.WWE31hTB_mcv2O_lf-xI-MNY3d8txc0MzpqFx4QnYDfFIxB95Lo2Fm3r46YSjLLdL7xCWdEJrJP5bHgRCejAGg \ No newline at end of file diff --git a/tests/resources/models/apiException.json b/tests/resources/models/apiException.json new file mode 100644 index 0000000..a270c53 --- /dev/null +++ b/tests/resources/models/apiException.json @@ -0,0 +1,4 @@ +{ + "errorCode": 5000000, + "errorMessage": "An unknown error occurred." +} \ No newline at end of file diff --git a/tests/resources/models/apiTooManyRequestsException.json b/tests/resources/models/apiTooManyRequestsException.json new file mode 100644 index 0000000..3b3cb9c --- /dev/null +++ b/tests/resources/models/apiTooManyRequestsException.json @@ -0,0 +1,4 @@ +{ + "errorCode": 4290000, + "errorMessage": "Rate limit exceeded." +} \ No newline at end of file diff --git a/tests/resources/models/apiUnknownError.json b/tests/resources/models/apiUnknownError.json new file mode 100644 index 0000000..9377dd7 --- /dev/null +++ b/tests/resources/models/apiUnknownError.json @@ -0,0 +1,4 @@ +{ + "errorCode": 9990000, + "errorMessage": "Testing error." +} \ No newline at end of file diff --git a/tests/resources/models/appTransaction.json b/tests/resources/models/appTransaction.json new file mode 100644 index 0000000..b3b937b --- /dev/null +++ b/tests/resources/models/appTransaction.json @@ -0,0 +1,13 @@ +{ + "receiptType": "LocalTesting", + "appAppleId": 531412, + "bundleId": "com.example", + "applicationVersion": "1.2.3", + "versionExternalIdentifier": 512, + "receiptCreationDate": 1698148900000, + "originalPurchaseDate": 1698148800000, + "originalApplicationVersion": "1.1.2", + "deviceVerification": "device_verification_value", + "deviceVerificationNonce": "48ccfa42-7431-4f22-9908-7e88983e105a", + "preorderDate": 1698148700000 +} \ No newline at end of file diff --git a/tests/resources/models/extendRenewalDateForAllActiveSubscribersResponse.json b/tests/resources/models/extendRenewalDateForAllActiveSubscribersResponse.json new file mode 100644 index 0000000..21fd582 --- /dev/null +++ b/tests/resources/models/extendRenewalDateForAllActiveSubscribersResponse.json @@ -0,0 +1,3 @@ +{ + "requestIdentifier": "758883e8-151b-47b7-abd0-60c4d804c2f5" +} \ No newline at end of file diff --git a/tests/resources/models/extendSubscriptionRenewalDateResponse.json b/tests/resources/models/extendSubscriptionRenewalDateResponse.json new file mode 100644 index 0000000..6c5f89f --- /dev/null +++ b/tests/resources/models/extendSubscriptionRenewalDateResponse.json @@ -0,0 +1,6 @@ +{ + "originalTransactionId": "2312412", + "webOrderLineItemId": "9993", + "success": true, + "effectiveDate": 1698148900000 +} \ No newline at end of file diff --git a/tests/resources/models/getAllSubscriptionStatusesResponse.json b/tests/resources/models/getAllSubscriptionStatusesResponse.json new file mode 100644 index 0000000..b5d139c --- /dev/null +++ b/tests/resources/models/getAllSubscriptionStatusesResponse.json @@ -0,0 +1,35 @@ +{ + "environment": "LocalTesting", + "bundleId": "com.example", + "appAppleId": 5454545, + "data": [ + { + "subscriptionGroupIdentifier": "sub_group_one", + "lastTransactions": [ + { + "status": 1, + "originalTransactionId": "3749183", + "signedTransactionInfo": "signed_transaction_one", + "signedRenewalInfo": "signed_renewal_one" + }, + { + "status": 5, + "originalTransactionId": "5314314134", + "signedTransactionInfo": "signed_transaction_two", + "signedRenewalInfo": "signed_renewal_two" + } + ] + }, + { + "subscriptionGroupIdentifier": "sub_group_two", + "lastTransactions": [ + { + "status": 2, + "originalTransactionId": "3413453", + "signedTransactionInfo": "signed_transaction_three", + "signedRenewalInfo": "signed_renewal_three" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/resources/models/getNotificationHistoryResponse.json b/tests/resources/models/getNotificationHistoryResponse.json new file mode 100644 index 0000000..75c27b7 --- /dev/null +++ b/tests/resources/models/getNotificationHistoryResponse.json @@ -0,0 +1,27 @@ +{ + "paginationToken": "57715481-805a-4283-8499-1c19b5d6b20a", + "hasMore": true, + "notificationHistory": [ + { + "sendAttempts": [ + { + "attemptDate": 1698148900000, + "sendAttemptResult": "NO_RESPONSE" + }, { + "attemptDate": 1698148950000, + "sendAttemptResult": "SUCCESS" + } + ], + "signedPayload": "signed_payload_one" + }, + { + "sendAttempts": [ + { + "attemptDate": 1698148800000, + "sendAttemptResult": "CIRCULAR_REDIRECT" + } + ], + "signedPayload": "signed_payload_two" + } + ] +} \ No newline at end of file diff --git a/tests/resources/models/getRefundHistoryResponse.json b/tests/resources/models/getRefundHistoryResponse.json new file mode 100644 index 0000000..d1ff65a --- /dev/null +++ b/tests/resources/models/getRefundHistoryResponse.json @@ -0,0 +1,8 @@ +{ + "signedTransactions": [ + "signed_transaction_one", + "signed_transaction_two" + ], + "revision": "revision_output", + "hasMore": true +} \ No newline at end of file diff --git a/tests/resources/models/getStatusOfSubscriptionRenewalDateExtensionsResponse.json b/tests/resources/models/getStatusOfSubscriptionRenewalDateExtensionsResponse.json new file mode 100644 index 0000000..9bd7ddc --- /dev/null +++ b/tests/resources/models/getStatusOfSubscriptionRenewalDateExtensionsResponse.json @@ -0,0 +1,7 @@ +{ + "requestIdentifier": "20fba8a0-2b80-4a7d-a17f-85c1854727f8", + "complete": true, + "completeDate": 1698148900000, + "succeededCount": 30, + "failedCount": 2 +} \ No newline at end of file diff --git a/tests/resources/models/getTestNotificationStatusResponse.json b/tests/resources/models/getTestNotificationStatusResponse.json new file mode 100644 index 0000000..9f83b90 --- /dev/null +++ b/tests/resources/models/getTestNotificationStatusResponse.json @@ -0,0 +1,12 @@ +{ + "signedPayload": "signed_payload", + "sendAttempts": [ + { + "attemptDate": 1698148900000, + "sendAttemptResult": "NO_RESPONSE" + }, { + "attemptDate": 1698148950000, + "sendAttemptResult": "SUCCESS" + } + ] +} \ No newline at end of file diff --git a/tests/resources/models/lookupOrderIdResponse.json b/tests/resources/models/lookupOrderIdResponse.json new file mode 100644 index 0000000..09a43d5 --- /dev/null +++ b/tests/resources/models/lookupOrderIdResponse.json @@ -0,0 +1,7 @@ +{ + "status": 1, + "signedTransactions": [ + "signed_transaction_one", + "signed_transaction_two" + ] +} \ No newline at end of file diff --git a/tests/resources/models/requestTestNotificationResponse.json b/tests/resources/models/requestTestNotificationResponse.json new file mode 100644 index 0000000..3ecc9e2 --- /dev/null +++ b/tests/resources/models/requestTestNotificationResponse.json @@ -0,0 +1,3 @@ +{ + "testNotificationToken": "ce3af791-365e-4c60-841b-1674b43c1609" +} \ No newline at end of file diff --git a/tests/resources/models/signedNotification.json b/tests/resources/models/signedNotification.json new file mode 100644 index 0000000..bd473c4 --- /dev/null +++ b/tests/resources/models/signedNotification.json @@ -0,0 +1,16 @@ +{ + "notificationType": "SUBSCRIBED", + "subtype": "INITIAL_BUY", + "notificationUUID": "002e14d5-51f5-4503-b5a8-c3a1af68eb20", + "data": { + "environment": "LocalTesting", + "appAppleId": 41234, + "bundleId": "com.example", + "bundleVersion": "1.2.3", + "signedTransactionInfo": "signed_transaction_info_value", + "signedRenewalInfo": "signed_renewal_info_value", + "status": 1 + }, + "version": "2.0", + "signedDate": 1698148900000 +} \ No newline at end of file diff --git a/tests/resources/models/signedRenewalInfo.json b/tests/resources/models/signedRenewalInfo.json new file mode 100644 index 0000000..17c07a8 --- /dev/null +++ b/tests/resources/models/signedRenewalInfo.json @@ -0,0 +1,16 @@ +{ + "expirationIntent": 1, + "originalTransactionId": "12345", + "autoRenewProductId": "com.example.product.2", + "productId": "com.example.product", + "autoRenewStatus": 1, + "isInBillingRetryPeriod": true, + "priceIncreaseStatus": 0, + "gracePeriodExpiresDate": 1698148900000, + "offerType": 2, + "offerIdentifier": "abc.123", + "signedDate": 1698148800000, + "environment": "LocalTesting", + "recentSubscriptionStartDate": 1698148800000, + "renewalDate": 1698148850000 +} \ No newline at end of file diff --git a/tests/resources/models/signedSummaryNotification.json b/tests/resources/models/signedSummaryNotification.json new file mode 100644 index 0000000..3a22ec0 --- /dev/null +++ b/tests/resources/models/signedSummaryNotification.json @@ -0,0 +1,21 @@ +{ + "notificationType": "RENEWAL_EXTENSION", + "subtype": "SUMMARY", + "notificationUUID": "002e14d5-51f5-4503-b5a8-c3a1af68eb20", + "version": "2.0", + "signedDate": 1698148900000, + "summary": { + "environment": "LocalTesting", + "appAppleId": 41234, + "bundleId": "com.example", + "productId": "com.example.product", + "requestIdentifier": "efb27071-45a4-4aca-9854-2a1e9146f265", + "storefrontCountryCodes": [ + "CAN", + "USA", + "MEX" + ], + "succeededCount": 5, + "failedCount": 2 + } +} \ No newline at end of file diff --git a/tests/resources/models/signedTransaction.json b/tests/resources/models/signedTransaction.json new file mode 100644 index 0000000..3c44a56 --- /dev/null +++ b/tests/resources/models/signedTransaction.json @@ -0,0 +1,25 @@ +{ + "transactionId":"23456", + "originalTransactionId":"12345", + "webOrderLineItemId":"34343", + "bundleId":"com.example", + "productId":"com.example.product", + "subscriptionGroupIdentifier":"55555", + "purchaseDate":1698148900000, + "originalPurchaseDate":1698148800000, + "expiresDate":1698149000000, + "quantity":1, + "type":"Auto-Renewable Subscription", + "appAccountToken": "7e3fb20b-4cdb-47cc-936d-99d65f608138", + "inAppOwnershipType":"PURCHASED", + "signedDate":1698148900000, + "revocationReason": 1, + "revocationDate": 1698148950000, + "isUpgraded": true, + "offerType":1, + "offerIdentifier": "abc.123", + "environment":"LocalTesting", + "transactionReason":"PURCHASE", + "storefront":"USA", + "storefrontId":"143441" +} \ No newline at end of file diff --git a/tests/resources/models/transactionHistoryResponse.json b/tests/resources/models/transactionHistoryResponse.json new file mode 100644 index 0000000..c5cc638 --- /dev/null +++ b/tests/resources/models/transactionHistoryResponse.json @@ -0,0 +1,11 @@ +{ + "revision": "revision_output", + "hasMore": true, + "bundleId": "com.example", + "appAppleId": 323232, + "environment": "LocalTesting", + "signedTransactions": [ + "signed_transaction_value", + "signed_transaction_value2" + ] +} \ No newline at end of file diff --git a/tests/resources/models/transactionInfoResponse.json b/tests/resources/models/transactionInfoResponse.json new file mode 100644 index 0000000..57d84e2 --- /dev/null +++ b/tests/resources/models/transactionInfoResponse.json @@ -0,0 +1,3 @@ +{ + "signedTransactionInfo": "signed_transaction_info_value" +} \ No newline at end of file diff --git a/tests/resources/xcode/xcode-app-receipt-empty b/tests/resources/xcode/xcode-app-receipt-empty new file mode 100644 index 0000000..f5acce8 --- /dev/null +++ b/tests/resources/xcode/xcode-app-receipt-empty @@ -0,0 +1 @@ +MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwGggCSABIHhMYHeMA8CAQACAQEEBwwFWGNvZGUwCwIBAQIBAQQDAgEAMDUCAQICAQEELQwrY29tLmV4YW1wbGUubmF0dXJlbGFiLmJhY2t5YXJkYmlyZHMuZXhhbXBsZTALAgEDAgEBBAMMATEwEAIBBAIBAQQI0bz+zwQAAAAwHAIBBQIBAQQU4nEwK24WxZhKi0PSGTYgWoXOIqMwCgIBCAIBAQQCFgAwHgIBDAIBAQQWFhQyMDIzLTEwLTE5VDAxOjE4OjU0WjAeAgEV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PDK4vBcpvemR/ICx15kyxEtP94x9eDX24WNegfOR/Y6uXmivDKtjQsuHVWg05G29nKKkSg9aHeG2ZvV6zCuCYzvbqw45taeu3QIE9hz1wUdHEXY2l3H9qWBreYHY3Uuz/rBldDBUvig/1icjXKx0e7CuRBac9TzGCAY8wggGLAgEBMGQwXzERMA8GA1UEAwwIU3RvcmVLaXQxETAPBgNVBAoMCFN0b3JlS2l0MREwDwYDVQQLDAhTdG9yZUtpdDELMAkGA1UEBhMCVVMxFzAVBgkqhkiG9w0BCQEWCFN0b3JlS2l0AgEBMA0GCWCGSAFlAwQCAQUAMA0GCSqGSIb3DQEBCwUABIIBAIjP3bmY+TrOM0e8n7PeH3OEies1+spNT1n8om4424n/NyIJ9XRyj1QGxshxh6p2BQuUQV8mkWKpHYQJqPobVEcl72ndbHSfzkH2vM57jy/2bCopLt+zWQl0QMA9iKEB3G075wgyD6lcSveZnER/4J6E9+tO6O3R2YFVziwL2UmNR1XgfOhKyNwCfSV1CyVVoSUkkZI7fJ1S6Pce2nLKM1pf+oCWr5vAySd9E4givt/YagGJF+3RHZMEcrqHnnP8kQKi99xnXcIfYyK6VMD9uBb2+4N7MCRDhoY/8+vX9I75paW0UicS6MwacJPueNxLaAboOP4nFSlYhEhZuLiZrdIAAAAAAAA= \ No newline at end of file diff --git a/tests/resources/xcode/xcode-app-receipt-with-transaction b/tests/resources/xcode/xcode-app-receipt-with-transaction new file mode 100644 index 0000000..6b2d6e7 --- /dev/null +++ b/tests/resources/xcode/xcode-app-receipt-with-transaction @@ -0,0 +1 @@ +MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwGggCSABIIBdjGCAXIwDwIBAAIBAQQHDAVYY29kZTALAgEBAgEBBAMCAQAwNQIBAgIBAQQtDCtjb20uZXhhbXBsZS5uYXR1cmVsYWIuYmFja3lhcmRiaXJkcy5leGFtcGxlMAsCAQMCAQEEAwwBMTAQAgEEAgEBBAjyv/X7DwA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l8SwQIDAQABozswOTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIChDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDAzANBgkqhkiG9w0BAQsFAAOCAQEAsgDgPPHo6WK9wNYdQJ5XuTiQd3ZS0qhLcG64Z5n7s4pVn+8dKLhfKtFznzVHN7tG03YQ8vBp7M1imXH5YIqESDjEvYtnJbmrbDNlrdjCmnhID+nMwScNxs9kPG2AWTOMyjYGKhEbjUnOCP9mwEcoS+tawSsJViylqgkDezIx3OiFeEjOwMUSEWoPDK4vBcpvemR/ICx15kyxEtP94x9eDX24WNegfOR/Y6uXmivDKtjQsuHVWg05G29nKKkSg9aHeG2ZvV6zCuCYzvbqw45taeu3QIE9hz1wUdHEXY2l3H9qWBreYHY3Uuz/rBldDBUvig/1icjXKx0e7CuRBac9TzGCAY8wggGLAgEBMGQwXzERMA8GA1UEAwwIU3RvcmVLaXQxETAPBgNVBAoMCFN0b3JlS2l0MREwDwYDVQQLDAhTdG9yZUtpdDELMAkGA1UEBhMCVVMxFzAVBgkqhkiG9w0BCQEWCFN0b3JlS2l0AgEBMA0GCWCGSAFlAwQCAQUAMA0GCSqGSIb3DQEBCwUABIIBAMNY9TpOCg59NnKdDA6Xc4D74lEaa+YwQqD/z8ajAGxpw3efoQRvx8Q1qR6IVs9BcRYGyJmsFrau19QeSIRjjqaxhV8ZbRFenWp0Yps6OCPVHw94Ej3AstAL/8WIArBM1OS6OZJESJdQz5xpwavWLGm1rU2730glMdHzHfm2h0wNp/0BKV0ugV9SRQN4RsyAMNS+rCO1mtSDI6nx8E+dEVMIa4mUg+yhXRlg6KzdzKWnr9vDtRVmhdq0ANfP+jfvncsyC+d/c3cAsXOK066hKFwYWTKaRZ7M2eXus5TcU83/aaovHyKVyKKCRnKuP7VPt9d5eWLSg/7v2ctHJtjmhqsAAAAAAAA= \ No newline at end of file diff --git a/tests/resources/xcode/xcode-signed-app-transaction b/tests/resources/xcode/xcode-signed-app-transaction new file m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GUiLCJhcHBsaWNhdGlvblZlcnNpb24iOiIxIiwiZGV2aWNlVmVyaWZpY2F0aW9uTm9uY2UiOiI0OGM4YjkyZC1jZTBkLTQyMjktYmVkZi1lNjFiNGY5Y2ZjOTIiLCJyZWNlaXB0VHlwZSI6Ilhjb2RlIiwicmVjZWlwdENyZWF0aW9uRGF0ZSI6MTY5NzY4MDEyMjI1Ny40NDcsImRldmljZVZlcmlmaWNhdGlvbiI6ImNZVXNYYzUzRWJZYzBwT2VYRzVkNlwvMzFMR0hlVkdmODRzcVNOME9ySmk1dVwvajJIODlXV0tnUzhOMGhNc01sZiIsInJlcXVlc3REYXRlIjoxNjk3NjgwMTIyMjU3LjQ0Nywib3JpZ2luYWxBcHBsaWNhdGlvblZlcnNpb24iOiIxIiwib3JpZ2luYWxQdXJjaGFzZURhdGUiOi02MjEzNTc2OTYwMDAwMH0.Dpdk_VsO2MUCevwyS407alJpPc1Nq_UIP9EiDHaQBxlyi35NFnsKUVNuFNcGWrGRCCImnb4QGBKHfQC2i4sPCg \ No newline at end of file diff --git a/tests/resources/xcode/xcode-signed-renewal-info b/tests/resources/xcode/xcode-signed-renewal-info new file mode 100644 index 0000000..d18123c --- /dev/null +++ b/tests/resources/xcode/xcode-signed-renewal-info @@ -0,0 +1 @@ +eyJraWQiOiJBcHBsZV9YY29kZV9LZXkiLCJ0eXAiOiJKV1QiLCJ4NWMiOlsiTUlJQnpEQ0NBWEdnQXdJQkFnSUJBVEFLQmdncWhrak9QUVFEQWpCSU1TSXdJQVlEVlFRREV4bFRkRzl5WlV0cGRDQlVaWE4wYVc1bklHbHVJRmhqYjJSbE1TSXdJQVlEVlFRS0V4bFRkRzl5WlV0cGRDQlVaWE4wYVc1bklHbHVJRmhqYjJSbE1CNFhEVEl6TVRBeE9UQXhORFV6TmxvWERUSTBNVEF4T0RBeE5EVXpObG93U0RFaU1DQUdBMVVFQXhNWlUzUnZjbVZMYVhRZ1ZHVnpkR2x1WnlCcGJpQllZMjlrWlRFaU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UHJvZHVjdElkIjoicGFzcy5wcmVtaXVtIn0.WnT3aB9Lwjbr0ICUGn_5CdglzedVd7eOkrqirhcWFvwJZzN1FajuMV6gFEbgD82aL0Ix6HGZcwkNDlVNLvYOEQ \ No newline at end of file diff --git a/tests/resources/xcode/xcode-signed-transaction b/tests/resources/xcode/xcode-signed-transaction new file mode 100644 index 0000000..6daf517 --- /dev/null +++ b/tests/resources/xcode/xcode-signed-transaction @@ -0,0 +1 @@ +eyJraWQiOiJBcHBsZV9YY29kZV9LZXkiLCJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlCekRDQ0FYR2dBd0lCQWdJQkFUQUtCZ2dxaGtqT1BRUURBakJJTVNJd0lBWURWUVFERXhsVGRHOXlaVXRwZENCVVpYTjBhVzVuSUdsdUlGaGpiMlJsTVNJd0lBWURWUVFLRXhsVGRHOXlaVXRwZENCVVpYTjBhVzVuSUdsdUlGaGpiMlJsTUI0WERUSXpNVEF4T1RBeE5EVXpObG9YRFRJME1UQXhPREF4TkRVek5sb3dTREVpTUNBR0ExVUVBeE1aVTNSdmNtVkxhWFFnVkdWemRHbHVaeUJwYmlCWVkyOWtaVEVpTUNBR0ExVUVDaE1aVTNSdmNtVkxhWFFnVkdWemRHbHVaeUJwYmlCWVkyOWtaVEJaTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEEwSUFCS1hFUWdZakNvdVB0VHN0R3JLcFk4STUzbkg3cmJESG5jSUxHbm9nU0F1bElJM3NcL3VmTTBnOURjM0JjcjQ5N0FVZ3pHVHZXcGl3SnhwZUIzNzFOZ1YralREQktNQklHQTFVZEV3RUJcL3dRSU1BWUJBZjhDQVFBd0pBWURWUjBSQkIwd0c0RVpVM1J2Y21WTGFYUWdWR1Z6ZEdsdVp5QnBiaUJZWTI5a1pUQU9CZ05WSFE4QkFmOEVCQU1DQjRBd0NnWUlLb1pJemowRUF3SURTUUF3UmdJaEFNWnZWWUo2NENGK2gyZm1z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hoIR2ThmNFnyKcx5XxIakXYdh-1oKtEVEU5zQAiONaLDpBDO5JhLLrTbfp7LS5tMiqmgHw \ No newline at end of file diff --git a/tests/unit-tests/jwt_verification.test.ts b/tests/unit-tests/jwt_verification.test.ts index 09fcd75..d66eaa9 100644 --- a/tests/unit-tests/jwt_verification.test.ts +++ b/tests/unit-tests/jwt_verification.test.ts @@ -4,6 +4,7 @@ import assert = require("assert"); import { KeyObject, X509Certificate } from "crypto"; import { SignedDataVerifier, VerificationException, VerificationStatus } from "../../jwt_verification"; import { Environment } from "../../models/Environment"; +import { readFile, getSignedPayloadVerifierWithDefaultAppAppleId, getDefaultSignedPayloadVerifier } from "../util"; const ROOT_CA_BASE64_ENCODED = "MIIBgjCCASmgAwIBAgIJALUc5ALiH5pbMAoGCCqGSM49BAMDMDYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlDdXBlcnRpbm8wHhcNMjMwMTA1MjEzMDIyWhcNMzMwMTAyMjEzMDIyWjA2MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJQ3VwZXJ0aW5vMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEc+/Bl+gospo6tf9Z7io5tdKdrlN1YdVnqEhEDXDShzdAJPQijamXIMHf8xWWTa1zgoYTxOKpbuJtDplz1XriTaMgMB4wDAYDVR0TBAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwCgYIKoZIzj0EAwMDRwAwRAIgemWQXnMAdTad2JDJWng9U4uBBL5mA7WI05H7oH7c6iQCIHiRqMjNfzUAyiu9h6rOU/K+iTR0I/3Y/NSWsXHX+acc"; const INTERMEDIATE_CA_BASE64_ENCODED = "MIIBnzCCAUWgAwIBAgIBCzAKBggqhkjOPQQDAzA2MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJQ3VwZXJ0aW5vMB4XDTIzM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ubWVudCI6IlNhbmRib3giLCJidW5kbGVJZCI6ImNvbS5leGFtcGxlIiwic2lnbmVkRGF0ZSI6MTY3Mjk1NjE1NDAwMH0.PnHWpeIJZ8f2Q218NSGLo_aR0IBEJvC6PxmxKXh-qfYTrZccx2suGl223OSNAX78e4Ylf2yJCG2N-FfU-NIhZQ"; - describe("Decoding checks", () => { it('should fail to verify with a missing x5c header', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example"); + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.PRODUCTION, "com.example") try { - await verifier.verifyAndDecodeNotification(MISSING_X5C_HEADER_CLAIM) + const missingX5CHeaderClaim = readFile('tests/resources/mock_signed_data/missingX5CHeaderClaim') + await verifier.verifyAndDecodeNotification(missingX5CHeaderClaim) assert(false) } catch (e) { expect(e).toBeInstanceOf(VerificationException) @@ -134,9 +129,10 @@ describe("Decoding checks", () => { }) it('should fail to verify with an invalid bundle id', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example"); + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example") try { - await verifier.verifyAndDecodeNotification(WRONG_BUNDLE_ID) + const wrongBundelId = readFile('tests/resources/mock_signed_data/wrongBundleId') + await verifier.verifyAndDecodeNotification(wrongBundelId) assert(false) } catch (e) { expect(e).toBeInstanceOf(VerificationException) @@ -145,9 +141,10 @@ describe("Decoding checks", () => { }) it('should fail to verify with an invalid bundle id for transaction', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example.x"); try { - await verifier.verifyAndDecodeTransaction(TRANSACTION_INFO) + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example.x") + const transactionInfo = readFile('tests/resources/mock_signed_data/transactionInfo') + await verifier.verifyAndDecodeTransaction(transactionInfo) assert(false) } catch (e) { expect(e).toBeInstanceOf(VerificationException) @@ -156,9 +153,11 @@ describe("Decoding checks", () => { }) it('should fail to verify with an invalid environment', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234); try { - await verifier.verifyAndDecodeNotification(TEST_NOTIFICATION) + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.PRODUCTION, "com.example") + const testNotification = readFile('tests/resources/mock_signed_data/testNotification') + const notification = await verifier.verifyAndDecodeNotification(testNotification) + await verifier.verifyAndDecodeNotification(testNotification) assert(false) } catch (e) { expect(e).toBeInstanceOf(VerificationException) @@ -167,45 +166,47 @@ describe("Decoding checks", () => { }) it('should fail to verify with a malformed JWT with too many parts', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example"); + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example") try { await verifier.verifyAndDecodeNotification("a.b.c.d") assert(false) } catch (e) { expect(e).toBeInstanceOf(VerificationException) - expect((e as VerificationException).status).toEqual(VerificationStatus.INVALID_CERTIFICATE) + expect((e as VerificationException).status).toEqual(VerificationStatus.VERIFICATION_FAILURE) } }) it('should fail to verify with a malformed JWT', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example"); + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example") try { await verifier.verifyAndDecodeNotification("a.b.c") assert(false) } catch (e) { expect(e).toBeInstanceOf(VerificationException) - expect((e as VerificationException).status).toEqual(VerificationStatus.INVALID_CERTIFICATE) + expect((e as VerificationException).status).toEqual(VerificationStatus.VERIFICATION_FAILURE) } }) it('should verify and decode a valid notification', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example"); - - const notification = await verifier.verifyAndDecodeNotification(TEST_NOTIFICATION) + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example") + const testNotification = readFile('tests/resources/mock_signed_data/testNotification') + const notification = await verifier.verifyAndDecodeNotification(testNotification) expect(notification.notificationType).toEqual("TEST") }) it('should verify and decode a valid renewal info', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example"); + const verifier =getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example") - const notification = await verifier.verifyAndDecodeRenewalInfo(RENEWAL_INFO) + const renewalInfo = readFile('tests/resources/mock_signed_data/renewalInfo') + const notification = await verifier.verifyAndDecodeRenewalInfo(renewalInfo) expect(notification.environment).toEqual(Environment.SANDBOX) }) it('should verify and decode a valid transaction info', async () => { - const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.SANDBOX, "com.example"); + const verifier = getSignedPayloadVerifierWithDefaultAppAppleId(Environment.SANDBOX, "com.example") - const notification = await verifier.verifyAndDecodeRenewalInfo(TRANSACTION_INFO) + const transactionInfo = readFile('tests/resources/mock_signed_data/transactionInfo') + const notification = await verifier.verifyAndDecodeRenewalInfo(transactionInfo) expect(notification.environment).toEqual(Environment.SANDBOX) }) }); \ No newline at end of file diff --git a/tests/unit-tests/receipt_utility.test.ts b/tests/unit-tests/receipt_utility.test.ts new file mode 100644 index 0000000..7717925 --- /dev/null +++ b/tests/unit-tests/receipt_utility.test.ts @@ -0,0 +1,26 @@ +// Copyright (c) 2023 Apple Inc. Licensed under MIT License. + +import { ReceiptUtility } from "../../receipt_utility" +import { readFile } from "../util" + + +describe('Receipt Utility Tets', () => { + it('should not extract a transaction id from an xcode receipt without a transaction', async () => { + const receipt = readFile('tests/resources/xcode/xcode-app-receipt-empty') + const receipt_utility = new ReceiptUtility() + const extracted_transaction_id = receipt_utility.extractTransactionIdFromAppReceipt(receipt) + expect(extracted_transaction_id).toBeNull() + }) + it('should extract a transaction id from an xcode receipt with a transaction', async () => { + const receipt = readFile('tests/resources/xcode/xcode-app-receipt-with-transaction') + const receipt_utility = new ReceiptUtility() + const extracted_transaction_id = receipt_utility.extractTransactionIdFromAppReceipt(receipt) + expect(extracted_transaction_id).toBe("0") + }) + it('should extract a transaction id from an xcode transaction receipt', async () => { + const receipt = readFile('tests/resources/mock_signed_data/legacyTransaction') + const receipt_utility = new ReceiptUtility() + const extracted_transaction_id = receipt_utility.extractTransactionIdFromTransactionReceipt(receipt) + expect(extracted_transaction_id).toBe("33993399") + }) +}) \ No newline at end of file diff --git a/tests/unit-tests/transaction_decoding.test.ts b/tests/unit-tests/transaction_decoding.test.ts new file mode 100644 index 0000000..0b7e3d1 --- /dev/null +++ b/tests/unit-tests/transaction_decoding.test.ts @@ -0,0 +1,126 @@ +// Copyright (c) 2023 Apple Inc. Licensed under MIT License. + +import { AutoRenewStatus } from "../../models/AutoRenewStatus"; +import { Environment } from "../../models/Environment"; +import { ExpirationIntent } from "../../models/ExpirationIntent"; +import { NotificationTypeV2 } from "../../models/NotificationTypeV2"; +import { OfferType } from "../../models/OfferType"; +import { PriceIncreaseStatus } from "../../models/PriceIncreaseStatus"; +import { Status } from "../../models/Status"; +import { Subtype } from "../../models/Subtype"; +import { createSignedDataFromJson, getDefaultSignedPayloadVerifier } from "../util" +import { InAppOwnershipType } from "../../models/InAppOwnershipType"; +import { RevocationReason } from "../../models/RevocationReason"; +import { TransactionReason } from "../../models/TransactionReason"; +import { Type } from "../../models/Type"; + + +describe('Testing decoding of signed data', () => { + it('should decode an app transaction', async () => { + const signedAppTransaction = createSignedDataFromJson("tests/resources/models/appTransaction.json") + + const appTransaction = await getDefaultSignedPayloadVerifier().verifyAndDecodeAppTransaction(signedAppTransaction) + + expect(Environment.LOCAL_TESTING).toBe(appTransaction.receiptType) + expect(531412).toBe(appTransaction.appAppleId) + expect("com.example").toBe(appTransaction.bundleId) + expect("1.2.3").toBe(appTransaction.applicationVersion) + expect(512).toBe(appTransaction.versionExternalIdentifier) + expect(1698148900000).toBe(appTransaction.receiptCreationDate) + expect(1698148800000).toBe(appTransaction.originalPurchaseDate) + expect("1.1.2").toBe(appTransaction.originalApplicationVersion) + expect("device_verification_value").toBe(appTransaction.deviceVerification) + expect("48ccfa42-7431-4f22-9908-7e88983e105a").toBe(appTransaction.deviceVerificationNonce) + expect(1698148700000).toBe(appTransaction.preorderDate) + }) + it('should decode a renewal info', async () => { + const signedRenewalInfo = createSignedDataFromJson("tests/resources/models/signedRenewalInfo.json") + + const renewalInfo = await getDefaultSignedPayloadVerifier().verifyAndDecodeRenewalInfo(signedRenewalInfo) + + expect(ExpirationIntent.CUSTOMER_CANCELLED).toBe(renewalInfo.expirationIntent) + expect("12345").toBe(renewalInfo.originalTransactionId) + expect("com.example.product.2").toBe(renewalInfo.autoRenewProductId) + expect("com.example.product").toBe(renewalInfo.productId) + expect(AutoRenewStatus.ON).toBe(renewalInfo.autoRenewStatus) + expect(renewalInfo.isInBillingRetryPeriod).toBe(true) + expect(PriceIncreaseStatus.CUSTOMER_HAS_NOT_RESPONDED).toBe(renewalInfo.priceIncreaseStatus) + expect(1698148900000).toBe(renewalInfo.gracePeriodExpiresDate) + expect(OfferType.PROMOTIONAL_OFFER).toBe(renewalInfo.offerType) + expect("abc.123").toBe(renewalInfo.offerIdentifier) + expect(1698148800000).toBe(renewalInfo.signedDate) + expect(Environment.LOCAL_TESTING).toBe(renewalInfo.environment) + expect(1698148800000).toBe(renewalInfo.recentSubscriptionStartDate) + expect(1698148850000).toBe(renewalInfo.renewalDate) + }) + it('should decode a transaction info', async () => { + const signedTransaction = createSignedDataFromJson("tests/resources/models/signedTransaction.json") + + const transaction = await getDefaultSignedPayloadVerifier().verifyAndDecodeTransaction(signedTransaction) + + expect("12345").toBe(transaction.originalTransactionId) + expect("23456").toBe(transaction.transactionId) + expect("34343").toBe(transaction.webOrderLineItemId) + expect("com.example").toBe(transaction.bundleId) + expect("com.example.product").toBe(transaction.productId) + expect("55555").toBe(transaction.subscriptionGroupIdentifier) + expect(1698148800000).toBe(transaction.originalPurchaseDate) + expect(1698148900000).toBe(transaction.purchaseDate) + expect(1698148950000).toBe(transaction.revocationDate) + expect(1698149000000).toBe(transaction.expiresDate) + expect(1).toBe(transaction.quantity) + expect(Type.AUTO_RENEWABLE_SUBSCRIPTION).toBe(transaction.type) + expect("7e3fb20b-4cdb-47cc-936d-99d65f608138").toBe(transaction.appAccountToken) + expect(InAppOwnershipType.PURCHASED).toBe(transaction.inAppOwnershipType) + expect(1698148900000).toBe(transaction.signedDate) + expect(RevocationReason.REFUNDED_DUE_TO_ISSUE).toBe(transaction.revocationReason) + expect("abc.123").toBe(transaction.offerIdentifier) + expect(transaction.isUpgraded).toBe(true) + expect(OfferType.INTRODUCTORY_OFFER).toBe(transaction.offerType) + expect("USA").toBe(transaction.storefront) + expect("143441").toBe(transaction.storefrontId) + expect(TransactionReason.PURCHASE).toBe(transaction.transactionReason) + expect(Environment.LOCAL_TESTING).toBe(transaction.environment) + }) + it('should decode a signed notification', async () => { + const signedNotification = createSignedDataFromJson("tests/resources/models/signedNotification.json") + + const notification = await getDefaultSignedPayloadVerifier().verifyAndDecodeNotification(signedNotification) + + expect(NotificationTypeV2.SUBSCRIBED).toBe(notification.notificationType) + expect(Subtype.INITIAL_BUY).toBe(notification.subtype) + expect("002e14d5-51f5-4503-b5a8-c3a1af68eb20").toBe(notification.notificationUUID) + expect("2.0").toBe(notification.version) + expect(1698148900000).toBe(notification.signedDate) + expect(notification.data).toBeTruthy() + expect(notification.summary).toBeFalsy() + expect(Environment.LOCAL_TESTING).toBe(notification.data!.environment) + expect(41234).toBe(notification.data!.appAppleId) + expect("com.example").toBe(notification.data!.bundleId) + expect("1.2.3").toBe(notification.data!.bundleVersion) + expect("signed_transaction_info_value").toBe(notification.data!.signedTransactionInfo) + expect("signed_renewal_info_value").toBe(notification.data!.signedRenewalInfo) + expect(Status.ACTIVE).toBe(notification.data!.status) + }) + it('should decode a signed summary notification', async () => { + const signedNotification = createSignedDataFromJson("tests/resources/models/signedSummaryNotification.json") + + const notification = await getDefaultSignedPayloadVerifier().verifyAndDecodeNotification(signedNotification) + + expect(NotificationTypeV2.RENEWAL_EXTENSION).toBe(notification.notificationType) + expect(Subtype.SUMMARY).toBe(notification.subtype) + expect("002e14d5-51f5-4503-b5a8-c3a1af68eb20").toBe(notification.notificationUUID) + expect("2.0").toBe(notification.version) + expect(1698148900000).toBe(notification.signedDate) + expect(notification.data).toBeFalsy(); + expect(notification.summary).toBeTruthy(); + expect(Environment.LOCAL_TESTING).toBe(notification.summary!.environment) + expect(41234).toBe(notification.summary!.appAppleId) + expect("com.example").toBe(notification.summary!.bundleId) + expect("com.example.product").toBe(notification.summary!.productId) + expect("efb27071-45a4-4aca-9854-2a1e9146f265").toBe(notification.summary!.requestIdentifier) + expect(["CAN", "USA", "MEX"]).toStrictEqual(notification.summary!.storefrontCountryCodes) + expect(5).toBe(notification.summary!.succeededCount) + expect(2).toBe(notification.summary!.failedCount) + }) +}) \ No newline at end of file diff --git a/tests/util.ts b/tests/util.ts new file mode 100644 index 0000000..93f8a21 --- /dev/null +++ b/tests/util.ts @@ -0,0 +1,47 @@ +// Copyright (c) 2023 Apple Inc. Licensed under MIT License. + +import * as fs from 'fs'; +import { Environment } from '../models/Environment'; +import { SignedDataVerifier } from '../jwt_verification'; +import { ECKeyPairOptions, generateKeyPairSync } from 'crypto'; +import jsonwebtoken = require('jsonwebtoken'); + +export function readFile(path: string): string { + return fs.readFileSync(path, { + encoding: 'utf8' + }) +} + +export function readBytes(path: string): Buffer { + return fs.readFileSync(path) +} + +export function getSignedPayloadVerifier(environment: Environment, bundleId: string, appAppleId: number): SignedDataVerifier { + return new SignedDataVerifier([readBytes('tests/resources/certs/testCA.der')], false, environment, bundleId, appAppleId) +} + +export function getSignedPayloadVerifierWithDefaultAppAppleId(environment: Environment, bundleId: string): SignedDataVerifier { + return getSignedPayloadVerifier(environment, bundleId, 1234) +} + +export function getDefaultSignedPayloadVerifier(): SignedDataVerifier { + return getSignedPayloadVerifierWithDefaultAppAppleId(Environment.LOCAL_TESTING, "com.example") +} + +export function createSignedDataFromJson(path: string): string { + const fileContents = readFile(path) + const keyPairOptions: ECKeyPairOptions<'pem', 'pem'> = { + namedCurve: 'prime256v1', + publicKeyEncoding: { + type: 'spki', + format: 'pem' + }, + privateKeyEncoding: { + type: 'pkcs8', + format: 'pem' + } + } + const keypair = generateKeyPairSync("ec", keyPairOptions) + const privateKey = keypair.privateKey + return jsonwebtoken.sign(fileContents, privateKey, { algorithm: 'ES256'}); +} \ No newline at end of file