Skip to content

Resolves https://github.com/apple/app-store-server-library-node/issue… #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const environment = Environment.SANDBOX
const appAppleId = undefined // appAppleId is required when the environment is Production

const client = new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment)
const client = new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment, appAppleId)

try {
const response: SendTestNotificationResponse = await client.requestTestNotification()
Expand Down
3 changes: 3 additions & 0 deletions jws_verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export class SignedDataVerifier {
this.bundleId = bundleId;
this.environment = environment
this.appAppleId = appAppleId
if (environment === Environment.PRODUCTION && appAppleId === undefined) {
throw new Error("appAppleId is required when the environment is Production")
}
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/unit-tests/jws_verification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SignedJWTVerifierTest extends SignedDataVerifier {

describe("Chain Verification Checks", () => {
it('should validate a chain without OCSP', async () => {
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
const publicKey = await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
expect(Buffer.from(LEAF_CERT_PUBLIC_KEY_BASE64_ENCODED, 'base64')).toMatchObject(publicKey.export({
type: 'spki',
Expand All @@ -43,7 +43,7 @@ describe("Chain Verification Checks", () => {
})

it('should fail to validate a chain with an invalid intermediate OID', async () => {
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
try {
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_FOR_INTERMEDIATE_CA_INVALID_OID_BASE64_ENCODED, INTERMEDIATE_CA_INVALID_OID_BASE64_ENCODED)
assert(false)
Expand All @@ -54,7 +54,7 @@ describe("Chain Verification Checks", () => {
})

it('should fail to validate a chain with an invalid leaf OID', async () => {
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
try {
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_INVALID_OID_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
assert(false)
Expand All @@ -65,7 +65,7 @@ describe("Chain Verification Checks", () => {
})

it('should fail to validate a chain with empty root certificate array', async () => {
const verifier = new SignedJWTVerifierTest([], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([], false, Environment.PRODUCTION, "com.example", 1234);
try {
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
assert(false)
Expand All @@ -76,7 +76,7 @@ describe("Chain Verification Checks", () => {
})

it('should fail to validate a chain with an expired chain', async () => {
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
verifier.effectiveDate = new Date(2280946846000)
try {
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
Expand All @@ -88,12 +88,12 @@ describe("Chain Verification Checks", () => {
})

it('should validate a real chain with OCSP', async () => {
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], true, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], true, Environment.PRODUCTION, "com.example", 1234);
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), REAL_APPLE_SIGNING_CERTIFICATE_BASE64_ENCODED, REAL_APPLE_INTERMEDIATE_BASE64_ENCODED)
})

it('should fail to validate a chain with mismatched root certificates', async () => {
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
try {
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
assert(false)
Expand All @@ -106,7 +106,7 @@ describe("Chain Verification Checks", () => {

it('should fail to validate a chain with invalid root certificates', async () => {
try {
const verifier = new SignedJWTVerifierTest([Buffer.from("abc", "utf-8")], false, Environment.PRODUCTION, "com.example");
const verifier = new SignedJWTVerifierTest([Buffer.from("abc", "utf-8")], false, Environment.PRODUCTION, "com.example", 1234);
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
} catch (e) {
return
Expand Down