Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
d8894109
Commit
d8894109
authored
10 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
Add gen-updates command
parent
f98339d6
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/models/key.js
+5
-0
5 additions, 0 deletions
app/models/key.js
app/models/publickey.js
+17
-0
17 additions, 0 deletions
app/models/publickey.js
app/service/KeychainService.js
+90
-16
90 additions, 16 deletions
app/service/KeychainService.js
bin/ucoind
+5
-0
5 additions, 0 deletions
bin/ucoind
with
117 additions
and
16 deletions
app/models/key.js
+
5
−
0
View file @
d8894109
...
...
@@ -124,6 +124,11 @@ KeySchema.statics.findMembersWhereSignatory = function(signatory, done){
Key
.
find
({
member
:
true
,
signatories
:
new
RegExp
(
signatory
.
substring
(
24
)
+
'
$
'
)
},
done
);
};
KeySchema
.
statics
.
findMembersWithUpdates
=
function
(
done
){
var
Key
=
this
.
model
(
'
Key
'
);
Key
.
find
({
member
:
true
,
$or
:
[
{
signatories
:
{
$not
:
{
$size
:
0
}}},
{
subkeys
:
{
$not
:
{
$size
:
0
}}}]
},
done
);
};
KeySchema
.
statics
.
addMember
=
function
(
fingerprint
,
done
){
var
Key
=
this
.
model
(
'
Key
'
);
Key
.
update
({
fingerprint
:
fingerprint
},
{
member
:
true
},
function
(
err
)
{
...
...
This diff is collapsed.
Click to expand it.
app/models/publickey.js
+
17
−
0
View file @
d8894109
...
...
@@ -128,6 +128,23 @@ PublicKeySchema.methods = {
if
(
hashedCertifs
[
md5hash
])
{
var
decoded
=
base64
.
decode
(
hashedCertifs
[
md5hash
]);
var
otherList
=
new
openpgp
.
packet
.
List
();
// Should read a 1 packet list (signature)
otherList
.
read
(
decoded
);
packets
.
concat
(
otherList
);
}
});
return
packets
;
},
getSubkeysFromMD5List
:
function
(
md5array
){
var
packets
=
new
openpgp
.
packet
.
List
();
var
key
=
keyhelper
.
fromArmored
(
this
.
raw
);
var
hashedSubkeys
=
key
.
getHashedSubkeyPackets
();
md5array
.
forEach
(
function
(
md5hash
){
if
(
hashedSubkeys
[
md5hash
])
{
var
decoded
=
base64
.
decode
(
hashedSubkeys
[
md5hash
]);
var
otherList
=
new
openpgp
.
packet
.
List
();
// Should read a 2 packets list (subkey + binding signature)
otherList
.
read
(
decoded
);
packets
.
concat
(
otherList
);
}
...
...
This diff is collapsed.
Click to expand it.
app/service/KeychainService.js
+
90
−
16
View file @
d8894109
...
...
@@ -267,8 +267,8 @@ function KeyService (conn, conf, PublicKeyService) {
async
.
parallel
({
certifications
:
function
(
callback
){
// Check certifications
async
.
forEach
(
keyhelper
.
toPacketlist
(
kc
.
certpackets
),
function
(
certif
,
callback2
){
kc
.
certifiers
=
[];
async
.
forEach
(
keyhelper
.
toPacketlist
(
kc
.
certpackets
),
function
(
certif
,
callback2
){
async
.
waterfall
([
function
(
next
){
checkCertificationOfKey
(
certif
,
kc
.
fingerprint
,
newKeys
,
next
);
...
...
@@ -330,8 +330,8 @@ function KeyService (conn, conf, PublicKeyService) {
// TODO: check subkeys?
// Check certifications
async
.
forEach
(
keyhelper
.
toPacketlist
(
kc
.
certpackets
),
function
(
certif
,
callback
){
kc
.
certifiers
=
[];
async
.
forEach
(
keyhelper
.
toPacketlist
(
kc
.
certpackets
),
function
(
certif
,
callback
){
async
.
waterfall
([
function
(
next
){
checkCertificationOfKey
(
certif
,
kc
.
fingerprint
,
newKeys
,
next
);
...
...
@@ -725,6 +725,67 @@ function KeyService (conn, conf, PublicKeyService) {
done
(
null
,
block
);
}
/**
* Generate a "newcomers" keyblock
*/
this
.
generateUpdates
=
function
(
done
)
{
var
updates
=
{};
var
subupdates
=
{};
async
.
waterfall
([
function
(
next
){
Key
.
findMembersWithUpdates
(
next
);
},
function
(
members
,
next
){
async
.
forEachSeries
(
members
,
function
(
member
,
callback
){
var
fpr
=
member
.
fingerprint
;
async
.
waterfall
([
function
(
next
){
PublicKey
.
getTheOne
(
fpr
,
next
);
},
function
(
pubkey
,
next
){
var
key
=
pubkey
.
getKey
();
var
finalPackets
=
new
openpgp
.
packet
.
List
();
var
certifs
=
pubkey
.
getCertificationsFromMD5List
(
member
.
certifs
);
var
subkeys
=
pubkey
.
getSubkeysFromMD5List
(
member
.
subkeys
);
if
(
subkeys
.
length
>
0
)
{
subupdates
[
fpr
]
=
subkeys
;
}
async
.
forEachSeries
(
certifs
,
function
(
certif
,
callback
){
var
issuerKeyId
=
certif
.
issuerKeyId
.
toHex
().
toUpperCase
();
async
.
waterfall
([
function
(
next
){
TrustedKey
.
getTheOne
(
issuerKeyId
,
next
);
},
function
(
trusted
,
next
){
// Issuer is a member
finalPackets
.
push
(
certif
);
next
();
},
],
function
(
err
)
{
// Issuer is not a member
callback
();
});
},
function
(
err
){
if
(
finalPackets
.
length
>
0
)
{
updates
[
fpr
]
=
finalPackets
;
}
next
();
});
},
],
callback
);
},
next
);
},
function
(
next
){
KeyBlock
.
current
(
function
(
err
,
current
)
{
next
(
null
,
current
||
null
);
});
},
function
(
current
,
next
){
createNewcomerBlock
(
current
,
null
,
{},
updates
,
subupdates
,
next
);
},
],
done
);
}
/**
this.generateNewcomers = function (done) {
* Generate a "newcomers" keyblock
...
...
@@ -922,7 +983,7 @@ function KeyService (conn, conf, PublicKeyService) {
updates
[
signedFPR
]
=
keptCertifs
;
});
// Create the block
createNewcomerBlock
(
current
,
wotMembers
.
concat
(
realNewcomers
),
finalJoinData
,
updates
,
next
);
createNewcomerBlock
(
current
,
wotMembers
.
concat
(
realNewcomers
),
finalJoinData
,
updates
,
{},
next
);
},
],
done
);
};
...
...
@@ -997,7 +1058,7 @@ function KeyService (conn, conf, PublicKeyService) {
return
matched
;
}
function
createNewcomerBlock
(
current
,
members
,
joinData
,
updates
,
done
)
{
function
createNewcomerBlock
(
current
,
members
,
joinData
,
updates
,
subupdates
,
done
)
{
var
block
=
new
KeyBlock
();
block
.
version
=
1
;
block
.
currency
=
current
?
current
.
currency
:
conf
.
currency
;
...
...
@@ -1005,6 +1066,7 @@ function KeyService (conn, conf, PublicKeyService) {
block
.
previousHash
=
current
?
current
.
hash
:
""
;
block
.
previousIssuer
=
current
?
current
.
issuer
:
""
;
// Members merkle
if
(
members
)
{
members
.
sort
();
var
tree
=
merkle
(
members
,
'
sha1
'
).
process
();
block
.
membersCount
=
members
.
length
;
...
...
@@ -1013,6 +1075,15 @@ function KeyService (conn, conf, PublicKeyService) {
_
(
joinData
).
keys
().
forEach
(
function
(
fpr
){
block
.
membersChanges
.
push
(
'
+
'
+
fpr
);
});
}
else
if
(
!
members
&&
current
)
{
// No members changes
block
.
membersCount
=
current
.
membersCount
;
block
.
membersRoot
=
current
.
membersRoot
;
block
.
membersChanges
=
[];
}
else
{
done
(
'
Wrong new block: cannot make a root block without members
'
);
return
;
}
// Keychanges - newcomers
block
.
keysChanges
=
[];
_
(
joinData
).
values
().
forEach
(
function
(
join
){
...
...
@@ -1029,13 +1100,16 @@ function KeyService (conn, conf, PublicKeyService) {
});
});
// Keychanges - updates: signatures from newcomers
_
(
updates
).
keys
().
forEach
(
function
(
fpr
){
if
(
updates
[
fpr
].
length
>
0
)
{
var
updateKeys
=
_
(
updates
).
keys
();
var
subkeyKeys
=
_
(
subupdates
).
keys
();
var
allUpdates
=
_
(
updateKeys
.
concat
(
subkeyKeys
)).
uniq
();
allUpdates
.
forEach
(
function
(
fpr
){
if
((
updates
[
fpr
]
&&
updates
[
fpr
].
length
>
0
)
||
(
subupdates
[
fpr
]
&&
subupdates
[
fpr
].
length
>
0
))
{
block
.
keysChanges
.
push
({
type
:
'
U
'
,
fingerprint
:
fpr
,
keypackets
:
''
,
certpackets
:
base64
.
encode
(
updates
[
fpr
].
write
()),
keypackets
:
subupdates
[
fpr
]
?
base64
.
encode
(
subupdates
[
fpr
].
write
())
:
''
,
certpackets
:
updates
[
fpr
]
?
base64
.
encode
(
updates
[
fpr
].
write
())
:
''
,
membership
:
{}
});
}
...
...
This diff is collapsed.
Click to expand it.
bin/ucoind
+
5
−
0
View file @
d8894109
...
...
@@ -226,6 +226,11 @@ program
.
description
(
'
Tries to generate the next keyblock of the keychain without any changes
'
)
.
action
(
service
(
DO_NOT_LISTEN_HTTP
,
ucoin
.
createWOTServer
,
generateAndSend
(
"
generateEmptyNext
"
)));
program
.
command
(
'
gen-updates [host] [port] [difficulty]
'
)
.
description
(
'
Tries to generate an update (#2+) keyblock, containing only update changes
'
)
.
action
(
service
(
DO_NOT_LISTEN_HTTP
,
ucoin
.
createWOTServer
,
generateAndSend
(
"
generateUpdates
"
)));
program
.
command
(
'
gen-newcomers [host] [port] [difficulty]
'
)
.
description
(
'
Tries to generate a newcomers (#2+) keyblock, containing only newcomers changes
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment