SHA256
Исправить регистрацию free-пользователей без учёта регистра
НЕ ПРОВЕРЕНО: учтены логины с большими и маленькими буквами. Добавлен временный devnet-смарт-контракт для очистки тестового аккаунта от старых логинов; после сброса его необходимо удалить и восстановить штатный контракт.
This commit is contained in:
+1
-1
@@ -37,7 +37,7 @@ import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Discovers individual App=test5591 DataItems and imports the exact signed ANS-104 bytes.
|
||||
* Discovers individual App=test5592 DataItems and imports the exact signed ANS-104 bytes.
|
||||
* The importer is transport-agnostic: a DataItem may have reached Arweave through Turbo
|
||||
* or inside a direct server-created ANS-104 bundle.
|
||||
*/
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package server.archive.registration;
|
||||
|
||||
import blockchain.Ans104DataItem;
|
||||
import blockchain.ShineProtocolTags;
|
||||
import utils.crypto.Ed25519Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -16,7 +17,7 @@ import java.util.Locale;
|
||||
public final class FreeRegistrationCertificateV1 {
|
||||
private static final byte[] DOMAIN = "SHiNE_FREE_REG_V1\0".getBytes(StandardCharsets.UTF_8);
|
||||
private static final List<Ans104DataItem.Tag> TAGS = List.of(
|
||||
new Ans104DataItem.Tag("App", "test5591"),
|
||||
new Ans104DataItem.Tag(ShineProtocolTags.APP_TAG_NAME, ShineProtocolTags.APP_TAG_VALUE),
|
||||
new Ans104DataItem.Tag("t", "reg"),
|
||||
new Ans104DataItem.Tag("Protocol", "SHiNE-Free-Registration-V1"));
|
||||
|
||||
@@ -27,8 +28,8 @@ public final class FreeRegistrationCertificateV1 {
|
||||
private FreeRegistrationCertificateV1() {}
|
||||
|
||||
public static String validateLogin(String login) {
|
||||
if (login == null || !login.matches("[a-z0-9_]+@[a-z0-9_]+") || login.length() > 30)
|
||||
throw new IllegalArgumentException("Full login must be lowercase ASCII, <= 30 bytes");
|
||||
if (login == null || !login.matches("[A-Za-z0-9_]+@[a-z0-9_]+") || login.length() > 30)
|
||||
throw new IllegalArgumentException("Full login must use ASCII letters (any local-part case), lowercase namespace, <= 30 bytes");
|
||||
return login;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public final class FreeRegistrationIssuer {
|
||||
}
|
||||
try (PreparedStatement ps = conn.prepareStatement(
|
||||
"SELECT 1 FROM user_identity_current WHERE normalized_login = ?")) {
|
||||
ps.setString(1, fullLogin);
|
||||
ps.setString(1, fullLogin.toLowerCase(java.util.Locale.ROOT));
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) throw new IllegalArgumentException("Login is already registered");
|
||||
}
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ public final class FreeRegistrationWorkflow {
|
||||
}
|
||||
}
|
||||
try (PreparedStatement p=c.prepareStatement("SELECT 1 FROM user_identity_current WHERE normalized_login=?")) {
|
||||
p.setString(1, login);
|
||||
p.setString(1, login.toLowerCase(java.util.Locale.ROOT));
|
||||
try (ResultSet rs=p.executeQuery()) { return new LoginCheck(!rs.next(),type,minimum,fee); }
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public final class FreeRegistrationWorkflow {
|
||||
LEFT JOIN shine_namespace_current n ON n.namespace=i.namespace
|
||||
WHERE i.normalized_login=?
|
||||
""")) {
|
||||
p.setString(1,login);
|
||||
p.setString(1,login.toLowerCase(java.util.Locale.ROOT));
|
||||
try (ResultSet r=p.executeQuery()) {
|
||||
return r.next()?new State(r.getString(1),r.getString(2),r.getString(3),
|
||||
r.getBytes(4)==null?null:Base64.getEncoder().encodeToString(r.getBytes(4)),
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ public final class VerifiedFreeRegistrationImporter {
|
||||
var cert = FreeRegistrationCertificateV1.verify(raw, readRegistrar(c, namespace, login));
|
||||
try (PreparedStatement ps = c.prepareStatement(
|
||||
"SELECT free_data_item_id FROM user_identity_current WHERE normalized_login=?")) {
|
||||
ps.setString(1, login);
|
||||
ps.setString(1, login.toLowerCase(java.util.Locale.ROOT));
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next() && !cert.idBase64Url().equals(rs.getString(1)))
|
||||
throw new IllegalArgumentException("Login is already registered");
|
||||
@@ -96,11 +96,11 @@ public final class VerifiedFreeRegistrationImporter {
|
||||
blockchain_name, is_server, registered_at_ms, updated_at_ms)
|
||||
VALUES (?, ?, ?, 'ARWEAVE', 'FREE_CERT', NULL, ?, ?, ?, ?, ?, false, ?, ?)
|
||||
""")) {
|
||||
insert.setString(1, login); insert.setString(2, login); insert.setString(3, namespace);
|
||||
insert.setString(1, login); insert.setString(2, login.toLowerCase(java.util.Locale.ROOT)); insert.setString(3, namespace);
|
||||
insert.setString(4, id); insert.setString(5, Base58Util.encode(cert.rootKey()));
|
||||
insert.setString(6, Base58Util.encode(cert.clientKey()));
|
||||
insert.setString(7, Base58Util.encode(cert.blockchainKey()));
|
||||
insert.setString(8, login + "-001"); insert.setLong(9, now); insert.setLong(10, now);
|
||||
insert.setString(8, login.toLowerCase(java.util.Locale.ROOT) + "-001"); insert.setLong(9, now); insert.setLong(10, now);
|
||||
insert.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement insert = c.prepareStatement("""
|
||||
|
||||
+27
-26
@@ -1,42 +1,43 @@
|
||||
package server.archive;
|
||||
|
||||
import server.archive.registration.*;
|
||||
import blockchain.Ans104DataItem;
|
||||
import blockchain.ShineProtocolTags;
|
||||
import utils.crypto.Ed25519Util;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HexFormat;
|
||||
|
||||
/** Запуск: java ... server.archive.FreeRegistrationCertificateV1Check file.hex */
|
||||
/** Standalone test (no legacy signed fixture): certificate issue/verify for CURRENT App tag. */
|
||||
public final class FreeRegistrationCertificateV1Check {
|
||||
static final HexFormat HEX = HexFormat.of();
|
||||
public static void main(String[] args) throws Exception {
|
||||
byte[] raw = HEX.parseHex(Files.readString(Path.of(args[0])).trim());
|
||||
byte[] pub = HEX.parseHex("174553b456dddfc6908ecab1c101fe6ab21e2baa0617795b7d43a63482993fd5");
|
||||
var result = FreeRegistrationCertificateV1.verify(raw, pub);
|
||||
if (!"bob@free".equals(result.login()) || !result.idBase64Url().equals(
|
||||
java.util.Base64.getUrlEncoder().withoutPadding().encodeToString(
|
||||
HEX.parseHex("45ef42eda7c7e76d222ecce8a7678edb923ae63f8419ea0899701551c2466770"))))
|
||||
throw new AssertionError("Wrong fixture identity / DataItem id");
|
||||
byte[] corrupted = raw.clone(); corrupted[corrupted.length-1] ^= 1;
|
||||
try { FreeRegistrationCertificateV1.verify(corrupted, pub); throw new AssertionError("Email bit flip accepted"); }
|
||||
catch (IllegalArgumentException expected) {}
|
||||
corrupted = raw.clone(); corrupted[corrupted.length-40] ^= 1;
|
||||
try { FreeRegistrationCertificateV1.verify(corrupted, pub); throw new AssertionError("Inner signature tampering accepted"); }
|
||||
catch (IllegalArgumentException expected) {}
|
||||
|
||||
byte[] seed = Ed25519Util.generatePrivateKeyFromString("TEST-only-reg-v1-check");
|
||||
byte[] root = HEX.parseHex("03a107bff3ce10be1d70dd18e74bc09967e4d6309ba50d5f1ddc8664125531b8");
|
||||
byte[] chain = HEX.parseHex("29acbae141bccaf0b22e1a94d34d0bc7361e526d0bfe12c89794bc9322966dd7");
|
||||
byte[] client = HEX.parseHex("2543b92ff1095511476adc8369db6ddc933665a11978dda1404ee1066ca9559d");
|
||||
try (var signer = new LocalRegistrarSigner(seed)) {
|
||||
byte[] cert = FreeRegistrationCertificateV1.issue("bob@free",
|
||||
HEX.parseHex("03a107bff3ce10be1d70dd18e74bc09967e4d6309ba50d5f1ddc8664125531b8"),
|
||||
HEX.parseHex("29acbae141bccaf0b22e1a94d34d0bc7361e526d0bfe12c89794bc9322966dd7"),
|
||||
HEX.parseHex("2543b92ff1095511476adc8369db6ddc933665a11978dda1404ee1066ca9559d"),
|
||||
" Alice.Example+Tag@Example.COM ", signer);
|
||||
var verified = FreeRegistrationCertificateV1.verify(cert, signer.publicKey32());
|
||||
if (!Arrays.equals(verified.emailSha256(),
|
||||
HEX.parseHex("cbc605c49fd774ff4d9ea789d8f6bffa719e9774cb86f62d11fd244121150956")))
|
||||
byte[] cert = FreeRegistrationCertificateV1.issue("SuperMan@free", root, chain, client,
|
||||
" Alice.Example+Tag@Example.COM ", signer);
|
||||
var item = new Ans104DataItem(cert);
|
||||
if (!item.hasTag(ShineProtocolTags.APP_TAG_NAME, ShineProtocolTags.APP_TAG_VALUE))
|
||||
throw new AssertionError("Current App tag missing");
|
||||
var result = FreeRegistrationCertificateV1.verify(cert, signer.publicKey32());
|
||||
if (!"SuperMan@free".equals(result.login()) || !Arrays.equals(result.rootKey(), root)
|
||||
|| !Arrays.equals(result.blockchainKey(), chain) || !Arrays.equals(result.clientKey(), client))
|
||||
throw new AssertionError("Certificate identity corrupted");
|
||||
if (!Arrays.equals(result.emailSha256(), HEX.parseHex(
|
||||
"cbc605c49fd774ff4d9ea789d8f6bffa719e9774cb86f62d11fd244121150956")))
|
||||
throw new AssertionError("Email normalization differs");
|
||||
byte[] bad = cert.clone(); bad[bad.length - 1] ^= 1;
|
||||
try { FreeRegistrationCertificateV1.verify(bad, signer.publicKey32());
|
||||
throw new AssertionError("Email bit flip accepted"); }
|
||||
catch (IllegalArgumentException expected) {}
|
||||
bad = cert.clone(); bad[bad.length - 40] ^= 1;
|
||||
try { FreeRegistrationCertificateV1.verify(bad, signer.publicKey32());
|
||||
throw new AssertionError("Inner signature tampering accepted"); }
|
||||
catch (IllegalArgumentException expected) {}
|
||||
}
|
||||
System.out.println("PASS: Java registrar fixture, inner+outer Ed25519, email normalization, tamper rejection");
|
||||
System.out.println("PASS: current App=" + ShineProtocolTags.APP_TAG_VALUE
|
||||
+ ", Java registrar inner+outer Ed25519, original case, email, tamper rejection");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user