diff --git a/app/lib/common-libs/crypto/keyring.ts b/app/lib/common-libs/crypto/keyring.ts index 9f9f31e741aa5827d183d22af89ec33d2c7fbf0c..778f2a3ba06d8ca566b21f0d825c938e4c198316 100644 --- a/app/lib/common-libs/crypto/keyring.ts +++ b/app/lib/common-libs/crypto/keyring.ts @@ -50,11 +50,11 @@ export class Key { } } - sign(msg:string) { - return Promise.resolve(this.signSync(msg)) + signBuggy(msg:string) { + return Promise.resolve(this.signSyncBuggy(msg)) } - signSync(msg:string) { + signSyncBuggy(msg:string) { const m = decodeUTF8(msg); const signedMsg = naclBinding.sign(m, this.rawSec()); const sig = new Uint8Array(crypto_sign_BYTES); @@ -85,7 +85,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); diff --git a/app/lib/dto/TransactionDTO.ts b/app/lib/dto/TransactionDTO.ts index 245ac10f32b0863a143842e5ac8119c80d8d9788..aee44796a760b6ca4b362be05e7a2bb47e6dff68 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 {verifyBuggy} from "../common-libs/crypto/keyring" export interface BaseDTO { base: number @@ -245,7 +245,7 @@ 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) + sigResult.sigs[i].ok = matching = verifyBuggy(raw, sig, pub) i++ } return sigResult diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts index 1ce20345022e992f6adcdba560c0f517b7086a0a..8ea092799aea792ae16dcefbf8f7b0cbe715d03b 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 } diff --git a/app/lib/rules/global_rules.ts b/app/lib/rules/global_rules.ts index 10ee6aca0cee501f60bab2013ae820e0add88ad1..4842cd4ee3f363717e3796492022efa08f6d7826 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" @@ -317,7 +317,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 87bcfa9fbc5c7cdecb5060d78c232c15caab407a..64eb5fe4dedc746f3ea03f12124898d2a86ba569 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 {verifyBuggy} from "../common-libs/crypto/keyring" import {hashf} from "../common" import {CommonConstants} from "../common-libs/constants" import {IdentityDTO} from "../dto/IdentityDTO" @@ -87,7 +87,7 @@ export const LOCAL_RULES_FUNCTIONS = { }, checkBlockSignature: async (block:BlockDTO) => { - if (!verify(block.getSignedPart(), block.signature, block.issuer)) + if (!verifyBuggy(block.getSignedPart(), block.signature, block.issuer)) throw Error('Block\'s signature must match'); return true; }, @@ -108,7 +108,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'); } @@ -439,7 +439,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 }){ 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..2d7bba35595c127f7643d257e55d192ae93b2742 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" @@ -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/proof.ts b/app/modules/prover/lib/proof.ts index d01bfb0b68f688e42ddce8769851ffba6d1564a6..34ad316ea224b5bfd1726b605efe6d99cf9829c6 100644 --- a/app/modules/prover/lib/proof.ts +++ b/app/modules/prover/lib/proof.ts @@ -121,7 +121,7 @@ export function createPowWorker() { } 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 = ""; 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 99b1b1d534e9d5db12d81f77217822cffbd87578..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; } @@ -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/test/fast/crypto/crypto.ts b/test/fast/crypto/crypto.ts index c494a67f98005093b4236a307ecab6d123c3956c..61ed80c1339487452eb7a7a102715f41bcac8b2c 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, 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,7 @@ 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(); }); 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/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/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 {