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

Initial go client interface for signing keys #10

Merged
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
35 changes: 35 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package client

import (
"github.com/docker/parsec/types"
)

// Client is a Parsec client representing a connection and set of API implementations
type Client struct {
*conn
SystemClient
KeyManagerClient
}

// KeyManagerClient is an interface to the key management facilities of Parsec
type KeyManagerClient interface {
KeyGet(keyid types.KeyID) (Key, error)
KeyImport(k Key) error
KeyDelete(keyid types.KeyID) error
KeyList() ([]Key, error)
}

// SystemClient is an interface to the system calls of Parsec
type SystemClient interface {
Version() string
Info() (types.Info, error)
}

// InitClient initializes a Parsec client
func InitClient() (*Client, error) {
return nil, nil
}

func (c Client) KeyGet(keyid types.KeyID) (Key, error) {
return &key{}, nil
}
34 changes: 34 additions & 0 deletions client/conn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package client

import (
"io"
"sync"
)

type conn struct {
sync.Mutex
rwc *io.ReadWriteCloser
path string
}

func (conn *conn) close() error {
conn.Lock()
defer conn.Unlock()
if conn.rwc != nil {
rwc := *conn.rwc
rwc.Close()
}
conn.rwc = nil
return nil
}

func (conn *conn) open() error {
conn.Lock()
defer conn.Unlock()
// rwc, err := OpenParsec(conn.path)
// if err != nil {
// return err
// }
// conn.rwc = &rwc
return nil
}
39 changes: 39 additions & 0 deletions client/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package client

import (
"io"
"crypto"
"github.com/docker/parsec/types"
)

// Key defines an interface for any cryptographic key
type Key interface {
}

// VerifyingKey defines an interface for a public key used to verify digital signatures
type VerifyingKey interface {
Key
crypto.PublicKey
Verify(digest []byte, signature []byte) error
}

// SigningKey defines an interface for a private key used to generate digital signatures
type SigningKey interface {
Key
crypto.Signer
}

// DecryptingKey defines an interface for a private key used to decrypt data
type DecryptingKey interface {
Key
crypto.Decrypter
}

type key struct {
conn *conn
attributes types.KeyAttributes
}

func (key key) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) {
return nil, nil
}
21 changes: 21 additions & 0 deletions client/tls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package client

import (
"errors"
"crypto/tls"
"encoding/pem"
)

// X509KeyPair returns a TLS certificate based on a PEM-encoded certificate and a parsec defined private key
func X509KeyPair(certPEMBlock []byte, k Key) (*tls.Certificate, error) {
cert := &tls.Certificate{}
cert.PrivateKey = k
certDERBlock, _ := pem.Decode(certPEMBlock)
if certDERBlock == nil {
return nil, errors.New("Failed to read certificate")
}
if certDERBlock.Type == "CERTIFICATE" {
cert.Certificate = append(cert.Certificate, certDERBlock.Bytes)
}
return cert, nil
}
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"log"
"crypto/tls"
"github.com/docker/parsec/client"
)

func main(){
c, err := client.InitClient()
if err != nil {
log.Println(err)
return
}

k, err := c.KeyGet("keyid1")
if err != nil {
log.Println(err)
return
}
cert, err := client.X509KeyPair([]byte{}, k)
if err != nil {
log.Println(err)
return
}
config := &tls.Config{Certificates: []tls.Certificate{*cert}}
log.Println(config)
}
15 changes: 15 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package types

import (
)

// Info defines all information related to Parsec server
type Info struct {
}

// KeyAttributes defines all attributes that define a Key implementation
type KeyAttributes struct {
}

// KeyID represents a key identifier
type KeyID string