Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add full copy of mozilla/pkcs7 module as internal dependency
The full contents of the git repository @432b2356ecb... was copied. Only go.mod was removed from it.
- Loading branch information
Showing
17 changed files
with
3,485 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof |
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,10 @@ | ||
language: go | ||
go: | ||
- "1.11" | ||
- "1.12" | ||
- "1.13" | ||
- tip | ||
before_install: | ||
- make gettools | ||
script: | ||
- make |
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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Andrew Smith | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
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,20 @@ | ||
all: vet staticcheck test | ||
|
||
test: | ||
go test -covermode=count -coverprofile=coverage.out . | ||
|
||
showcoverage: test | ||
go tool cover -html=coverage.out | ||
|
||
vet: | ||
go vet . | ||
|
||
lint: | ||
golint . | ||
|
||
staticcheck: | ||
staticcheck . | ||
|
||
gettools: | ||
go get -u honnef.co/go/tools/... | ||
go get -u golang.org/x/lint/golint |
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,69 @@ | ||
# pkcs7 | ||
|
||
[![GoDoc](https://godoc.org/go.mozilla.org/pkcs7?status.svg)](https://godoc.org/go.mozilla.org/pkcs7) | ||
[![Build Status](https://travis-ci.org/mozilla-services/pkcs7.svg?branch=master)](https://travis-ci.org/mozilla-services/pkcs7) | ||
|
||
pkcs7 implements parsing and creating signed and enveloped messages. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"fmt" | ||
"os" | ||
|
||
"go.mozilla.org/pkcs7" | ||
) | ||
|
||
func SignAndDetach(content []byte, cert *x509.Certificate, privkey *rsa.PrivateKey) (signed []byte, err error) { | ||
toBeSigned, err := NewSignedData(content) | ||
if err != nil { | ||
err = fmt.Errorf("Cannot initialize signed data: %s", err) | ||
return | ||
} | ||
if err = toBeSigned.AddSigner(cert, privkey, SignerInfoConfig{}); err != nil { | ||
err = fmt.Errorf("Cannot add signer: %s", err) | ||
return | ||
} | ||
|
||
// Detach signature, omit if you want an embedded signature | ||
toBeSigned.Detach() | ||
|
||
signed, err = toBeSigned.Finish() | ||
if err != nil { | ||
err = fmt.Errorf("Cannot finish signing data: %s", err) | ||
return | ||
} | ||
|
||
// Verify the signature | ||
pem.Encode(os.Stdout, &pem.Block{Type: "PKCS7", Bytes: signed}) | ||
p7, err := pkcs7.Parse(signed) | ||
if err != nil { | ||
err = fmt.Errorf("Cannot parse our signed data: %s", err) | ||
return | ||
} | ||
|
||
// since the signature was detached, reattach the content here | ||
p7.Content = content | ||
|
||
if bytes.Compare(content, p7.Content) != 0 { | ||
err = fmt.Errorf("Our content was not in the parsed data:\n\tExpected: %s\n\tActual: %s", content, p7.Content) | ||
return | ||
} | ||
if err = p7.Verify(); err != nil { | ||
err = fmt.Errorf("Cannot verify our signed data: %s", err) | ||
return | ||
} | ||
|
||
return signed, nil | ||
} | ||
``` | ||
|
||
|
||
|
||
## Credits | ||
This is a fork of [fullsailor/pkcs7](https://github.com/fullsailor/pkcs7) |
Oops, something went wrong.