Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
timothe
duniter
Commits
6ee4ff25
Commit
6ee4ff25
authored
Dec 15, 2019
by
Éloïs
Committed by
Cédric Moreau
Jan 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ref] keyring: add suffix Buggy to functions sign, signSync and verify
parent
3df56aaf
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
73 additions
and
73 deletions
+73
-73
app/lib/common-libs/crypto/keyring.ts
app/lib/common-libs/crypto/keyring.ts
+4
-4
app/lib/dto/TransactionDTO.ts
app/lib/dto/TransactionDTO.ts
+2
-2
app/lib/indexer.ts
app/lib/indexer.ts
+3
-3
app/lib/rules/global_rules.ts
app/lib/rules/global_rules.ts
+2
-2
app/lib/rules/local_rules.ts
app/lib/rules/local_rules.ts
+4
-4
app/modules/crawler/lib/req2fwd.ts
app/modules/crawler/lib/req2fwd.ts
+2
-2
app/modules/prover/lib/blockGenerator.ts
app/modules/prover/lib/blockGenerator.ts
+3
-3
app/modules/prover/lib/proof.ts
app/modules/prover/lib/proof.ts
+1
-1
app/modules/ws2p/lib/WS2PCluster.ts
app/modules/ws2p/lib/WS2PCluster.ts
+5
-5
app/modules/ws2p/lib/WS2PConnection.ts
app/modules/ws2p/lib/WS2PConnection.ts
+8
-8
app/service/IdentityService.ts
app/service/IdentityService.ts
+3
-3
app/service/PeeringService.ts
app/service/PeeringService.ts
+2
-2
test/fast/crypto/crypto.ts
test/fast/crypto/crypto.ts
+7
-7
test/fast/crypto/randomKey.ts
test/fast/crypto/randomKey.ts
+5
-5
test/fast/modules/common/common-crypto-test.ts
test/fast/modules/common/common-crypto-test.ts
+5
-5
test/fast/modules/common/common-random-key.ts
test/fast/modules/common/common-random-key.ts
+5
-5
test/integration/tools/TestUser.ts
test/integration/tools/TestUser.ts
+7
-7
test/integration/ws2p/ws2p_connection.ts
test/integration/ws2p/ws2p_connection.ts
+5
-5
No files found.
app/lib/common-libs/crypto/keyring.ts
View file @
6ee4ff25
...
...
@@ -50,11 +50,11 @@ export class Key {
}
}
sign
(
msg
:
string
)
{
return
Promise
.
resolve
(
this
.
signSync
(
msg
))
sign
Buggy
(
msg
:
string
)
{
return
Promise
.
resolve
(
this
.
signSync
Buggy
(
msg
))
}
signSync
(
msg
:
string
)
{
signSync
Buggy
(
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
verify
Buggy
(
rawMsg
:
string
,
rawSig
:
string
,
rawPub
:
string
)
{
const
msg
=
decodeUTF8
(
rawMsg
);
const
sig
=
decodeBase64
(
rawSig
);
const
pub
=
Base58decode
(
rawPub
);
...
...
app/lib/dto/TransactionDTO.ts
View file @
6ee4ff25
...
...
@@ -13,7 +13,7 @@
import
{
hashf
}
from
"
../common
"
import
{
Cloneable
}
from
"
./Cloneable
"
import
{
verify
}
from
"
../common-libs/crypto/keyring
"
import
{
verify
Buggy
}
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
=
verify
Buggy
(
raw
,
sig
,
pub
)
i
++
}
return
sigResult
...
...
app/lib/indexer.ts
View file @
6ee4ff25
...
...
@@ -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
{
verify
Buggy
}
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
=
verify
Buggy
(
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
=
verify
Buggy
(
raw
,
cert
.
sig
,
cert
.
issuer
);
if
(
!
verified
)
{
throw
constants
.
ERRORS
.
WRONG_SIGNATURE_FOR_CERT
}
...
...
app/lib/rules/global_rules.ts
View file @
6ee4ff25
...
...
@@ -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
{
verify
Buggy
}
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
=
verify
Buggy
(
raw
,
cert
.
sig
,
cert
.
from
);
if
(
!
verified
)
{
throw
constants
.
ERRORS
.
WRONG_SIGNATURE_FOR_CERT
}
...
...
app/lib/rules/local_rules.ts
View file @
6ee4ff25
...
...
@@ -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
Buggy
}
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
(
!
verify
Buggy
(
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
=
!
verify
Buggy
(
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
verify
Buggy
(
ms
.
getRaw
(),
ms
.
signature
,
ms
.
issuer
);
}
function
checkBunchOfTransactions
(
transactions
:
TransactionDTO
[],
conf
:
ConfDTO
,
medianTime
:
number
,
options
?:{
dontCareAboutChaining
?:
boolean
}){
...
...
app/modules/crawler/lib/req2fwd.ts
View file @
6ee4ff25
...
...
@@ -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
{
verify
Buggy
}
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
=
verify
Buggy
(
rawCertNoSig
,
received
.
sig
,
received
.
from
)
if
(
!
chkSig
)
{
throw
"
Wrong signature for certification?!
"
}
...
...
app/modules/prover/lib/blockGenerator.ts
View file @
6ee4ff25
...
...
@@ -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
{
verify
Buggy
}
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
=
verify
Buggy
(
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
(
verify
Buggy
(
rawCert
,
certSig
,
cert
.
from
))
{
cert
.
sig
=
certSig
;
let
exists
=
false
;
if
(
current
)
{
...
...
app/modules/prover/lib/proof.ts
View file @
6ee4ff25
...
...
@@ -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
).
signSync
Buggy
(
msg
)
}
signatureFunc
=
sigFunc
;
let
pow
=
""
,
sig
=
""
,
raw
=
""
;
...
...
app/modules/ws2p/lib/WS2PCluster.ts
View file @
6ee4ff25
...
...
@@ -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
,
verify
Buggy
}
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
=
verify
Buggy
(
head
.
message
,
head
.
sig
,
pub
)
const
sigV2OK
=
(
head
.
messageV2
!==
undefined
&&
head
.
sigV2
!==
undefined
)
?
verify
Buggy
(
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
.
signSync
Buggy
(
message
)
const
messageV2
=
`
${
api
}
:HEAD:2:
${
key
.
publicKey
}
:
${
number
}
-
${
hash
}
:
${
ws2pId
}
:
${
software
}
:
${
softVersion
}
:
${
prefix
}
:
${
freeMemberRoom
}
:
${
freeMirorRoom
}
`
const
sigV2
=
key
.
signSync
(
messageV2
)
const
sigV2
=
key
.
signSync
Buggy
(
messageV2
)
const
myHead
:
WS2PHead
=
{
message
,
...
...
app/modules/ws2p/lib/WS2PConnection.ts
View file @
6ee4ff25
...
...
@@ -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
,
verify
Buggy
}
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
.
signSync
Buggy
(
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
=
verify
Buggy
(
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
=
verify
Buggy
(
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
.
signSync
Buggy
(
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
.
signSync
Buggy
(
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
=
verify
Buggy
(
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
.
signSync
Buggy
(
challengeMessage
)
await
ws
.
send
(
JSON
.
stringify
({
auth
:
'
OK
'
,
sig
...
...
app/service/IdentityService.ts
View file @
6ee4ff25
...
...
@@ -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
{
verify
Buggy
}
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
=
verify
Buggy
(
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
=
verify
Buggy
(
raw
,
revoc
.
revocation
,
revoc
.
pubkey
);
if
(
!
verified
)
{
throw
'
Wrong signature for revocation
'
;
}
...
...
app/service/PeeringService.ts
View file @
6ee4ff25
...
...
@@ -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
{
verify
Buggy
}
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
=
verify
Buggy
(
raw
,
sig
,
pub
);
return
!!
signaturesMatching
;
};
...
...
test/fast/crypto/crypto.ts
View file @
6ee4ff25
...
...
@@ -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
Buggy
}
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
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
=
verify
Buggy
(
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
=
verify
Buggy
(
msg
,
"
ImvQDdpGv2M6CxSnBuseM/azJhBUGzWVgQhIvb5L2oGLm2GyLk/Sbi5wkb4IjbjbQfdRPdlcx5zxaHhvZCiWAA==
"
,
"
Com8rJukCozHZyFao6AheSsfDQdPApxQRnz7QYFf64mm
"
);
verified
.
should
.
equal
(
true
);
done
();
});
...
...
test/fast/crypto/randomKey.ts
View file @
6ee4ff25
...
...
@@ -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
,
verify
Buggy
}
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
msg
+
'
delta
'
,
sig
,
key
.
publicKey
);
verified
.
should
.
equal
(
false
);
done
();
});
...
...
test/fast/modules/common/common-crypto-test.ts
View file @
6ee4ff25
...
...
@@ -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
,
verify
Buggy
}
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
msg
+
'
delta
'
,
sig
,
rawPub
);
verified
.
should
.
equal
(
false
);
done
();
});
...
...
test/fast/modules/common/common-random-key.ts
View file @
6ee4ff25
...
...
@@ -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
,
verify
Buggy
}
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
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
).
signSync
Buggy
(
msg
);
const
verified
=
verify
Buggy
(
msg
+
'
delta
'
,
sig
,
key
.
publicKey
);
verified
.
should
.
equal
(
false
);
done
();
});
...
...
test/integration/tools/TestUser.ts
View file @
6ee4ff25
...
...
@@ -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
).
signSync
Buggy
(
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
).
signSync
Buggy
(
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
).
signSync
Buggy
(
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
).
signSync
Buggy
(
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
).
signSync
Buggy
(
raw
)];
if
(
user2
)
{
signatures
.
push
(
KeyGen
(
user2
.
pub
,
user2
.
sec
).
signSync
(
raw
));
signatures
.
push
(
KeyGen
(
user2
.
pub
,
user2
.
sec
).
signSync
Buggy
(
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
).
signSync
Buggy
(
rawPeer
)
return
PeerDTO
.
fromJSONObject
(
peer
)
}
...
...
test/integration/ws2p/ws2p_connection.ts
View file @
6ee4ff25
...
...
@@ -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
,
verify
Buggy
}
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
.
signSync
Buggy
(
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
(
!
verify
Buggy
(
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
.
signSync
Buggy
(
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
=
verify
Buggy
(
challengeMessage
,
sig
,
pub
)
if
(
!
this
.
authenticated
)
{
this
.
serverAuthReject
(
"
Wrong signature from server ACK
"
)
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment