Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Schulz authored and dominikschulz committed Feb 6, 2018
1 parent 80f8a6e commit bdff9b9
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 383 deletions.
10 changes: 5 additions & 5 deletions backend/crypto/xc/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ func (x *XC) Decrypt(ctx context.Context, buf []byte) ([]byte, error) {
// findDecryptionKey tries to find a suiteable decryption key from the available
// decryption keys and the recipients
func (x *XC) findDecryptionKey(hdr *xcpb.Header) (*keyring.PrivateKey, error) {
for _, pk := range x.keyring.DecryptionKeys() {
if _, found := hdr.Recipients[pk.Fingerprint()]; found {
return pk, nil
for _, pk := range x.secring.KeyIDs() {
if _, found := hdr.Recipients[pk]; found {
return x.secring.Get(pk), nil
}
}
return nil, fmt.Errorf("no decryption key found for: %+v", hdr.Recipients)
}

// findPublicKey tries to find a given public key in the keyring
func (x *XC) findPublicKey(needle string) (*keyring.PublicKey, error) {
for _, id := range x.keyring.PublicKeyIDs() {
for _, id := range x.pubring.KeyIDs() {
if id == needle {
return x.keyring.Get(id).PublicKey, nil
return x.pubring.Get(id), nil
}
}
return nil, fmt.Errorf("no sender found for id '%s'", needle)
Expand Down
8 changes: 4 additions & 4 deletions backend/crypto/xc/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const (
// Encrypt encrypts the given plaintext for all the given recipients and returns the
// ciphertext
func (x *XC) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) {
privKeys := x.keyring.DecryptionKeys()
if len(privKeys) < 1 {
privKeyIDs := x.secring.KeyIDs()
if len(privKeyIDs) < 1 {
return nil, fmt.Errorf("no signing keys available on our keyring")
}
privKey := privKeys[0]
privKey := x.secring.Get(privKeyIDs[0])

// encrypt body (als generates a random nonce and a random session key)
sk, nonce, body, err := encryptBody(plaintext)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (x *XC) encryptHeader(signKey *keyring.PrivateKey, sk, nonce []byte, recipi

// encryptForRecipients encrypts the given session key for the given recipient
func (x *XC) encryptForRecipient(sender *keyring.PrivateKey, sk []byte, recipient string) ([]byte, error) {
recp := x.keyring.Get(recipient).PublicKey
recp := x.pubring.Get(recipient)
if recp == nil {
return nil, fmt.Errorf("recipient public key not available for %s", recipient)
}
Expand Down
6 changes: 4 additions & 2 deletions backend/crypto/xc/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (

// ExportPublicKey exports a given public key
func (x *XC) ExportPublicKey(ctx context.Context, id string) ([]byte, error) {
k := x.keyring.Get(id).PublicKey
k := x.pubring.Get(id)
if k == nil {
return nil, fmt.Errorf("key not found")
}
return k.Marshal()
// TODO
return nil, fmt.Errorf("not yet implemented")
//return k.Marshal()
}
17 changes: 8 additions & 9 deletions backend/crypto/xc/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package xc

import (
"context"
"path/filepath"

"github.com/justwatchcom/gopass/backend/crypto/xc/keyring"
"fmt"
)

// ImportPublicKey imports a given public key into the keyring
func (x *XC) ImportPublicKey(ctx context.Context, buf []byte) error {
k := &keyring.PublicKey{}
if err := k.Unmarshal(buf); err != nil {
return err
}
x.keyring.Set(k, nil)
return x.keyring.Save(filepath.Join(x.dir, keyringFilename))
return fmt.Errorf("not yet implemented")
//k := &keyring.PublicKey{}
//if err := k.Unmarshal(buf); err != nil {
// return err
//}
//x.keyring.Set(k, nil)
//return x.keyring.Save(filepath.Join(x.dir, keyringFilename))
}
7 changes: 0 additions & 7 deletions backend/crypto/xc/keyring/entity.go

This file was deleted.

162 changes: 0 additions & 162 deletions backend/crypto/xc/keyring/entity_list.go

This file was deleted.

36 changes: 0 additions & 36 deletions backend/crypto/xc/keyring/entity_list_test.go

This file was deleted.

23 changes: 0 additions & 23 deletions backend/crypto/xc/keyring/identity.go

This file was deleted.

16 changes: 0 additions & 16 deletions backend/crypto/xc/keyring/private_key.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keyring

import (
"bytes"
"encoding/gob"
"fmt"
"io"
"time"
Expand Down Expand Up @@ -67,20 +65,6 @@ func (p *PrivateKey) Encrypt(passphrase string) error {
return nil
}

// Marshal marshals the private key
func (p *PrivateKey) Marshal() ([]byte, error) {
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)
err := enc.Encode(p)
return buf.Bytes(), err
}

// Unmarshal unmarshals the private key
func (p *PrivateKey) Unmarshal(buf []byte) error {
dec := gob.NewDecoder(bytes.NewReader(buf))
return dec.Decode(p)
}

// Decrypt decrypts the private key
func (p *PrivateKey) Decrypt(passphrase string) error {
if !p.Encrypted {
Expand Down
10 changes: 0 additions & 10 deletions backend/crypto/xc/keyring/private_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ func TestPrivateKeyMarshal(t *testing.T) {
assert.NoError(t, key.Encrypt(passphrase))
t.Logf("Key: %+v\n", key)

buf, err := key.Marshal()
assert.NoError(t, err)

// reset key
key = &PrivateKey{}
assert.NoError(t, key.Unmarshal(buf))
t.Logf("Key: %+v\n", key)

assert.Equal(t, zeroArray32, key.PrivateKey())

assert.NoError(t, key.Decrypt(passphrase))
t.Logf("Key: %+v\n", key)
assert.NotEqual(t, zeroArray32, key.PrivateKey())
Expand Down
Loading

0 comments on commit bdff9b9

Please sign in to comment.