Разделить среды и закрепить лицензии в HEADER 1.0

This commit is contained in:
AidarKC
2026-12-05 11:42:20 +03:00
parent a64168a748
commit 77c7021aed
89 changed files with 4204 additions and 211 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ public class M5_FORK_CHECK {
check(Arrays.equals(fork.prevLineHash32,hex.parseHex(history.get(fork.prevLineNumber+1).split("\t")[3])));
check(fork.reasonCode==3 && fork.comment.equals("test\nFORK"));
check(fork.forkPointTimestampMs==(1700000000L+cutoff)*1000 && fork.parentTipTimestampMs==1700000007000L);
check(b.getCoreDataItem().hasTag("App","test5595"));
check(b.getCoreDataItem().hasTag("App","test5570"));
byte[] bad=raw.clone();bad[bad.length-1]^=1;
try {BchBlockEntry.fromCoreContent(bad);throw new AssertionError("tampering accepted");} catch(IllegalArgumentException expected){}
count++;
+18
View File
@@ -0,0 +1,18 @@
import blockchain.*;
import utils.config.ServerEnvironment;
import java.nio.file.*;
import java.util.HexFormat;
import java.util.List;
public class ServerEnvironmentCheck {
public static void main(String[] args) throws Exception {
boolean test = Boolean.parseBoolean(args[0]);
if (ServerEnvironment.TEST_MODE != test || !ServerEnvironment.ARWEAVE_APP_TAG.equals(test ? "test5570" : "SHiNE") || !ServerEnvironment.SOLANA_CLUSTER.equals(test ? "devnet" : "mainnet-beta")) throw new AssertionError("wrong environment");
for (String x : new String[]{null,"true","False","invalid",""}) if (!ServerEnvironment.isTestMode(x)) throw new AssertionError("unsafe default");
if (ServerEnvironment.isTestMode("false")) throw new AssertionError("explicit production ignored");
var row = Files.readAllLines(Path.of(args[1])).get(1).split("\t");
var item = new Ans104DataItem(HexFormat.of().parseHex(row[6]));
try { CoreContentTransport.requireApp(item); if (!test) throw new AssertionError("test CORE accepted in production"); }
catch (CoreContentTransport.WrongAppNamespace e) { if (test) throw e; }
System.out.println("PASS environment=" + ServerEnvironment.ARWEAVE_APP_TAG + ", cluster=" + ServerEnvironment.SOLANA_CLUSTER);
}
}
+1 -1
View File
@@ -9,6 +9,6 @@ B=SHiNE-server/shine-server-blockchain/src/main/java/blockchain
A=SHiNE-server/shine-server-archive/src
javac --release 17 -cp "$BCPROV_JAR" -d "$OUT" $(find "$B" -name '*.java') \
SHiNE-server/shine-server-crypto/src/main/java/utils/crypto/{Ed25519Util,HashSHA256Util}.java \
SHiNE-server/shine-server-config/src/main/java/utils/config/ShineSignatureConstants.java \
SHiNE-server/shine-server-config/src/main/java/utils/config/{ShineSignatureConstants,AppConfig,ServerEnvironment}.java \
"$A/main/java/server/archive/ArchiveBlockPair.java" "$A/test/java/server/archive/M4ArchiveBlockPairCheck.java"
java -cp "$OUT:$BCPROV_JAR" server.archive.M4ArchiveBlockPairCheck docs/Blockchain/vectors/core-content-v1.tsv
+9 -1
View File
@@ -10,6 +10,14 @@ B=SHiNE-server/shine-server-blockchain/src/main/java/blockchain
T=SHiNE-server/shine-server-blockchain/src/test/java/blockchain
javac --release 17 -cp "$BCPROV_JAR" -d "$CLASSES" $(find "$B" -name '*.java') \
SHiNE-server/shine-server-crypto/src/main/java/utils/crypto/{Ed25519Util,HashSHA256Util}.java \
SHiNE-server/shine-server-config/src/main/java/utils/config/ShineSignatureConstants.java
SHiNE-server/shine-server-config/src/main/java/utils/config/{ShineSignatureConstants,AppConfig,ServerEnvironment}.java
javac --release 17 -cp "$CLASSES:$BCPROV_JAR" -d "$CLASSES" "$T"/body/*ContentBody.java "$T/StageAProtocolChecks.java"
java -cp "$CLASSES:$BCPROV_JAR" blockchain.StageAProtocolChecks
javac --release 17 -cp "$CLASSES:$BCPROV_JAR" -d "$CLASSES" scripts/tests/ServerEnvironmentCheck.java
VECTOR="$PWD/docs/Blockchain/vectors/core-content-v1.tsv"
mkdir "$CLASSES/test-env" "$CLASSES/prod-env" "$CLASSES/invalid-env"
printf 'server.testMode=false\n' > "$CLASSES/prod-env/application.properties"
printf 'server.testMode=oops\n' > "$CLASSES/invalid-env/application.properties"
(cd "$CLASSES/test-env"; java -cp "$CLASSES:$BCPROV_JAR" ServerEnvironmentCheck true "$VECTOR")
(cd "$CLASSES/prod-env"; java -cp "$CLASSES:$BCPROV_JAR" ServerEnvironmentCheck false "$VECTOR")
(cd "$CLASSES/invalid-env"; java -cp "$CLASSES:$BCPROV_JAR" ServerEnvironmentCheck true "$VECTOR")
+1 -1
View File
@@ -8,6 +8,6 @@ M5_FORK_FIXTURES="$OUT/fork.tsv" node --test shine-UI/tests/m5-key-rotation-pair
B=SHiNE-server/shine-server-blockchain/src/main/java/blockchain
javac --release 17 -cp "$BCPROV_JAR" -d "$OUT" $(find "$B" -name '*.java') \
SHiNE-server/shine-server-crypto/src/main/java/utils/crypto/{Ed25519Util,HashSHA256Util}.java \
SHiNE-server/shine-server-config/src/main/java/utils/config/ShineSignatureConstants.java \
SHiNE-server/shine-server-config/src/main/java/utils/config/{ShineSignatureConstants,AppConfig,ServerEnvironment}.java \
scripts/tests/M5_FORK_CHECK.java
java -cp "$OUT:$BCPROV_JAR" M5_FORK_CHECK "$OUT/fork.tsv" docs/Blockchain/vectors/core-content-v1.tsv
@@ -12,7 +12,7 @@ A=SHiNE-server/shine-server-archive/src
C=SHiNE-server/shine-server-config/src/main/java/utils/config
javac --release 17 -cp "$BCPROV_JAR" -d "$CLASSES" $(find "$B" -name '*.java') \
SHiNE-server/shine-server-crypto/src/main/java/utils/crypto/{Ed25519Util,HashSHA256Util}.java \
"$C"/{ShineSignatureConstants,AppConfig}.java \
"$C"/{ShineSignatureConstants,AppConfig,ServerEnvironment}.java \
SHiNE-server/shine-server-db/src/main/java/shine/db/entities/BlockEntry.java \
"$N/main/java/server/logic/ws_protocol/JSON/handlers/blockchain/Net_AddBlock_Handler_utils/LineContinuity.java" \
"$N/test/java/server/logic/ws_protocol/JSON/handlers/blockchain/M2LineContinuityCheck.java" \
@@ -10,5 +10,5 @@ static bool sha256(const uint8_t* p,size_t n,uint8_t* out){return EVP_Digest(p,n
static bool sha384(const uint8_t* p,size_t n,uint8_t* out){return EVP_Digest(p,n,out,nullptr,EVP_sha384(),nullptr)==1;}
static bool sign(const Bytes& b,const uint8_t* seed,uint8_t* out){auto* key=EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519,nullptr,seed,32);auto* ctx=EVP_MD_CTX_new();size_t len=64;bool ok=key&&ctx&&EVP_DigestSignInit(ctx,nullptr,nullptr,nullptr,key)==1&&EVP_DigestSign(ctx,out,&len,b.data(),b.size())==1&&len==64;EVP_MD_CTX_free(ctx);EVP_PKEY_free(key);return ok;}
int main(int argc,char** argv){assert(argc==2);std::ifstream in(argv[1]);assert(in);std::string line;std::getline(in,line);uint8_t seed[32];for(int i=0;i<32;i++)seed[i]=i;int count=0;
while(std::getline(in,line)){if(line.empty())continue;std::istringstream ss(line);std::vector<std::string> f;std::string x;while(std::getline(ss,x,'\t'))f.push_back(x);assert(f.size()==10);auto core=unhex(f[2]),content=unhex(f[4]),owner=unhex(f[1]),ci=unhex(f[6]),pi=unhex(f[8]);auto u16=[](const uint8_t* p){return uint16_t(p[0]*256+p[1]);};uint16_t type=u16(content.data()+1),sub=u16(content.data()+3),ver=u16(content.data()+5);uint64_t timestamp=0;for(int i=37;i<45;i++)timestamp=(timestamp<<8)|core[i];Bytes body;if(core.size()==149){if(type!=3&&type!=4)putBE(body,type==0?0:getBE(core.data()+109),4);body.insert(body.end(),core.begin()+113,core.begin()+149);putBE(body,17,4);}body.insert(body.end(),content.begin()+7,content.end());Bytes actual,expected;putBE(expected,ci.size(),4);expected.insert(expected.end(),ci.begin(),ci.end());expected.insert(expected.end(),pi.begin(),pi.end());assert(buildPair(type,sub,ver,body,getBE(core.data()+33),timestamp,core.data()+1,owner.data(),seed,"test5595",sha256,sha384,sign,actual));assert(actual==expected);++count;}
while(std::getline(in,line)){if(line.empty())continue;std::istringstream ss(line);std::vector<std::string> f;std::string x;while(std::getline(ss,x,'\t'))f.push_back(x);assert(f.size()==10);auto core=unhex(f[2]),content=unhex(f[4]),owner=unhex(f[1]),ci=unhex(f[6]),pi=unhex(f[8]);auto u16=[](const uint8_t* p){return uint16_t(p[0]*256+p[1]);};uint16_t type=u16(content.data()+1),sub=u16(content.data()+3),ver=u16(content.data()+5);uint64_t timestamp=0;for(int i=37;i<45;i++)timestamp=(timestamp<<8)|core[i];Bytes body;if(core.size()==149){if(type!=3&&type!=4)putBE(body,type==0?0:getBE(core.data()+109),4);body.insert(body.end(),core.begin()+113,core.begin()+149);putBE(body,17,4);}body.insert(body.end(),content.begin()+7,content.end());Bytes actual,expected;putBE(expected,ci.size(),4);expected.insert(expected.end(),ci.begin(),ci.end());expected.insert(expected.end(),pi.begin(),pi.end());assert(buildPair(type,sub,ver,body,getBE(core.data()+33),timestamp,core.data()+1,owner.data(),seed,"test5570",sha256,sha384,sign,actual));assert(actual==expected);++count;}
assert(count>0);std::cout<<count<<" portable remote signer fixtures: byte-identical\n";}