forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new crypto protocol with sign RPC
This will be used by kbfs. Also add methods to GenericKey to sign/verify to bytes. Also plumb through subkey to the CurrentSession RPC. Remove redundant nil key checks. Move SecretUI and LoginUI methods to the right place (service/handler.go). Remove unused test/main.go file. This closes keybase#421.
- Loading branch information
Showing
37 changed files
with
575 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package engine | ||
|
||
import ( | ||
"github.com/keybase/client/go/libkb" | ||
) | ||
|
||
type CryptoSignEngine struct { | ||
libkb.Contextified | ||
msg []byte | ||
reason string | ||
sig []byte | ||
} | ||
|
||
func NewCryptoSignEngine(ctx *libkb.GlobalContext, msg []byte, reason string) *CryptoSignEngine { | ||
cse := &CryptoSignEngine{msg: msg, reason: reason} | ||
cse.SetGlobalContext(ctx) | ||
return cse | ||
} | ||
|
||
func (cse *CryptoSignEngine) Name() string { | ||
return "CryptoSign" | ||
} | ||
|
||
func (cse *CryptoSignEngine) GetPrereqs() EnginePrereqs { return EnginePrereqs{} } | ||
|
||
func (cse *CryptoSignEngine) RequiredUIs() []libkb.UIKind { | ||
return []libkb.UIKind{ | ||
libkb.SecretUIKind, | ||
} | ||
} | ||
|
||
func (cse *CryptoSignEngine) SubConsumers() []libkb.UIConsumer { | ||
return []libkb.UIConsumer{} | ||
} | ||
|
||
func (cse *CryptoSignEngine) Run(ctx *Context) (cserr error) { | ||
me, err := libkb.LoadMe(libkb.LoadUserArg{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sigKey, _, err := cse.G().Keyrings.GetSecretKeyWithPrompt(libkb.SecretKeyArg{ | ||
Me: me, | ||
KeyType: libkb.DeviceKeyType, | ||
}, ctx.SecretUI, cse.reason) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = sigKey.CheckSecretKey(); err != nil { | ||
return err | ||
} | ||
|
||
sig, err := sigKey.SignToBytes(cse.msg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cse.sig = sig | ||
return nil | ||
} | ||
|
||
func (cse *CryptoSignEngine) GetSignature() []byte { | ||
return cse.sig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package engine | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/keybase/client/go/libkb" | ||
) | ||
|
||
// Test that CryptoSignEngine yields a signature that the device | ||
// subkey can verify. | ||
// | ||
// (For general tests that valid signatures are accepted and invalid | ||
// signatures are rejected, see naclwrap_test.go.) | ||
func TestCryptoSign(t *testing.T) { | ||
tc := SetupEngineTest(t, "crypto_sign") | ||
defer tc.Cleanup() | ||
|
||
fu := CreateAndSignupFakeUser(tc, "sign") | ||
|
||
msg := []byte("test message") | ||
|
||
me, err := libkb.LoadUser(libkb.LoadUserArg{Name: fu.Username}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
cse := NewCryptoSignEngine(tc.G, msg, "test reason") | ||
secui := libkb.TestSecretUI{Passphrase: fu.Passphrase} | ||
ctx := &Context{ | ||
SecretUI: secui, | ||
} | ||
err = RunEngine(cse, ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
sibkey, _, err := me.GetDeviceKeys() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = sibkey.VerifyBytes(cse.GetSignature(), msg) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.