WIP: parse mime
This commit is contained in:
parent
7ccc3545ab
commit
2d45c99a89
14 changed files with 105 additions and 15 deletions
2
armor.go
2
armor.go
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
29
glide.lock
generated
29
glide.lock
generated
|
|
@ -1,8 +1,10 @@
|
||||||
hash: 217e5bc8c4d3160eeddd18dda7f8f8785f1b2b7f2ca58779b94ed8fd91ab226d
|
hash: 834f29378b80e2f7486b79420679fb1d854c16f2989574090ba80d322a7b71c5
|
||||||
updated: 2018-06-05T11:36:14.582087-07:00
|
updated: 2018-09-02T14:56:08.452174+02:00
|
||||||
imports:
|
imports:
|
||||||
|
- name: github.com/Sirupsen/logrus
|
||||||
|
version: 78fa2915c1fa231f62e0438da493688c21ca678e
|
||||||
- name: golang.org/x/crypto
|
- name: golang.org/x/crypto
|
||||||
version: 4dad02e057d03c4f12a519a73d4b4f1837de135d
|
version: 9e4251120d8c43f10024d798bc6dde21d40704a0
|
||||||
repo: https://github.com/ProtonMail/crypto.git
|
repo: https://github.com/ProtonMail/crypto.git
|
||||||
subpackages:
|
subpackages:
|
||||||
- bitcurves
|
- bitcurves
|
||||||
|
|
@ -11,6 +13,8 @@ imports:
|
||||||
- curve25519
|
- curve25519
|
||||||
- ed25519
|
- ed25519
|
||||||
- ed25519/internal/edwards25519
|
- ed25519/internal/edwards25519
|
||||||
|
- internal/randutil
|
||||||
|
- internal/syscall/unix
|
||||||
- openpgp
|
- openpgp
|
||||||
- openpgp/aes/keywrap
|
- openpgp/aes/keywrap
|
||||||
- openpgp/armor
|
- openpgp/armor
|
||||||
|
|
@ -23,4 +27,23 @@ imports:
|
||||||
- openpgp/internal/encoding
|
- openpgp/internal/encoding
|
||||||
- openpgp/packet
|
- openpgp/packet
|
||||||
- openpgp/s2k
|
- openpgp/s2k
|
||||||
|
- rand
|
||||||
|
- rsa
|
||||||
|
- ssh/terminal
|
||||||
|
- name: golang.org/x/sys
|
||||||
|
version: fa5fdf94c78965f1aa8423f0cc50b8b8d728b05a
|
||||||
|
subpackages:
|
||||||
|
- unix
|
||||||
|
- windows
|
||||||
|
- name: golang.org/x/text
|
||||||
|
version: 6e3c4e7365ddcc329f090f96e4348398f6310088
|
||||||
|
subpackages:
|
||||||
|
- encoding
|
||||||
|
- encoding/charmap
|
||||||
|
- encoding/internal
|
||||||
|
- encoding/internal/identifier
|
||||||
|
- transform
|
||||||
|
- name: mimeparser
|
||||||
|
version: f4de8a5a52ecd93189c785c7d87259ac637e1d7c
|
||||||
|
repo: git@gitlab.protontech.ch:ProtonMail/go-pm-mime.git
|
||||||
testImports: []
|
testImports: []
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package: pm
|
package: proton/pmcrypto
|
||||||
import:
|
import:
|
||||||
- package: golang.org/x/crypto
|
- package: golang.org/x/crypto
|
||||||
version: v1.0.0
|
version: v1.0.0
|
||||||
repo: https://github.com/ProtonMail/crypto.git
|
repo: https://github.com/ProtonMail/crypto.git
|
||||||
|
- package: mimeparser
|
||||||
|
repo: git@gitlab.protontech.ch:ProtonMail/go-pm-mime.git
|
||||||
|
|
|
||||||
2
key.go
2
key.go
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
65
mime.go
Normal file
65
mime.go
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
package pmcrypto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/mail"
|
||||||
|
"strings"
|
||||||
|
"net/textproto"
|
||||||
|
"io/ioutil"
|
||||||
|
"bytes"
|
||||||
|
"mimeparser"
|
||||||
|
)
|
||||||
|
|
||||||
|
func parseMIME(mimeBody string) (body *mimeparser.BodyCollector, atts, attHeaders []string, err error) {
|
||||||
|
|
||||||
|
mm, err := mail.ReadMessage(strings.NewReader(mimeBody))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h := textproto.MIMEHeader(mm.Header)
|
||||||
|
mmBodyData, err := ioutil.ReadAll(mm.Body)
|
||||||
|
|
||||||
|
printAccepter := mimeparser.NewMIMEPrinter()
|
||||||
|
bodyCollector := mimeparser.NewBodyCollector(printAccepter)
|
||||||
|
attachmentsCollector := mimeparser.NewAttachmentsCollector(bodyCollector)
|
||||||
|
err = mimeparser.VisitAll(bytes.NewReader(mmBodyData), h, attachmentsCollector)
|
||||||
|
|
||||||
|
body = bodyCollector
|
||||||
|
atts = attachmentsCollector.GetAttachments()
|
||||||
|
attHeaders = attachmentsCollector.GetAttHeaders()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// define call back interface
|
||||||
|
type MIMECallbacks interface {
|
||||||
|
onBody(body string, mimetype string)
|
||||||
|
onAttachment(headers string, data []byte)
|
||||||
|
// Encrypted headers can be an attachment and thus be placed at the end of the mime structure
|
||||||
|
onEncryptedHeaders(headers string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OpenPGP) decryptMIMEMessage(encryptedText string, verifierKey string, privateKeys []byte,
|
||||||
|
passphrase string, callbacks MIMECallbacks, verifyTime int64) (verifier int, err error) {
|
||||||
|
decsignverify, error := o.DecryptMessageVerifyPrivbinkeys(encryptedText, verifierKey, privateKeys, passphrase, verifyTime)
|
||||||
|
if (error != nil) {
|
||||||
|
return 0, error
|
||||||
|
}
|
||||||
|
|
||||||
|
body, attachments, attachmentHeaders, error := parseMIME(decsignverify.Plaintext
|
||||||
|
if (error != nil) {
|
||||||
|
return 0, error
|
||||||
|
})
|
||||||
|
bodyContent, bodyMimeType := body.GetBody()
|
||||||
|
callbacks.onBody(bodyContent, bodyMimeType)
|
||||||
|
for i := 0; i < len(attachments); i++ {
|
||||||
|
callbacks.onAttachment(attachmentHeaders[i], []byte(attachments[i]))
|
||||||
|
}
|
||||||
|
callbacks.onEncryptedHeaders("")
|
||||||
|
|
||||||
|
// Todo verify the signature included in the attachment
|
||||||
|
|
||||||
|
return verifier, nil
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
||||||
2
time.go
2
time.go
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package pm
|
package pmcrypto
|
||||||
|
|
||||||
// Version get current lib version
|
// Version get current lib version
|
||||||
func Version() string {
|
func Version() string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue