diff --git a/.gitignore b/.gitignore index 99b3bbb..bea5308 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store bin +pkg vendor -.vscode \ No newline at end of file +.vscode diff --git a/build.sh b/build.sh index ae2de9f..4467f5f 100755 --- a/build.sh +++ b/build.sh @@ -7,18 +7,23 @@ ANDROID_OUT=${OUTPUT_PATH}/"Android" IOS_OUT=${OUTPUT_PATH}/"iOS" mkdir -p $ANDROID_OUT mkdir -p $IOS_OUT + +ln -s . vendor/src + # CHECK="${1-0}" # if [ ${CHECK} -eq "1" ]; then printf "\e[0;32mStart Building iOS framework .. Location: ${IOS_OUT} \033[0m\n\n" -gomobile bind -target ios -o ${IOS_OUT}/pmcrypto.framework proton/pmcrypto/crypto proton/pmcrypto/armor proton/pmcrypto/constants proton/pmcrypto/key proton/pmcrypto/models +GOPATH="$SCRIPT_LOCATION:$SCRIPT_LOCATION/vendor:$GOPATH" gomobile bind -target ios -o ${IOS_OUT}/pmcrypto.framework gitlab.com/ProtonMail/go-pm-crypto/crypto gitlab.com/ProtonMail/go-pm-crypto/armor gitlab.com/ProtonMail/go-pm-crypto/constants gitlab.com/ProtonMail/go-pm-crypto/key gitlab.com/ProtonMail/go-pm-crypto/models printf "\e[0;32mStart Building Android lib .. Location: ${ANDROID_OUT} \033[0m\n\n" -gomobile bind -target android -javapkg com.proton.pmcrypto -o ${ANDROID_OUT}/pmcrypto.aar proton/pmcrypto/crypto proton/pmcrypto/armor proton/pmcrypto/constants proton/pmcrypto/key proton/pmcrypto/models +GOPATH="$SCRIPT_LOCATION:$SCRIPT_LOCATION/vendor:$GOPATH" gomobile bind -target android -javapkg com.proton.pmcrypto -o ${ANDROID_OUT}/pmcrypto.aar gitlab.com/ProtonMail/go-pm-crypto/crypto gitlab.com/ProtonMail/go-pm-crypto/armor gitlab.com/ProtonMail/go-pm-crypto/constants gitlab.com/ProtonMail/go-pm-crypto/key gitlab.com/ProtonMail/go-pm-crypto/models printf "\e[0;32mInstalling frameworks. \033[0m\n\n" +unlink vendor/src + printf "\e[0;32mAll Done. \033[0m\n\n" diff --git a/dist/Android/pmcrypto-sources.jar b/dist/Android/pmcrypto-sources.jar index 1787558..92bf958 100644 Binary files a/dist/Android/pmcrypto-sources.jar and b/dist/Android/pmcrypto-sources.jar differ diff --git a/dist/Android/pmcrypto.aar b/dist/Android/pmcrypto.aar index f4d33e2..28877dd 100644 Binary files a/dist/Android/pmcrypto.aar and b/dist/Android/pmcrypto.aar differ diff --git a/glide.lock b/glide.lock index 428a4b2..365c9df 100644 --- a/glide.lock +++ b/glide.lock @@ -1,8 +1,10 @@ -hash: 0e0069ce69a4e3bde6233726f21a880347400808a97c2e6f7a173e4d7daea51c -updated: 2018-09-07T10:20:50.211694+02:00 +hash: 7169f4883725d9716bbd62ecee1f32d73e8529b4bb0989173826e986395afe6b +updated: 2018-10-24T18:02:15.233807+02:00 imports: +- name: github.com/konsorten/go-windows-terminal-sequences + version: 5c8c8bd35d3832f5d134ae1e1e375b69a4d25242 - name: github.com/Sirupsen/logrus - version: 3791101e143bf0f32515ac23e831475684f61229 + version: 4fabf2fffcecfd47f802869b7b92d75e43c5a095 - name: golang.org/x/crypto version: 9e4251120d8c43f10024d798bc6dde21d40704a0 repo: https://github.com/ProtonMail/crypto.git @@ -31,12 +33,12 @@ imports: - rsa - ssh/terminal - name: golang.org/x/sys - version: 8cf3aee429924738c56c34bb819c4ea8273fc434 + version: 5cd93ef61a7c8f0f858690154eb6de2e69415fa1 subpackages: - unix - windows - name: golang.org/x/text - version: 4ae1256249243a4eb350a9a372e126557f2aa346 + version: 4d1c5fb19474adfe9562c9847ba425e7da817e81 subpackages: - encoding - encoding/charmap @@ -44,6 +46,6 @@ imports: - encoding/internal/identifier - transform - name: proton/pmmime - version: 347d69204aa62d6958bcb3b9bbacccb24a36372b + version: 72b7b1bf2d1b491e1d003632a0fda41410b0bb59 repo: git@gitlab.protontech.ch:ProtonMail/go-pm-mime.git testImports: [] diff --git a/glide.yaml b/glide.yaml index d62c93c..a22b341 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,4 +1,4 @@ -package: proton/pmcrypto +package: gitlab.com/ProtonMail/go-pm-crypto import: - package: golang.org/x/crypto version: v1.0.0 diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..643b0ba --- /dev/null +++ b/init.sh @@ -0,0 +1,3 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +GOPATH="$DIR" glide up +GOPATH="$DIR:$DIR/vendor:$GOPATH" gomobile init -ndk $ANDROID_NDK diff --git a/armor/armor.go b/src/gitlab.com/ProtonMail/go-pm-crypto/armor/armor.go similarity index 100% rename from armor/armor.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/armor/armor.go diff --git a/armor/constants.go b/src/gitlab.com/ProtonMail/go-pm-crypto/armor/constants.go similarity index 100% rename from armor/constants.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/armor/constants.go diff --git a/constants/version.go b/src/gitlab.com/ProtonMail/go-pm-crypto/constants/version.go similarity index 100% rename from constants/version.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/constants/version.go diff --git a/crypto/attachment.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/attachment.go similarity index 96% rename from crypto/attachment.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/attachment.go index f5c8019..35f089a 100644 --- a/crypto/attachment.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/attachment.go @@ -8,9 +8,9 @@ import ( "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/armor" "golang.org/x/crypto/openpgp/packet" - armorUtils "proton/pmcrypto/armor" - "proton/pmcrypto/internal" - "proton/pmcrypto/models" + armorUtils "gitlab.com/ProtonMail/go-pm-crypto/armor" + "gitlab.com/ProtonMail/go-pm-crypto/internal" + "gitlab.com/ProtonMail/go-pm-crypto/models" ) //EncryptAttachmentBinKey ... diff --git a/crypto/key.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/key.go similarity index 99% rename from crypto/key.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/key.go index a418ec2..6ab6ce6 100644 --- a/crypto/key.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/key.go @@ -11,7 +11,7 @@ import ( "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/packet" "math/big" - "proton/pmcrypto/armor" + "gitlab.com/ProtonMail/go-pm-crypto/armor" ) const ( diff --git a/crypto/message.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/message.go similarity index 98% rename from crypto/message.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/message.go index e2bd6fb..9a2a696 100644 --- a/crypto/message.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/message.go @@ -13,9 +13,9 @@ import ( errors2 "golang.org/x/crypto/openpgp/errors" "golang.org/x/crypto/openpgp/packet" "math" - armorUtils "proton/pmcrypto/armor" - "proton/pmcrypto/internal" - "proton/pmcrypto/models" + armorUtils "gitlab.com/ProtonMail/go-pm-crypto/armor" + "gitlab.com/ProtonMail/go-pm-crypto/internal" + "gitlab.com/ProtonMail/go-pm-crypto/models" ) // DecryptMessage decrypt encrypted message use private key (string ) diff --git a/crypto/mime.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/mime.go similarity index 97% rename from crypto/mime.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/mime.go index 3ad5ec7..f1dfc4f 100644 --- a/crypto/mime.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/mime.go @@ -9,8 +9,7 @@ import ( "io/ioutil" "bytes" "golang.org/x/crypto/openpgp" - "proton/pmcrypto/armor" -) + ) // ======================== Attachments Collector ============== // Collect contents of all attachment parts and return @@ -34,7 +33,6 @@ func (pm PmCrypto) parseMIME(mimeBody string, verifierKey []byte) (*pmmime.BodyC bodyCollector := pmmime.NewBodyCollector(printAccepter) attachmentsCollector := pmmime.NewAttachmentsCollector(bodyCollector) mimeVisitor := pmmime.NewMimeVisitor(attachmentsCollector) - str, err := armor.ArmorKey(verifierKey) signatureCollector := newSignatureCollector(mimeVisitor, pubKeyEntries, config) err = pmmime.VisitAll(bytes.NewReader(mmBodyData), h, signatureCollector) diff --git a/crypto/mime_test.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/mime_test.go similarity index 99% rename from crypto/mime_test.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/mime_test.go index d2718ae..21156b7 100644 --- a/crypto/mime_test.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/mime_test.go @@ -3,7 +3,7 @@ package crypto import ( "fmt" "io/ioutil" - "proton/pmcrypto/internal" + "gitlab.com/ProtonMail/go-pm-crypto/internal" "testing" ) diff --git a/crypto/pmcrypto.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/pmcrypto.go similarity index 100% rename from crypto/pmcrypto.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/pmcrypto.go diff --git a/crypto/session.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/session.go similarity index 98% rename from crypto/session.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/session.go index f1188b5..10bbd0f 100644 --- a/crypto/session.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/session.go @@ -9,8 +9,8 @@ import ( "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/packet" - "proton/pmcrypto/armor" - "proton/pmcrypto/models" + "gitlab.com/ProtonMail/go-pm-crypto/armor" + "gitlab.com/ProtonMail/go-pm-crypto/models" ) //RandomToken ... diff --git a/crypto/sign_detached.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/sign_detached.go similarity index 99% rename from crypto/sign_detached.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/sign_detached.go index 14772d6..8503b40 100644 --- a/crypto/sign_detached.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/sign_detached.go @@ -10,7 +10,7 @@ import ( "golang.org/x/crypto/openpgp/packet" errors2 "golang.org/x/crypto/openpgp/errors" "io" - "proton/pmcrypto/internal" + "gitlab.com/ProtonMail/go-pm-crypto/internal" ) // SignTextDetached sign detached text type diff --git a/crypto/signature_collector.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/signature_collector.go similarity index 99% rename from crypto/signature_collector.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/signature_collector.go index bd1d544..4cd862c 100644 --- a/crypto/signature_collector.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/signature_collector.go @@ -1,14 +1,12 @@ package crypto import ( - "bufio" "bytes" "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/packet" "io" "io/ioutil" "mime" - "mime/multipart" "net/textproto" "proton/pmmime" ) diff --git a/crypto/time.go b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/time.go similarity index 57% rename from crypto/time.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/crypto/time.go index a2e980d..06ab0a4 100644 --- a/crypto/time.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/crypto/time.go @@ -7,7 +7,6 @@ import ( // UpdateTime update cached time func (pm *PmCrypto) UpdateTime(newTime int64) { pm.latestServerTime = newTime - pm.latestClientTime = time.Now() } //GetTime get latest cached time @@ -16,10 +15,8 @@ func (pm *PmCrypto) GetTime() int64 { } func (pm *PmCrypto) getNow() time.Time { - if pm.latestServerTime > 0 && !pm.latestClientTime.IsZero() { - // Sub is monotome, it uses a monotime time clock in this case instead of the wall clock - extrapolate := int64(pm.latestClientTime.Sub(time.Now()).Seconds()) - return time.Unix(pm.latestServerTime + extrapolate, 0) + if pm.latestServerTime > 0 { + return time.Unix(pm.latestServerTime, 0) } return time.Now() diff --git a/internal/armor.go b/src/gitlab.com/ProtonMail/go-pm-crypto/internal/armor.go similarity index 100% rename from internal/armor.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/internal/armor.go diff --git a/internal/common.go b/src/gitlab.com/ProtonMail/go-pm-crypto/internal/common.go similarity index 100% rename from internal/common.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/internal/common.go diff --git a/key/fingerprint.go b/src/gitlab.com/ProtonMail/go-pm-crypto/key/fingerprint.go similarity index 94% rename from key/fingerprint.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/key/fingerprint.go index 08394c3..9632cb2 100644 --- a/key/fingerprint.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/key/fingerprint.go @@ -6,7 +6,7 @@ import ( "errors" "golang.org/x/crypto/openpgp" - "proton/pmcrypto/armor" + "gitlab.com/ProtonMail/go-pm-crypto/armor" ) // GetFingerprint get a armored public key fingerprint diff --git a/key/key.go b/src/gitlab.com/ProtonMail/go-pm-crypto/key/key.go similarity index 97% rename from key/key.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/key/key.go index b54f83e..bf3cde0 100644 --- a/key/key.go +++ b/src/gitlab.com/ProtonMail/go-pm-crypto/key/key.go @@ -6,7 +6,7 @@ import ( "fmt" "golang.org/x/crypto/openpgp/packet" "bytes" - "proton/pmcrypto/armor" + "gitlab.com/ProtonMail/go-pm-crypto/armor" ) //CheckPassphrase check is private key passphrase ok diff --git a/models/models.go b/src/gitlab.com/ProtonMail/go-pm-crypto/models/models.go similarity index 100% rename from models/models.go rename to src/gitlab.com/ProtonMail/go-pm-crypto/models/models.go