Commit 64f7111e authored by Saad Karim's avatar Saad Karim
Browse files

Fixing build issues. Resubmitting latest code.



Change-Id: Ibab4ddcbce1025b6779f1da2c8525fd5d76b7bb6
Signed-off-by: default avatarSaad Karim <skarim@us.ibm.com>
parent ddb33acd

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
cli/cop/cop
*.pem
*.csr
/*
* This file is simply a mirror of the interfaces in interfaces/interfaces.go.
* This was done in order to prevent an import cycle.
*/
package cop
import (
"fmt"
"os"
real "github.com/hyperledger/fabric/cop/api"
def "github.com/hyperledger/fabric/cop/lib/defaultImpl"
)
// Mgr is the main interface to COP functionality
type Mgr interface {
real.Mgr
}
// Client is a COP client
type Client interface {
real.Client
}
// CertMgr is a COP certificate manager
type CertMgr interface {
real.CertMgr
}
// JoinRequest is the state of a request to join the blockchain network
type JoinRequest struct {
real.JoinRequest
}
// JoinRequestListener is a listener for join requests
type JoinRequestListener real.JoinRequestListener
// JoinRequestStatus is the status of a join request
type JoinRequestStatus real.JoinRequestStatus
// Values denoting the possible values of the JoinRequestStatus
const (
JRSWaiting = real.JRSWaiting
JRSApproved = real.JRSApproved
JRSDenied = real.JRSDenied
)
// JoinResponseType are the types of responses which can be provided to a JoinRequest
type JoinResponseType real.JoinResponseType
// Values denoting the possible values of the JoinResponseType
const (
JRTApprove = real.JRTApprove
JRTDeny = real.JRTDeny
JRTAbstain = real.JRTAbstain
JRTCount = real.JRTCount
)
// CertHandler provides functions related to a certificate
type CertHandler interface {
real.CertHandler
}
// KeyHandler provides functions related to a key
type KeyHandler interface {
real.KeyHandler
}
// Registration information
type Registration struct {
real.Registration
}
// Identity is any type of identity which is opaque for now
type Identity real.Identity
// The following are all the error codes returned by COP.
// The values begin with "100000" to avoid overlap with CFSSL errors.
// Add all new errors to the end of the current list.
const (
// NotImplemented means not yet implemented but plans to support
NotImplemented = real.NotImplemented
// NotSupported means no current plans to support
NotSupported = real.NotSupported
InvalidProviderName = real.InvalidProviderName
TooManyArgs = real.TooManyArgs
NotInitialized = real.NotInitialized
)
// Error is an interface with a Code method
type Error interface {
real.Error
}
func init() {
provider := os.Getenv("COP.PROVIDER")
if provider == "" {
provider = "default"
}
if provider == "default" {
real.SetMgr(new(def.Mgr))
} else {
fmt.Printf("invalid COP provider: %s\n", provider)
os.Exit(1)
}
}
// NewClient creates a COP client
func NewClient() Client {
return real.NewClient()
}
// NewCertMgr creates a COP certificate manager
func NewCertMgr() CertMgr {
return real.NewCertMgr()
}
/*
* This file contains interfaces for the COP library.
* COP provides police-like security functions for Hyperledger Fabric.
*/
package api
// Mgr is the main interface to COP functionality
type Mgr interface {
// NewClient creates a COP client
NewClient() Client
// NewCertMgr creates a COP certificate manager
NewCertMgr() CertMgr
}
// Client is a COP client
type Client interface {
// SetConfig initializes by JSON config
SetConfig(json string) Error
// Register a new identity
Register(registration *Registration) Error
// Enroll a registered identity
// Enroll(user, pass string) (Identity, Error)
Enroll(id string, secret string, remoteHost string, csrJSON string) ([]byte, Error)
// RegisterAndEnroll registers and enrolls a new identity
RegisterAndEnroll(registration *Registration) (Identity, Error)
/*
// Set the identity information associated with this client
SetMyIdentity(identity Identity) Error
// SubmitJoinRequest submits a join request, implicitly approving by the caller
// Returns the join request ID
SubmitJoinRequest(participantFilePath string) (JoinRequest, Error)
// ApproveJoinRequest approves the join request
ApproveJoinRequest(joinRequestID string) Error
// DenyJoinRequest denies the join request
DenyJoinRequest(joinRequestID string) Error
// ListJoinRequests lists the currently outstanding join requests for the blockchain network
ListJoinRequests() ([]JoinRequest, Error)
// ListParticipants lists the current participants in the blockchain network
ListParticipants() ([]string, Error)
// Set the listener to be called when a JoinRequestEvent is emitted
SetJoinRequestListener(listener JoinRequestListener)
*/
}
// JoinRequest is the state of a request to join the blockchain network
type JoinRequest struct {
ID string // Unique ID of join request
Info string // The original JSON request from the participant
Status JoinRequestStatus // waiting, approved, or denied
Responses [JRTCount][]string // participant names of approvers
}
// JoinRequestListener is a listener for join requests
type JoinRequestListener func(JoinRequest)
// JoinRequestStatus is the status of a join request
type JoinRequestStatus int
// Values denoting the possible values of the JoinRequestStatus
const (
JRSWaiting JoinRequestStatus = iota
JRSApproved
JRSDenied
)
// JoinResponseType are the types of responses which can be provided to a JoinRequest
type JoinResponseType int
// Values denoting the possible values of the JoinResponseType
const (
JRTApprove JoinResponseType = iota
JRTDeny
JRTAbstain
JRTCount
)
// CertMgr is the interface for all certificate-based management
type CertMgr interface {
// GenCert generates a certificate
GenCert(csr string, prefix string, participantFile string) Error
// InitSelfSign generates self-signed certs and updates the participant file
InitSelfSign(domain string, path string) Error
// InitLego gets certificates from Let's Encrypt and updates the participant file
InitLego(host string) Error
// SetECAKey sets the ECA key
SetECAKey(key []byte) Error
// SetTCAKey sets the TCA key
SetTCAKey(key []byte) Error
// Set the path for the participant file
SetParticipantFilePath(path string) Error
// UpdateParticipantFile
UpdateParticipantFile() Error
// LoadFromString
//LoadFromString(str string) Error
// StoreToString
//StoreToString() string
// NewCertHandler creates a COP certificate handler
NewCertHandler(cert []byte) (CertHandler, Error)
// NewKeyHandler creates a COP key handler
NewKeyHandler(key []byte) (KeyHandler, Error)
}
// CertHandler provides functions related to a certificate
type CertHandler interface {
// GetId returns the ID of the owner of this cert
GetID() string
// GetPartipantId returns the participant ID associated with this cert
GetParticipantID() string
// Determine if the caller has a specific role (e.g. 'orderer', 'peer', etc)
IsType(role string) bool
// Verify a signature against this certificate
Verify(buf []byte, signature []byte) (bool, Error)
}
// KeyHandler provides functions related to a key
type KeyHandler interface {
CertHandler
// Create a signature using this key
Sign(buf []byte) ([]byte, Error)
}
// Registration information
type Registration struct {
ID string
Roles []string
}
// Identity is any type of identity which is opaque for now
type Identity interface{}
var mgr Mgr
// SetMgr sets the COP manager
func SetMgr(m Mgr) {
mgr = m
}
// NewClient creates a COP client
func NewClient() Client {
return mgr.NewClient()
}
// NewCertMgr creates a COP certificate manager
func NewCertMgr() CertMgr {
return mgr.NewCertMgr()
}
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package api
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package api
import (
"fmt"
cfssl "github.com/cloudflare/cfssl/errors"
)
// The following are all the error codes returned by COP.
// The values begin with "100000" to avoid overlap with CFSSL errors.
// Add all new errors to the end of the current list to preserver backwards compatibility.
const (
// NotImplemented means not yet implemented but plans to support
NotImplemented int = 100000 + iota
// NotSupported means no current plans to support
NotSupported
TooManyArgs
InvalidProviderName
ErrorReadingFile
InvalidConfig
NotInitialized
CFSSL
Output
Input
)
// Error is an interface with a Code method
type Error interface {
error
// Code returns the specific error code
Code() int
}
// ErrorImpl is the implementation of the Error interface
type ErrorImpl struct {
ErrorCode int `json:"code"`
Message string `json:"message"`
}
// Error implements the error interface
func (e *ErrorImpl) Error() string {
return fmt.Sprintf("%d: %s", e.ErrorCode, e.Message)
}
// Code implements the error interface
func (e *ErrorImpl) Code() int {
return e.ErrorCode
}
// NewError constructor for COP errors
func NewError(code int, format string, args ...interface{}) *ErrorImpl {
msg := fmt.Sprintf(format, args)
return &ErrorImpl{ErrorCode: code, Message: msg}
}
// WrapError another COP error
func WrapError(err error, code int, format string, args ...interface{}) *ErrorImpl {
msg := fmt.Sprintf(format, args)
msg = fmt.Sprintf("%s [%s]", msg, err.Error())
return &ErrorImpl{ErrorCode: code, Message: msg}
}
// WrapCFSSLError wraps a CFSSL error
func WrapCFSSLError(error *cfssl.Error, code int, format string, args ...interface{}) *ErrorImpl {
msg := fmt.Sprintf(format, args)
msg = fmt.Sprintf("%s [CFSSL %d: %s]", msg, error.ErrorCode, error.Message)
return &ErrorImpl{ErrorCode: code, Message: msg}
}
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package api
import (
"fmt"
"testing"
)
func TestNewError(t *testing.T) {
err := NewError(InvalidProviderName, "invalid factory name: %s", "foo")
if err == nil {
t.Error("Error creation failed.")
}
if err.Code() != 100003 {
t.Errorf("invalid error code; expecting 100003 but found %d", err.ErrorCode)
}
fmt.Printf("TestNew: %v", err)
}
func TestWrapError(t *testing.T) {
err := NewError(InvalidProviderName, "invalid factory name: %s", "foo")
if err == nil {
t.Error("Error creation failed.")
}
err = WrapError(err, NotImplemented, "feature 'foo' has not implemented")
if err == nil {
t.Error("Wrap creation failed.")
}
}
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cop
package enroll
import (
"github.com/cloudflare/cfssl/cli"
"github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric/cop"
"github.com/hyperledger/fabric/cop/cli/cop/config"
)
var usageText = `cop client enroll -- Enroll with COP server
Usage of client enroll command:
Enroll a client and get an ecert:
cop client enroll ID SECRET COP-SERVER-ADDR
Arguments:
ID: Enrollment ID
SECRET: Enrollment secret returned by register
CSRJSON: Certificate Signing Request JSON information
COP-SERVER-ADDR: COP server address
Flags:
`
var flags = []string{}
func myMain(args []string, c cli.Config) error {
config.Init(&c)
log.Debug("in myMain of 'cop client enroll'")
id, args, err := cli.PopFirstArgument(args)
if err != nil {
return err
}
secret, args, err := cli.PopFirstArgument(args)
if err != nil {
return err
}
csrJSON, args, err := cli.PopFirstArgument(args)
if err != nil {
return err
}
copServer, args, err := cli.PopFirstArgument(args)
if err != nil {
return err
}
_ = args
client := cop.NewClient()
_, err = client.Enroll(id, secret, copServer, csrJSON)
return err
}
// Command assembles the definition of Command 'enroll'
var Command = &cli.Command{UsageText: usageText, Flags: flags, Main: myMain}
package register
import "github.com/cloudflare/cfssl/cli"
var usageText = `cop client register -- Register an ID with COP server and return an enrollment secret
Usage of client register command:
Register a client with COP server:
cop client register ID COP-SERVER-ADDR // TODO: modify
Arguments:
ID: Enrollment ID
COP-SERVER-ADDR: COP server address
Flags:
`
var flags = []string{}
func myMain(args []string, c cli.Config) error {
id, args, err := cli.PopFirstArgument(args)
if err != nil {
return err
}
copServer, args, err := cli.PopFirstArgument(args)
if err != nil {
return err
}
//client := cop.NewClient()
//client.Register
_ = id
_ = copServer
_ = args
return nil
}
// Command assembles the definition of Command 'enroll'
var Command = &cli.Command{UsageText: usageText, Flags: flags, Main: myMain}
package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/cloudflare/cfssl/cli"
"github.com/cloudflare/cfssl/log"
)
// Config is COP config structure
type Config struct {
Debug bool `json:"debug,omitempty"`
Authentication bool `json:"authentication,omitempty"`
Users map[string]*User `jon:"users,omitempty"`
}
// User information
type User struct {
Pass string `json:"pass"` // enrollment secret
}
// Constructor for COP config
func newConfig() *Config {
c := new(Config)
c.Authentication = true
return c
}
// CFG is the COP-specific config
var CFG *Config
// Init initializes the COP config given the CFSSL config
func Init(cfg *cli.Config) {
CFG = newConfig()
if cfg.ConfigFile != "" {
body, err := ioutil.ReadFile(cfg.ConfigFile)
if err != nil {
panic(err.Error())
}
err = json.Unmarshal(body, CFG)
if err != nil {
panic(fmt.Sprintf("error parsing %s: %s", cfg.ConfigFile, err.Error()))
}
}
dbg := os.Getenv("COP_DEBUG")
if dbg != "" {
CFG.Debug = dbg == "true"
}
if CFG.Debug {
log.Level = log.LevelDebug
}
}
package main
import (
"flag"
"fmt"