diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index f39c4e76fd08fd8c12fa0f15d8c1c26b8433b811..13d8ed290c36cd382b40354f6ac057e8d9b141ce 100755 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -20,7 +20,7 @@ const SIGNATURE = "[A-Za-z0-9+\\/=]{87,88}" const USER_ID = "[A-Za-z0-9_-]{2,100}" const INTEGER = "(0|[1-9]\\d{0,18})" const FINGERPRINT = "[A-F0-9]{64}" -const BLOCK_VERSION = "(10|11)" +const BLOCK_VERSION = "(10|11|12)" const TX_VERSION = "(10)" const DIVIDEND = "[1-9][0-9]{0,5}" const ZERO_OR_POSITIVE_INT = "0|[1-9][0-9]{0,18}" @@ -101,8 +101,10 @@ export const CommonConstants = { SIGNATURE }, - BLOCK_GENERATED_VERSION: 10, - BLOCK_NEW_GENERATED_VERSION: 11, // Put it to 11 when ready + // Version of genesis block + BLOCK_GENESIS_VERSION: 10, + // Highest supported version of DUBP protocol (= next version of the protocol) + DUBP_NEXT_VERSION: 12, LAST_VERSION_FOR_TX: 10, TRANSACTION_VERSION: 10, DOCUMENTS_VERSION: 10, diff --git a/app/lib/common-libs/crypto/keyring.ts b/app/lib/common-libs/crypto/keyring.ts index 9f9f31e741aa5827d183d22af89ec33d2c7fbf0c..a20eb7a41a9e6c6d986e55acfe97d918ec8b5924 100644 --- a/app/lib/common-libs/crypto/keyring.ts +++ b/app/lib/common-libs/crypto/keyring.ts @@ -50,13 +50,27 @@ export class Key { } } + signBuggy(msg:string) { + return Promise.resolve(this.signSyncBuggy(msg)) + } + + signSyncBuggy(msg:string) { + const m = decodeUTF8(msg); + const signedMsg = naclBinding.sign(m, this.rawSec()); + const sig = new Uint8Array(crypto_sign_BYTES); + for (let i = 0; i < sig.length; i++) { + sig[i] = signedMsg[i]; + } + return encodeBase64(sig) + }; + sign(msg:string) { return Promise.resolve(this.signSync(msg)) } signSync(msg:string) { const m = decodeUTF8(msg); - const signedMsg = naclBinding.sign(m, this.rawSec()); + const signedMsg = nacl.sign(m, this.rawSec()); const sig = new Uint8Array(crypto_sign_BYTES); for (let i = 0; i < sig.length; i++) { sig[i] = signedMsg[i]; @@ -85,7 +99,7 @@ export function KeyGen(pub:string, sec:string) { * Verify a signature against data & public key. * Return true of false as callback argument. */ -export function verify(rawMsg:string, rawSig:string, rawPub:string) { +export function verifyBuggy(rawMsg:string, rawSig:string, rawPub:string) { const msg = decodeUTF8(rawMsg); const sig = decodeBase64(rawSig); const pub = Base58decode(rawPub); @@ -98,3 +112,16 @@ export function verify(rawMsg:string, rawSig:string, rawPub:string) { // Call to verification lib... return naclBinding.verify(m, sm, pub); } + +/** + * Verify a signature against data & public key. + * Return true of false as callback argument. + */ +export function verify(rawMsg:string, rawSig:string, rawPub:string) { + const msg = decodeUTF8(rawMsg); + const sig = decodeBase64(rawSig); + const pub = Base58decode(rawPub); + + // Call to verification lib... + return nacl.sign.detached.verify(msg, sig, pub); +} diff --git a/app/lib/computation/BlockchainContext.ts b/app/lib/computation/BlockchainContext.ts index 015a9047eb3836a420160ee826c4c75e369ced81..899b4b266336e9763a6ec2bc0f87654c3b71af71 100644 --- a/app/lib/computation/BlockchainContext.ts +++ b/app/lib/computation/BlockchainContext.ts @@ -53,7 +53,7 @@ export class BlockchainContext { // But if no HEAD_1 exist, we must initialize a block with default values if (!this.vHEAD_1) { block = { - version: constants.BLOCK_GENERATED_VERSION, + version: constants.BLOCK_GENESIS_VERSION, time: Math.round(Date.now() / 1000), powMin: this.conf.powMin || 0, powZeros: 0, diff --git a/app/lib/constants.ts b/app/lib/constants.ts index ee55efaa0229b188d87e50d1018478c667655d12..8e2b5c6bf9f1b4ce8e208dbd3b2adcc827cb1733 100644 --- a/app/lib/constants.ts +++ b/app/lib/constants.ts @@ -99,7 +99,7 @@ module.exports = { PUBLIC_KEY: exact(PUBKEY), DOCUMENTS_VERSION: CommonConstants.DOCUMENTS_VERSION, - BLOCK_GENERATED_VERSION: CommonConstants.BLOCK_GENERATED_VERSION, + BLOCK_GENESIS_VERSION: CommonConstants.BLOCK_GENESIS_VERSION, LAST_VERSION_FOR_TX: 10, TRANSACTION_VERSION: CommonConstants.TRANSACTION_VERSION, diff --git a/app/lib/dto/TransactionDTO.ts b/app/lib/dto/TransactionDTO.ts index 245ac10f32b0863a143842e5ac8119c80d8d9788..64fcd3ed96a1324db9ad7dff5c014e5d80f58332 100644 --- a/app/lib/dto/TransactionDTO.ts +++ b/app/lib/dto/TransactionDTO.ts @@ -13,7 +13,7 @@ import {hashf} from "../common" import {Cloneable} from "./Cloneable" -import {verify} from "../common-libs/crypto/keyring" +import {verify, verifyBuggy} from "../common-libs/crypto/keyring" export interface BaseDTO { base: number @@ -237,7 +237,7 @@ export class TransactionDTO implements Cloneable { } } - getTransactionSigResult() { + getTransactionSigResult(dubp_version: number) { const sigResult = new TxSignatureResultImpl(this.issuers.slice()) let i = 0 const raw = this.getRawTxNoSig() @@ -245,14 +245,19 @@ export class TransactionDTO implements Cloneable { while (matching && i < this.signatures.length) { const sig = this.signatures[i] const pub = this.issuers[i] - sigResult.sigs[i].ok = matching = verify(raw, sig, pub) + if (dubp_version >= 12) { + sigResult.sigs[i].ok = verify(raw, sig, pub) + } else { + sigResult.sigs[i].ok = verifyBuggy(raw, sig, pub) + } + matching = sigResult.sigs[i].ok i++ } return sigResult } - checkSignatures() { - return this.getTransactionSigResult().allMatching + checkSignatures(dubp_version: number) { + return this.getTransactionSigResult(dubp_version).allMatching } static fromJSONObject(obj:any, currency:string = "") { diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts index 1ce20345022e992f6adcdba560c0f517b7086a0a..72377e871226a29aeef88e60116f5b9a7b83fe90 100644 --- a/app/lib/indexer.ts +++ b/app/lib/indexer.ts @@ -18,7 +18,7 @@ import {RevocationDTO} from "./dto/RevocationDTO" import {CertificationDTO} from "./dto/CertificationDTO" import {TransactionDTO} from "./dto/TransactionDTO" import {DBHead} from "./db/DBHead" -import {verify} from "./common-libs/crypto/keyring" +import {verifyBuggy} from "./common-libs/crypto/keyring" import {rawer, txunlock} from "./common-libs/index" import {CommonConstants} from "./common-libs/constants" import {MembershipDTO} from "./dto/MembershipDTO" @@ -2089,7 +2089,7 @@ async function sigCheckRevoke(entry: MindexEntry, dal: FileDAL, currency: string sig: idty.sig, revocation: '' }); - let sigOK = verify(rawRevocation, sig, pubkey); + let sigOK = verifyBuggy(rawRevocation, sig, pubkey); if (!sigOK) { throw Error("Revocation signature must match"); } @@ -2144,7 +2144,7 @@ async function checkCertificationIsValid (block: BlockDTO, cert: CindexEntry, fi buid: buid, sig: '' }) - const verified = verify(raw, cert.sig, cert.issuer); + const verified = verifyBuggy(raw, cert.sig, cert.issuer); if (!verified) { throw constants.ERRORS.WRONG_SIGNATURE_FOR_CERT } @@ -2160,7 +2160,7 @@ function txSourceUnlock(ENTRY:SindexEntry, source:{ conditions: string, written_ const tx = ENTRY.txObj; const unlockParams:string[] = TransactionDTO.unlock2params(ENTRY.unlock || '') const unlocksMetadata:UnlockMetadata = {} - const sigResult = TransactionDTO.fromJSONObject(tx).getTransactionSigResult() + const sigResult = TransactionDTO.fromJSONObject(tx).getTransactionSigResult(HEAD.version) if (!source.conditions) { return false // Unlock fail } diff --git a/app/lib/rules/global_rules.ts b/app/lib/rules/global_rules.ts index 10ee6aca0cee501f60bab2013ae820e0add88ad1..21779706ac242ef610004fd1b321625be956fe19 100644 --- a/app/lib/rules/global_rules.ts +++ b/app/lib/rules/global_rules.ts @@ -16,7 +16,7 @@ import {FileDAL} from "../dal/fileDAL" import {DBBlock} from "../db/DBBlock" import {TransactionDTO, TxSignatureResult} from "../dto/TransactionDTO" import {BlockDTO} from "../dto/BlockDTO" -import {verify} from "../common-libs/crypto/keyring" +import {verifyBuggy} from "../common-libs/crypto/keyring" import {rawer, txunlock} from "../common-libs/index" import {CommonConstants} from "../common-libs/constants" import {IdentityDTO} from "../dto/IdentityDTO" @@ -94,7 +94,7 @@ export const GLOBAL_RULES_FUNCTIONS = { return true; }, - checkSourcesAvailability: async (block:{ transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, findSourceTx:(txHash:string) => Promise<DBTx|null>) => { + checkSourcesAvailability: async (block:{ version: number, transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, findSourceTx:(txHash:string) => Promise<DBTx|null>) => { const txs = block.transactions const current = await dal.getCurrentBlockOrNull(); for (const tx of txs) { @@ -150,7 +150,7 @@ export const GLOBAL_RULES_FUNCTIONS = { unlocksMetadata.elapsedTime = block.medianTime - dbSrc.written_time; } - const sigs = tx.getTransactionSigResult() + const sigs = tx.getTransactionSigResult(block.version) try { if (!txunlock(dbSrc.conditions, unlocksForCondition, sigs, unlocksMetadata)) { @@ -213,13 +213,18 @@ export const GLOBAL_RULES_HELPERS = { checkSingleTransaction: ( tx:TransactionDTO, - block:{ medianTime: number }, + dubp_version: number, + medianTime: number, conf:ConfDTO, dal:FileDAL, - findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability({ - transactions: [tx], - medianTime: block.medianTime - }, conf, dal, findSourceTx), + findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability( + { + version: dubp_version, + transactions: [tx], + medianTime: medianTime + }, + conf, dal, findSourceTx + ), checkTxBlockStamp: async (tx:TransactionDTO, dal:FileDAL) => { const number = parseInt(tx.blockstamp.split('-')[0]) @@ -317,7 +322,7 @@ async function checkCertificationShouldBeValid (block:{ number:number, currency: buid: buid, sig: '' }) - const verified = verify(raw, cert.sig, cert.from); + const verified = verifyBuggy(raw, cert.sig, cert.from); if (!verified) { throw constants.ERRORS.WRONG_SIGNATURE_FOR_CERT } diff --git a/app/lib/rules/local_rules.ts b/app/lib/rules/local_rules.ts index 35ed12a8a1ac1fad33d040cadd9dab3d198cc6ef..ad297305314e69a7c8d09ad1f3f3d913e5d67eaf 100644 --- a/app/lib/rules/local_rules.ts +++ b/app/lib/rules/local_rules.ts @@ -16,7 +16,7 @@ import {ConfDTO} from "../dto/ConfDTO" import {CindexEntry, IndexEntry, Indexer, MindexEntry, SindexEntry} from "../indexer" import {BaseDTO, TransactionDTO} from "../dto/TransactionDTO" import {DBBlock} from "../db/DBBlock" -import {verify} from "../common-libs/crypto/keyring" +import {verify, verifyBuggy} from "../common-libs/crypto/keyring" import {hashf} from "../common" import {CommonConstants} from "../common-libs/constants" import {IdentityDTO} from "../dto/IdentityDTO" @@ -87,8 +87,13 @@ export const LOCAL_RULES_FUNCTIONS = { }, checkBlockSignature: async (block:BlockDTO) => { - if (!verify(block.getSignedPart(), block.signature, block.issuer)) + // Historically, Duniter used a buggy version of TweetNaCl (see #1390) + // Starting with the v12 blocks, Duniter uses a fixed version of TweetNaCl. + if (block.version >= 12 && !verify(block.getSignedPart(), block.signature, block.issuer)) { throw Error('Block\'s signature must match'); + } else if (!verifyBuggy(block.getSignedPart(), block.signature, block.issuer)) { + throw Error('Block\'s signature must match'); + } return true; }, @@ -108,7 +113,7 @@ export const LOCAL_RULES_FUNCTIONS = { while (!wrongSig && i < block.identities.length) { const idty = IdentityDTO.fromInline(block.identities[i]); idty.currency = block.currency; - wrongSig = !verify(idty.rawWithoutSig(), idty.sig, idty.pubkey); + wrongSig = !verifyBuggy(idty.rawWithoutSig(), idty.sig, idty.pubkey); if (wrongSig) { throw Error('Identity\'s signature must match'); } @@ -385,7 +390,7 @@ export const LOCAL_RULES_FUNCTIONS = { const txs = block.transactions // Check rule against each transaction for (const tx of txs) { - if (!tx.checkSignatures()) { + if (!tx.checkSignatures(block.version)) { throw Error('Signature from a transaction must match') } } @@ -439,7 +444,7 @@ function getTransactionDepth(txHash:string, sindex:SindexShortEntry[], localDept } function checkSingleMembershipSignature(ms:any) { - return verify(ms.getRaw(), ms.signature, ms.issuer); + return verifyBuggy(ms.getRaw(), ms.signature, ms.issuer); } function checkBunchOfTransactions(transactions:TransactionDTO[], conf:ConfDTO, medianTime: number, options?:{ dontCareAboutChaining?:boolean }){ @@ -529,7 +534,7 @@ export const LOCAL_RULES_HELPERS = { return !current // 1. We use legacy version - ? constants.BLOCK_GENERATED_VERSION : (async () => { + ? constants.BLOCK_GENESIS_VERSION : (async () => { // 2. If we can, we go to the next version const blocksInFrame = (await dal.getBlocksBetween(current.number - current.issuersFrame + 1, current.number)) @@ -539,8 +544,9 @@ export const LOCAL_RULES_HELPERS = { const nbNoncesWithNextVersionCode = lastNonceOfEachIssuer.filter(nonce => nonce.substr(-11, 3) === '999').length // More than 70% of the computing network converted? Let's go to next version. - if (Math.floor(nbNoncesWithNextVersionCode / uniqIssuersInFrame.length) > 0.6) { - return constants.BLOCK_NEW_GENERATED_VERSION + let propIssuersReadyToJump = nbNoncesWithNextVersionCode / uniqIssuersInFrame.length; + if (propIssuersReadyToJump > 0.7) { + return constants.DUBP_NEXT_VERSION } // Otherwise, we stay on same version diff --git a/app/modules/crawler/lib/req2fwd.ts b/app/modules/crawler/lib/req2fwd.ts index 9e12619dd19e6690346b1dbc22d541a72c6c37f8..113b1e38c0004d3c84b2ce355d15a73793fc9ace 100644 --- a/app/modules/crawler/lib/req2fwd.ts +++ b/app/modules/crawler/lib/req2fwd.ts @@ -12,7 +12,7 @@ // GNU Affero General Public License for more details. import {Contacter} from "./contacter" -import {verify} from "../../../lib/common-libs/crypto/keyring" +import {verifyBuggy} from "../../../lib/common-libs/crypto/keyring" import {rawer} from "../../../lib/common-libs/index" import {HttpRequirements} from "../../bma/lib/dtos" @@ -80,7 +80,7 @@ export const req2fwd = async (requirements: HttpRequirements, toHost:string, toP buid: received.blockstamp }); try { - const chkSig = verify(rawCertNoSig, received.sig, received.from) + const chkSig = verifyBuggy(rawCertNoSig, received.sig, received.from) if (!chkSig) { throw "Wrong signature for certification?!" } diff --git a/app/modules/prover/lib/blockGenerator.ts b/app/modules/prover/lib/blockGenerator.ts index 547ded67434f0b1a16024cabfdb852c85ce401a3..45529c4106eb3dad6fdf60aed8aa4e79e4833f12 100644 --- a/app/modules/prover/lib/blockGenerator.ts +++ b/app/modules/prover/lib/blockGenerator.ts @@ -19,7 +19,7 @@ import {GLOBAL_RULES_HELPERS} from "../../../lib/rules/global_rules" import {LOCAL_RULES_HELPERS} from "../../../lib/rules/local_rules" import {Indexer} from "../../../lib/indexer" import {DBBlock} from "../../../lib/db/DBBlock" -import {verify} from "../../../lib/common-libs/crypto/keyring" +import {verifyBuggy} from "../../../lib/common-libs/crypto/keyring" import {rawer} from "../../../lib/common-libs/index" import {hashf} from "../../../lib/common" import {CommonConstants} from "../../../lib/common-libs/constants" @@ -144,8 +144,8 @@ export class BlockGenerator { const tx = TransactionDTO.fromJSONObject(obj); try { await LOCAL_RULES_HELPERS.checkBunchOfTransactions(passingTxs.concat(tx), this.conf, medianTime, options) - const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 }; - await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, nextBlockWithFakeTimeVariation, this.conf, this.dal, async (txHash:string) => { + const fakeTimeVariation = current.medianTime + 1; + await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, current.version, fakeTimeVariation, this.conf, this.dal, async (txHash:string) => { return Underscore.findWhere(passingTxs, { hash: txHash }) || null }); await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal); @@ -380,7 +380,7 @@ export class BlockGenerator { const idty = IdentityDTO.fromJSONObject(identity); idty.currency = this.conf.currency; const createIdentity = idty.rawWithoutSig(); - const verified = verify(createIdentity, idty.sig, idty.pubkey); + const verified = verifyBuggy(createIdentity, idty.sig, idty.pubkey); if (!verified) { throw constants.ERRORS.IDENTITY_WRONGLY_SIGNED; } @@ -761,7 +761,7 @@ class NextBlockGenerator implements BlockGeneratorInterface { idty_sig: targetIdty.sig, buid: current ? [cert.block_number, targetBlock.hash].join('-') : CommonConstants.SPECIAL_BLOCK, }).getRawUnSigned(); - if (verify(rawCert, certSig, cert.from)) { + if (verifyBuggy(rawCert, certSig, cert.from)) { cert.sig = certSig; let exists = false; if (current) { diff --git a/app/modules/prover/lib/blockProver.ts b/app/modules/prover/lib/blockProver.ts index 9bcdfe74901e2240acc0b183b340b7736eaf00aa..9b3b3953012d311179393d4cbccb1831229d9f45 100644 --- a/app/modules/prover/lib/blockProver.ts +++ b/app/modules/prover/lib/blockProver.ts @@ -163,7 +163,7 @@ export class BlockProver { const remainder = difficulty % 16; const nbZeros = (difficulty - remainder) / 16; const highMark = CommonConstants.PROOF_OF_WORK.UPPER_BOUND[remainder]; - const notifyVersionJumpReady = block.version === 10 && CommonConstants.BLOCK_NEW_GENERATED_VERSION === 11 + const notifyVersionJumpReady: boolean = (block.version + 1) === CommonConstants.DUBP_NEXT_VERSION; return (async () => { diff --git a/app/modules/prover/lib/proof.ts b/app/modules/prover/lib/proof.ts index d01bfb0b68f688e42ddce8769851ffba6d1564a6..1d723da5f768c7661b09c167407d5904949a0982 100644 --- a/app/modules/prover/lib/proof.ts +++ b/app/modules/prover/lib/proof.ts @@ -17,7 +17,7 @@ import {hashf} from "../../../lib/common" import {DBBlock} from "../../../lib/db/DBBlock" import {ConfDTO} from "../../../lib/dto/ConfDTO" import {ProverConstants} from "./constants" -import {KeyGen} from "../../../lib/common-libs/crypto/keyring" +import {KeyGen, verify, verifyBuggy} from "../../../lib/common-libs/crypto/keyring" import {dos2unix} from "../../../lib/common-libs/dos2unix" import {rawer} from "../../../lib/common-libs/index" import {ProcessCpuProfiler} from "../../../ProcessCpuProfiler" @@ -36,7 +36,9 @@ export function createPowWorker() { // By default, we do not prefix the PoW by any number let prefix = 0; - let signatureFunc:any, lastSecret:any, currentCPU = 1; + let sigFuncSaved: (msg:string) => string; + let verifyFuncSaved: (msg:string, sig:string) => boolean; + let lastSecret:any, lastVersion: number, currentCPU:number = 1; process.on('uncaughtException', (err:any) => { console.error(err.stack || Error(err)) @@ -115,21 +117,36 @@ export function createPowWorker() { prefix *= 100 * ProverConstants.NONCE_RANGE } const highMark = stuff.highMark; + + // Define sigFunc + // Use Buggy version for performance reasons let sigFunc = null; - if (signatureFunc && lastSecret === pair.sec) { - sigFunc = signatureFunc; - } - else { + if (sigFuncSaved && lastSecret === pair.sec) { + sigFunc = sigFuncSaved; + } else { lastSecret = pair.sec; - sigFunc = (msg:string) => KeyGen(pair.pub, pair.sec).signSync(msg) + sigFunc = (msg:string) => KeyGen(pair.pub, pair.sec).signSyncBuggy(msg) } - signatureFunc = sigFunc; - let pow = "", sig = "", raw = ""; + // Define verifyFunc + let verifyFunc = null; + if (verifyFuncSaved && lastSecret === pair.sec && lastVersion === block.version) { + verifyFunc = verifyFuncSaved; + } else { + lastSecret = pair.sec; + lastVersion = block.version; + if (block.version >= 12) { + verifyFunc = (msg:string, sig:string) => verify(msg, sig, pair.pub) + } else { + verifyFunc = (msg:string, sig:string) => verifyBuggy(msg, sig, pair.pub) + } + } + /***************** * GO! ****************/ - + + let pow = "", sig = "", raw = ""; let pausePeriod = 1; let testsCount = 0; let found = false; @@ -195,6 +212,12 @@ export function createPowWorker() { } if (charOK) { found = !!(pow[nbZeros].match(new RegExp('[0-' + highMark + ']'))) + if (found) { + let sigOk = verifyFunc(raw, sig); + if (!sigOk) { + found = false; + } + } } if (!found && nbZeros > 0 && j - 1 >= ProverConstants.POW_MINIMAL_TO_SHOW) { pSend({ pow: { pow: pow, block: block, nbZeros: nbZeros }}); diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 0ffe1fb9baab48380d5a0526b349a9707cc1a993..b5eced67809cd26869d0edaccdeb725008fd2ab1 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -24,7 +24,7 @@ import {WS2PConstants} from "./constants" import {PeerDTO, WS2PEndpoint} from '../../../lib/dto/PeerDTO'; import {GlobalFifoPromise} from "../../../service/GlobalFifoPromise" import {OtherConstants} from "../../../lib/other_constants" -import {Key, verify} from "../../../lib/common-libs/crypto/keyring" +import {Key, verifyBuggy} from "../../../lib/common-libs/crypto/keyring" import {WS2PServerMessageHandler} from "./interface/WS2PServerMessageHandler" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import {CommonConstants} from '../../../lib/common-libs/constants'; @@ -208,8 +208,8 @@ export class WS2PCluster { ) { const head:WS2PHead = { message: h.message, sig: h.sig, messageV2: h.messageV2, sigV2: h.sigV2, step: h.step } - const sigOK = verify(head.message, head.sig, pub) - const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false + const sigOK = verifyBuggy(head.message, head.sig, pub) + const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verifyBuggy(head.messageV2, head.sigV2, pub):false if ((sigV2OK && sigOK) || sigOK) { // Already known or more recent or closer ? const step = (this.headsCache[fullId]) ? this.headsCache[fullId].step || 0:0 @@ -605,9 +605,9 @@ export class WS2PCluster { const prefix = this.server.conf.prefix || ProverConstants.DEFAULT_PEER_ID const { freeMemberRoom , freeMirorRoom } = await this.countFreeRooms() const message = `${api}:HEAD:1:${key.publicKey}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` - const sig = key.signSync(message) + const sig = key.signSyncBuggy(message) const messageV2 = `${api}:HEAD:2:${key.publicKey}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}:${freeMemberRoom}:${freeMirorRoom}` - const sigV2 = key.signSync(messageV2) + const sigV2 = key.signSyncBuggy(messageV2) const myHead:WS2PHead = { message, diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index acb39587474fdc5c5fde2ea391de9b21a79ee27c..cde3a4ae6e07c75b53c64ba9daea508fe4ebcb6c 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -import {Key, verify} from "../../../lib/common-libs/crypto/keyring" +import {Key, verifyBuggy} from "../../../lib/common-libs/crypto/keyring" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import {BlockDTO} from "../../../lib/dto/BlockDTO" import {IdentityDTO} from "../../../lib/dto/IdentityDTO" @@ -129,7 +129,7 @@ export class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { async sendACK(ws: any): Promise<void> { const challengeMessage = `WS2P:ACK:${this.currency}:${this.pair.pub}:${this.challenge}` Logger.log('sendACK >>> ' + challengeMessage) - const sig = this.pair.signSync(challengeMessage) + const sig = this.pair.signSyncBuggy(challengeMessage) await ws.send(JSON.stringify({ auth: 'ACK', pub: this.pair.pub, @@ -153,7 +153,7 @@ export class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { this.givenCurrency.resolve(this.currency) const challengeMessage = (ws2pVersion > 1) ? `WS2P:${type}:${this.currency}:${pub}:${ws2pId}:${challenge}`:`WS2P:${type}:${this.currency}:${pub}:${challenge}` Logger.log('registerCONNECT >>> ' + challengeMessage) - const verified = verify(challengeMessage, sig, pub) + const verified = verifyBuggy(challengeMessage, sig, pub) if (verified) { this.remoteVersion = ws2pVersion this.challenge = challenge @@ -166,7 +166,7 @@ export class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { async registerOK(sig: string): Promise<boolean> { const challengeMessage = `WS2P:OK:${this.currency}:${this.remotePub}:${this.challenge}` Logger.log('registerOK >>> ' + challengeMessage) - this.authenticatedByRemote = verify(challengeMessage, sig, this.remotePub) + this.authenticatedByRemote = verifyBuggy(challengeMessage, sig, this.remotePub) if (!this.authenticatedByRemote) { this.serverAuthReject("Wrong signature from remote OK") } else { @@ -215,7 +215,7 @@ export class WS2PPubkeyLocalAuth implements WS2PLocalAuth { if (ws2pVersion > 1) { const challengeMessage = `WS2P:${ws2pVersion}:${connectWord}:${this.currency}:${this.pair.pub}:${this.ws2pId}:${this.challenge}` Logger.log('sendCONNECT >>> ' + challengeMessage) - const sig = this.pair.signSync(challengeMessage) + const sig = this.pair.signSyncBuggy(challengeMessage) await ws.send(JSON.stringify({ auth: `${connectWord}`, version: ws2pVersion, @@ -229,7 +229,7 @@ export class WS2PPubkeyLocalAuth implements WS2PLocalAuth { } else if (ws2pVersion == 1) { const challengeMessage = `WS2P:${connectWord}:${this.currency}:${this.pair.pub}:${this.challenge}` Logger.log('sendCONNECT >>> ' + challengeMessage) - const sig = this.pair.signSync(challengeMessage) + const sig = this.pair.signSyncBuggy(challengeMessage) await ws.send(JSON.stringify({ auth: `${connectWord}`, pub: this.pair.pub, @@ -248,7 +248,7 @@ export class WS2PPubkeyLocalAuth implements WS2PLocalAuth { } const challengeMessage = `WS2P:ACK:${this.currency}:${pub}:${this.challenge}` Logger.log('registerACK >>> ' + challengeMessage) - this.authenticated = verify(challengeMessage, sig, pub) + this.authenticated = verifyBuggy(challengeMessage, sig, pub) if (!this.authenticated) { this.serverAuthReject("Wrong signature from server ACK") } else { @@ -260,7 +260,7 @@ export class WS2PPubkeyLocalAuth implements WS2PLocalAuth { async sendOK(ws:any): Promise<void> { const challengeMessage = `WS2P:OK:${this.currency}:${this.pair.pub}:${this.challenge}` Logger.log('sendOK >>> ' + challengeMessage) - const sig = this.pair.signSync(challengeMessage) + const sig = this.pair.signSyncBuggy(challengeMessage) await ws.send(JSON.stringify({ auth: 'OK', sig diff --git a/app/service/IdentityService.ts b/app/service/IdentityService.ts index db27bbf8a6faa57fb0be151af85ceb843662658e..7f16a34fcd6913d82d95751dda4f81a1e56a4545 100644 --- a/app/service/IdentityService.ts +++ b/app/service/IdentityService.ts @@ -21,7 +21,7 @@ import {RevocationDTO} from "../lib/dto/RevocationDTO" import {BasicIdentity, IdentityDTO} from "../lib/dto/IdentityDTO" import {CertificationDTO} from "../lib/dto/CertificationDTO" import {DBCert} from "../lib/dal/sqliteDAL/CertDAL" -import {verify} from "../lib/common-libs/crypto/keyring" +import {verifyBuggy} from "../lib/common-libs/crypto/keyring" import {FIFOService} from "./FIFOService" import {MindexEntry} from "../lib/indexer" import {DataErrors} from "../lib/common-libs/errors" @@ -121,7 +121,7 @@ export class IdentityService extends FIFOService { this.logger.info('⬇ IDTY %s %s', idty.pubkey, idty.uid); try { // Check signature's validity - let verified = verify(createIdentity, idty.sig, idty.pubkey); + let verified = verifyBuggy(createIdentity, idty.sig, idty.pubkey); if (!verified) { throw constants.ERRORS.SIGNATURE_DOES_NOT_MATCH; } @@ -149,7 +149,7 @@ export class IdentityService extends FIFOService { } toSave.expires_on = basedBlock.medianTime + this.conf.idtyWindow; } - await GLOBAL_RULES_FUNCTIONS.checkIdentitiesAreWritable({ identities: [idtyObj.inline()], version: (current && current.version) || constants.BLOCK_GENERATED_VERSION }, this.conf, this.dal); + await GLOBAL_RULES_FUNCTIONS.checkIdentitiesAreWritable({ identities: [idtyObj.inline()], version: (current && current.version) || constants.BLOCK_GENESIS_VERSION }, this.conf, this.dal); if (byAbsorption !== BY_ABSORPTION) { if (!(await this.dal.idtyDAL.sandbox.acceptNewSandBoxEntry({ certsCount: 0, @@ -271,7 +271,7 @@ export class IdentityService extends FIFOService { return this.pushFIFO<RevocationDTO>(hash, async () => { try { this.logger.info('⬇ REVOCATION %s %s', revoc.pubkey, revoc.idty_uid); - let verified = verify(raw, revoc.revocation, revoc.pubkey); + let verified = verifyBuggy(raw, revoc.revocation, revoc.pubkey); if (!verified) { throw 'Wrong signature for revocation'; } diff --git a/app/service/PeeringService.ts b/app/service/PeeringService.ts index ef7d82c8b82e96348cfa1b73a378d1d92b5a4396..ef5972183524a127cf935730fe787d92399d8687 100755 --- a/app/service/PeeringService.ts +++ b/app/service/PeeringService.ts @@ -16,7 +16,7 @@ import {FileDAL} from "../lib/dal/fileDAL" import {DBBlock} from "../lib/db/DBBlock" import {Multicaster} from "../lib/streams/multicaster" import {PeerDTO} from "../lib/dto/PeerDTO" -import {verify} from "../lib/common-libs/crypto/keyring" +import {verifyBuggy} from "../lib/common-libs/crypto/keyring" import {dos2unix} from "../lib/common-libs/dos2unix" import {rawer} from "../lib/common-libs/index" import {Server} from "../../server" @@ -82,7 +82,7 @@ export class PeeringService { const raw = rawer.getPeerWithoutSignature(p); const sig = p.signature; const pub = p.pubkey; - const signaturesMatching = verify(raw, sig, pub); + const signaturesMatching = verifyBuggy(raw, sig, pub); return !!signaturesMatching; }; diff --git a/app/service/TransactionsService.ts b/app/service/TransactionsService.ts index 489ed660e1aaf794f3324cf60a3dab2045350bc5..a343b625b13e6756e365b1ed7e422ea0bad7cdaf 100644 --- a/app/service/TransactionsService.ts +++ b/app/service/TransactionsService.ts @@ -54,11 +54,11 @@ export class TransactionService extends FIFOService { throw constants.ERRORS.TX_ALREADY_PROCESSED; } // Start checks... - const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 }; + const fakeTimeVariation = current.medianTime + 1; const dto = TransactionDTO.fromJSONObject(tx) await LOCAL_RULES_HELPERS.checkSingleTransactionLocally(dto, this.conf) await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal); - await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, nextBlockWithFakeTimeVariation, this.conf, this.dal, this.dal.getTxByHash.bind(this.dal)); + await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, current.version, fakeTimeVariation, this.conf, this.dal, this.dal.getTxByHash.bind(this.dal)); const server_pubkey = this.conf.pair && this.conf.pair.pub; if (!(await this.dal.txsDAL.sandbox.acceptNewSandBoxEntry({ issuers: tx.issuers, diff --git a/package.json b/package.json index ce0f583139dd94aba11cfba55de4a3c59c7ef0c9..9454e92fd09e249ad08ca69126c60a0363348f56 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "socks-proxy-agent": "4.0.2", "sqlite3": "3.1.13", "tail": "^2.0.2", - "tweetnacl": "0.14.3", + "tweetnacl": "^1.0.1", "typedoc": "^0.11.1", "underscore": "1.8.3", "unzip": "0.1.11", diff --git a/test/dal/basic-dal-tests.ts b/test/dal/basic-dal-tests.ts index 6b578f7d5ca597ed18ffa22d0023605dce018d23..3692640125fed0f48cdd96f1cb9945fd1985a809 100644 --- a/test/dal/basic-dal-tests.ts +++ b/test/dal/basic-dal-tests.ts @@ -34,7 +34,7 @@ var mocks = { block0: { "hash" : "00063EB6E83F8717CEF1D25B3E2EE308374A14B1", "signature" : "+78w7251vvRdhoIJ6IWHEiEOLxNrmfQf45Y5sYvPdnAdXkVpO1unMV5YA/G5Vhphyz1dICrbeKCPM5qbFsoWAQ==", - "version" : constants.BLOCK_GENERATED_VERSION, + "version" : constants.BLOCK_GENESIS_VERSION, "currency" : "meta_brouzouf", "issuer" : "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", "parameters" : "0.1:86400:100:604800:2629800:3:3:2629800:3:11:600:20:144:0.67", diff --git a/test/fast/crypto/crypto.ts b/test/fast/crypto/crypto.ts index c494a67f98005093b4236a307ecab6d123c3956c..d35f9ea3ec77a5dd9d256d0425b2e905b41eb108 100644 --- a/test/fast/crypto/crypto.ts +++ b/test/fast/crypto/crypto.ts @@ -14,7 +14,7 @@ "use strict"; import {Base58decode, Base58encode} from "../../../app/lib/common-libs/crypto/base58" import {decodeBase64, encodeBase64} from "../../../app/lib/common-libs/crypto/nacl-util" -import {KeyGen, verify} from "../../../app/lib/common-libs/crypto/keyring" +import {KeyGen, verify, verifyBuggy} from "../../../app/lib/common-libs/crypto/keyring" const should = require('should'); @@ -46,16 +46,16 @@ describe('ed25519 tests:', function(){ it('good signature from generated key should be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(rawPub, rawSec).signSync(msg); - const verified = verify(msg, sig, rawPub); + const sig = KeyGen(rawPub, rawSec).signSyncBuggy(msg); + const verified = verifyBuggy(msg, sig, rawPub); verified.should.equal(true); done(); }); it('wrong signature from generated key should NOT be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(rawPub, rawSec).signSync(msg); - const verified = verify(msg + 'delta', sig, rawPub); + const sig = KeyGen(rawPub, rawSec).signSyncBuggy(msg); + const verified = verifyBuggy(msg + 'delta', sig, rawPub); verified.should.equal(false); done(); }); @@ -68,7 +68,7 @@ describe('ed25519 tests:', function(){ "Block: 33291-0000088375C232A4DDAE171BB3D3C51347CB6DC8B7AA8BE4CD4DAEEADF26FEB8\n" + "Endpoints:\n" + "BASIC_MERKLED_API g1.duniter.org 10901\n" - const verified = verify(msg, "u8t1IoWrB/C7T+2rS0rKYJfjPG4FN/HkKGFiUO5tILIzjFDvxxQiVC+0o/Vaz805SMmqJvXqornI71U7//+wCg==", "3AF7bhGQRt6ymcBZgZTBMoDsEtSwruSarjNG8kDnaueX"); + const verified = verifyBuggy(msg, "u8t1IoWrB/C7T+2rS0rKYJfjPG4FN/HkKGFiUO5tILIzjFDvxxQiVC+0o/Vaz805SMmqJvXqornI71U7//+wCg==", "3AF7bhGQRt6ymcBZgZTBMoDsEtSwruSarjNG8kDnaueX"); verified.should.equal(true); done(); }); @@ -82,7 +82,39 @@ describe('ed25519 tests:', function(){ "Endpoints:\n" + "BASIC_MERKLED_API g1.duniter.tednet.fr 37.187.0.204 8999\n" + "BMAS g1.duniter.tednet.fr 9000\n" - const verified = verify(msg, "ImvQDdpGv2M6CxSnBuseM/azJhBUGzWVgQhIvb5L2oGLm2GyLk/Sbi5wkb4IjbjbQfdRPdlcx5zxaHhvZCiWAA==", "Com8rJukCozHZyFao6AheSsfDQdPApxQRnz7QYFf64mm"); + const verified = verifyBuggy(msg, "ImvQDdpGv2M6CxSnBuseM/azJhBUGzWVgQhIvb5L2oGLm2GyLk/Sbi5wkb4IjbjbQfdRPdlcx5zxaHhvZCiWAA==", "Com8rJukCozHZyFao6AheSsfDQdPApxQRnz7QYFf64mm"); + verified.should.equal(true); + done(); + }); + + it('wrong block signature due to oldest tweetnacl should be verified with verifyBuggy', function(done){ + const msg = "InnerHash: 8B194B5C38CF0A38D16256405AC3E5FA5C2ABD26BE4DCC0C7ED5CC9824E6155B\nNonce: 30400000119992\n"; + const rawSig = "fJusVDRJA8akPse/sv4uK8ekUuvTGj1OoKYVdMQQAACs7OawDfpsV6cEMPcXxrQTCTRMrTN/rRrl20hN5zC9DQ=="; + const verified = verifyBuggy(msg, rawSig, "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx"); + verified.should.equal(true); + done(); + }); + + it('wrong block signature due to oldest tweetnacl should NOT be verified with verify', function(done){ + const msg = "InnerHash: 8B194B5C38CF0A38D16256405AC3E5FA5C2ABD26BE4DCC0C7ED5CC9824E6155B\nNonce: 30400000119992\n"; + const rawSig = "fJusVDRJA8akPse/sv4uK8ekUuvTGj1OoKYVdMQQAACs7OawDfpsV6cEMPcXxrQTCTRMrTN/rRrl20hN5zC9DQ=="; + const verified = verify(msg, rawSig, "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx"); + verified.should.equal(false); + done(); + }); + + it('rectified block signature should be NOT verified with verifyBuggy', function(done){ + const msg = "InnerHash: 8B194B5C38CF0A38D16256405AC3E5FA5C2ABD26BE4DCC0C7ED5CC9824E6155B\nNonce: 30400000119992\n"; + const rawSig = "aZusVDRJA8akPse/sv4uK8ekUuvTGj1OoKYVdMQQ/3+VMaDJ02I795GBBaLgjypZFEKYlPMssJMn/X+F/pxgAw=="; + const verified = verifyBuggy(msg, rawSig, "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx"); + verified.should.equal(false); + done(); + }); + + it('rectified block signature should be verified with verify', function(done){ + const msg = "InnerHash: 8B194B5C38CF0A38D16256405AC3E5FA5C2ABD26BE4DCC0C7ED5CC9824E6155B\nNonce: 30400000119992\n"; + const rawSig = "aZusVDRJA8akPse/sv4uK8ekUuvTGj1OoKYVdMQQ/3+VMaDJ02I795GBBaLgjypZFEKYlPMssJMn/X+F/pxgAw=="; + const verified = verify(msg, rawSig, "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx"); verified.should.equal(true); done(); }); diff --git a/test/fast/crypto/randomKey.ts b/test/fast/crypto/randomKey.ts index c3a64cc91ee1bf6be035b63835a337da17bd03f1..6ad90ed9c50458a6fb8be6dd0edb59e38f107ec1 100644 --- a/test/fast/crypto/randomKey.ts +++ b/test/fast/crypto/randomKey.ts @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -import {Key, KeyGen, randomKey, verify} from "../../../app/lib/common-libs/crypto/keyring" +import {Key, KeyGen, randomKey, verifyBuggy} from "../../../app/lib/common-libs/crypto/keyring" const should = require('should'); @@ -26,16 +26,16 @@ describe('Random keypair', function(){ it('good signature from generated key should be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(key.publicKey, key.secretKey).signSync(msg); - const verified = verify(msg, sig, key.publicKey); + const sig = KeyGen(key.publicKey, key.secretKey).signSyncBuggy(msg); + const verified = verifyBuggy(msg, sig, key.publicKey); verified.should.equal(true); done(); }); it('wrong signature from generated key should NOT be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(key.publicKey, key.secretKey).signSync(msg); - const verified = verify(msg + 'delta', sig, key.publicKey); + const sig = KeyGen(key.publicKey, key.secretKey).signSyncBuggy(msg); + const verified = verifyBuggy(msg + 'delta', sig, key.publicKey); verified.should.equal(false); done(); }); diff --git a/test/fast/modules/common/common-crypto-test.ts b/test/fast/modules/common/common-crypto-test.ts index 092e8d1cbe3d2c3267f2952ce961815848176cdc..ddea8be7ca301b69c64b3e6f26d4812863c075c9 100644 --- a/test/fast/modules/common/common-crypto-test.ts +++ b/test/fast/modules/common/common-crypto-test.ts @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -import {KeyGen, verify} from "../../../../app/lib/common-libs/crypto/keyring" +import {KeyGen, verifyBuggy} from "../../../../app/lib/common-libs/crypto/keyring" import {Base58decode, Base58encode} from "../../../../app/lib/common-libs/crypto/base58" const should = require('should'); @@ -41,16 +41,16 @@ describe('ed25519 tests:', function(){ it('good signature from generated key should be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(rawPub, rawSec).signSync(msg); - const verified = verify(msg, sig, rawPub); + const sig = KeyGen(rawPub, rawSec).signSyncBuggy(msg); + const verified = verifyBuggy(msg, sig, rawPub); verified.should.equal(true); done(); }); it('wrong signature from generated key should NOT be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(rawPub, rawSec).signSync(msg); - const verified = verify(msg + 'delta', sig, rawPub); + const sig = KeyGen(rawPub, rawSec).signSyncBuggy(msg); + const verified = verifyBuggy(msg + 'delta', sig, rawPub); verified.should.equal(false); done(); }); diff --git a/test/fast/modules/common/common-random-key.ts b/test/fast/modules/common/common-random-key.ts index 172154b8d23d52953843b058a6c3343289e8e0b1..7751264debde373b7d347c8c7acb249d94478dcd 100644 --- a/test/fast/modules/common/common-random-key.ts +++ b/test/fast/modules/common/common-random-key.ts @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -import {Key, KeyGen, randomKey, verify} from "../../../../app/lib/common-libs/crypto/keyring" +import {Key, KeyGen, randomKey, verifyBuggy} from "../../../../app/lib/common-libs/crypto/keyring" const should = require('should'); @@ -26,16 +26,16 @@ describe('Random keypair', function(){ it('good signature from generated key should be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(key.publicKey, key.secretKey).signSync(msg); - const verified = verify(msg, sig, key.publicKey); + const sig = KeyGen(key.publicKey, key.secretKey).signSyncBuggy(msg); + const verified = verifyBuggy(msg, sig, key.publicKey); verified.should.equal(true); done(); }); it('wrong signature from generated key should NOT be verified', function(done){ const msg = "Some message to be signed"; - const sig = KeyGen(key.publicKey, key.secretKey).signSync(msg); - const verified = verify(msg + 'delta', sig, key.publicKey); + const sig = KeyGen(key.publicKey, key.secretKey).signSyncBuggy(msg); + const verified = verifyBuggy(msg + 'delta', sig, key.publicKey); verified.should.equal(false); done(); }); diff --git a/test/fast/prover/prover-pow-1-cluster.ts b/test/fast/prover/prover-pow-1-cluster.ts index da63563cc5003612d28ba12f729bb10556307752..ea00618c0ebb3e204810328e60656546d16fef45 100644 --- a/test/fast/prover/prover-pow-1-cluster.ts +++ b/test/fast/prover/prover-pow-1-cluster.ts @@ -62,7 +62,7 @@ describe('PoW Cluster', () => { master.nbWorkers.should.above(0) }) - it('should answer within 50ms for a basic PoW (warm)', async () => { + it('should answer within 100ms for a basic PoW (warm)', async () => { const start = Date.now() await master.proveByWorkers({ newPoW: { @@ -85,7 +85,7 @@ describe('PoW Cluster', () => { } }) const delay = Date.now() - start - delay.should.be.below(50) + delay.should.be.below(100) }) it('should be able to stop all the cores on cancel', async () => { diff --git a/test/integration/branches/branches_revert2.ts b/test/integration/branches/branches_revert2.ts index 78748f5e75eeedd5bddbc7036954b9ef1d3f2199..e1f1010b8256da2a61ab7a627826c5ac2eb129de 100644 --- a/test/integration/branches/branches_revert2.ts +++ b/test/integration/branches/branches_revert2.ts @@ -43,7 +43,7 @@ describe("Revert two blocks", function() { before(async () => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 s1 = NewTestingServer( Underscore.extend({ @@ -291,6 +291,6 @@ describe("Revert two blocks", function() { }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) }); diff --git a/test/integration/certification/certification-expiry.ts b/test/integration/certification/certification-expiry.ts index 0ea21e8069dbc29ff57df93a1355eb3a4422bad8..3c24878b4b8308177d0e63fd146882d97613022c 100644 --- a/test/integration/certification/certification-expiry.ts +++ b/test/integration/certification/certification-expiry.ts @@ -21,7 +21,7 @@ describe('Certification expiry + trimming', () => writeBasicTestWithConfAnd2User }, (test) => { before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 }) const now = 1500000000 @@ -109,6 +109,6 @@ describe('Certification expiry + trimming', () => writeBasicTestWithConfAnd2User }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) })) diff --git a/test/integration/certification/certification-replay.ts b/test/integration/certification/certification-replay.ts index 88ddce86fe94b0ae3a20bda300ecf305a19e41b5..f67a69358ddbc6d274dd8123ff8a97a16060690a 100644 --- a/test/integration/certification/certification-replay.ts +++ b/test/integration/certification/certification-replay.ts @@ -23,7 +23,7 @@ describe('Certification replay', () => writeBasicTestWithConfAnd2Users({ }, (test) => { before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 }) const now = 1500000000 @@ -126,6 +126,6 @@ describe('Certification replay', () => writeBasicTestWithConfAnd2Users({ }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) })) diff --git a/test/integration/fork-resolution/block-with-comebacker-revert.ts b/test/integration/fork-resolution/block-with-comebacker-revert.ts index d88d1613068db92a98b0560a1f86f9b6bc6939b7..ac08ff55c97707ad7c522750c444e54668f3ed72 100644 --- a/test/integration/fork-resolution/block-with-comebacker-revert.ts +++ b/test/integration/fork-resolution/block-with-comebacker-revert.ts @@ -14,7 +14,7 @@ import {assertEqual, writeBasicTestWithConfAnd2Users} from "../tools/test-framework" import {CommonConstants} from "../../../app/lib/common-libs/constants" -const currentVersion = CommonConstants.BLOCK_GENERATED_VERSION +const currentVersion = CommonConstants.BLOCK_GENESIS_VERSION describe('Block revert with a comebacker in it', () => writeBasicTestWithConfAnd2Users({ sigQty: 2, @@ -28,7 +28,7 @@ describe('Block revert with a comebacker in it', () => writeBasicTestWithConfAnd const now = 1500000000 test('(t = 0) should init with a 4 members WoT with bidirectionnal certs', async (s1, cat, tac, toc) => { - CommonConstants.BLOCK_GENERATED_VERSION = 11 + CommonConstants.BLOCK_GENESIS_VERSION = 11 await cat.createIdentity() await tac.createIdentity() await toc.createIdentity() @@ -111,7 +111,7 @@ describe('Block revert with a comebacker in it', () => writeBasicTestWithConfAnd }) after(() => { - CommonConstants.BLOCK_GENERATED_VERSION = currentVersion + CommonConstants.BLOCK_GENESIS_VERSION = currentVersion }) })) diff --git a/test/integration/fork-resolution/register-fork-blocks.ts b/test/integration/fork-resolution/register-fork-blocks.ts index f74d1d9c10a5f00faafc3e8a8a4c423896759253..d448373d5f28797f5bb7148e6dbf79d604aed692 100644 --- a/test/integration/fork-resolution/register-fork-blocks.ts +++ b/test/integration/fork-resolution/register-fork-blocks.ts @@ -28,7 +28,7 @@ describe("Fork blocks", function() { before(async () => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 s1 = NewTestingServer({ @@ -235,6 +235,6 @@ describe("Fork blocks", function() { }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 10 }) }) diff --git a/test/integration/membership_chainability.ts b/test/integration/membership_chainability.ts index 458f30349d4305c079e34e1a56ca9868091a6c46..bf93672302c7cc8b62160dc37db536341e74eeea 100644 --- a/test/integration/membership_chainability.ts +++ b/test/integration/membership_chainability.ts @@ -35,18 +35,18 @@ describe("Membership chainability", function() { const res1 = await simpleNodeWith2Users(conf) s1 = res1.s1 cat = res1.cat - const nowVersion = CommonConstants.BLOCK_NEW_GENERATED_VERSION - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + const nowVersion = CommonConstants.DUBP_NEXT_VERSION + CommonConstants.DUBP_NEXT_VERSION = 10 await s1.commit({ time: now }) await s1.commit({ time: now }) await s1.commit({ time: now, actives: [ 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:rppB5NEwmdMUCxw3N/QPMk+V1h2Jpn0yxTzdO2xxcNN3MACv6x8vNTChWwM6DOq+kXiQHTczFzoux+82WkMfDQ==:1-12D7B9BEBE941F6929A4A61CDC06DEEEFCB00FD1DA72E42FFF7B19A338D421E1:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cat' ]}) - CommonConstants.BLOCK_NEW_GENERATED_VERSION = nowVersion + CommonConstants.DUBP_NEXT_VERSION = nowVersion }) before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 }) it('current should be the 2nd', () => s1.expect('/blockchain/current', (res:any) => { @@ -55,7 +55,7 @@ describe("Membership chainability", function() { })) before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) after(async () => { diff --git a/test/integration/protocol-version-jump.ts b/test/integration/protocol-version-jump.ts new file mode 100644 index 0000000000000000000000000000000000000000..01d006875d8443d7310f8c6ff24002b5a5299457 --- /dev/null +++ b/test/integration/protocol-version-jump.ts @@ -0,0 +1,205 @@ +// Source file from duniter: Crypto-currency software to manage libre currency such as Ğ1 +// Copyright (C) 2018 Cedric Moreau <cem.moreau@gmail.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +import {NewTestingServer, TestingServer} from "./tools/toolbox" +import {TestUser} from "./tools/TestUser" +import {CommonConstants} from "../../app/lib/common-libs/constants" + +const assert = require('assert'); + +const now = 1500000000 +const forksize = 10 + +let s1:TestingServer, s2:TestingServer, s3:TestingServer, s4:TestingServer, cat1:TestUser, tac1:TestUser, toc1:TestUser, tic1:TestUser + + +describe("protocol version jump", function() { + + before(async () => { + + CommonConstants.BLOCK_GENESIS_VERSION = 11; + CommonConstants.DUBP_NEXT_VERSION = 12; + + s1 = NewTestingServer({ + + // The common conf + nbCores:1, + medianTimeBlocks: 1, + udTime0: now, + udReevalTime0: now, + forksize, + + pair: { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } + }); + + s2 = NewTestingServer({ + + // The common conf + nbCores:1, + medianTimeBlocks: 1, + udTime0: now, + udReevalTime0: now, + forksize, + + pair: { + pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', + sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' + } + }); + + s3 = NewTestingServer({ + + // The common conf + nbCores:1, + medianTimeBlocks: 1, + udTime0: now, + udReevalTime0: now, + forksize, + + pair: { + pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', + sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' + } + }); + + s4 = NewTestingServer({ + + // The common conf + nbCores:1, + medianTimeBlocks: 1, + udTime0: now, + udReevalTime0: now, + forksize, + + pair: { + pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', + sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7' + } + }); + + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc1 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic1 = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + + await s1.prepareForNetwork(); + await s2.prepareForNetwork(); + await s3.prepareForNetwork(); + await s4.prepareForNetwork(); + + // Publishing identities + await cat1.createIdentity(); + await tac1.createIdentity(); + await toc1.createIdentity(); + await tic1.createIdentity(); + await cat1.cert(tac1); + await tac1.cert(cat1); + await tac1.cert(toc1); + await toc1.cert(tic1); + await cat1.join(); + await tac1.join(); + await toc1.join(); + await tic1.join(); + }) + + it('Blockchain before protocol jump', async () => { + // Servers s1 and s2 are in old version + CommonConstants.DUBP_NEXT_VERSION = CommonConstants.BLOCK_GENESIS_VERSION; + const b0 = await s1.commit({ time: now }) + await s2.writeBlock(b0) + await s3.writeBlock(b0) + await s4.writeBlock(b0) + + await s2.waitToHaveBlock(0) + const b1 = await s2.commit({ time: now + 1 }) + await s1.writeBlock(b1) + await s3.writeBlock(b1) + await s4.writeBlock(b1) + + // Servers s3 and s4 are in new version + CommonConstants.DUBP_NEXT_VERSION = CommonConstants.BLOCK_GENESIS_VERSION + 1; + await s3.waitToHaveBlock(1) + const b2 = await s3.commit({ time: now + 2 }) + await s1.writeBlock(b2) + await s2.writeBlock(b2) + await s4.writeBlock(b2) + + await s4.waitToHaveBlock(2) + const b3 = await s4.commit({ time: now + 3 }) + await s1.writeBlock(b3) + await s2.writeBlock(b3) + await s3.writeBlock(b3) + + await s1.waitToHaveBlock(3) + await s2.waitToHaveBlock(3) + await s3.waitToHaveBlock(3) + + // b0 and b1 should not have 999 pattern in their nonce + assert.notEqual('999', b0.nonce.toString().substr(-11, 3)) + assert.notEqual('999', b1.nonce.toString().substr(-11, 3)) + // b2 and b3 should have 999 pattern in their nonce + assert.equal('999', b2.nonce.toString().substr(-11, 3)) + assert.equal('999', b3.nonce.toString().substr(-11, 3)) + + // All blocks should have old version + assert.equal(CommonConstants.BLOCK_GENESIS_VERSION, b0.version) + assert.equal(CommonConstants.BLOCK_GENESIS_VERSION, b1.version) + assert.equal(CommonConstants.BLOCK_GENESIS_VERSION, b2.version) + assert.equal(CommonConstants.BLOCK_GENESIS_VERSION, b3.version) + + }) + + it('s1 upgrade should cause protocol version jump', async () => { + const b4 = await s1.commit({ time: now + 4 }) + await s2.writeBlock(b4) + await s3.writeBlock(b4) + await s4.writeBlock(b4) + await s2.waitToHaveBlock(4) + await s3.waitToHaveBlock(4) + await s4.waitToHaveBlock(4) + + // b4 should have 999 pattern in their nonce + assert.equal('999', b4.nonce.toString().substr(-11, 3)) + + // 75% of the issuers of the current frame have the new version, + // the next block emitted by one of them must perform the protocol version jump. + const b5 = await s1.commit({ time: now + 5 }) + await s2.writeBlock(b5) + await s3.writeBlock(b5) + await s4.writeBlock(b5) + await s2.waitToHaveBlock(5) + await s3.waitToHaveBlock(5) + await s4.waitToHaveBlock(5) + + // b5 should jump to next protocol version + assert.equal(CommonConstants.DUBP_NEXT_VERSION, b5.version) + + // b5 should not have 999 pattern in their nonce + assert.notEqual('999', b5.nonce.toString().substr(-11, 3)) + }); + + after(() => { + CommonConstants.BLOCK_GENESIS_VERSION = 10; + CommonConstants.DUBP_NEXT_VERSION = 11; + return Promise.all([ + s1.closeCluster(), + s2.closeCluster(), + s3.closeCluster(), + s4.closeCluster() + ]) + }) + +}); diff --git a/test/integration/sandbox/expired-certifications.ts b/test/integration/sandbox/expired-certifications.ts index e3af0d5f5925bbfe8673db830a5f3b3147bbb075..5697fefacfb7c7b6eb399e2c1ae494c6f7c80203 100644 --- a/test/integration/sandbox/expired-certifications.ts +++ b/test/integration/sandbox/expired-certifications.ts @@ -24,7 +24,7 @@ describe('Expired certifications', () => writeBasicTestWithConfAnd2Users({ }, (test) => { before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 }) const now = 1500000000 @@ -58,6 +58,6 @@ describe('Expired certifications', () => writeBasicTestWithConfAnd2Users({ }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) })) diff --git a/test/integration/sandbox/expired-identity.ts b/test/integration/sandbox/expired-identity.ts index 5d8af970213a677a3dfd133bdaf5e7bfdb36b5b9..9f0990bfc3421f2bd020771802c6286a957d8eae 100644 --- a/test/integration/sandbox/expired-identity.ts +++ b/test/integration/sandbox/expired-identity.ts @@ -23,7 +23,7 @@ describe('Expired identities', () => writeBasicTestWithConfAnd2Users({ }, (test) => { before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 }) const now = 1500000000 @@ -47,6 +47,6 @@ describe('Expired identities', () => writeBasicTestWithConfAnd2Users({ }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) })) diff --git a/test/integration/sandbox/expired-membership.ts b/test/integration/sandbox/expired-membership.ts index b98ebe3ab1517f805aa27881ea2aefa329581a00..d71a74011053c7f85ddecd34931076ad3aa830a4 100644 --- a/test/integration/sandbox/expired-membership.ts +++ b/test/integration/sandbox/expired-membership.ts @@ -23,7 +23,7 @@ describe('Expired membership', () => writeBasicTestWithConfAnd2Users({ }, (test) => { before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 }) const now = 1500000000 @@ -58,6 +58,6 @@ describe('Expired membership', () => writeBasicTestWithConfAnd2Users({ }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) })) diff --git a/test/integration/sandbox/expired-transactions.ts b/test/integration/sandbox/expired-transactions.ts index fe950d99b375696770b013d6a3cd358e301f9688..2c8cc49bdc4d80e7cdc18be984dff810fa18a831 100644 --- a/test/integration/sandbox/expired-transactions.ts +++ b/test/integration/sandbox/expired-transactions.ts @@ -22,7 +22,7 @@ describe('Expired transactions', () => writeBasicTestWithConfAnd2Users({ let oldTxWindowValue: number before(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 oldTxWindowValue = CommonConstants.TX_WINDOW CommonConstants.TX_WINDOW = 2 // We need a low value to pass time bounds rules }) @@ -48,7 +48,7 @@ describe('Expired transactions', () => writeBasicTestWithConfAnd2Users({ }) after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 CommonConstants.TX_WINDOW = oldTxWindowValue }) })) diff --git a/test/integration/tools/TestUser.ts b/test/integration/tools/TestUser.ts index cf25abe881bb9b9cf0d26129812cb1e5fc171cae..7746b3b01245e743fee601fc5a9e5c03d07439fb 100644 --- a/test/integration/tools/TestUser.ts +++ b/test/integration/tools/TestUser.ts @@ -85,7 +85,7 @@ export class TestUser { issuer: this.pub, currency: this.node.server.conf.currency }).getRawUnSigned() - return this.createdIdentity += KeyGen(this.pub, this.sec).signSync(this.createdIdentity) + '\n' + return this.createdIdentity += KeyGen(this.pub, this.sec).signSyncBuggy(this.createdIdentity) + '\n' } public submitIdentity(raw:string, fromServer?: TestingServer) { @@ -116,7 +116,7 @@ export class TestUser { } Underscore.extend(cert, overrideProps || {}); const rawCert = CertificationDTO.fromJSONObject(cert).getRawUnSigned() - cert.sig = KeyGen(this.pub, this.sec).signSync(rawCert) + cert.sig = KeyGen(this.pub, this.sec).signSyncBuggy(rawCert) return CertificationDTO.fromJSONObject(cert) } @@ -157,7 +157,7 @@ export class TestUser { }; Underscore.extend(revocation, overrideProps || {}); const rawRevocation = RevocationDTO.fromJSONObject(revocation).getRawUnsigned() - revocation.revocation = KeyGen(this.pub, this.sec).signSync(rawRevocation); + revocation.revocation = KeyGen(this.pub, this.sec).signSyncBuggy(rawRevocation); return RevocationDTO.fromJSONObject(revocation) } @@ -185,7 +185,7 @@ export class TestUser { }; Underscore.extend(join, overrideProps || {}); const rawJoin = MembershipDTO.fromJSONObject(join).getRaw() - join.signature = KeyGen(this.pub, this.sec).signSync(rawJoin) + join.signature = KeyGen(this.pub, this.sec).signSyncBuggy(rawJoin) return MembershipDTO.fromJSONObject(join) } @@ -306,9 +306,9 @@ export class TestUser { } private signed(raw:string, user2?:TestUser) { - let signatures = [KeyGen(this.pub, this.sec).signSync(raw)]; + let signatures = [KeyGen(this.pub, this.sec).signSyncBuggy(raw)]; if (user2) { - signatures.push(KeyGen(user2.pub, user2.sec).signSync(raw)); + signatures.push(KeyGen(user2.pub, user2.sec).signSyncBuggy(raw)); } return raw + signatures.join('\n') + '\n'; } @@ -356,7 +356,7 @@ export class TestUser { }); Underscore.extend(peer, overrideProps || {}); const rawPeer = PeerDTO.fromJSONObject(peer).getRawUnsigned() - peer.signature = KeyGen(this.pub, this.sec).signSync(rawPeer) + peer.signature = KeyGen(this.pub, this.sec).signSyncBuggy(rawPeer) return PeerDTO.fromJSONObject(peer) } diff --git a/test/integration/wot/wotb.ts b/test/integration/wot/wotb.ts index b9acfcb24873c5d2f2fcf35c33d0862606ce8ab5..e72ed7cfcfe5053fe967acee993856b97ec03398 100644 --- a/test/integration/wot/wotb.ts +++ b/test/integration/wot/wotb.ts @@ -59,7 +59,7 @@ describe("WOTB module", () => { before(async () => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 11 + CommonConstants.DUBP_NEXT_VERSION = 11 s1 = NewTestingServer( Underscore.extend({ @@ -452,7 +452,7 @@ describe("WOTB module", () => { }); after(() => { - CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 + CommonConstants.DUBP_NEXT_VERSION = 10 }) }); }); diff --git a/test/integration/ws2p/ws2p_connection.ts b/test/integration/ws2p/ws2p_connection.ts index 72c1ebcaa8773ee1f13243df19f53e76f0d86516..3309e0ec4164e735b02a8d1d356b689fa7e004ac 100644 --- a/test/integration/ws2p/ws2p_connection.ts +++ b/test/integration/ws2p/ws2p_connection.ts @@ -18,7 +18,7 @@ import { WS2PPubkeyRemoteAuth, WS2PRemoteAuth } from "../../../app/modules/ws2p/lib/WS2PConnection" -import {Key, verify} from "../../../app/lib/common-libs/crypto/keyring" +import {Key, verifyBuggy} from "../../../app/lib/common-libs/crypto/keyring" import {getNewTestingPort} from "../tools/toolbox" import {WS2PMessageHandler} from "../../../app/modules/ws2p/lib/impl/WS2PMessageHandler" import {WS2PResponse} from "../../../app/modules/ws2p/lib/impl/WS2PResponse" @@ -83,7 +83,7 @@ describe('WS2P', () => { if (obj.auth) { if (nbAsk == 1 || nbAsk == 3) { const challengeMessage = `WS2P:ACK:gtest:${serverKeypair.pub}:${obj.challenge}` - const sig = serverKeypair.signSync(challengeMessage) + const sig = serverKeypair.signSyncBuggy(challengeMessage) if (nbAsk == 1) { ws.send(JSON.stringify({ auth: 'ACK', pub: serverKeypair.pub, sig: 'hiohoihio' })) } @@ -95,7 +95,7 @@ describe('WS2P', () => { // We do like if the key was wrong const clientPub = 'GgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd' const challengeMessage = `WS2P:CONNECT:${clientPub}:${obj.challenge}` - if (!verify(challengeMessage, obj.sig, clientPub)) { + if (!verifyBuggy(challengeMessage, obj.sig, clientPub)) { clientAskError = 'Wrong signature from client CONNECT' } } @@ -332,7 +332,7 @@ describe('WS2P', () => { class WS2PPubkeyAnsweringWithWrongSigForACK extends WS2PPubkeyRemoteAuth { async sendACK(ws: any): Promise<void> { const challengeMessage = `WS2P:WRONG:${this.pair.pub}:${this.challenge}` - const sig = this.pair.signSync(challengeMessage) + const sig = this.pair.signSyncBuggy(challengeMessage) await ws.send(JSON.stringify({ auth: 'ACK', pub: this.pair.pub, @@ -354,7 +354,7 @@ describe('WS2P', () => { async registerACK(sig: string, pub: string): Promise<boolean> { const challengeMessage = `WS2P:BLABLA:${pub}:${this.challenge}` - this.authenticated = verify(challengeMessage, sig, pub) + this.authenticated = verifyBuggy(challengeMessage, sig, pub) if (!this.authenticated) { this.serverAuthReject("Wrong signature from server ACK") } else { diff --git a/yarn.lock b/yarn.lock index 54957fc71fdb458d9ea8631d35a9ba8273cadc20..84058dbbfe12639c9e9aba685f2e5528e4e17436 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4428,14 +4428,15 @@ tunnel-agent@~0.4.0: version "0.4.3" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb" -tweetnacl@0.14.3: - version "0.14.3" - resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.3.tgz#3da382f670f25ded78d7b3d1792119bca0b7132d" - tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" +tweetnacl@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.1.tgz#2594d42da73cd036bd0d2a54683dd35a6b55ca17" + integrity sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A== + type-check@~0.3.1, type-check@~0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"