-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
16 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,53 @@ | ||
package openpgputil | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
// Avoid importing the log type information unnecessarily. There's a small cost | ||
// associated with using an interface rather than the type. Depending on how | ||
// often the logger is plugged in, it would be worth using the type instead. | ||
type log_Logger interface { | ||
Output(calldepth int, s string) error | ||
} | ||
|
||
var globalLoggerLock sync.Mutex | ||
var globalLogger log_Logger | ||
var globalDebug bool | ||
|
||
// Specify the *log.Logger object where log messages should be sent to. | ||
func SetLogger(logger log_Logger) { | ||
globalLoggerLock.Lock() | ||
globalLogger = logger | ||
globalLoggerLock.Unlock() | ||
} | ||
|
||
// Enable the delivery of debug messages to the logger. Only meaningful | ||
// if a logger is also set. | ||
func SetDebug(debug bool) { | ||
globalLoggerLock.Lock() | ||
globalDebug = debug | ||
globalLoggerLock.Unlock() | ||
} | ||
|
||
// logf sends to the logger registered via SetLogger the string resulting | ||
// from running format and args through Sprintf. | ||
func logf(format string, args ...interface{}) { | ||
globalLoggerLock.Lock() | ||
defer globalLoggerLock.Unlock() | ||
if globalLogger != nil { | ||
globalLogger.Output(2, fmt.Sprintf(format, args...)) | ||
} | ||
} | ||
|
||
// debugf sends to the logger registered via SetLogger the string resulting | ||
// from running format and args through Sprintf, but only if debugging was | ||
// enabled via SetDebug. | ||
func debugf(format string, args ...interface{}) { | ||
globalLoggerLock.Lock() | ||
defer globalLoggerLock.Unlock() | ||
if globalDebug && globalLogger != nil { | ||
globalLogger.Output(2, fmt.Sprintf(format, args...)) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package setup | ||
package openpgputil | ||
|
||
import ( | ||
"bytes" | ||
|
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,25 @@ | ||
package openpgputil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "gopkg.in/check.v1" | ||
|
||
"github.com/canonical/chisel/internal/openpgputil" | ||
) | ||
|
||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
type S struct{} | ||
|
||
var _ = Suite(&S{}) | ||
|
||
func (s *S) SetUpTest(c *C) { | ||
openpgputil.SetDebug(true) | ||
openpgputil.SetLogger(c) | ||
} | ||
|
||
func (s *S) TearDownTest(c *C) { | ||
openpgputil.SetDebug(false) | ||
openpgputil.SetLogger(nil) | ||
} |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ import ( | |
|
||
"golang.org/x/crypto/openpgp/packet" | ||
|
||
"github.com/canonical/chisel/internal/setup" | ||
"github.com/canonical/chisel/internal/openpgputil" | ||
) | ||
|
||
type Key struct { | ||
|
@@ -16,7 +16,7 @@ type Key struct { | |
PrivateKey *packet.PrivateKey | ||
} | ||
|
||
var gpgKeys = map[string]*Key{ | ||
var pgpKeys = map[string]*Key{ | ||
"ubuntu-archive-key-2018": { | ||
ID: "871920D1991BC93C", | ||
ArmoredPublicKey: ubuntuArchiveSignKey2018, | ||
|
@@ -38,16 +38,16 @@ var gpgKeys = map[string]*Key{ | |
} | ||
|
||
func init() { | ||
for name, key := range gpgKeys { | ||
for name, key := range pgpKeys { | ||
if key.ArmoredPublicKey != "" { | ||
pubKeys, privKeys, err := setup.DecodeKeys([]byte(key.ArmoredPublicKey)) | ||
pubKeys, privKeys, err := openpgputil.DecodeKeys([]byte(key.ArmoredPublicKey)) | ||
if err != nil || len(privKeys) > 0 || len(pubKeys) != 1 || pubKeys[0].KeyIdString() != key.ID { | ||
log.Panicf("invalid public key armored data: %s", name) | ||
} | ||
key.PublicKey = pubKeys[0] | ||
} | ||
if key.ArmoredPrivateKey != "" { | ||
pubKeys, privKeys, err := setup.DecodeKeys([]byte(key.ArmoredPrivateKey)) | ||
pubKeys, privKeys, err := openpgputil.DecodeKeys([]byte(key.ArmoredPrivateKey)) | ||
if err != nil || len(pubKeys) > 0 || len(privKeys) != 1 || privKeys[0].KeyIdString() != key.ID { | ||
log.Panicf("invalid private key armored data: %s", name) | ||
} | ||
|
@@ -57,7 +57,7 @@ func init() { | |
} | ||
|
||
func GetGPGKey(name string) *Key { | ||
return gpgKeys[name] | ||
return pgpKeys[name] | ||
} | ||
|
||
// Ubuntu Archive Automatic Signing Key (2018) <[email protected]>. | ||
|