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

go/common/crypto/signature/signers/ledger: Descriptive error on user reject #3050

Merged
merged 1 commit into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/3050.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/common/crypto/signature/signers/ledger: Descriptive error on user reject

Make Ledger signer return a more descriptive error message when a user rejects
a transaction on the Ledger device.
21 changes: 20 additions & 1 deletion go/common/crypto/signature/signers/ledger/ledger_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
package ledger

import (
"errors"
"fmt"
"io"

ledger "github.com/zondax/ledger-go"

"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
ledgerCommon "github.com/oasisprotocol/oasis-core/go/common/ledger"
)
Expand Down Expand Up @@ -33,6 +36,10 @@ var (
roleDerivationRootPaths = map[signature.SignerRole][]uint32{
signature.SignerEntity: SignerDerivationRootPath,
}

// NOTE: The 0x6986 ISO 7816 error code is returned by the Oasis Ledger App
// iff when a user rejects the transaction on the Ledger device.
ledgerRejectTxErrorMsg = ledger.ErrorMessage(0x6986)
)

// Factory is a Ledger backed SignerFactory.
Expand Down Expand Up @@ -125,7 +132,19 @@ func (s *Signer) ContextSign(context signature.Context, message []byte) ([]byte,
if err != nil {
return nil, err
}
return s.device.SignEd25519(s.path, preparedContext, message)
signature, err := s.device.SignEd25519(s.path, preparedContext, message)
switch {
case err == nil:
return signature, nil
// XXX: At the moment, ledger-go doesn't use proper Go error semantics and
// doesn't expose errors as variables so we can't compare them directly with
// errors.Is().
case err.Error() == ledgerRejectTxErrorMsg:
// Replace Ledger's raw APDU error with a more descriptive one.
return nil, errors.New("transaction was rejected on Ledger device")
default:
return nil, err
}
}

// String returns the address of the account on the Ledger device.
Expand Down
1 change: 1 addition & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ require (
github.com/uber/jaeger-client-go v2.16.0+incompatible
github.com/uber/jaeger-lib v2.0.0+incompatible // indirect
github.com/whyrusleeping/go-logging v0.0.1
github.com/zondax/ledger-go v0.11.0
github.com/zondax/ledger-oasis-go v0.3.0
gitlab.com/yawning/dynlib.git v0.0.0-20200603163025-35fe007b0761
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
Expand Down