Merge pull request #1828 from Luis-Fernando-Molina/develop

Contribution: Governance: Signature Hash Validation
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-09-21 16:34:30 -04:00
commit 8a70df1ffa
3 files changed
+102 -12

No files matched your search

+76 -12
View File
@@ -301,6 +301,7 @@ exports.newGithubServer = function newGithubServer() {
if (await validateFileNameEqualsGithubUsername() === false) { continue }
if (await validateFileChangedIsUserProfile() === false) { continue }
if (await validateMessageSignedIsGithubUsername() === false) { continue }
if (await validateMessageSignedHashIsSignatureHash() === false) { continue }
if (await validateUserProfileNodeNameEqualsGithubUsername() === false) { continue }
if (await validateUserProfileIdDoesNotBelongtoAnotherUserProfile() === false) { continue }
if (await validateUserProfileBlockchainAccountDoesNotBelongtoAnotherUserProfile() === false) { continue }
@@ -441,12 +442,46 @@ exports.newGithubServer = function newGithubServer() {
}
}
async function validateMessageSignedHashIsSignatureHash() {
/*
Validation #5: The message signed has is equal to the signature messageHash.
*/
let config = JSON.parse(userProfile.config)
let serverResponse = await PL.servers.WEB3_SERVER.hashData(
config.signature.message
)
let messageSignedHash = serverResponse.hash
let signatureHash = config.signature.messageHash
if (messageSignedHash !== signatureHash) {
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #5 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Message Signed Hash is not equal to the the Signature Hash. -> messageSignedHash = ' + messageSignedHash + '-> signatureHash = ' + signatureHash)
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: pullRequest.number,
body: 'This Pull Request could not be automatically merged and was closed by the Superalgos Governance System because the Message Signed Hash is not equal to the the Signature Hash.\n\n messageSignedHash = "' + messageSignedHash + '"\n\n signatureHash = "' + signatureHash + '"'
});
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.pulls.update({
owner: owner,
repo: repo,
pull_number: pullRequest.number,
state: 'closed'
});
return false
}
}
async function validateUserProfileNodeNameEqualsGithubUsername() {
/*
Validation #5: The name of the User Profile node is not the Github Username.
Validation #6: The name of the User Profile node is not the Github Username.
*/
if (userProfile.name !== githubUsername) {
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #5 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Github Username is not equal to the User Profile node\'s name. -> Github Username = ' + githubUsername + '-> userProfile.name = ' + userProfile.name)
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #6 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Github Username is not equal to the User Profile node\'s name. -> Github Username = ' + githubUsername + '-> userProfile.name = ' + userProfile.name)
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.issues.createComment({
@@ -469,7 +504,7 @@ exports.newGithubServer = function newGithubServer() {
async function validateUserProfileIdDoesNotBelongtoAnotherUserProfile() {
/*
Validation #6: The id of the User Profile can not be the id of an already existing User Profile
Validation #7: The id of the User Profile can not be the id of an already existing User Profile
unless the existing one belongs to the same Github username.
*/
let userProfileIdMap = new Map()
@@ -494,7 +529,7 @@ exports.newGithubServer = function newGithubServer() {
if (testUserProfile === undefined) { return true }
if (testUserProfile !== userProfile.name) {
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #6 Failed -> Pull Request "' + pullRequest.title + '" not merged because the User Profile Id already exists and belongs to another User Profile on record. -> Profile Id = ' + userProfile.id + '-> User Profile with the same Id = ' + testUserProfile)
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #7 Failed -> Pull Request "' + pullRequest.title + '" not merged because the User Profile Id already exists and belongs to another User Profile on record. -> Profile Id = ' + userProfile.id + '-> User Profile with the same Id = ' + testUserProfile)
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.issues.createComment({
@@ -518,7 +553,7 @@ exports.newGithubServer = function newGithubServer() {
async function validateUserProfileBlockchainAccountDoesNotBelongtoAnotherUserProfile() {
try {
/*
Validation #7 The blockchain account of the User Profile can not be the
Validation #8 The blockchain account of the User Profile can not be the
blockchain account of an already existing User Profile
unless the existing one belongs to the same Github username.
*/
@@ -555,7 +590,7 @@ exports.newGithubServer = function newGithubServer() {
if (testUserProfile === undefined) { return true }
if (testUserProfile !== userProfile.name) {
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #7 Failed -> Pull Request "' + pullRequest.title + '" not merged because the User Profile Blockchain Account already exists and belongs to another User Profile on record. -> Profile Blockchain Account = ' + serverResponse.address + '-> User Profile with the same Blockchain Account = ' + testUserProfile)
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #8 Failed -> Pull Request "' + pullRequest.title + '" not merged because the User Profile Blockchain Account already exists and belongs to another User Profile on record. -> Profile Blockchain Account = ' + serverResponse.address + '-> User Profile with the same Blockchain Account = ' + testUserProfile)
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.issues.createComment({
@@ -581,20 +616,20 @@ exports.newGithubServer = function newGithubServer() {
async function validateUserProfileSigningAccountsDoesNotBelongtoAnotherUserProfile() {
try {
/*
Validation #8 Signing accounts of the User Profile
must have a signature of the same Github username of the User Profile.
*/
if (userProfile.signingAccounts === undefined) { return true }
for (let i = 0; i < userProfile.signingAccounts.signingAccounts.length; i++) {
let signingAccount = userProfile.signingAccounts.signingAccounts[i]
let config = JSON.parse(signingAccount.config)
/*
Validation #9 Signing accounts of the User Profile
must have a signature of the same Github username of the User Profile.
*/
let messageSigned = config.signature.message
if (messageSigned !== githubUsername) {
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #8 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Signing Account ' + signingAccount.name + ' has not signed the current Github User Account, but something else. -> messageSigned = ' + messageSigned + '-> githubUsername = ' + githubUsername)
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #9 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Signing Account ' + signingAccount.name + ' has not signed the current Github User Account, but something else. -> messageSigned = ' + messageSigned + '-> githubUsername = ' + githubUsername)
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.issues.createComment({
@@ -603,7 +638,36 @@ exports.newGithubServer = function newGithubServer() {
issue_number: pullRequest.number,
body: 'This Pull Request could not be automatically merged and was closed by the Superalgos Governance System because the Signing Account "' + signingAccount.name + '" has not signed the current Github User Account, but something else. \n\n messageSigned = "' + messageSigned + '" \n\n githubUsername = "' + githubUsername + '"'
});
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.pulls.update({
owner: owner,
repo: repo,
pull_number: pullRequest.number,
state: 'closed'
});
return false
}
/*
Validation #10: The message signed has is equal to the signature messageHash.
*/
let serverResponse = await PL.servers.WEB3_SERVER.hashData(
config.signature.message
)
let messageSignedHash = serverResponse.hash
let signatureHash = config.signature.messageHash
if (messageSignedHash !== signatureHash) {
console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #10 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Message Signed Hash is not equal to the the Signature Hash. -> messageSignedHash = ' + messageSignedHash + '-> signatureHash = ' + signatureHash)
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: pullRequest.number,
body: 'This Pull Request could not be automatically merged and was closed by the Superalgos Governance System because the Message Signed Hash is not equal to the the Signature Hash.\n\n messageSignedHash = "' + messageSignedHash + '"\n\n signatureHash = "' + signatureHash + '"'
});
await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
await octokit.rest.pulls.update({
owner: owner,
+9
View File
@@ -93,6 +93,15 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
case 'hashData': {
let serverResponse = await PL.servers.WEB3_SERVER.hashData(
params.data
)
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
case 'recoverAddress': {
let serverResponse = await PL.servers.WEB3_SERVER.recoverAddress(
+17
View File
@@ -7,6 +7,7 @@ exports.newWeb3Server = function newWeb3Server() {
createWalletAccount: createWalletAccount,
getWalletBalances: getWalletBalances,
signData: signData,
hashData: hashData,
recoverAddress: recoverAddress,
mnemonicToPrivateKey: mnemonicToPrivateKey,
payContributors: payContributors,
@@ -223,6 +224,22 @@ exports.newWeb3Server = function newWeb3Server() {
}
}
async function hashData(data) {
try {
let web3 = new Web3()
let hash = web3.eth.accounts.hashMessage(data)
return {
hash: hash,
result: 'Ok'
}
} catch (err) {
return { error: 'Could not hash the data. ' + err.stack }
}
}
async function recoverAddress(signature) {
try {
let signatureObject = JSON.parse(signature)