diff --git a/build.gradle b/build.gradle index 0725a1c7..4c6d2acf 100644 --- a/build.gradle +++ b/build.gradle @@ -75,9 +75,35 @@ publishing { password findProperty("mavenPassword") } if(project.version.endsWith('-SNAPSHOT')) { - url "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url "https://central.sonatype.com/repository/maven-snapshots/" } else { - url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + url "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/" + } + } + } +} + +tasks.named('publish') { + finalizedBy tasks.named('postRelease') +} + +tasks.register('postRelease') { + doLast { + if (!project.version.endsWith('-SNAPSHOT')) { + def username = findProperty("mavenUsername") + def password = findProperty("mavenPassword") + def url = "https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.apple.itunes.storekit" + def connection = new URL(url).openConnection() as HttpURLConnection + connection.setRequestMethod("POST") + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded") + connection.setRequestProperty('Authorization', 'Basic ' + "${username}:${password}".bytes.encodeBase64().toString()) + def responseCode = connection.responseCode + if (responseCode == 200) { + def response = connection.inputStream.text + println "Success: $response" + } else { + def error = connection.errorStream?.text ?: "No error details" + println "Error $responseCode: $error" } } } diff --git a/src/main/java/com/apple/itunes/storekit/verification/SignedDataVerifier.java b/src/main/java/com/apple/itunes/storekit/verification/SignedDataVerifier.java index 7caefed5..2914f038 100644 --- a/src/main/java/com/apple/itunes/storekit/verification/SignedDataVerifier.java +++ b/src/main/java/com/apple/itunes/storekit/verification/SignedDataVerifier.java @@ -70,12 +70,8 @@ public SignedDataVerifier(Set rootCertificates, String bundleId, Lo */ public JWSTransactionDecodedPayload verifyAndDecodeTransaction(String signedTransaction) throws VerificationException { JWSTransactionDecodedPayload transaction = decodeSignedObject(signedTransaction, JWSTransactionDecodedPayload.class); - if (!bundleId.equals(transaction.getBundleId())) { - throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER); - } - if (!this.environment.equals(transaction.getEnvironment())) { - throw new VerificationException(VerificationStatus.INVALID_ENVIRONMENT); - } + validateBundleId(transaction.getBundleId()); + validateEnvironment(transaction.getEnvironment()); return transaction; } @@ -89,9 +85,7 @@ public JWSTransactionDecodedPayload verifyAndDecodeTransaction(String signedTran */ public JWSRenewalInfoDecodedPayload verifyAndDecodeRenewalInfo(String signedRenewalInfo) throws VerificationException { JWSRenewalInfoDecodedPayload renewalInfo = decodeSignedObject(signedRenewalInfo, JWSRenewalInfoDecodedPayload.class); - if (!this.environment.equals(renewalInfo.getEnvironment())) { - throw new VerificationException(VerificationStatus.INVALID_ENVIRONMENT); - } + validateEnvironment(renewalInfo.getEnvironment()); return renewalInfo; } @@ -135,12 +129,9 @@ public ResponseBodyV2DecodedPayload verifyAndDecodeNotification(String signedPay } protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) throws VerificationException { - if (!this.bundleId.equals(bundleId) || (this.environment.equals(Environment.PRODUCTION) && !this.appAppleId.equals(appAppleId))) { - throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER); - } - if (!this.environment.equals(notificationEnv)) { - throw new VerificationException(VerificationStatus.INVALID_ENVIRONMENT); - } + validateBundleId(bundleId); + validateAppAppleId(appAppleId); + validateEnvironment(notificationEnv); } /** @@ -154,13 +145,28 @@ protected void verifyNotification(String bundleId, Long appAppleId, Environment public AppTransaction verifyAndDecodeAppTransaction(String signedAppTransaction) throws VerificationException { AppTransaction appTransaction = decodeSignedObject(signedAppTransaction, AppTransaction.class); Environment environment = appTransaction.getReceiptType(); - if (!this.bundleId.equals(appTransaction.getBundleId()) || (this.environment.equals(Environment.PRODUCTION) && !this.appAppleId.equals(appTransaction.getAppAppleId()))) { + validateBundleId(appTransaction.getBundleId()); + validateAppAppleId(appTransaction.getAppAppleId()); + validateEnvironment(environment); + return appTransaction; + } + + protected void validateAppAppleId(Long appAppleId) throws VerificationException { + if (this.environment.equals(Environment.PRODUCTION) && !this.appAppleId.equals(appAppleId)) { + throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER); + } + } + + protected void validateBundleId(String bundleId) throws VerificationException { + if (!this.bundleId.equals(bundleId)) { throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER); } + } + + protected void validateEnvironment(Environment environment) throws VerificationException { if (!this.environment.equals(environment)) { throw new VerificationException(VerificationStatus.INVALID_ENVIRONMENT); } - return appTransaction; } protected T decodeSignedObject(String signedObject, Class clazz) throws VerificationException {