Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEX-873 Admin Identity Certificates #8

Merged
merged 8 commits into from
Aug 31, 2020
Merged

Conversation

KarlTheProgrammer
Copy link
Collaborator

Implement admin identity certificate endpoint and improve identity data comparisons.

@@ -115,7 +116,22 @@ func Run(approver oracle.ApproverInterface) {
}

spyNode := spynode.NewNode(spyConfig, spyStorage)
spyNode.AddTxFilter(&TxFilter{})

// -------------------------------------------------------------------------

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's lose these / -----------------------.... lines

If these setup is that big, use funcs rather than comments to clarify the setup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will make the code more complex and less readable. The functions would each require a fair number of parameters and would greatly increase the line count and code complexity. I don't see any benefit.

@@ -90,11 +99,18 @@ func (v *Verify) XPubSignature(ctx context.Context, log logger.Logger, w http.Re
return translate(errors.Wrap(err, "unmarshal request"))
}

for _, xpub := range requestData.XPubs {
if xpub.IsPrivate() {
web.Respond(ctx, log, w, "private keys not allowed", http.StatusUnprocessableEntity)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return web.Respond(...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This web.Respond doesn't return an error. It creates a response no matter what.

dbConn := v.MasterDB.Copy()
defer dbConn.Close()

// Verify that the public key is associated with the entity.
sigHash, height, approved, err := oracle.VerifyXPub(ctx, dbConn, v.BlockHandler,
sigHash, height, approved, description, err := oracle.VerifyXPub(ctx, dbConn, v.BlockHandler,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of return elements.

How about a struct and an error ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just kind of evolved like that. I will fix it.

Expiration: expiration,
}

web.RespondData(ctx, log, w, response, http.StatusOK)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return web.Respond...

}

if err := web.Unmarshal(r.Body, &requestData); err != nil {
return translate(errors.Wrap(err, "unmarshal request"))
}

for _, xpub := range requestData.XPubs {
if xpub.IsPrivate() {
web.Respond(ctx, log, w, "private keys not allowed", http.StatusUnprocessableEntity)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return web.Respond(ctx, ...

}

if err := web.Unmarshal(r.Body, &requestData); err != nil {
return translate(errors.Wrap(err, "unmarshal request"))
}

for _, xpub := range requestData.XPubs {
if xpub.IsPrivate() {
web.Respond(ctx, log, w, "private keys not allowed", http.StatusUnprocessableEntity)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

@@ -67,7 +74,7 @@ func (t *Transfers) TransferSignature(ctx context.Context, log logger.Logger, w
}
}

expiration := uint64(time.Now().Add(time.Duration(t.ExpirationDurationSeconds) * time.Second).UnixNano())
expiration := uint64(time.Now().Add(time.Duration(t.TransferExpirationDurationSeconds) * time.Second).UnixNano())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line.

@@ -119,8 +123,25 @@ github.com/tokenized/pkg v0.0.0-20200528005955-162f9c3d87f8/go.mod h1:qVlOZ6a37X
github.com/tokenized/pkg v0.0.0-20200724032845-ccddf7770c5a/go.mod h1:qVlOZ6a37XqvfYQFoWhxBUGvGgzY0EkvoCHDBs+cjSA=
github.com/tokenized/pkg v0.0.0-20200730051124-244d94211b53 h1:XTLCUNW8dRdfQrwBAq0bHsOlDOb3JJINuXtmJ5CwxgY=
github.com/tokenized/pkg v0.0.0-20200730051124-244d94211b53/go.mod h1:StHV+mlXyhmmYZSRghRb+3Zy7QSiJe0jDaQw05SYnyQ=
github.com/tokenized/pkg v0.0.0-20200814000235-256842f23ba4/go.mod h1:StHV+mlXyhmmYZSRghRb+3Zy7QSiJe0jDaQw05SYnyQ=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go mod tidy

// Check for pre-existing
b, err := cm.st.Read(ctx, key)
if err == nil {
// Check timestamp vs current version to ensure we keep the latest.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De-nest this main block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to be careful to not prioritize statement depth of logic complexity. It is difficult for me because I have always thought that positive if statements are simpler, but golang seems to want a lot more negative if statements (if not error). I subconsciously default to the if "condition I want" statement, which I think has merit. I have changed this code though because it is a 3 way if statement that is difficult to read in any form. Just something to think about.

if err != nil {
t.Errorf("Entity didn't verify : %s", err)
}
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else.

Just t.Fatal above to stop this test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else is needed to check for the cases that are supposed to cause an error. I will add log statements to make that more clear.

@@ -13,75 +13,163 @@ import (
)

func VerifyPubKey(ctx context.Context, dbConn *db.DB, blockHandler *BlockHandler,
entity *actions.EntityField, xpub bitcoin.ExtendedKey, index uint32) ([]byte, uint32, bool, error) {
entity *actions.EntityField, xpub bitcoin.ExtendedKey, index uint32) ([]byte, uint32, bool, string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deserves a struct, rather than so many elements in the return.

// uint32 - block height of block hash included in signature hash
// bitcoin.Hash32 - block hash included in signature hash
// bool - true if approved
func CreateAdminCertificate(ctx context.Context, dbConn *db.DB, isTest bool,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number of return elements. Use struct.

return nil, 0, false, "", errors.Wrap(err, "get contract formation")
}

if err := VerifyEntityIsSubset(cf.Issuer, userEntity); err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These blocks can be improved.

The previous block, and the last half of this one are identical.

internal/oracle/xpub.go Outdated Show resolved Hide resolved
@@ -70,6 +78,7 @@ func unmarshalNested(data []byte, cfg *Config) error {
err = json.Unmarshal(data, &cfg.Storage)
err = json.Unmarshal(data, &cfg.SpyNode)
err = json.Unmarshal(data, &cfg.NodeStorage)
err = json.Unmarshal(data, &cfg.RpcNode)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy of the "flat json" idea which meant this had to be changed anytime the config changed.

Just use "normal" json. Take a look at nexus-api

Copy link
Collaborator Author

@KarlTheProgrammer KarlTheProgrammer Aug 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a separate ticket to update the configs to use a common system. NEX-851

@@ -91,6 +100,9 @@ func SafeConfig(cfg Config) *Config {
if len(cfgSafe.NodeStorage.Secret) > 0 {
cfgSafe.NodeStorage.Secret = "*** Masked ***"
}
if len(cfgSafe.RpcNode.Password) > 0 {
cfgSafe.RpcNode.Password = "*** Masked ***"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to use the masked idea out of nexus-api

@KarlTheProgrammer KarlTheProgrammer merged commit a4ad62a into master Aug 31, 2020
@KarlTheProgrammer KarlTheProgrammer deleted the NEX-873-admin-cert branch August 31, 2020 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants