-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signature: add OpenPGP signing mechanism based on Sequoia
This adds a new OpenPGP signing mechanism based Sequoia[1]. As Sequoia is written in Rust and doesn't provide a stable C FFI, this integration uses a minimal shared library as a "point solution". To build, first follow the instruction at [2] and install `libpodman_sequoia.so*` into the library path, and then build with the following command from the top-level directory: $ make BUILDTAGS="btrfs_noversion libdm_no_deferred_remove containers_image_sequoia" Note also that, for testing on Fedora, crypto-policies settings might need to be modified to explictly allow SHA-1 and 1024 bit RSA, as the testing keys in signature/fixtures are using those legacy algorithms. 1. https://sequoia-pgp.org/ 2. https://github.com/ueno/podman-sequoia Signed-off-by: Daiki Ueno <dueno@redhat.com>
- Loading branch information
Showing
6 changed files
with
134 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//go:build containers_image_sequoia | ||
// +build containers_image_sequoia | ||
|
||
package signature | ||
|
||
import ( | ||
"fmt" | ||
"github.com/containers/storage/pkg/homedir" | ||
"github.com/ueno/podman-sequoia/go/sequoia" | ||
"os" | ||
"path" | ||
) | ||
|
||
// A GPG/OpenPGP signing mechanism, implemented using Sequoia. | ||
type sequoiaSigningMechanism struct { | ||
inner *sequoia.SigningMechanism | ||
} | ||
|
||
// newGPGSigningMechanismInDirectory returns a new GPG/OpenPGP signing mechanism, using optionalDir if not empty. | ||
// The caller must call .Close() on the returned SigningMechanism. | ||
func newGPGSigningMechanismInDirectory(optionalDir string) (signingMechanismWithPassphrase, error) { | ||
sequoiaHome := optionalDir | ||
if sequoiaHome == "" { | ||
dataHome, err := homedir.GetDataHome() | ||
if err != nil { | ||
return nil, err | ||
} | ||
sequoiaHome = path.Join(dataHome, "sequoia") | ||
} | ||
|
||
mech, err := sequoia.NewMechanismFromDirectory(sequoiaHome) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Migrate GnuPG keyrings if exist. For compatibility reasons, | ||
// we allow both sequoiaHome and gpgHome to be the same | ||
// directory given by optionalDir. | ||
gpgHome := optionalDir | ||
if gpgHome == "" { | ||
gpgHome = os.Getenv("GNUPGHOME") | ||
if gpgHome == "" { | ||
gpgHome = path.Join(homedir.Get(), ".gnupg") | ||
} | ||
} | ||
|
||
for _, keyring := range []string{"pubring.gpg", "secring.gpg"} { | ||
blob, err := os.ReadFile(path.Join(gpgHome, keyring)) | ||
if err != nil { | ||
if !os.IsNotExist(err) { | ||
return nil, err | ||
} | ||
} else if _, err := mech.ImportKeys(blob); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &sequoiaSigningMechanism{ | ||
inner: mech, | ||
}, nil | ||
} | ||
|
||
// newEphemeralGPGSigningMechanism returns a new GPG/OpenPGP signing mechanism which | ||
// recognizes _only_ public keys from the supplied blobs, and returns the identities | ||
// of these keys. | ||
// The caller must call .Close() on the returned SigningMechanism. | ||
func newEphemeralGPGSigningMechanism(blobs [][]byte) (signingMechanismWithPassphrase, []string, error) { | ||
mech, err := sequoia.NewEphemeralMechanism() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
keyIdentities := []string{} | ||
for _, blob := range blobs { | ||
ki, err := mech.ImportKeys(blob) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
keyIdentities = append(keyIdentities, ki...) | ||
} | ||
|
||
return &sequoiaSigningMechanism{ | ||
inner: mech, | ||
}, keyIdentities, nil | ||
} | ||
|
||
func (m *sequoiaSigningMechanism) Close() error { | ||
return m.inner.Close() | ||
} | ||
|
||
// SupportsSigning returns nil if the mechanism supports signing, or a SigningNotSupportedError. | ||
func (m *sequoiaSigningMechanism) SupportsSigning() error { | ||
return m.inner.SupportsSigning() | ||
} | ||
|
||
// Sign creates a (non-detached) signature of input using keyIdentity and passphrase. | ||
// Fails with a SigningNotSupportedError if the mechanism does not support signing. | ||
func (m *sequoiaSigningMechanism) SignWithPassphrase(input []byte, keyIdentity string, passphrase string) ([]byte, error) { | ||
return m.inner.SignWithPassphrase(input, keyIdentity, passphrase) | ||
} | ||
|
||
// Sign creates a (non-detached) signature of input using keyIdentity. | ||
// Fails with a SigningNotSupportedError if the mechanism does not support signing. | ||
func (m *sequoiaSigningMechanism) Sign(input []byte, keyIdentity string) ([]byte, error) { | ||
return m.inner.Sign(input, keyIdentity) | ||
} | ||
|
||
// Verify parses unverifiedSignature and returns the content and the signer's identity | ||
func (m *sequoiaSigningMechanism) Verify(unverifiedSignature []byte) (contents []byte, keyIdentity string, err error) { | ||
return m.inner.Verify(unverifiedSignature) | ||
} | ||
|
||
// UntrustedSignatureContents returns UNTRUSTED contents of the signature WITHOUT ANY VERIFICATION, | ||
// along with a short identifier of the key used for signing. | ||
// WARNING: The short key identifier (which corresponds to "Key ID" for OpenPGP keys) | ||
// is NOT the same as a "key identity" used in other calls to this interface, and | ||
// the values may have no recognizable relationship if the public key is not available. | ||
func (m *sequoiaSigningMechanism) UntrustedSignatureContents(untrustedSignature []byte) (untrustedContents []byte, shortKeyIdentifier string, err error) { | ||
return gpgUntrustedSignatureContents(untrustedSignature) | ||
} | ||
|
||
func init() { | ||
err := sequoia.Init() | ||
if err != nil { | ||
panic(fmt.Sprintf("sequoia cannot be loaded: %v", 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