Skip to content

Commit

Permalink
Merge pull request #237 from ProtonMail/feat/signature-context-mobile…
Browse files Browse the repository at this point in the history
…-helpers

Add mobile helpers to verify signature contexts and prepare v2.7.1
  • Loading branch information
marinthiercelin authored Apr 21, 2023
2 parents 753a3fe + 2cf7a8c commit d37f4eb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.7.1] 2023-04-21

- Add mobile helpers for signature verification with contexts.

## [2.7.0] 2023-04-14
### Changed
- The `SignatureVerificationError` struct now has a `Cause error` field, which is returned by the the Unwrap function. The cause is also included in the error message.
Expand Down
2 changes: 1 addition & 1 deletion constants/armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package constants

// Constants for armored data.
const (
ArmorHeaderVersion = "GopenPGP 2.7.0"
ArmorHeaderVersion = "GopenPGP 2.7.1"
ArmorHeaderComment = "https://gopenpgp.org"
PGPMessageHeader = "PGP MESSAGE"
PGPSignatureHeader = "PGP SIGNATURE"
Expand Down
2 changes: 1 addition & 1 deletion constants/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package constants

const Version = "2.7.0"
const Version = "2.7.1"
29 changes: 29 additions & 0 deletions helper/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ func DecryptExplicitVerify(
return newExplicitVerifyMessage(message, err)
}

// DecryptExplicitVerifyWithContext decrypts a PGP message given a private keyring
// and a public keyring to verify the embedded signature. Returns the plain
// data and an error on signature verification failure.
// The caller can provide a context that will be used to verify the signature.
func DecryptExplicitVerifyWithContext(
pgpMessage *crypto.PGPMessage,
privateKeyRing, publicKeyRing *crypto.KeyRing,
verifyTime int64,
verificationContext *crypto.VerificationContext,
) (*ExplicitVerifyMessage, error) {
message, err := privateKeyRing.DecryptWithContext(pgpMessage, publicKeyRing, verifyTime, verificationContext)
return newExplicitVerifyMessage(message, err)
}

// DecryptSessionKeyExplicitVerify decrypts a PGP data packet given a session key
// and a public keyring to verify the embedded signature. Returns the plain data and
// an error on signature verification failure.
Expand All @@ -39,6 +53,21 @@ func DecryptSessionKeyExplicitVerify(
return newExplicitVerifyMessage(message, err)
}

// DecryptSessionKeyExplicitVerifyWithContext decrypts a PGP data packet given a session key
// and a public keyring to verify the embedded signature. Returns the plain data and
// an error on signature verification failure.
// The caller can provide a context that will be used to verify the signature.
func DecryptSessionKeyExplicitVerifyWithContext(
dataPacket []byte,
sessionKey *crypto.SessionKey,
publicKeyRing *crypto.KeyRing,
verifyTime int64,
verificationContext *crypto.VerificationContext,
) (*ExplicitVerifyMessage, error) {
message, err := sessionKey.DecryptAndVerifyWithContext(dataPacket, publicKeyRing, verifyTime, verificationContext)
return newExplicitVerifyMessage(message, err)
}

func newExplicitVerifyMessage(message *crypto.PlainMessage, err error) (*ExplicitVerifyMessage, error) {
var explicitVerify *ExplicitVerifyMessage
if err != nil {
Expand Down

0 comments on commit d37f4eb

Please sign in to comment.