-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add signature package for signing events and verifying signatures
The new package basically contains two types, Signer and Verifier, which, unsurprisingly, sign events and verifies signatures of existing events. Signer instances are configured with an identity and a private key and signs events into byte slices. Verifier instance require you to pass something that implements the PublicKeyLocator interface. That interface looks up which public key(s) can be used to verify the signature of an event with a given meta.security.authorIdentity. Because public key lookups are expected to be application-dependent we don't include a type that implements PublicKeyLocator, but that might change over time once we understand typical usage patterns. Since we wanted to use the errors.Join function, introduced in Go 1.20, we stepped the Go version requirement in go.mod to 1.21. That's the currently oldest supported version so it's a totally reasonable requirement. The compiler upgrade triggered a new linter violation because of the deprecation of strings.Title in Go 1.18, so we had to address that too.
- Loading branch information
1 parent
3900560
commit 52e18dd
Showing
14 changed files
with
1,071 additions
and
41 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,25 @@ | ||
// Copyright Axis Communications AB. | ||
// | ||
// For a full list of individual contributors, please see the commit history. | ||
// | ||
// 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 main | ||
|
||
import "strings" | ||
|
||
// initialCapital converts the first letter of a string into uppercase, | ||
// similar to the deprecated strings.Title. | ||
func initialCapital(s string) string { | ||
return strings.ToUpper(s[0:1]) + s[1:] | ||
} |
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,31 @@ | ||
// Copyright Axis Communications AB. | ||
// | ||
// For a full list of individual contributors, please see the commit history. | ||
// | ||
// 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 signature | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrMarshaling = errors.New("the marshaling of the event was unsuccessful") | ||
ErrPublicKeyInvalid = errors.New("public key had the wrong type") | ||
ErrPublicKeyLookup = errors.New("an error occurred looking up the public key for this identity") | ||
ErrPublicKeyNotFound = errors.New("no public key for verifying events signed by this identify was found") | ||
ErrSignatureMismatch = errors.New("the signature couldn't be verified") | ||
ErrSigningFailed = errors.New("signing of the event failed") | ||
ErrUnsupportedAlgorithm = errors.New("unsupported algorithm") | ||
ErrUnverifiableEvent = errors.New("event cannot be verified because an essential field is unset or empty") | ||
ErrVerificationFailed = errors.New("the signature couldn't be verified by any of the available public keys") | ||
) |
Oops, something went wrong.