Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change in beevik/etree & RFC3161 support for ClickOnce #4

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/appmanifest/signmanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func makeLicense(asi *etree.Element, subjectName, manifestHash string) (*etree.E
// ManifestInformation contains a hash value which is, for some inane reason,
// the same hash that the outer signature references but in reverse byte order.
func makeManifestHash(sig *etree.Element) string {
dv := sig.FindElement("//DigestValue")
dv := sig.FindElement(".//DigestValue")
blob, _ := base64.StdEncoding.DecodeString(dv.Text())
for i := 0; i < len(blob)/2; i++ {
j := len(blob) - i - 1
Expand Down Expand Up @@ -209,7 +209,7 @@ func (m *SignedManifest) AddTimestamp(token *pkcs7.ContentInfoSignedData) error
if err != nil {
return err
}
cs, err := pkcs9.VerifyMicrosoftToken(token, m.EncryptedDigest)
cs, err := VerifyTimestamp(token, m.EncryptedDigest, m.Signature.Intermediates)
if err != nil {
return fmt.Errorf("failed to validate timestamp: %s", err)
}
Expand Down
19 changes: 18 additions & 1 deletion lib/appmanifest/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package appmanifest

import (
"crypto"
"crypto/x509"
"encoding/base64"
"errors"
"fmt"
Expand Down Expand Up @@ -91,7 +92,8 @@ func Verify(manifest []byte) (*ManifestSignature, error) {
if err != nil {
return nil, fmt.Errorf("invalid timestamp: %s", err)
}
cs, err := pkcs9.VerifyMicrosoftToken(timestamp, secondary.EncryptedDigest)

cs, err := VerifyTimestamp(timestamp, secondary.EncryptedDigest, secondary.Certificates)
if err != nil {
return nil, fmt.Errorf("invalid timestamp: %s", err)
}
Expand All @@ -105,3 +107,18 @@ func Verify(manifest []byte) (*ManifestSignature, error) {
PublicKeyToken: token,
}, nil
}

func VerifyTimestamp(timestamp *pkcs7.ContentInfoSignedData, encryptedDigest []byte, extraCerts []*x509.Certificate) (*pkcs9.CounterSignature, error) {
var cs *pkcs9.CounterSignature
var err error

if timestamp.Content.ContentInfo.ContentType.Equal(pkcs9.OidTSTInfo) {
// pkcs9 timestamp
cs, err = pkcs9.Verify(timestamp, encryptedDigest, extraCerts)
} else {
// legacy timestamp
cs, err = pkcs9.VerifyMicrosoftToken(timestamp, encryptedDigest)
}

return cs, err
}
1 change: 1 addition & 0 deletions lib/pkcs9/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (

var (
OidKeyPurposeTimeStamping = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 8}
OidTSTInfo = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 1, 4}
OidAttributeTimeStampToken = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 2, 14}
OidAttributeCounterSign = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 6}

Expand Down
5 changes: 4 additions & 1 deletion signers/appmanifest/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var AppSigner = &signers.Signer{
}

func init() {
AppSigner.Flags().Bool("rfc3161-timestamp", true, "(APPMANIFEST) Timestamp with RFC3161 server")
signers.Register(AppSigner)
}

Expand All @@ -66,8 +67,10 @@ func sign(r io.Reader, cert *certloader.Certificate, opts signers.SignOpts) ([]b
if cert.Timestamper != nil {
tsreq := &pkcs9.Request{
EncryptedDigest: signed.EncryptedDigest,
Legacy: true,
Legacy: !opts.Flags.GetBool("rfc3161-timestamp"),
Hash: opts.Hash,
}

token, err := cert.Timestamper.Timestamp(opts.Context(), tsreq)
if err != nil {
return nil, err
Expand Down