diff --git a/platform/src/main/java/org/stellar/anchor/platform/config/PropertySep10Config.java b/platform/src/main/java/org/stellar/anchor/platform/config/PropertySep10Config.java index c67e6b7c7e..909de601e5 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/config/PropertySep10Config.java +++ b/platform/src/main/java/org/stellar/anchor/platform/config/PropertySep10Config.java @@ -87,6 +87,18 @@ void validateConfig(Errors errors) { errors.rejectValue( "homeDomain", "home-domain-empty", "The sep10.home_domain is not defined."); } else { + try { + new ManageDataOperation.Builder(String.format("%s %s", homeDomain, "auth"), new byte[64]) + .build(); + } catch (IllegalArgumentException iaex) { + errors.rejectValue( + "homeDomain", + "sep10-home-domain-invalid", + format( + "The sep10.home_domain (%s) is longer than the maximum length (64) of a domain. Error=%s", + homeDomain, iaex)); + } + if (!NetUtil.isServerPortValid(homeDomain)) { errors.rejectValue( "homeDomain", @@ -96,6 +108,17 @@ void validateConfig(Errors errors) { } if (isNotEmpty(webAuthDomain)) { + try { + new ManageDataOperation.Builder(webAuthDomain, new byte[64]).build(); + } catch (IllegalArgumentException iaex) { + errors.rejectValue( + "webAuthDomain", + "sep10-web-auth-domain-invalid", + format( + "The sep10.web_auth_home_domain (%s) is longer than the maximum length (64) of a domain. Error=%s", + webAuthDomain, iaex)); + } + if (!NetUtil.isServerPortValid(webAuthDomain)) { errors.rejectValue( "webAuthDomain", @@ -117,30 +140,6 @@ void validateConfig(Errors errors) { "sep10-jwt-timeout-invalid", "The sep10.jwt_timeout must be greater than 0"); } - - byte[] nonce = new byte[64]; - - try { - new ManageDataOperation.Builder(String.format("%s %s", homeDomain, "auth"), nonce).build(); - } catch (IllegalArgumentException iaex) { - errors.rejectValue( - "homeDomain", - "sep10-home-domain-invalid", - format( - "The sep10.home_domain (%s) is longer than the maximum length (64) of a domain. Error=%s", - homeDomain, iaex)); - } - - try { - if (webAuthDomain != null) new ManageDataOperation.Builder(webAuthDomain, nonce).build(); - } catch (IllegalArgumentException iaex) { - errors.rejectValue( - "webAuthDomain", - "sep10-web-auth-domain-invalid", - format( - "The sep10.web_auth_home_domain (%s) is longer than the maximum length (64) of a domain. Error=%s", - webAuthDomain, iaex)); - } } void validateClientAttribution(Errors errors) { diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/config/Sep10ConfigTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/config/Sep10ConfigTest.kt index 6400c2582f..a41532ce17 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/config/Sep10ConfigTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/config/Sep10ConfigTest.kt @@ -141,11 +141,11 @@ class Sep10ConfigTest { @ValueSource( strings = [ + "this-is-longer-than-64-bytes-which-is-the-maximum-length-for-a-web-auth-domain.stellar.org", "stellar .org", "abc", "299.0.0.1", "0123456789012345678901234567890123456789012345678912.stellar.org", - "this-is-longer-than-64-bytes-which-is-the-maximum-length-for-a-web-auth-domain.stellar.org" ] ) fun `test invalid web auth domains`(value: String) { @@ -159,13 +159,13 @@ class Sep10ConfigTest { @ValueSource( strings = [ + "this-is-longer-than-64-bytes-which-is-the-maximum-length-for-a-home-domain.stellar.org", "stellar .org", "abc", "299.0.0.1", "http://stellar.org", "https://stellar.org", "://stellar.org", - "this-is-longer-than-64-bytes-which-is-the-maximum-length-for-a-home-domain.stellar.org" ] ) fun `test invalid home domains`(value: String) {